Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2024-08-02 (3) #8578

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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