All files / src/sections/PayBuilder/components/products/ProductPageContainer index.tsx

87.8% Statements 36/41
85.29% Branches 29/34
62.5% Functions 5/8
87.5% Lines 35/40

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                                                                                                          12x                   665x 665x 665x     665x   665x                           665x 665x 665x 665x       665x   665x         665x 665x         665x 558x                   558x                                   665x       665x       665x       665x 665x 665x 511x   511x   511x 340x   171x     511x     154x   154x                                                                                                                                   154x                           12x 108x 32x                          
import NiceModal from "@ebay/nice-modal-react";
import { rgbToHex, Stack } from "@mui/material";
 
import { useCart } from "@sections/PayBuilder/provider/CartContext";
import { usePayBuilderContext } from "@sections/PayBuilder/provider/PayBuilderContext";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import { usePublicSeating } from "@hooks/payment-forms/usePublicSeating";
import { Item_Layout } from "@sections/PayBuilder/provider/provider.type";
import { ProductItemType } from "@sections/PayBuilder/types";
import GiveLink from "@shared/Link/GiveLink";
import { styled, useAppTheme } from "@theme/v2/Provider";
import {
  PRIVACY_POLICY_MODAL,
  PUBLIC_PRODUCT_ITEM_MODAL,
  REFUND_POLICY_MODAL,
  TERMS_OF_SERVICE_REBRAND_MODAL,
} from "modals/modal_names";
import React, { useEffect } from "react";
import { DarkWithCustomTheme } from "@sections/PayBuilder/FormPreview";
import useCheckFormType from "../../hooks/useCheckFormType";
import { TFormStatus, TFormStatusEnum } from "../types";
import PageContainer from "../PageContainer";
import { CartCheckoutFooter } from "../CartCheckoutFooter";
import ProductPageLogoComponent from "./ProductPageLogoComponent";
import { useCreateDefaultFundraiserCart } from "./useCreateDefaultFundraiserCart";
import {
  PreviewProductSkeletonLoader,
  StandardProductSkeleton,
} from "../../loaders/PreviewProductPlaceholder";
import { PreviewDonationSkeletonLoader } from "../../loaders/PreviewDonationPlaceholder";
import ProductPageMainContent from "./ProductPageMainContent";
import { resolveSharedProductDeepLink } from "./deepLink";
import { HeroImage } from "../Hero/HeroImage";
import { useImageSource } from "@sections/PayBuilder/Forms/About/utils";
import {
  getTextColorsBasedOnBackground,
  getYoutubeVideoThumbnail,
  useGetRedesignedFormTypes,
} from "@sections/PayBuilder/utils";
 
interface ProductPageContainerProps {
  displayStatus: TFormStatus;
  children?: React.ReactNode;
  items?: ProductItemType[];
  itemLayout?: Item_Layout;
  header?: any;
  isPeekMode?: boolean;
  savedLogo?: string;
  accentColor?: string;
  isPreview?: boolean;
  showBackToPortalButton?: boolean;
}
 
