Rev 3391 | Rev 3393 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import { Controller } from 'react-hook-form'
import { InputLabel } from '@mui/material'
import Datetime from 'react-datetime'
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback'
import 'react-datetime/css/react-datetime.css'
export default function DatetimePicker({
control,
rules,
name = '',
label = '',
displayTime = false,
dateFormat = 'DD-MM-YYYY',
parseFormat = 'YYYY-MM-DD',
defaultValue
}) {
return (
<Controller
name={name}
control={control}
rules={rules}
render={({
field: { onChange, ref, value, name },
fieldState: { error }
}) => (
<>
{label && <InputLabel>{label}</InputLabel>}
<Datetime
dateFormat={dateFormat}
onChange={(e) => onChange(e.format(parseFormat))}
timeFormat={displayTime}
inputProps={{ className: 'form-control', ref, name }}
value={value}
initialValue={defaultValue}
closeOnSelect
/>
{error && <FormErrorFeedback>{error.message}</FormErrorFeedback>}
</>
)}
/>
)
}