All files / src/components/common/RHFStreetAddress GiveHFStreetAddress.tsx

69.23% Statements 9/13
50% Branches 2/4
60% Functions 3/5
81.81% Lines 9/11

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          55x         476x 476x   476x 497x 497x 497x     476x         497x                            
import * as React from "react";
import { useFormContext, Controller } from "react-hook-form";
import { HFGiveInputProps } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import { GiveInput } from "@shared/GiveInputs/GiveInput";
 
export const GiveHFStreetAddress: React.FC<HFGiveInputProps> = ({
  name,
  helperText,
  ...props
}) => {
  const { control } = useFormContext();
  const [isFocused, setIsFocused] = React.useState(false);
 
  const getHelperText = (error: any) => {
    Iif (error) return error.message;
    Iif (helperText) return helperText;
    return undefined;
  };
 
  return (
    <Controller
      name={name}
      control={control}
      render={({ field: { ref, value, ...rest }, fieldState: { error } }) => (
        <GiveInput
          inputRef={ref}
          {...rest}
          value={value}
          onFocus={() => setIsFocused(true)}
          onBlur={() => setIsFocused(false)}
          {...props}
          error={!!error}
          helperText={getHelperText(error)}
        />
      )}
    />
  );
};