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

68.88% Statements 31/45
37.31% Branches 25/67
60% Functions 3/5
69.76% Lines 30/43

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                                                                    18x   18x 18x 18x     18x 18x 18x 18x 18x 18x 18x       18x 18x     18x   27x   18x 3x           3x     3x     18x     18x 18x                 18x                                           18x 18x 18x                         18x             18x                     18x 18x                                                                                                                                                                                                                  
import { rgbToHex, Stack } from "@mui/material";
import { HeroImage } from "@sections/PayBuilder/components/products/Hero/HeroImage";
import { usePayBuilderContext } from "@sections/PayBuilder/provider/PayBuilderContext";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import {
  getTextColorsBasedOnBackground,
  useGetRedesignedFormTypes,
} from "@sections/PayBuilder/utils";
import EventDateLocation, {
  LocationComponent,
} from "@sections/PayBuilder/views/events/components/EventDateLocation";
import EventMap from "@sections/PayBuilder/views/events/components/EventMap";
import {
  StyledStack,
  ContentComponent,
} from "@sections/PayBuilder/views/fundraiser/components/Atom.component";
import { useMemo, useState } from "react";
import { FormType } from "@sections/PayBuilder/utils";
import { useImageSource } from "@sections/PayBuilder/Forms/About/utils";
import EventTicketList from "@sections/PayBuilder/views/events/components/EventTickets";
import HeroSectionFloatingButton from "./HeroSectionFloatingButton";
import NiceModal from "@ebay/nice-modal-react";
import { EVENT_TICKET_LIST_MODAL } from "modals/modal_names";
import TicketListBottomSheetPreview from "@sections/PayBuilder/components/products/TicketListBottomSheetPreview";
import { useEventDateLocationData } from "@sections/PayBuilder/hooks/useEventDateLocationData";
import { checkEnd } from "@utils/date.helpers";
import PublicEventReviews from "@sections/PayBuilder/views/events/components/PublicEventReviews";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
 
