Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | 5x 5x 5x 5x 94x 94x 94x 94x 94x 94x 20x 94x 49x 44x 5x 4x 4x 94x 48x 6x 6x 6x 1x 1x 94x 20x 94x 94x 94x 44x 132x 50x 6x 44x 56x 2x 94x 1x 93x 93x 93x 20x 20x 93x 93x 5x 191x 93x 93x 90x 91x 132x | import { ReactNode, useEffect, useRef } from "react";
import { Box, Stack } from "@mui/material";
import { InfoIcon } from "@phosphor-icons/react";
import GiveAlert from "@shared/GiveAlert/GiveAlert";
import GiveButton from "@shared/Button/GiveButton";
import GiveSearchBar from "@shared/SearchBar/GiveSearchBar";
import { styled } from "@theme/v2/Provider";
import TabErrorState from "../TabErrorState";
import EventReviewListItem from "./EventReviewListItem";
import EventReviewSidebar from "./EventReviewSidebar";
import EventReviewsEmptyState from "./EventReviewsEmptyState";
import { useEventReviews } from "./useEventReviews";
type Props = {
eventId?: string;
/** The shared banner head — see EventTicketsTab for why this is a render fn. */
renderHead: (options?: { hideToolbar?: boolean }) => ReactNode;
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
/** Defaulted rather than merely optional — the redux-backed value starts undefined. */
searchQuery?: string;
handleSearchChange: (value: string) => void;
/**
* A review id from the URL: the side panel links straight to one, so the tab
* scrolls it into view on arrival.
*/
focusReviewId?: number;
};
const SKELETON_CARDS = [0, 1, 2];
/**
* How many pages the tab will pull on its own to reach a `?review=` deep link.
*
* The link is not guaranteed to name a review that is still in the list — a
* deleted review, a stale notification, an id that never existed — and without a
* cap the walk pages to exhaustion looking for it, one request per render. The
* panel links to a recent review, so page one answers the ordinary case and this
* only has to cover a link that has aged a little.
*/
const FOCUS_PAGE_LOOKAHEAD = 3;
export const REPLY_NOTICE =
"Your reply will be public. Once posted, it can't be changed.";
/**
* PayBuilder 034 — the Event Detail Reviews tab (frames 7501-72341,
* 7506-74389, 7506-74973, 7508-75519, 7508-75946, 7508-77120).
*
* Two columns: the reviews on the left under their own sticky search, the
* event's score and filters on the right. Not a table, like Inventory, so it
* owns its scroller — which is also what drives the page's sticky breadcrumb.
*
* The right column is sticky on desktop and simply stacks above the list on
* mobile, where only the search stays put (annotations on frames 7506-75497 /
* 7506-75503).
*/
const EventReviewsTab = ({
eventId,
renderHead,
onScroll,
searchQuery = "",
handleSearchChange,
focusReviewId,
}: Props) => {
const {
rows,
stats,
isStatsError,
isLoading,
isError,
hasNextPage,
fetchNextPage,
isFetchingNextPage,
ratings,
awaitingReplyOnly,
toggleRating,
toggleAwaitingReply,
isUnfiltered,
searchTerm,
isEmpty,
canReply,
submitReply,
replyingTo,
} = useEventReviews(eventId, searchQuery);
const scrollerRef = useRef<HTMLDivElement | null>(null);
// Which review this tab has already jumped to. Without it every refetch — the
// invalidate after publishing a reply included — would yank the viewport back
// to the linked card, because `rows` is a new array each time.
const scrolledToRef = useRef<number | null>(null);
// A deep link can point past the first page, so pull a bounded number of
// further pages until the linked review is loaded or the list is exhausted.
// Cheap in the ordinary case: the panel links to a recent review, which is on
// page one.
const isFocusLoaded =
!focusReviewId || rows.some((row) => row.id === focusReviewId);
// Pages fetched for the link's sake, reset when the link changes — so giving
// up on one id does not stop the next link from being followed.
const focusPagesPulled = useRef(0);
useEffect(() => {
focusPagesPulled.current = 0;
}, [focusReviewId]);
useEffect(() => {
if (isFocusLoaded || isLoading || isFetchingNextPage || !hasNextPage)
return;
if (focusPagesPulled.current >= FOCUS_PAGE_LOOKAHEAD) return;
focusPagesPulled.current += 1;
fetchNextPage();
}, [
isFocusLoaded,
isLoading,
isFetchingNextPage,
hasNextPage,
fetchNextPage,
]);
// Arriving from the side panel's Reply / View your reply: bring that review
// into view once its row exists, and once only. A link to a review the current
// filters exclude — or one the lookahead above did not reach — simply does
// nothing; "Load more" is still there to go further by hand.
useEffect(() => {
if (!focusReviewId || isLoading) return;
Iif (scrolledToRef.current === focusReviewId) return;
const node = scrollerRef.current?.querySelector(
`[data-testid="event-review-${focusReviewId}"]`,
);
if (!node) return;
scrolledToRef.current = focusReviewId;
node.scrollIntoView({ block: "center" });
}, [focusReviewId, isLoading, rows]);
// Leaving the linked review behind (a tab switch clears `?review=`) re-arms
// the jump, so coming back to the same link scrolls again.
useEffect(() => {
if (!focusReviewId) scrolledToRef.current = null;
}, [focusReviewId]);
// The notice is about writing a reply, so it is only worth the space while at
// least one review can still be answered — and only for someone who is
// allowed to answer it.
const canReplyToAny =
canReply && rows.some((row) => !row.hasReply && row.canReply);
const list = (() => {
if (isLoading) {
return (
<Stack gap="16px">
{SKELETON_CARDS.map((key) => (
<SkeletonCard key={key} data-testid="event-review-skeleton" />
))}
</Stack>
);
}
if (isEmpty) {
return (
<EventReviewsEmptyState
ratings={ratings}
awaitingReplyOnly={awaitingReplyOnly}
isUnfiltered={isUnfiltered}
searchTerm={searchTerm}
/>
);
}
return (
<Stack gap="16px">
{canReplyToAny && (
<GiveAlert
type="blue"
variant="notice"
Icon={<InfoIcon size={20} />}
description={REPLY_NOTICE}
dataTestId="event-review-public-notice"
/>
)}
{rows.map((review) => (
<EventReviewListItem
key={review.id}
review={review}
canReply={canReply}
onReply={submitReply}
isSubmitting={replyingTo === review.id}
/>
))}
{/* The list is cards rather than a table, so there is no pager to hang
the rest of the reviews off — without this everything past the first
page is unreachable while the sidebar still counts it. */}
{hasNextPage && (
<GiveButton
variant="outline"
size="large"
label={isFetchingNextPage ? "Loading…" : "Load more"}
disabled={isFetchingNextPage}
onClick={() => fetchNextPage()}
sx={{ alignSelf: "center" }}
data-testid="event-reviews-load-more"
/>
)}
</Stack>
);
})();
// The list read failed: say so rather than letting the empty state tell the
// merchant their customers wrote nothing. Same treatment as EventHostTab.
if (isError && !isLoading) {
return <TabErrorState head={renderHead({ hideToolbar: true })} />;
}
// Frame 7328-64282: an event with no reviews at all shows only the empty
// state — no 0.00 score, no awaiting-reply toggle, no star-distribution
// filters. Those earn their space once there is at least one review to
// summarise or narrow. A failed summary read is not the same as zero: the
// list may still have rows, and the filters act on it.
const showSidebar =
isLoading || isStatsError || stats.total > 0 || rows.length > 0;
// Frame 7328-64280 (GB-21735): the search bar goes with it. An event with no
// reviews has nothing to search, so the box would only hang over the empty
// state promising a filter that cannot narrow anything.
//
// Held open while anything is typed, whatever the counts say — hiding the box
// a fruitless search went into would leave no way to clear the term.
const showSearch = showSidebar || !isUnfiltered;
return (
<Scroller
ref={scrollerRef}
onScroll={onScroll}
data-testid="event-reviews-tab"
>
<Inner>
{renderHead({ hideToolbar: true })}
<Layout withSidebar={showSidebar}>
<ListColumn>
{showSearch && (
<StickySearch>
<GiveSearchBar
value={searchQuery}
handleChange={(value) => handleSearchChange(value)}
handleClearSearch={() => handleSearchChange("")}
placeholder="Search"
/>
</StickySearch>
)}
{list}
</ListColumn>
{showSidebar && (
<SidebarColumn>
<EventReviewSidebar
stats={stats}
// The summary is its own request and fails on its own. Say so:
// EMPTY_STATS beside a populated list would read as the event
// scoring 0.00 across the board.
isStatsError={isStatsError}
ratings={ratings}
awaitingReplyOnly={awaitingReplyOnly}
onToggleRating={toggleRating}
onToggleAwaitingReply={toggleAwaitingReply}
/>
</SidebarColumn>
)}
</Layout>
</Inner>
</Scroller>
);
};
export default EventReviewsTab;
// Mirrors the Inventory tab: the page's own scroll container, centred and
// capped, with the gutters that keep the banner head aligned across tabs.
const Scroller = styled(Box)(() => ({
position: "relative",
zIndex: 100,
width: "100%",
height: "100%",
overflowY: "auto",
display: "flex",
justifyContent: "center",
}));
const Inner = styled(Box)(({ theme }) => ({
width: "100%",
maxWidth: "1920px",
height: "fit-content",
padding: "0 40px",
paddingBottom: "40px",
[theme.breakpoints.up("v2_lg")]: {
padding: "0 64px 40px",
},
[theme.breakpoints.down("v2_sm")]: {
padding: "0 20px 40px",
},
}));
// 688 / 24 / 328 at the mockup's 1048 content width, expressed as a ratio so it
// keeps its proportions on wider screens. Collapses to one column when there is
// nothing to put on the right — otherwise the empty state sits in a 2/3 lane
// beside a hole.
const Layout = styled(Box, {
shouldForwardProp: (prop) => prop !== "withSidebar",
})<{ withSidebar?: boolean }>(({ theme, withSidebar = true }) => ({
display: "grid",
gridTemplateColumns: withSidebar
? "minmax(0, 688fr) minmax(0, 328fr)"
: "minmax(0, 1fr)",
gap: "24px",
paddingTop: "24px",
alignItems: "start",
[theme.breakpoints.down("v2_md")]: {
gridTemplateColumns: "minmax(0, 1fr)",
},
}));
const ListColumn = styled(Box)(() => ({
display: "flex",
flexDirection: "column",
gap: "16px",
minWidth: 0,
}));
// On mobile the summary and filters stack above the list, so the sidebar comes
// first in source order there and only the search stays pinned.
const SidebarColumn = styled(Box)(({ theme }) => ({
position: "sticky",
top: "24px",
[theme.breakpoints.down("v2_md")]: {
position: "static",
order: -1,
},
}));
const StickySearch = styled(Box)(({ theme }) => ({
position: "sticky",
top: 0,
zIndex: 2,
paddingBottom: "4px",
backgroundColor: theme.palette.surface?.primary,
}));
const SkeletonCard = styled(Box)(({ theme }) => ({
height: "190px",
borderRadius: "16px",
backgroundColor: theme.palette.surface?.tertiary,
}));
|