Skip to content

Commit

Permalink
fix: show success messages for cost center buyer actions (#959, #1249)
Browse files Browse the repository at this point in the history
Co-authored-by: MStockmann <m.stockmann@intershop.de>
  • Loading branch information
DiverDori and martinstockmann authored Aug 31, 2022
1 parent ccc2ff5 commit 9e079a2
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('Cost Center Buyer Edit Dialog Component', () => {

form = fb.group({
login: ['jlink@test.intershop.de'],
firstName: ['Jack'],
lastName: ['Link'],
budgetValue: [123, [SpecialValidators.moneyAmount]],
budgetPeriod: ['monthly'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class CostCenterBuyerEditDialogComponent implements OnInit {

const changedBuyer: CostCenterBuyer = {
login: this.buyer.login,
firstName: this.buyer.firstName,
lastName: this.buyer.lastName,
budget: PriceHelper.getPrice(this.buyer.budget.currency, this.model.budgetValue ?? 0),
budgetPeriod: this.model.budgetPeriod,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ describe('Cost Centers Effects', () => {

effects.triggerLoadCostCenter$.subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[CostCenters] Load Cost Center:
costCenterId: "100400"
`);
[CostCenters] Load Cost Center:
costCenterId: "100400"
`);
done();
});
});
Expand Down Expand Up @@ -357,21 +357,13 @@ describe('Cost Centers Effects', () => {
it('should add costCenterBuyers when triggered', done => {
actions$ = of(addCostCenterBuyers({ costCenterId, buyers }));

effects.addCostCenterBuyers$.subscribe(action => {
expect(action.type).toMatchInlineSnapshot(`"[CostCenters API] Add Cost Center Buyers Success"`);
expect(action.payload).toMatchInlineSnapshot(`
Object {
"costCenter": Object {
"budget": Object {
"currency": "USD",
"value": 500,
},
"budgetPeriod": "monthly",
"costCenterId": "100400",
"id": "1",
"name": "Headquarter",
},
}
effects.addCostCenterBuyers$.pipe(toArray()).subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[CostCenters API] Add Cost Center Buyers Success:
costCenter: {"id":"1","costCenterId":"100400","name":"Headquarter","budg...
[Message] Success Toast:
message: "account.organization.cost_center_management.buyer.add.confi...
messageParams: {"0":"2"}
`);
done();
});
Expand Down Expand Up @@ -419,21 +411,13 @@ describe('Cost Centers Effects', () => {
it('should update a costCenterBuyer when triggered', done => {
actions$ = of(updateCostCenterBuyer({ costCenterId, buyer }));

effects.updateCostCenterBuyer$.subscribe(action => {
expect(action.type).toMatchInlineSnapshot(`"[CostCenters API] Update Cost Center Buyer Success"`);
expect(action.payload).toMatchInlineSnapshot(`
Object {
"costCenter": Object {
"budget": Object {
"currency": "USD",
"value": 500,
},
"budgetPeriod": "monthly",
"costCenterId": "100400",
"id": "1",
"name": "Headquarter",
},
}
effects.updateCostCenterBuyer$.pipe(toArray()).subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[CostCenters API] Update Cost Center Buyer Success:
costCenter: {"id":"1","costCenterId":"100400","name":"Headquarter","budg...
[Message] Success Toast:
message: "account.organization.cost_center_management.buyer.update.co...
messageParams: {"0":"undefined undefined"}
`);
done();
});
Expand Down Expand Up @@ -469,21 +453,13 @@ describe('Cost Centers Effects', () => {
it('should delete a costCenterBuyer when triggered', done => {
actions$ = of(deleteCostCenterBuyer({ costCenterId, login }));

effects.deleteCostCenterBuyer$.subscribe(action => {
expect(action.type).toMatchInlineSnapshot(`"[CostCenters API] Delete Cost Center Buyer Success"`);
expect(action.payload).toMatchInlineSnapshot(`
Object {
"costCenter": Object {
"budget": Object {
"currency": "USD",
"value": 500,
},
"budgetPeriod": "monthly",
"costCenterId": "100400",
"id": "1",
"name": "Headquarter",
},
}
effects.deleteCostCenterBuyer$.pipe(toArray()).subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[CostCenters API] Delete Cost Center Buyer Success:
costCenter: {"id":"1","costCenterId":"100400","name":"Headquarter","budg...
[Message] Success Toast:
message: "account.organization.cost_center_management.buyer.remove.co...
messageParams: {"0":"pmiller@test.intershop.de"}
`);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,17 @@ export class CostCentersEffects {
mapToPayload(),
mergeMap(payload =>
this.costCentersService.addCostCenterBuyers(payload.costCenterId, payload.buyers).pipe(
concatMap(costCenter => this.navigateTo('../').pipe(map(() => addCostCenterBuyersSuccess({ costCenter })))),
concatMap(costCenter =>
this.navigateTo('../').pipe(
mergeMap(() => [
addCostCenterBuyersSuccess({ costCenter }),
displaySuccessMessage({
message: 'account.organization.cost_center_management.buyer.add.confirmation',
messageParams: { 0: `${payload.buyers.length}` },
}),
])
)
),
mapErrorToAction(addCostCenterBuyersFail)
)
)
Expand All @@ -163,7 +173,13 @@ export class CostCentersEffects {
mapToPayload(),
mergeMap(payload =>
this.costCentersService.updateCostCenterBuyer(payload.costCenterId, payload.buyer).pipe(
map(costCenter => updateCostCenterBuyerSuccess({ costCenter })),
mergeMap(costCenter => [
updateCostCenterBuyerSuccess({ costCenter }),
displaySuccessMessage({
message: 'account.organization.cost_center_management.buyer.update.confirmation',
messageParams: { 0: `${payload.buyer.firstName} ${payload.buyer.lastName}` || `${payload.buyer.login}` },
}),
]),
mapErrorToAction(updateCostCenterBuyerFail)
)
)
Expand All @@ -176,7 +192,13 @@ export class CostCentersEffects {
mapToPayload(),
mergeMap(payload =>
this.costCentersService.deleteCostCenterBuyer(payload.costCenterId, payload.login).pipe(
map(costCenter => deleteCostCenterBuyerSuccess({ costCenter })),
mergeMap(costCenter => [
deleteCostCenterBuyerSuccess({ costCenter }),
displaySuccessMessage({
message: 'account.organization.cost_center_management.buyer.remove.confirmation',
messageParams: { 0: `${payload.login}` },
}),
]),
mapErrorToAction(deleteCostCenterBuyerFail)
)
)
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 @@ -255,6 +255,9 @@
"account.ordertemplates.widget.view_all.link": "Alle Bestellvorlagen ansehen",
"account.organization.cost_center_management": "Kostenstellenverwaltung",
"account.organization.cost_center_management.back_to_list": "Zurück zur Kostenstellenverwaltung",
"account.organization.cost_center_management.buyer.add.confirmation": "{{0, plural, one{# Einkäufer wurde der Kostenstelle hinzugefügt.} other{# Einkäufer wurden der Kostenstelle hinzugefügt.}}}",
"account.organization.cost_center_management.buyer.remove.confirmation": "Der Benutzer \"{{0}}\" wurde aus der Kostenstelle entfernt.",
"account.organization.cost_center_management.buyer.update.confirmation": "Das Budget des Benutzers \"{{0}}\" wurde aktualisiert.",
"account.organization.cost_center_management.create.confirmation": "Die Kostenstelle \"{{0}}\" wurde erstellt.",
"account.organization.cost_center_management.delete.confirmation": "Die Kostenstelle wurde gelöscht.",
"account.organization.cost_center_management.update.confirmation": "Die Kostenstelle \"{{0}}\" wurde geändert.",
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 @@ -255,6 +255,9 @@
"account.ordertemplates.widget.view_all.link": "View All Order Templates",
"account.organization.cost_center_management": "Cost Center Management",
"account.organization.cost_center_management.back_to_list": "Back to Cost Center Management",
"account.organization.cost_center_management.buyer.add.confirmation": "{{0, plural, one{# buyer has been added to the cost center.} other{# buyers have been added to the cost center.}}}",
"account.organization.cost_center_management.buyer.remove.confirmation": "The user \"{{0}}\" has been removed from the cost center.",
"account.organization.cost_center_management.buyer.update.confirmation": "The budget of user \"{{0}}\" has been updated.",
"account.organization.cost_center_management.create.confirmation": "The cost center \"{{0}}\" has been created.",
"account.organization.cost_center_management.delete.confirmation": "The cost center has been deleted.",
"account.organization.cost_center_management.update.confirmation": "The cost center \"{{0}}\" has been updated.",
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 @@ -255,6 +255,9 @@
"account.ordertemplates.widget.view_all.link": "Afficher tous les modèles de commande",
"account.organization.cost_center_management": "Gestion des centres de coûts",
"account.organization.cost_center_management.back_to_list": "Retourner à la gestion des centres de coûts",
"account.organization.cost_center_management.buyer.add.confirmation": "{{0, plural, one{# acheteur a été ajouté au centre de coût.} other{# acheteurs ont été ajoutés au centre de coût.}}}",
"account.organization.cost_center_management.buyer.remove.confirmation": "L’utilisateur \"{{0}}\" a été supprimé du centre de coûts.",
"account.organization.cost_center_management.buyer.update.confirmation": "Le budget de l’utilisateur \"{{0}}\" a été mis à jour.",
"account.organization.cost_center_management.create.confirmation": "Le centre de coûts \"{{0}}\" a été créé.",
"account.organization.cost_center_management.delete.confirmation": "Le centre de coûts a été supprimé.",
"account.organization.cost_center_management.update.confirmation": "Le centre de coûts \"{{0}}\" a été mise à jour.",
Expand Down

0 comments on commit 9e079a2

Please sign in to comment.