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

100% Statements 6/6
100% Branches 2/2
100% Functions 2/2
100% Lines 6/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                  14x               9x 1x             9x 7x                   2x        
import { GiveInput, InputProps } from "@shared/GiveInputs/GiveInput";
import GiveSelect, { GiveSelectProps } from "@shared/GiveInputs/GiveSelect";
 
export type ProvinceFieldProps = InputProps & {
  isUS: boolean;
  options: GiveSelectProps["options"];
  name?: string;
};
 
export const ProvinceField = ({
  isUS,
  options,
  name,
  onChange,
  label,
  ...rest
}: ProvinceFieldProps) => {
  const handleSelectChange = (e: { target: { value: string | number } }) => {
    onChange?.({
      target: {
        value: e.target.value.toString(),
      },
    } as React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>);
  };
 
  if (isUS)
    return (
      <GiveSelect
        label="State"
        name={name}
        options={options}
        onChange={handleSelectChange}
        {...rest}
      />
    );
 
  return (
    <GiveInput label="Province" name={name} onChange={onChange} {...rest} />
  );
};