interface Props {
  isPeekMode?: boolean;
  isPreview?: boolean;
}
function EventsHero({ isPreview, isPeekMode }: Props) {
  const [showTicketListSheet, setShowTicketListSheet] = useState(false);
 
  const paybuilderFormValues = usePayBuilderForm();
  const { parsedValues, methods, data: eventData } = paybuilderFormValues;
  const paybuilderContextValues = usePayBuilderContext();
  const {
    screenStates: { isMobileView, isTabletView },
  } = paybuilderContextValues;
  const redesignedFormTypes = useGetRedesignedFormTypes();
  const { isEventReviewsEnabled } = useGetFeatureFlagValues();
  const { DateLocation } = methods.watch();
  const accentColor = parsedValues.accentColor;
  const position = parsedValues.assetPosition;
  const { isInputColorLight } = getTextColorsBasedOnBackground(
    rgbToHex(parsedValues.background).toUpperCase(),
  );
  const { dateData, locationData, eventDateLocationProps, isOnSite, isOnline } =
    useEventDateLocationData();
  const { Items } = methods.watch();
 
  const hasEnded =
    checkEnd(eventData?.startsAt, eventData?.endsAt || 0, eventData?.includeTime) <
    Date.now();
  const isEmpty = Items?.filter((x) => x.display).length === 0 || hasEnded;
 
  const direction = useMemo(() => {
    Iif (isMobileView) {
      if (position === "right") {
        return "column";
      }
      return "column-reverse";
    }
    Iif (position === "left") {
      return "row";
    }
    return "row-reverse";
  }, [isMobileView, position]);
 
  const isSmallDevice = isMobileView || isTabletView;
 
  let mt;
  if ((isOnSite && DateLocation?.isManualAddress) || isOnline) {
    mt = undefined;
  } else E{
    if (isSmallDevice) {
      mt = "38px";
    } else {
      mt = "40px";
    }
  }
  const Location = (
    <Stack flex={1} mt={mt}>
      <LocationComponent
        data={locationData}
        adaptiveColorToBackground={isInputColorLight ? "black" : "white"}
      />
 
      {DateLocation?.locationShortAddress &&
        DateLocation?.locationPosition === "onsite" &&
        !DateLocation?.isManualAddress && (
          <EventMap
            hideTitle
            containerStyle={{
              flex: 1,
            }}
            locations={{
              locationShortAddress: DateLocation.locationShortAddress,
            }}
          />
        )}
    </Stack>
  );
 
  const closeTicketSheetList = () => setShowTicketListSheet(false);
  const { data } = useImageSource(parsedValues?.selectedImage);
  const adaptiveColorToBackground = isInputColorLight ? "black" : "white";
 
  /**
   * PayBuilder 034 — the event's reviews, below the description (frame
   * 7357-80162). Read-only here: the customer writes in the GiveCash app and
   * the merchant answers in the portal.
   *
   * Only on the live page, never in the builder preview: a draft has no
   * product id to read against, and a merchant arranging their form is not
   * looking at other customers' feedback. The component renders nothing when
   * the event has no reviews, so an ended event without feedback stays clean.
   */
  const reviewsSection =
    isEventReviewsEnabled && !isPreview && hasEnded && eventData?.id ? (
      <PublicEventReviews
        productId={eventData.id}
        adaptiveColorToBackground={adaptiveColorToBackground}
      />
    ) : undefined;
 
  const contentBaseProps = {
    description: parsedValues.description,
    heading: parsedValues.heading,
    isMobileView: isMobileView,
    dateData: dateData,
    Location: DateLocation?.isManualAddress || !isOnSite ? Location : undefined,
    isPreview: isPreview,
    adaptiveColorToBackground,
    footerContent: reviewsSection,
  };
 
  Eif (redesignedFormTypes.includes(FormType.EVENTS)) {
    return (
      <>
        {isPreview ? (
          <TicketListBottomSheetPreview
            open={showTicketListSheet}
            onClose={closeTicketSheetList}
          />
        ) : (
          <></>
        )}
        <StyledStack
          isMobile={isMobileView}
          direction={isMobileView ? "column" : "row"}
          spacing={4}
        >
          <ContentComponent
            {...contentBaseProps}
            dateData={undefined}
            Location={undefined}
            innerContent={
              isMobileView && (
                <>
                  <EventDateLocation {...eventDateLocationProps} />
                  {!isEmpty && (
                    <HeroSectionFloatingButton
                      title="Get tickets"
                      accentColor={accentColor}
                      isPreview={isPreview}
                      onClick={() => {
                        if (isPreview && isMobileView) {
                          setShowTicketListSheet(true);
                          return;
                        }
                        NiceModal.show(EVENT_TICKET_LIST_MODAL, {
                          paybuilderContextValues,
                          paybuilderFormValues,
                        });
                      }}
                    />
                  )}
                </>
              )
            }
          />
          {!isMobileView && (
            <Stack gap="16px">
              <EventDateLocation {...eventDateLocationProps} />
              <EventTicketList isPeekMode={isPeekMode} />
            </Stack>
          )}
        </StyledStack>
      </>
    );
  }
 
  const content = <ContentComponent {...contentBaseProps} />;
 
  return (
    <>
      <StyledStack direction={direction} spacing={3} isMobile={isMobileView}>
        <Stack
          sx={{
            display: "flex",
            flexDirection: "column",
            flex: 1,
          }}
        >
          <HeroImage
            src={data}
            isPreview={isPreview}
            canvasData={parsedValues?.selectedImage}
          />
          {isOnSite && !DateLocation?.isManualAddress && !isSmallDevice && (
            <Stack mt={mt}>
              <LocationComponent
                data={locationData}
                adaptiveColorToBackground={
                  isInputColorLight ? "black" : "white"
                }
              />
 
              {DateLocation?.locationShortAddress &&
                DateLocation?.locationPosition === "onsite" &&
                !DateLocation?.isManualAddress && (
                  <EventMap
                    hideTitle
                    containerStyle={{
                      flex: 1,
                    }}
                    locations={{
                      locationShortAddress: DateLocation.locationShortAddress,
                    }}
                  />
                )}
            </Stack>
          )}
        </Stack>
        {content}
      </StyledStack>
      {isOnSite && !DateLocation?.isManualAddress && isSmallDevice && Location}
    </>
  );
}
 
export default EventsHero;