All files / src/sections/PayBuilder/Checkout/components ContactSection.tsx

83.33% Statements 5/6
75% Branches 3/4
50% Functions 1/2
83.33% Lines 5/6

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                  46x 22x 22x   22x   22x                                                                                                              
import { Stack } from "@mui/material";
import { UserListIcon } from "@phosphor-icons/react";
import GiveText from "@shared/Text/GiveText";
import CheckoutDetailsSectionItem from "./CheckoutDetailsSectionItem";
import { GiveInput } from "@shared/GiveInputs/GiveInput";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import { Controller } from "react-hook-form";
import useCheckFormType from "@sections/PayBuilder/components/hooks/useCheckFormType";
 
const ContactSection = () => {
  const { methods } = usePayBuilderForm();
  const isPhoneNumberRendered = methods.watch().Checkout.phoneNumber.render;
  // Events only — mirrors the customer-facing Contact section.
  const { isEvent: showContactName } = useCheckFormType();
 
  return (
    <Stack gap="12px">
      <Stack direction="row" spacing={2}>
        <UserListIcon size={24} />
        <GiveText variant="bodyL">Contact</GiveText>
      </Stack>
      {showContactName && (
        <CheckoutDetailsSectionItem
          label="Full Name"
          name="name"
          isLocked
          showRequiredLabel
        />
      )}
      <CheckoutDetailsSectionItem
        label="Email"
        name="email"
        isLocked
        showRequiredLabel
      />
      <CheckoutDetailsSectionItem
        name="phoneNumber"
        label="Phone Number"
        showRequiredLabel
        showRequiredSwitch
        optionalInput={
          isPhoneNumberRendered ? (
            <Stack paddingLeft="28px">
              <Controller
                control={methods.control}
                name="Checkout.phoneNumber.optionalMessage"
                render={({ field: { onChange, value } }) => {
                  return (
                    <GiveInput
                      label="Note for customer (Optional)"
                      name="phoneNumber.optionalMessage"
                      value={value}
                      onChange={onChange}
                      maxLength={100}
                      displayCounter
                    />
                  );
                }}
              />
            </Stack>
          ) : (
            <></>
          )
        }
      />
    </Stack>
  );
};
 
export default ContactSection;