teqo-backup/src/components/FormInput.tsx
Francisco Ignácio Fontoura Solla bcac665cb5 Ship /campanha nuclei MVP with RBAC, invites, and vote estimates.
Adds electoral nuclei, leaderships, updates, and WhatsApp invite flows behind campaign auth, plus the consolidated schema migration that Vercel applies on deploy.
2026-07-18 15:01:56 -03:00

41 lines
991 B
TypeScript

'use client'
import type { ComponentProps } from 'react'
import { type FieldPath, type FieldValues, useFormContext } from 'react-hook-form'
import { FormattedInput } from '@/components/FormattedInput'
interface FormInputProps<
TFieldValues extends FieldValues,
TFieldName extends FieldPath<TFieldValues>,
> extends ComponentProps<'input'> {
name: TFieldName
format?: (value: string) => string
sanitize?: (value: string) => string
}
export const FormInput = <
TFieldValues extends FieldValues,
TFieldName extends FieldPath<TFieldValues>,
>({
name,
format,
sanitize,
...props
}: FormInputProps<TFieldValues, TFieldName>) => {
const { onChange, onBlur, ...registerResult } = useFormContext<TFieldValues>().register(
name,
sanitize ? { setValueAs: sanitize } : undefined,
)
return (
<FormattedInput
{...props}
{...registerResult}
format={format}
sanitize={sanitize}
onInput={onChange}
onBlur={onBlur}
/>
)
}