import { IDateInput } from '../../../../interfaces/dialog'; import { Control, useController } from 'react-hook-form'; import { FormValues } from '../../InputDialog'; import { DatePicker, DateRangePicker, TimeInput } from '@mantine/dates'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { row: IDateInput; index: number; control: Control; } const DateField: React.FC = (props) => { const controller = useController({ name: `test.${props.index}.value`, control: props.control, rules: { required: props.row.required }, }); return ( <> {props.row.type === 'date' && ( controller.field.onChange(date ? date.getTime() : null)} label={props.row.label} description={props.row.description} placeholder={props.row.placeholder} disabled={props.row.disabled} inputFormat="DD/MM/YYYY" withAsterisk={props.row.required} clearable={props.row.clearable} icon={props.row.icon && } minDate={props.row.min ? new Date(props.row.min) : undefined} maxDate={props.row.max ? new Date(props.row.max) : undefined} /> )} {props.row.type === 'date-range' && ( new Date(date)) : controller.field.value : controller.field.value } name={controller.field.name} ref={controller.field.ref} onBlur={controller.field.onBlur} onChange={(dates) => controller.field.onChange(dates.map((date: Date | null) => (date ? date.getTime() : null))) } label={props.row.label} description={props.row.description} placeholder={props.row.placeholder} disabled={props.row.disabled} inputFormat="DD/MM/YYYY" withAsterisk={props.row.required} clearable={props.row.clearable} icon={props.row.icon && } minDate={props.row.min ? new Date(props.row.min) : undefined} maxDate={props.row.max ? new Date(props.row.max) : undefined} /> )} ); }; export default DateField;