diff --git a/frontend/src/shared/components/DueDateManager/index.tsx b/frontend/src/shared/components/DueDateManager/index.tsx index a49bc6f..a9a2915 100644 --- a/frontend/src/shared/components/DueDateManager/index.tsx +++ b/frontend/src/shared/components/DueDateManager/index.tsx @@ -111,17 +111,13 @@ const HeaderActions = styled.div` const DueDateManager: React.FC = ({ task, onDueDateChange, onRemoveDueDate, onCancel }) => { const now = moment(); - const [textStartDate, setTextStartDate] = useState(now.format('YYYY-MM-DD')); + const { register, handleSubmit, errors, setValue, setError, formState, control } = useForm(); const [startDate, setStartDate] = useState(new Date()); - useEffect(() => { - setTextStartDate(moment(startDate).format('YYYY-MM-DD')); - }, [startDate]); - const [textEndTime, setTextEndTime] = useState(now.format('h:mm A')); - const [endTime, setEndTime] = useState(now.toDate()); useEffect(() => { - setTextEndTime(moment(endTime).format('h:mm A')); - }, [endTime]); + const newDate = moment(startDate).format('YYYY-MM-DD'); + setValue('endDate', newDate); + }, [startDate]); const years = _.range(2010, getYear(new Date()) + 10, 1); const months = [ @@ -138,9 +134,8 @@ const DueDateManager: React.FC = ({ task, onDueDateChange, 'November', 'December', ]; - const { register, handleSubmit, errors, setValue, setError, formState, control } = useForm(); const saveDueDate = (data: any) => { - const newDate = moment(`${data.endDate} ${data.endTime}`, 'YYYY-MM-DD h:mm A'); + const newDate = moment(`${data.endDate} ${moment(data.endTime).format('h:mm A')}`, 'YYYY-MM-DD h:mm A'); if (newDate.isValid()) { onDueDateChange(task, newDate.toDate()); } @@ -149,11 +144,12 @@ const DueDateManager: React.FC = ({ task, onDueDateChange, return ( ); @@ -168,7 +164,7 @@ const DueDateManager: React.FC = ({ task, onDueDateChange, width="100%" variant="alternate" label="Date" - defaultValue={textStartDate} + defaultValue={now.format('YYYY-MM-DD')} ref={register({ required: 'End date is required.', })} @@ -177,6 +173,7 @@ const DueDateManager: React.FC = ({ task, onDueDateChange, ( = ({ task, onDueDateChange, selected={startDate} inline onChange={date => { - setStartDate(date ?? new Date()); + if (date) { + setStartDate(date); + } }} /> diff --git a/frontend/src/shared/components/Input/index.tsx b/frontend/src/shared/components/Input/index.tsx index 2e82d3d..69e8c76 100644 --- a/frontend/src/shared/components/Input/index.tsx +++ b/frontend/src/shared/components/Input/index.tsx @@ -91,6 +91,7 @@ type InputProps = { name?: string; className?: string; defaultValue?: string; + value?: string; onClick?: (e: React.MouseEvent) => void; }; @@ -129,6 +130,7 @@ const Input = React.forwardRef( onClick, floatingLabel, defaultValue, + value, id, }: InputProps, $ref: any, @@ -166,6 +168,7 @@ const Input = React.forwardRef( onClick={onClick} autoComplete={autocomplete ? 'on' : 'off'} defaultValue={defaultValue} + value={value} hasIcon={typeof icon !== 'undefined'} width={width} placeholder={placeholder}