All files / src/componentsV2/Payment/components ExpirationDateField.tsx

88.88% Statements 8/9
75% Branches 3/4
100% Functions 3/3
88.88% Lines 8/9

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        13x 234x   234x 10x   10x 10x         234x     10x                    
import { GiveInput, InputProps } from "@shared/GiveInputs/GiveInput";
import { useFormContext } from "react-hook-form";
import { normalizeInput } from "@sections/PayBuilder/Checkout/helpers";
 
const ExpirationDateField = (props: InputProps) => {
  const { setValue } = useFormContext();
 
  const handleChange = (value: string) => {
    const normalizedValue = normalizeInput(value);
 
    if (normalizedValue && normalizedValue.length <= 7) {
      setValue("payment.expirationDate", normalizedValue, {
        shouldValidate: true,
      });
    } else EsetValue("payment.expirationDate", "");
  };
  return (
    <GiveInput
      {...props}
      onChange={(event) => handleChange(event.target.value)}
      InputProps={{
        inputMode: "numeric",
      }}
      maxLength={7}
    />
  );
};
 
export default ExpirationDateField;