From 47782d6d8625bb685b5e3a6b5092425d77cd305b Mon Sep 17 00:00:00 2001 From: Jordan Knott Date: Fri, 28 Aug 2020 20:59:45 -0500 Subject: [PATCH] fix: due date manager now sends the correct new due date --- .../components/DueDateManager/index.tsx | 25 +++++++++---------- .../src/shared/components/Input/index.tsx | 3 +++ 2 files changed, 15 insertions(+), 13 deletions(-) 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}