diff --git a/front/app/containers/Admin/projects/project/timeline/edit.tsx b/front/app/containers/Admin/projects/project/timeline/edit.tsx index db6a295f94c9..506d4fdcbf3e 100644 --- a/front/app/containers/Admin/projects/project/timeline/edit.tsx +++ b/front/app/containers/Admin/projects/project/timeline/edit.tsx @@ -14,6 +14,7 @@ import { IconTooltip, colors, } from '@citizenlab/cl2-component-library'; +import { isEmpty } from 'lodash-es'; import moment, { Moment } from 'moment'; import { useParams } from 'react-router-dom'; import { CLErrors, UploadFile, Multiloc } from 'typings'; @@ -362,47 +363,49 @@ const AdminPhaseEdit = () => { phase: IPhaseData | undefined, attributeDiff: IUpdatedPhaseProperties ) => { - if (!processing) { + if (!isEmpty(attributeDiff) && !processing) { setProcessing(true); - const start = getStartDate(); - const end = phaseAttrs.end_at ? moment(phaseAttrs.end_at) : null; - - // If the start date was automatically calculated, we need to update the dates in submit if even if the user didn't change them - const updatedAttr = { - ...attributeDiff, - ...(!attributeDiff.start_at && - start && { - start_at: start.locale('en').format('YYYY-MM-DD'), - end_at: - attributeDiff.end_at || - (end ? end.locale('en').format('YYYY-MM-DD') : ''), - }), - }; - - if (phase) { - updatePhase( - { phaseId: phase.id, ...updatedAttr }, - { - onSuccess: (response) => { - handleSaveResponse(response, false); - }, - onError: handleError, - } - ); - } else if (projectId) { - addPhase( - { - projectId, - campaigns_settings: initialCampaignsSettings, - ...updatedAttr, - }, - { - onSuccess: (response) => { - handleSaveResponse(response, true); + if (!isEmpty(attributeDiff)) { + const start = getStartDate(); + const end = phaseAttrs.end_at ? moment(phaseAttrs.end_at) : null; + + // If the start date was automatically calculated, we need to update the dates in submit if even if the user didn't change them + const updatedAttr = { + ...attributeDiff, + ...(!attributeDiff.start_at && + start && { + start_at: start.locale('en').format('YYYY-MM-DD'), + end_at: + attributeDiff.end_at || + (end ? end.locale('en').format('YYYY-MM-DD') : ''), + }), + }; + + if (phase) { + updatePhase( + { phaseId: phase.id, ...updatedAttr }, + { + onSuccess: (response) => { + handleSaveResponse(response, false); + }, + onError: handleError, + } + ); + } else if (projectId) { + addPhase( + { + projectId, + campaigns_settings: initialCampaignsSettings, + ...updatedAttr, }, - onError: handleError, - } - ); + { + onSuccess: (response) => { + handleSaveResponse(response, true); + }, + onError: handleError, + } + ); + } } } };