All files / src/features/Events/EventDetail/tickets TicketSummaryCard.tsx

100% Statements 14/14
100% Branches 18/18
100% Functions 4/4
100% Lines 13/13

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                                                                1x           32x   32x                                         1x                                                                                                   1x                                 1x 32x   32x 3x                         29x 4x                                   25x                               32x        
import { Stack } from "@mui/material";
import {
  CheckCircleIcon,
  CheckSquareIcon,
  ProhibitIcon,
} from "@phosphor-icons/react";
import GiveButton from "@shared/Button/GiveButton";
import GiveChip from "@shared/Chip/GiveChip";
import GiveText from "@shared/Text/GiveText";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { styled, useAppTheme } from "@theme/v2/Provider";
import {
  EventTicketRow,
  TICKET_DO_NOT_ADMIT_LABEL,
  TICKET_PANEL_STATUS,
} from "./ticket.types";
import { Card } from "./EventTicketPanel.atoms";
 
type Props = {
  row?: EventTicketRow;
  /** Desktop puts Check In beside the chip; the phone's lives in the sheet footer. */
  showCheckIn?: boolean;
  isCheckingIn?: boolean;
  onCheckIn: (row: EventTicketRow) => void;
};
 
/**
 * The panel's summary card: the code + state on top, then the ticket (with its
 * seat line above the name, per 7417-202396) against the holder. On a phone the
 * holder drops under the ticket instead.
 */
const TicketSummaryCard = ({
  row,
  showCheckIn,
  isCheckingIn,
  onCheckIn,
}: Props) => {
  const { isMobileView } = useCustomThemeV2();
 
  return (
    <Card gap="16px">
      <Stack
        direction="row"
        alignItems="center"
        justifyContent="space-between"
        gap="12px"
      >
        <GiveText variant="bodyS" color="secondary">
          {row?.displayId}
        </GiveText>
        <Stack direction="row" gap="12px" alignItems="center">
          <StatusChip row={row} />
          {showCheckIn && (
            <GiveButton
              label="Check In"
              variant="filled"
              size="small"
              startIcon={<CheckSquareIcon size={16} />}
              disabled={isCheckingIn}
              data-testid="ticket-panel-check-in"
              onClick={() => row && onCheckIn(row)}
            />
          )}
        </Stack>
      </Stack>
      <Divider />
      <Stack
        direction={isMobileView ? "column" : "row"}
        justifyContent="space-between"
        gap={isMobileView ? "8px" : "16px"}
        alignItems="flex-start"
        data-testid="ticket-panel-identity"
      >
        <Stack minWidth={0} maxWidth="100%">
          {row?.seatLabel && (
            <GiveTruncateText variant="bodyS" color="primary" lineClamp={1}>
              {row.seatLabel}
            </GiveTruncateText>
          )}
          <GiveTruncateText variant="bodyM" color="primary" lineClamp={1}>
            {row?.ticketName}
          </GiveTruncateText>
        </Stack>
        <Stack
          minWidth={0}
          maxWidth="100%"
          alignItems={isMobileView ? "flex-start" : "flex-end"}
        >
          <GiveTruncateText variant="bodyS" color="primary" lineClamp={1}>
            {row?.holderName}
          </GiveTruncateText>
          <GiveTruncateText variant="bodyS" color="secondary" lineClamp={1}>
            {row?.holderEmail}
          </GiveTruncateText>
        </Stack>
      </Stack>
    </Card>
  );
};
 
export default TicketSummaryCard;
 
/**
 * The pill every state shares (the `Label` instances 7397-91053 checked in and
 * 7560-55518 pending): a 40px radius with 16px sides, which is the design
 * system's `size="large"` chip, at 12px/28px with a 4px icon gap. `GiveChip`
 * sets a 12px gap and MUI adds its own icon margins, both at a specificity `sx`
 * only beats with `!important` — the override `ProviderMccSection`'s risk chip
 * needs for the same reason.
 */
const CHIP_SX = {
  height: "28px",
  fontSize: "12px",
  gap: "4px !important",
  "& .MuiChip-icon": { marginLeft: 0, marginRight: 0 },
};
 
/**
 * The state chip, per frames 7397-100891 (do not admit) and 7397-91007 (checked
 * in). Every state is the tinted treatment — surface at the `25` token (the
 * neutral one at `surface.tertiary`), label at `100`, icon at `50` — which is
 * `variant="light"` here: without it MUI ignores the theme's chip variants and
 * falls back to its own solid `filled` palette, which is what made "Do not
 * admit" read as a solid red action badge and "Checked in" a solid green one.
 * The icon carries its colour explicitly because it is a shade darker than the
 * label.
 */
const StatusChip = ({ row }: { row?: EventTicketRow }) => {
  const { palette } = useAppTheme();
 
  if (row?.doNotAdmit) {
    return (
      <GiveChip
        // "Prohibited" is the Check-in Status row's wording, not the chip's.
        label={TICKET_DO_NOT_ADMIT_LABEL}
        color="error"
        variant="light"
        size="large"
        sx={CHIP_SX}
        icon={<ProhibitIcon size={16} color={palette.primitive?.error?.[50]} />}
        data-testid="ticket-panel-status-chip"
      />
    );
  }
  if (row?.checkedInAt) {
    return (
      <GiveChip
        label={TICKET_PANEL_STATUS.checkedIn}
        color="success"
        variant="light"
        size="large"
        sx={CHIP_SX}
        icon={
          <CheckCircleIcon
            size={16}
            weight="fill"
            color={palette.primitive?.success?.[50]}
          />
        }
        data-testid="ticket-panel-status-chip"
      />
    );
  }
  return (
    <GiveChip
      label={
        row?.isExpired
          ? TICKET_PANEL_STATUS.expired
          : TICKET_PANEL_STATUS.pending
      }
      color="default"
      variant="light"
      size="large"
      sx={CHIP_SX}
      data-testid="ticket-panel-status-chip"
    />
  );
};
 
const Divider = styled("div")(({ theme }) => ({
  height: "1px",
  backgroundColor: theme.palette.border?.primary,
}));