All files / src/features/Minibuilders StyleSection.tsx

10% Statements 1/10
0% Branches 0/14
0% Functions 0/3
10% Lines 1/10

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                              4x                                                                                                                          
import { useEffect } from "react";
import { Box, Stack } from "@mui/material";
import { useFormContext } from "react-hook-form";
import { Text } from "@common/Text";
import { palette } from "@palette";
import { RHFCheckbox } from "@common/Checkbox";
import ImageGallery from "./ImageGallery";
import FadeUpWrapper from "@components/animation/FadeUpWrapper";
 
type FundraisersAboutProps = {
  title: string;
  titleSize?: "large" | "medium";
  isEdit?: boolean;
};
 
const StyleSection = ({
  title,
  titleSize = "large",
  isEdit = false,
}: FundraisersAboutProps) => {
  const { setValue, watch } = useFormContext();
  const values = watch();
 
  const handleSelect = (item: any) => {
    const isSelected = item?.URL === watch("style.image")?.URL;
 
    setValue("style.image", isSelected ? null : item, { shouldDirty: true });
  };
 
  useEffect(() => {
    if (!watch("style.image") && watch("style.useAsBackground"))
      setValue("style.useAsBackground", false, { shouldDirty: true });
  }, [watch("style.image")]);
 
  return (
    <Stack direction="column" gap={isEdit ? 2 : 4}>
      <FadeUpWrapper delay={isEdit ? 400 : 200}>
        <Stack direction="column" gap={isEdit ? 1 : 2}>
          <Box>
            <Text
              color={palette.black[100]}
              variant="body"
              lineHeight="16.8px"
              fontWeight="book"
              mb="4px"
            >
              Featured image
            </Text>
            <Text
              color={palette.gray[300]}
              variant="body"
              fontWeight="book"
              lineHeight="16.8px"
            >
              This image will be displayed at the top of the payment form so it
              should be representative. Minimum size recommended 2000x2000
            </Text>
          </Box>
 
          <ImageGallery
            handleSelect={handleSelect}
            selectedImage={values.style.image}
          />
          <RHFCheckbox
            name="style.useAsBackground"
            label="Use as background image"
            helperText="If checked this image will be integrated in the background of the form, can be later changed"
            disabled={!watch("style.image")}
          />
        </Stack>
      </FadeUpWrapper>
    </Stack>
  );
};
 
export default StyleSection;