Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion intervention-actions/intervention-actions.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const AMENDMENT_MERGE = 'amendment_merge';
export const TERMINATE = 'terminate';
export const REJECT_REVIEW = 'reject_review';
export const ACCEPT_ON_BEHALF_OF_PARTNER = 'accept_on_behalf_of_partner';
export const DELETE = 'delete';

export const EXPORT_ACTIONS = [EXPORT_PDF, EXPORT_XLS, EXPORT_COMMENTS, EXPORT_RESULTS];
export const BACK_ACTIONS = [SEND_TO_PARTNER, SEND_TO_UNICEF, UNLOCK, REJECT_REVIEW];
Expand Down Expand Up @@ -51,5 +52,6 @@ export const ActionNamesMap: GenericObject<string> = {
[SIGN_BUDGET_OWNER]: getTranslation('SIGN_BUDGET_OWNER'),
[TERMINATE]: getTranslation('TERMINATE'),
[REJECT_REVIEW]: getTranslation('REJECT_REVIEW'),
[ACCEPT_ON_BEHALF_OF_PARTNER]: getTranslation('ACCEPT_ON_BEHALF_OF_PARTNER')
[ACCEPT_ON_BEHALF_OF_PARTNER]: getTranslation('ACCEPT_ON_BEHALF_OF_PARTNER'),
[DELETE]: getTranslation('DELETE')
};
45 changes: 38 additions & 7 deletions intervention-actions/intervention-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import {
REVIEW,
SIGN,
ACCEPT_ON_BEHALF_OF_PARTNER,
SIGN_BUDGET_OWNER
SIGN_BUDGET_OWNER,
DELETE
} from './intervention-actions.constants';
import {PaperMenuButton} from '@polymer/paper-menu-button/paper-menu-button';
import {updateCurrentIntervention} from '../common/actions/interventions';
import {setShouldReGetList, updateCurrentIntervention} from '../common/actions/interventions';
import {getStore} from '@unicef-polymer/etools-modules-common/dist/utils/redux-store-access';
import {defaultKeyTranslate, formatServerErrorAsText} from '@unicef-polymer/etools-ajax/ajax-error-parser';
import {GenericObject} from '@unicef-polymer/etools-types';
Expand Down Expand Up @@ -206,22 +207,21 @@ export class InterventionActions extends LitElement {
return;
}

const endpoint = getEndpoint(interventionEndpoints.interventionAction, {
interventionId: this.interventionPartial.id,
action
});
const endpoint = this.determineEndpoint(action);
fireEvent(this, 'global-loading', {
active: true,
loadingSource: 'intervention-actions'
});
sendRequest({
endpoint,
body,
method: 'PATCH'
method: action === DELETE ? 'DELETE' : 'PATCH'
})
.then((intervention: Intervention) => {
if (action === AMENDMENT_MERGE) {
this.redirectToTabPage(intervention.id, 'metadata');
} else if (action === DELETE) {
this.handlePDDeleted();
} else {
getStore().dispatch(updateCurrentIntervention(intervention));
if (action === REVIEW) {
Expand All @@ -244,6 +244,32 @@ export class InterventionActions extends LitElement {
});
});
}
private handlePDDeleted() {
fireEvent(this, 'global-loading', {
active: false,
loadingSource: 'intervention-actions'
});

if (window.location.href.includes('/pmp/')) {
fireEvent(this, 'intervention-deleted', {
id: this.interventionPartial.id
});
} else {
getStore().dispatch(setShouldReGetList(true));
fireEvent(this, 'toast', {
text: 'PD/SPD successfully deleted.',
showCloseBtn: true
});
this.redirectToList();
}
}

determineEndpoint(action: string) {
return getEndpoint(interventionEndpoints.interventionAction, {
interventionId: this.interventionPartial.id,
action
});
}

private isActionWithInput(action: string) {
if (ACTIONS_WITH_INPUT.includes(action)) {
Expand All @@ -262,6 +288,11 @@ export class InterventionActions extends LitElement {
window.dispatchEvent(new CustomEvent('popstate'));
}

private redirectToList() {
history.pushState(window.history.state, '', `${ROOT_PATH}interventions/list`);
window.dispatchEvent(new CustomEvent('popstate'));
}

private openCommentDialog(action: string): Promise<any> {
return openDialog({
dialog: 'reason-popup',
Expand Down