All files / src/sections/PayBuilder/components/products/Hero TicketListBottomSheet.tsx

84% Statements 21/25
76.92% Branches 10/13
87.5% Functions 7/8
86.95% Lines 20/23

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                                          13x                                                           13x         5x 5x 5x 5x 5x 5x     5x 5x       5x 5x                                         5x   5x                                                                     13x 23x 5x                     13x 38x   5x                              
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import NiceModal from "@ebay/nice-modal-react";
import { Stack } from "@mui/material";
import { ProductItemType } from "@sections/PayBuilder/types";
import { EventTicketItem } from "@sections/PayBuilder/views/events/components/EventTickets";
import GiveButton from "@shared/Button/GiveButton";
import { CheckoutNavButton } from "../CheckoutNavButton";
import { useCart } from "@sections/PayBuilder/provider/CartContext";
import { usePublicSeating } from "@hooks/payment-forms/usePublicSeating";
import { areSeatsIncomplete } from "@sections/PayBuilder/seating.helpers";
import GiveSidePanel from "@shared/SidePanel/GiveSidePanel";
import GiveText from "@shared/Text/GiveText";
import { XIcon } from "@phosphor-icons/react";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { styled, useAppTheme } from "@theme/v2/Provider";
 
export interface Props {
  paybuilderContextValues: any;
  paybuilderFormValues: any;
}
 
const TicketListBottomSheet = NiceModal.create(
  ({ paybuilderContextValues, paybuilderFormValues }: Props) => {
    const { open, onClose } = useNiceModal();
    const { background } = paybuilderFormValues.parsedValues;
 
    return (
      <GiveSidePanel
        open={open}
        onClose={onClose}
        mobileStyle={{
          "& .MuiDrawer-paper": {
            height: "70dvh",
            maxHeight: "70dvh",
            overflow: "hidden",
            backgroundColor: background,
          },
        }}
        overRideIsMobile
        isSingleOnly
      >
        <TicketListBottomSheetBody
          onClose={onClose}
          paybuilderContextValues={paybuilderContextValues}
          paybuilderFormValues={paybuilderFormValues}
        />
      </GiveSidePanel>
    );
  },
);
 
export const TicketListBottomSheetBody = ({
  onClose,
  paybuilderContextValues,
  paybuilderFormValues,
}: { onClose: () => void } & Props) => {
  const { cartItems } = useCart();
  const { parsedValues, methods, data } = paybuilderFormValues;
  const { accentColor, background } = parsedValues;
  const { Items: items } = methods.watch();
  const { palette } = useAppTheme();
  const borderColor = palette.border?.primary;
  // PAY Builder 031 — same assigned-seating checkout gate as the desktop list, so the
  // mobile bottom sheet can't proceed to checkout with seatless tickets either.
  const { data: seating } = usePublicSeating(data?.id ?? "", Boolean(data?.id));
  const seatsIncomplete = areSeatsIncomplete(
    seating?.assignSeating ?? false,
    cartItems,
  );
  const hasQuantity = cartItems?.some((item) => item?.quantity > 0);
  return (
    <Stack
      sx={{
        height: "70dvh",
        overflow: "hidden",
      }}
    >
      <StyledHeader borderColor={borderColor}>
        <GiveText variant="bodyM">Tickets</GiveText>
        <GiveIconButton Icon={XIcon} variant="ghost" onClick={onClose} />
      </StyledHeader>
      <Stack
        gap="8px"
        sx={{
          flex: 1,
          minHeight: 0,
          overflowY: "auto",
          padding: "24px 20px",
        }}
      >
        {items.map((item: ProductItemType) => {
          Iif (!item.display) return null;
 
          return (
            <EventTicketItem
              key={item.id}
              product={item}
              accentColor={accentColor}
              background={background}
              displayStatus={paybuilderContextValues?.displayStatus}
              eventProductId={data?.id}
            />
          );
        })}
      </Stack>
      <StyledFooter
        direction="row"
        gap="12px"
        borderColor={borderColor}
        background={background}
      >
        <GiveButton
          label="Back"
          variant="ghost"
          size="small"
          onClick={onClose}
        />
        <CheckoutNavButton
          paybuilderContextValues={paybuilderContextValues}
          paybuilderFormValues={paybuilderFormValues}
          successCb={onClose}
          disabled={cartItems?.length === 0 || !hasQuantity || seatsIncomplete}
        />
      </StyledFooter>
    </Stack>
  );
};
 
const StyledHeader = styled(Stack, {
  shouldForwardProp: (prop) => prop !== "borderColor",
})<{ borderColor?: string }>(({ borderColor }) => ({
  padding: "16px 20px",
  height: "56px",
  flexShrink: 0,
  gap: "20px",
  borderBottom: `1px solid ${borderColor}`,
  flexDirection: "row",
  alignItems: "center",
  justifyContent: "space-between",
}));
 
const StyledFooter = styled(Stack, {
  shouldForwardProp: (prop) => prop !== "borderColor" && prop !== "background",
})<{ borderColor?: string; background?: string }>(
  ({ borderColor, background }) => ({
    justifyContent: "flex-end",
    padding: "16px 20px",
    borderTop: `1px solid ${borderColor}`,
    alignSelf: "flex-end",
    flexShrink: 0,
    position: "sticky",
    bottom: 0,
    zIndex: 1,
    background: background || "inherit",
    width: "100%",
  }),
);
 
export default TicketListBottomSheet;