diff --git a/src/components/Utils/ControlledDateTimePicker.tsx b/src/components/Utils/ControlledDateTimePicker.tsx new file mode 100644 index 0000000000000000000000000000000000000000..e649ffcffb6a08ae9ba1131f09517b9ffa2181cd --- /dev/null +++ b/src/components/Utils/ControlledDateTimePicker.tsx @@ -0,0 +1,35 @@ +/* eslint-disable react/jsx-props-no-spreading */ +import React, { FC } from 'react'; +import { Control, Controller, FieldValues } from 'react-hook-form'; +import { KeyboardDateTimePicker } from '@material-ui/pickers/DateTimePicker/DateTimePicker'; + +type DateTimePickerPropsType = { + control: Control<FieldValues>; + name: string; + label: string; + id: string; +}; + +export const ControlledDateTimePicker: FC<DateTimePickerPropsType> = ({ + control, + name, + label, + id, +}: DateTimePickerPropsType) => ( + <Controller + control={control} + name={name} + as={({ ref, ...rest }) => ( + <KeyboardDateTimePicker + margin="normal" + id={id} + label={label} + format="dd/MM/yyyy" + KeyboardButtonProps={{ + 'aria-label': { label }, + }} + {...rest} + /> + )} + /> +);