Skip to content

Commit

Permalink
Merge pull request #8578 from CitizenLabDotCo/master
Browse files Browse the repository at this point in the history
 Release 2024-08-02 (3)
  • Loading branch information
EdwinKato authored Aug 2, 2024
2 parents 87225ec + 7d2b1a2 commit 4efb0f9
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions front/app/containers/Admin/projects/project/timeline/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
}
);
}
}
}
};
Expand Down

0 comments on commit 4efb0f9

Please sign in to comment.