import { useId } from "@radix-ui/react-id"; import React, { forwardRef, ReactElement, ReactNode, Ref } from "react"; import { Check, Circle, Info, X } from "react-feather"; import { FieldErrors, FieldValues, FormProvider, SubmitHandler, useFormContext, UseFormReturn, } from "react-hook-form"; import classNames from "@calcom/lib/classNames"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/ui/v2/notfications"; import { Alert } from "../Alert"; type InputProps = Omit & { name: string }; export const Input = forwardRef(function Input(props, ref) { return ( ); }); export function Label(props: JSX.IntrinsicElements["label"]) { return ( ); } function HintsOrErrors(props: { hintErrors?: string[]; fieldName: string; t: (key: string) => string; }) { const methods = useFormContext() as ReturnType | null; /* If there's no methods it means we're using these components outside a React Hook Form context */ if (!methods) return null; const { formState } = methods; const { hintErrors, fieldName, t } = props; const fieldErrors: FieldErrors | undefined = formState.errors[fieldName]; if (!hintErrors && fieldErrors && !fieldErrors.message) { // no hints passed, field errors exist and they are custom ones return (
    {Object.keys(fieldErrors).map((key: string) => { return (
  • {t(`${fieldName}_hint_${key}`)}
  • ); })}
); } if (hintErrors && fieldErrors) { // hints passed, field errors exist return (
    {hintErrors.map((key: string) => { const submitted = formState.isSubmitted; const error = fieldErrors[key] || fieldErrors.message; return (
  • {error !== undefined ? ( submitted ? ( ) : ( ) ) : ( )} {t(`${fieldName}_hint_${key}`)}
  • ); })}
); } // errors exist, not custom ones, just show them as is if (fieldErrors) { return (
{fieldErrors.message}
); } if (!hintErrors) return null; // hints passed, no errors exist, proceed to just show hints return (
    {hintErrors.map((key: string) => { // if field was changed, as no error exist, show checked status and color const dirty = formState.dirtyFields[fieldName]; return (
  • {!!dirty ? ( ) : ( )} {t(`${fieldName}_hint_${key}`)}
  • ); })}
); } export function InputLeading(props: JSX.IntrinsicElements["div"]) { return ( {props.children} ); } type InputFieldProps = { label?: ReactNode; hint?: ReactNode; hintErrors?: string[]; addOnLeading?: ReactNode; addOnSuffix?: ReactNode; addOnFilled?: boolean; error?: string; labelSrOnly?: boolean; containerClassName?: string; t?: (key: string) => string; } & React.ComponentProps & { labelProps?: React.ComponentProps; }; const InputField = forwardRef(function InputField(props, ref) { const id = useId(); const { t: _t } = useLocale(); const t = props.t || _t; const { label = t(props.name), labelProps, /** Prevents displaying untranslated placeholder keys */ placeholder = t(props.name + "_placeholder") !== props.name + "_placeholder" ? t(props.name + "_placeholder") : "", className, addOnLeading, addOnSuffix, addOnFilled = true, hint, hintErrors, labelSrOnly, containerClassName, // eslint-disable-next-line @typescript-eslint/no-unused-vars t: __t, ...passThrough } = props; return (
{!!props.name && ( )} {addOnLeading || addOnSuffix ? (
{addOnLeading || addOnSuffix}
) : ( )} {hint &&
{hint}
}
); }); export const TextField = forwardRef(function TextField(props, ref) { return ; }); export const PasswordField = forwardRef(function PasswordField( props, ref ) { return ; }); export const EmailInput = forwardRef(function EmailInput(props, ref) { return ( ); }); export const EmailField = forwardRef(function EmailField(props, ref) { return ( ); }); type TextAreaProps = Omit & { name: string }; export const TextArea = forwardRef(function TextAreaInput(props, ref) { return (