All files / src/features/EnterprisePortal/EnterpriseSettings/components GiveClassification.tsx

80% Statements 8/10
50% Branches 2/4
50% Functions 2/4
80% Lines 8/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                          2x 58x   58x 58x   58x 7x 7x       58x                                                  
import { RHFInput } from "@common/Input/Input";
import { Box } from "@mui/material";
import { GiveSelectOption } from "@shared/GiveInputs/GiveSelect";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import HFGiveSelect from "@shared/HFInputs/HFGiveSelect/HFGiveSelect";
import { useEffect } from "react";
import { useFormContext } from "react-hook-form";
 
type Props = {
  options: GiveSelectOption[];
  disabled?: boolean;
};
 
export const ClassificationField = ({ options, disabled }: Props) => {
  const { watch, setValue, trigger } = useFormContext();
 
  const classification = watch("classification");
  const isOther = classification === "other";
 
  useEffect(() => {
    Eif (!isOther) {
      setValue("classDescription", undefined);
    }
  }, [isOther, setValue]);
 
  return (
    <>
      <HFGiveSelect
        name="classification"
        label="Classification"
        options={options}
        disabled={disabled}
        fullWidth
        renderFooter={
          isOther && (
            <Box p={1}>
              <HFGiveInput
                name="classDescription"
                autoFocus
                onClick={(e) => e.stopPropagation()}
                onKeyDown={(e) => e.stopPropagation()}
                fullWidth
              />
            </Box>
          )
        }
      />
    </>
  );
};