@@ -8,10 +8,14 @@ import {
88} from '@ifrc-go/ui' ;
99import { useTranslation } from '@ifrc-go/ui/hooks' ;
1010import {
11+ addNumDaysToDate ,
1112 addNumMonthsToDate ,
1213 encodeDate ,
1314} from '@ifrc-go/ui/utils' ;
14- import { isDefined } from '@togglecorp/fujs' ;
15+ import {
16+ isDefined ,
17+ isNotDefined ,
18+ } from '@togglecorp/fujs' ;
1519import {
1620 type EntriesAsList ,
1721 type Error ,
@@ -64,15 +68,23 @@ function Submission(props: Props) {
6468 const handleOperationStartDateChange = useCallback (
6569 ( val : string | undefined , name : 'operation_start_date' ) => {
6670 setFieldValue ( val , name ) ;
67- const endDate = addNumMonthsToDate (
68- val ,
69- value . total_operation_timeframe ,
70- ) ;
71- if ( isDefined ( endDate ) ) {
71+ let endDate ;
72+ if ( value . type_of_dref === TYPE_IMMINENT ) {
73+ endDate = addNumDaysToDate (
74+ val ,
75+ value . total_operation_timeframe ,
76+ ) ;
77+ } else {
78+ endDate = addNumMonthsToDate (
79+ val ,
80+ value . total_operation_timeframe ,
81+ ) ;
82+ }
83+ if ( isNotDefined ( endDate ) ) {
7284 setFieldValue ( encodeDate ( endDate ) , 'operation_end_date' ) ;
7385 }
7486 } ,
75- [ setFieldValue , value . total_operation_timeframe ] ,
87+ [ setFieldValue , value . total_operation_timeframe , value . type_of_dref ] ,
7688 ) ;
7789
7890 return (
0 commit comments