Skip to content

Commit

Permalink
feat: display a success/info message after a requisition has been app…
Browse files Browse the repository at this point in the history
…roved/rejected (#887)
  • Loading branch information
SGrueber committed Oct 22, 2021
1 parent 1fb61f3 commit 9846c87
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouterTestingModule } from '@angular/router/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { toArray } from 'rxjs/operators';
import { anyString, anything, instance, mock, verify, when } from 'ts-mockito';

import { LineItem } from 'ish-core/models/line-item/line-item.model';
Expand Down Expand Up @@ -152,18 +153,20 @@ describe('Requisitions Effects', () => {
});

it('should retrieve the requisition after updating the status', done => {
effects.updateRequisitionStatus$.subscribe(action => {
effects.updateRequisitionStatus$.pipe(toArray()).subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[Requisitions API] Update Requisition Status Success:
requisition: {"id":"testUUID","requisitionNo":"0001","user":{"firstName":...
[Message] Info Toast:
message: "approval.order_partially_approved.text"
`);
done();
});
});

it('should redirect to listing', done => {
effects.updateRequisitionStatus$.subscribe(() => {
expect(location.path()).toMatchInlineSnapshot(`"/account/requisitions/approver/testUUID;status=PENDING"`);
expect(location.path()).toEqual(`/account/requisitions/approver/testUUID;status=PENDING`);
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { from } from 'rxjs';
import { concatMap, map, mapTo, switchMap } from 'rxjs/operators';
import { concatMap, map, switchMap } from 'rxjs/operators';

import { ProductCompletenessLevel } from 'ish-core/models/product/product.model';
import { displayInfoMessage, displaySuccessMessage } from 'ish-core/store/core/messages';
import { loadProductIfNotLoaded } from 'ish-core/store/shopping/products';
import { mapErrorToAction, mapToPayload, mapToPayloadProperty } from 'ish-core/utils/operators';

Expand Down Expand Up @@ -83,7 +84,25 @@ export class RequisitionsEffects {
`/account/requisitions/approver/${requisition.id}`,
{ status: requisition.approval?.statusCode },
])
).pipe(mapTo(updateRequisitionStatusSuccess({ requisition })))
).pipe(
concatMap(() => {
let messageAction;
switch (requisition.approval?.statusCode) {
case 'APPROVED':
case 'REJECTED':
messageAction = displaySuccessMessage({
message: `approval.order_${requisition.approval.statusCode.toLowerCase()}.text`,
});
break;
case 'PENDING':
messageAction = displayInfoMessage({
message: `approval.order_partially_approved.text`,
});
}

return [updateRequisitionStatusSuccess({ requisition }), messageAction];
})
)
),
mapErrorToAction(updateRequisitionStatusFail)
)
Expand Down
1 change: 1 addition & 0 deletions scripts/clean-up-localizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const regExps = [
/^account\.budget\.type\..*/i,
/.*\.error.*/i,
/^locale\..*/i,
/^approval\.order_.*\.text/i,
];

// store localizations from default localization file in an object
Expand Down
3 changes: 3 additions & 0 deletions src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@
"approval.detailspage.reject.button.label": "Ablehnen",
"approval.detailspage.rejection_date.label": "Datum der Ablehnung",
"approval.detailspage.requisition.heading": "Bestellanfrage-Details",
"approval.order_approved.text": "Die Bestellanfrage wurde genehmigt.",
"approval.order_partially_approved.text": "Die Bestellanfrage muss noch von einem anderen Benutzer genehmigt werden. Sie wird erst nach der vollständigen Genehmigung in der Liste der genehmigten Bestellanfragen erscheinen.",
"approval.order_rejected.text": "Die Bestellanfrage wurde abgelehnt.",
"approval.rejectform.add_a_comment.label": "Kommentar hinzufügen",
"approval.rejectform.button.cancel.label": "Abbrechen",
"approval.rejectform.button.reject.label": "Ablehnen",
Expand Down
3 changes: 3 additions & 0 deletions src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@
"approval.detailspage.reject.button.label": "Reject",
"approval.detailspage.rejection_date.label": "Date of Rejection",
"approval.detailspage.requisition.heading": "Requisition Details",
"approval.order_approved.text": "The requisition has been approved.",
"approval.order_partially_approved.text": "The requisition still needs approval from another user. It will appear in the list of approved requisitions only after being approved completely.",
"approval.order_rejected.text": "The requisition has been rejected.",
"approval.rejectform.add_a_comment.label": "Add a Comment",
"approval.rejectform.button.cancel.label": "Cancel",
"approval.rejectform.button.reject.label": "Reject",
Expand Down
3 changes: 3 additions & 0 deletions src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@
"approval.detailspage.reject.button.label": "Rejeter",
"approval.detailspage.rejection_date.label": "Date de rejet",
"approval.detailspage.requisition.heading": "Détails de la demande",
"approval.order_approved.text": "La demande d’achat a été approuvée.",
"approval.order_partially_approved.text": "La demande d’achat doit encore être approuvée par un utilisateur. Elle ne figurera sur la liste des demandes d’achats qu’après l’approbation absolue.",
"approval.order_rejected.text": "La demande d’achat a été rejetée.",
"approval.rejectform.add_a_comment.label": "Ajouter un commentaire",
"approval.rejectform.button.cancel.label": "Annuler",
"approval.rejectform.button.reject.label": "Rejeter",
Expand Down

0 comments on commit 9846c87

Please sign in to comment.