All files / src/features/Events/EventDetail/tickets EventTicketPanel.atoms.tsx

100% Statements 13/13
87.5% Branches 7/8
100% Functions 6/6
100% Lines 11/11

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                            2x               2x 66x   66x 66x                   2x             66x                 2x                     332x                                 98x           332x        
import { ReactNode } from "react";
import { Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import { styled } from "@theme/v2/Provider";
import { useFormatDateInTimezone } from "@utils/date.helpers";
import { PLATFORM_TIMEZONE_LABEL } from "@utils/timezones";
 
/**
 * The ticket detail panel's shared building blocks — the card surface, the
 * titled section, the label/value row and the panel's date formatting — used by
 * the summary card and both detail sections.
 */
 
export const PLACEHOLDER = "-";
 
/**
 * A null/0 timestamp is "unset", never 1970 — the panel shows "-" instead.
 * The zone is the literal ET label, not a `zzz` token — date-fns-tz renders
 * that token as the raw offset ("GMT-4"), which contradicts the platform's
 * Eastern Time label and flips to GMT-5 for winter dates.
 */
export const usePanelDateTime = () => {
  const { formatInTimezone } = useFormatDateInTimezone();
 
  return (value?: number | null) =>
    value
      ? String(
          formatInTimezone(
            value,
            `MMM dd, yyyy hh:mma '${PLATFORM_TIMEZONE_LABEL}'`,
          ) ?? "",
        )
      : PLACEHOLDER;
};
 
export const Section = ({
  title,
  children,
}: {
  title: string;
  children: ReactNode;
}) => (
  <Stack gap="12px">
    <GiveText variant="bodyM" color="primary">
      {title}
    </GiveText>
    <Card gap="0px">{children}</Card>
  </Stack>
);
 
/** One label/value line. An unset value reads "-", never blank. */
export const Row = ({
  label,
  value,
  caption,
  testId,
}: {
  label: string;
  value?: string | null;
  caption?: string;
  testId?: string;
}) => (
  <RowContainer direction="row" gap="16px" data-testid={testId}>
    <GiveText variant="bodyS" color="secondary" sx={{ flex: "0 0 40%" }}>
      {label}
    </GiveText>
    <Stack minWidth={0} flex={1}>
      <GiveText variant="bodyS" color="primary">
        {value || PLACEHOLDER}
      </GiveText>
      {caption && (
        <GiveTruncateText variant="bodyS" color="secondary" lineClamp={1}>
          {caption}
        </GiveTruncateText>
      )}
    </Stack>
  </RowContainer>
);
 
export const Card = styled(Stack)(({ theme }) => ({
  padding: "16px",
  borderRadius: "12px",
  backgroundColor: theme.palette.surface?.primary,
}));
 
const RowContainer = styled(Stack)(() => ({
  paddingBlock: "6px",
  alignItems: "flex-start",
}));