All files / src/components/common/BusinessProfileInputs WebsiteInput.tsx

100% Statements 4/4
71.42% Branches 5/7
100% Functions 1/1
100% Lines 4/4

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                      69x           28x   28x   28x                                              
import CopyButton from "@common/CopyButton";
import { RHFInput } from "@common/Input";
import { RHFInputProps } from "@common/Input/Input";
import { useFormContext } from "react-hook-form";
 
type Props = {
  name: string;
  placeholder?: string;
  disabled?: boolean;
} & RHFInputProps;
 
const WebsiteInput = ({
  name,
  disabled = false,
  placeholder,
  ...props
}: Props) => {
  const { watch } = useFormContext();
 
  const prefix = "https://";
 
  return (
    <RHFInput
      name={name}
      label={props.label}
      placeholder={placeholder || "example.com"}
      fullWidth
      disabled={disabled}
      inputPrefix={prefix}
      endIcon={
        <CopyButton
          hidden={!watch(name)}
          text={prefix + watch(name) + (props?.inputSuffix || "")}
          testId={`copy-button-${
            typeof props.label === "string" ? props.label : name
          }`}
        />
      }
      {...props}
    />
  );
};
 
export default WebsiteInput;