All files / src/sections/PayBuilder/Forms/About VideoUploadTab.tsx

93.75% Statements 15/16
62.5% Branches 5/8
100% Functions 4/4
93.75% Lines 15/16

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                          44x         250x 250x 250x   250x   250x   3x         250x 7x         250x 250x                 119x     119x 119x 119x                    
import { Stack } from "@mui/material";
import {
  checkYoutubeVideoExistance,
  extractYoutubeVideoID,
} from "@sections/PayBuilder/utils";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import GiveText from "@shared/Text/GiveText";
import { useFormContext } from "react-hook-form";
import VideoPreview from "./VideoPreview";
import { debounce } from "lodash";
import { useCallback, useEffect } from "react";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
 
const VideoUploadTab = ({
  setIsExistingVideoURL,
}: {
  setIsExistingVideoURL: any;
}) => {
  const { watch, setValue } = useFormContext();
  const { methods } = usePayBuilderForm();
  const item = methods.getValues("About.selectedVideoURL");
 
  const videoURL = watch("videoURL");
 
  const debouncedCheckYoutubeVideo = useCallback(
    debounce((videoURL) => {
      checkYoutubeVideoExistance(videoURL, setIsExistingVideoURL);
    }, 300),
    [],
  );
 
  useEffect(() => {
    Iif (item && !videoURL) {
      setValue("videoURL", item);
    }
  }, []);
 
  const videoId = extractYoutubeVideoID(videoURL);
  return (
    <Stack gap="24px" paddingTop="24px" paddingBottom="98px">
      <GiveText variant="bodyS" color="secondary">
        We currently support YouTube videos only.
      </GiveText>
      <HFGiveInput
        name="videoURL"
        label="Video link"
        onChange={(e: any) => {
          setValue("videoURL", e.target.value, {
            shouldValidate: true,
          });
          const videoURL = watch("videoURL");
          Eif (videoURL) {
            debouncedCheckYoutubeVideo(videoURL);
          }
        }}
      />
      {videoId && <VideoPreview videoID={videoId} />}
    </Stack>
  );
};
 
export default VideoUploadTab;