const ProductPageContainer: React.FC<ProductPageContainerProps> = ({
  displayStatus,
  items,
  itemLayout,
  header,
  isPeekMode,
  isPreview,
  savedLogo,
  showBackToPortalButton,
}) => {
  const { isCartEmpty, addToCart, subTotal } = useCart();
  useCreateDefaultFundraiserCart({ isPreview });
  const redesignedFormTypes = useGetRedesignedFormTypes();
  const {
    screenStates: { isMobileView },
  } = usePayBuilderContext();
 
  const { palette } = useAppTheme();
 
  const {
    parsedValues: {
      logo,
      accentColor,
      background,
      selectedImage,
      selectedVideoURL,
    },
    isFetched,
    methods,
    isPaymentFormInfosLoading,
    data: formData,
  } = usePayBuilderForm();
  const { Style } = methods.watch();
  const isPublic = displayStatus === TFormStatusEnum.PUBLIC;
  const { luminance } = getTextColorsBasedOnBackground(
    rgbToHex(background).toUpperCase(),
  );
 
  const isLightBackground = luminance > 0.5;
  const { isFundraiser, isProduct, isMembership, isSweepstake, isEvent, formType } =
    useCheckFormType();
 
  // AC008/AC009 — for an assigned-seating event opened via a shared link, the deep-link
  // modal needs the same seating config EventTicketItem passes, else SeatPicker never
  // renders and add-to-cart submits seatless. Keyed on the event product id.
  const eventProductId = formData?.id;
  const { data: seating, isLoading: isSeatingLoading } = usePublicSeating(
    eventProductId ?? "",
    isEvent && Boolean(eventProductId),
  );
 
  useEffect(() => {
    const resolved = resolveSharedProductDeepLink({
      isPublic,
      isFetched,
      items,
      search: location.search,
      isEvent,
      eventProductId,
      isSeatingLoading,
      seating,
    });
    Iif (resolved) {
      NiceModal.show(PUBLIC_PRODUCT_ITEM_MODAL, {
        product: resolved.product,
        addToCart,
        accentColor,
        backgroundColor: background,
        secondaryColor: palette.text.secondary,
        subscribeBtnText: Style?.checkoutContent,
        productQuantity: 1,
        displayStatus,
        subTotal,
        assignSeating: resolved.assignSeating,
        seatingRows: resolved.seatingRows,
        takenSeats: resolved.takenSeats,
      });
    }
  }, [location.search, displayStatus, items, isSeatingLoading, seating]);
 
  const openPrivacyModal = () => {
    NiceModal.show(PRIVACY_POLICY_MODAL);
  };
 
  const openTermsModal = () => {
    NiceModal.show(TERMS_OF_SERVICE_REBRAND_MODAL);
  };
 
  const handleOpenRefundModal = () => {
    NiceModal.show(REFUND_POLICY_MODAL);
  };
 
  const logoUrl = isPublic ? savedLogo : logo;
  const { data: imageData } = useImageSource(selectedImage);
  if (isPaymentFormInfosLoading) {
    let Loader = null;
 
    Iif (isSweepstake || isFundraiser) {
      Loader = <PreviewDonationSkeletonLoader />;
    } else if (isProduct) {
      Loader = <StandardProductSkeleton />;
    } else {
      Loader = <PreviewProductSkeletonLoader />;
    }
 
    return <PageContainer>{Loader}</PageContainer>;
  }
 
  const showCartFooter = isPublic && !isPeekMode && !isCartEmpty && isProduct;
 
  return (
    <>
      <PageContainer
        displayStatus={displayStatus}
        disableGutters={isMobileView && redesignedFormTypes.includes(formType)}
      >
        <DarkWithCustomTheme>
          <ProductPageLogoComponent
            logoUrl={logoUrl}
            showBackToPortalButton={showBackToPortalButton}
            isPreview={isPreview}
          />
 
          {redesignedFormTypes.includes(formType) && (
            <HeroImage
              canvasData={selectedImage}
              isPreview={isPreview}
              src={
                selectedVideoURL
                  ? getYoutubeVideoThumbnail(selectedVideoURL)
                  : imageData
              }
              selectedVideoURL={selectedVideoURL}
            />
          )}
          <ProductPageMainContent
            displayStatus={displayStatus}
            items={items}
            itemLayout={itemLayout}
            isPreview={isPreview}
            header={header}
            isPeekMode={isPeekMode}
          />
 
          {isPublic && (
            <FooterWrapper>
              <Stack
                direction={isMobileView ? "column" : "row"}
                gap="24px"
                alignItems="center"
                justifyContent="center"
                width="100%"
              >
                <Stack direction="row" gap="24px">
                  <GiveLink onClick={handleOpenRefundModal}>
                    Refund Policy
                  </GiveLink>
                  <GiveLink onClick={openPrivacyModal}>Privacy Policy</GiveLink>
                </Stack>
                <GiveLink onClick={openTermsModal}>Terms & Conditions</GiveLink>
              </Stack>
            </FooterWrapper>
          )}
        </DarkWithCustomTheme>
      </PageContainer>
      {showCartFooter && (
        <StyledFooter direction="row" isLightBackground={isLightBackground}>
          <CartCheckoutFooter isLightBackground={isLightBackground} />
        </StyledFooter>
      )}
    </>
  );
};
 
export default ProductPageContainer;
 
const FooterWrapper = styled(Stack)(({ theme }) => ({
  padding: "24px 0",
  borderTop: "1px solid #CCCCC9",
  flexDirection: "row",
  justifyContent: "space-between",
  alignItems: "center",
  marginTop: "48px",
  gap: "24px",
  flexWrap: "wrap",
  [theme.breakpoints.down("v2_sm")]: {
    flexDirection: "column-reverse",
  },
}));
 
export const StyledFooter = styled(Stack, {
  shouldForwardProp: (prop) => prop !== "isLightBackground",
})<{ isLightBackground: boolean }>(({ theme, isLightBackground }) => ({
  position: "sticky",
  bottom: 0,
  left: 0,
  right: 0,
  height: "66px",
  padding: "16px",
  backdropFilter: "blur(7.5px)",
  background: isLightBackground ? "#E5E5E3B3" : "#4D4D4CB2",
  display: "flex",
  justifyContent: "center",
  zIndex: 5,
}));