Skip to content

Commit e0974fa

Browse files
committed
DRY distro emails & tweak notifier descriptions
1 parent 13e67c3 commit e0974fa

File tree

2 files changed

+50
-74
lines changed

2 files changed

+50
-74
lines changed

src/components/project/workflow/project-workflow.ts

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ResolveParams,
1414
} from './transitions/dynamic-step';
1515
import {
16-
EmailDistros,
16+
EmailDistro,
1717
FinancialApprovers,
1818
TeamMembers,
1919
} from './transitions/notifiers';
@@ -22,6 +22,16 @@ import {
2222
// Therefore, these should generally flow down.
2323
// "Back" transitions should come before/above "forward" transitions.
2424

25+
const Distros = {
26+
Projects: EmailDistro('[email protected]'),
27+
Approval: EmailDistro('[email protected]'),
28+
Extension: EmailDistro('[email protected]'),
29+
Revision: EmailDistro('[email protected]'),
30+
Suspension: EmailDistro('[email protected]'),
31+
Termination: EmailDistro('[email protected]'),
32+
Closing: EmailDistro('[email protected]'),
33+
};
34+
2535
export const ProjectWorkflow = defineWorkflow({
2636
id: '8297b9a1-b50b-4ec9-9021-a0347424b3ec',
2737
name: 'Project',
@@ -254,10 +264,7 @@ export const ProjectWorkflow = defineWorkflow({
254264
to: Step.Active,
255265
label: 'Confirm Project 🎉',
256266
type: Type.Approve,
257-
notifiers: [
258-
FinancialApprovers,
259-
260-
],
267+
notifiers: [FinancialApprovers, Distros.Approval, Distros.Projects],
261268
},
262269
'Pending Finance Confirmation -> Pending Regional Director Approval': {
263270
from: Step.PendingFinanceConfirmation,
@@ -306,30 +313,21 @@ export const ProjectWorkflow = defineWorkflow({
306313
to: Step.DiscussingChangeToPlan,
307314
label: 'Discuss Change to Plan',
308315
type: Type.Neutral,
309-
notifiers: [
310-
FinancialApprovers,
311-
312-
],
316+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
313317
},
314318
'Active -> Discussing Termination': {
315319
from: [Step.Active, Step.ActiveChangedPlan],
316320
to: Step.DiscussingTermination,
317321
label: 'Discuss Termination',
318322
type: Type.Neutral,
319-
notifiers: [
320-
FinancialApprovers,
321-
322-
],
323+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
323324
},
324325
'Active -> Finalizing Completion': {
325326
from: [Step.Active, Step.ActiveChangedPlan],
326327
to: Step.FinalizingCompletion,
327328
label: 'Finalize Completion',
328329
type: Type.Approve,
329-
notifiers: [
330-
FinancialApprovers,
331-
332-
],
330+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
333331
},
334332

335333
// Disucssing Change To Plan
@@ -338,27 +336,21 @@ export const ProjectWorkflow = defineWorkflow({
338336
to: Step.PendingChangeToPlanApproval,
339337
label: 'Submit for Approval',
340338
type: Type.Approve,
341-
notifiers: [
342-
343-
],
339+
notifiers: [Distros.Extension, Distros.Revision],
344340
},
345341
'Discussing Change To Plan -> Discussing Suspension': {
346342
from: Step.DiscussingChangeToPlan,
347343
to: Step.DiscussingSuspension,
348344
label: 'Discuss Suspension',
349345
type: Type.Neutral,
350-
notifiers: [
351-
352-
],
346+
notifiers: [Distros.Extension, Distros.Revision],
353347
},
354348
'Discussing Change To Plan -> Back To Active': {
355349
from: Step.DiscussingChangeToPlan,
356350
to: BackToActive,
357351
label: 'Will Not Change Plan',
358352
type: Type.Neutral,
359-
notifiers: [
360-
361-
],
353+
notifiers: [Distros.Extension, Distros.Revision],
362354
},
363355

364356
// Pending Change To Plan Approval
@@ -367,30 +359,21 @@ export const ProjectWorkflow = defineWorkflow({
367359
to: Step.DiscussingChangeToPlan,
368360
label: 'Send Back for Corrections',
369361
type: Type.Reject,
370-
notifiers: EmailDistros(
371-
372-
373-
),
362+
notifiers: [Distros.Extension, Distros.Revision],
374363
},
375364
'Pending Change To Plan Approval -> Pending Change To Plan Confirmation': {
376365
from: Step.PendingChangeToPlanApproval,
377366
to: Step.PendingChangeToPlanConfirmation,
378367
label: 'Approve Change to Plan',
379368
type: Type.Approve,
380-
notifiers: EmailDistros(
381-
382-
383-
),
369+
notifiers: [Distros.Extension, Distros.Revision],
384370
},
385371
'Pending Change To Plan Approval -> Back To Active': {
386372
from: Step.PendingChangeToPlanApproval,
387373
to: BackToActive,
388374
label: 'Reject Change to Plan',
389375
type: Type.Reject,
390-
notifiers: EmailDistros(
391-
392-
393-
),
376+
notifiers: [Distros.Extension, Distros.Revision],
394377
},
395378

396379
// Pending Change To Plan Confirmation
@@ -399,30 +382,21 @@ export const ProjectWorkflow = defineWorkflow({
399382
to: Step.DiscussingChangeToPlan,
400383
label: 'Send Back for Corrections',
401384
type: Type.Reject,
402-
notifiers: [
403-
FinancialApprovers,
404-
405-
],
385+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
406386
},
407387
'Pending Change To Plan Confirmation -> Active Changed Plan': {
408388
from: Step.PendingChangeToPlanConfirmation,
409389
to: Step.ActiveChangedPlan,
410390
label: 'Approve Change to Plan',
411391
type: Type.Approve,
412-
notifiers: [
413-
FinancialApprovers,
414-
415-
],
392+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
416393
},
417394
'Pending Change To Plan Confirmation -> Back To Active': {
418395
from: Step.PendingChangeToPlanConfirmation,
419396
to: BackToActive,
420397
label: 'Reject Change to Plan',
421398
type: Type.Reject,
422-
notifiers: [
423-
FinancialApprovers,
424-
425-
],
399+
notifiers: [FinancialApprovers, Distros.Extension, Distros.Revision],
426400
},
427401

428402
// Discussing Suspension
@@ -431,14 +405,14 @@ export const ProjectWorkflow = defineWorkflow({
431405
to: Step.PendingSuspensionApproval,
432406
label: 'Submit for Approval',
433407
type: Type.Neutral,
434-
notifiers: EmailDistros('[email protected]'),
408+
notifiers: Distros.Suspension,
435409
},
436410
'Discussing Suspension -> Back To Active': {
437411
from: Step.DiscussingSuspension,
438412
to: BackToActive,
439413
label: 'Will Not Suspend',
440414
type: Type.Neutral,
441-
notifiers: EmailDistros('[email protected]'),
415+
notifiers: Distros.Suspension,
442416
},
443417

444418
// Pending Suspension Approval
@@ -447,21 +421,21 @@ export const ProjectWorkflow = defineWorkflow({
447421
to: Step.DiscussingSuspension,
448422
label: 'Send Back for Corrections',
449423
type: Type.Reject,
450-
notifiers: EmailDistros('[email protected]'),
424+
notifiers: Distros.Suspension,
451425
},
452426
'Pending Suspension Approval -> Suspended': {
453427
from: Step.PendingSuspensionApproval,
454428
to: Step.Suspended,
455429
label: 'Approve Suspension',
456430
type: Type.Approve,
457-
notifiers: EmailDistros('[email protected]'),
431+
notifiers: Distros.Suspension,
458432
},
459433
'Pending Suspension Approval -> Back To Active': {
460434
from: Step.PendingSuspensionApproval,
461435
to: BackToActive,
462436
label: 'Reject Suspension',
463437
type: Type.Reject,
464-
notifiers: EmailDistros('[email protected]'),
438+
notifiers: Distros.Suspension,
465439
},
466440

467441
// Suspended
@@ -470,14 +444,14 @@ export const ProjectWorkflow = defineWorkflow({
470444
to: Step.DiscussingReactivation,
471445
label: 'Discuss Reactivation',
472446
type: Type.Neutral,
473-
notifiers: EmailDistros('[email protected]'),
447+
notifiers: Distros.Suspension,
474448
},
475449
'Suspended & Discussing Reactivation -> Discussing Termination': {
476450
from: [Step.Suspended, Step.DiscussingReactivation],
477451
to: Step.DiscussingTermination,
478452
label: 'Discuss Termination',
479453
type: Type.Neutral,
480-
notifiers: EmailDistros('[email protected]'),
454+
notifiers: Distros.Suspension,
481455
},
482456

483457
// Discussing Reactivation
@@ -486,7 +460,7 @@ export const ProjectWorkflow = defineWorkflow({
486460
to: Step.PendingReactivationApproval,
487461
label: 'Submit for Approval',
488462
type: Type.Approve,
489-
notifiers: EmailDistros('[email protected]'),
463+
notifiers: Distros.Suspension,
490464
},
491465

492466
// Pending Reactivation Approval
@@ -495,21 +469,21 @@ export const ProjectWorkflow = defineWorkflow({
495469
to: Step.ActiveChangedPlan,
496470
label: 'Approve Reactivation',
497471
type: Type.Approve,
498-
notifiers: EmailDistros('[email protected]'),
472+
notifiers: Distros.Suspension,
499473
},
500474
'Pending Reactivation Approval -> Discussing Reactivation': {
501475
from: Step.PendingReactivationApproval,
502476
to: Step.DiscussingReactivation,
503477
label: 'Send Back for Corrections',
504478
type: Type.Reject,
505-
notifiers: EmailDistros('[email protected]'),
479+
notifiers: Distros.Suspension,
506480
},
507481
'Pending Reactivation Approval -> Discussing Termination': {
508482
from: Step.PendingReactivationApproval,
509483
to: Step.DiscussingTermination,
510484
label: 'Discuss Termination',
511485
type: Type.Neutral,
512-
notifiers: EmailDistros('[email protected]'),
486+
notifiers: Distros.Suspension,
513487
},
514488

515489
// Discussing Termination
@@ -518,7 +492,7 @@ export const ProjectWorkflow = defineWorkflow({
518492
to: Step.PendingTerminationApproval,
519493
label: 'Submit for Approval',
520494
type: Type.Approve,
521-
notifiers: EmailDistros('[email protected]'),
495+
notifiers: Distros.Termination,
522496
},
523497
'Discussing Termination -> Back To Most Recent': {
524498
from: Step.DiscussingTermination,
@@ -530,7 +504,7 @@ export const ProjectWorkflow = defineWorkflow({
530504
),
531505
label: 'Will Not Terminate',
532506
type: Type.Neutral,
533-
notifiers: EmailDistros('[email protected]'),
507+
notifiers: Distros.Termination,
534508
},
535509

536510
// Pending Termination Approval
@@ -539,14 +513,14 @@ export const ProjectWorkflow = defineWorkflow({
539513
to: Step.Terminated,
540514
label: 'Approve Termination',
541515
type: Type.Approve,
542-
notifiers: EmailDistros('[email protected]'),
516+
notifiers: Distros.Termination,
543517
},
544518
'Pending Termination Approval -> Discussing Termination': {
545519
from: Step.PendingTerminationApproval,
546520
to: Step.DiscussingTermination,
547521
label: 'Send Back for Corrections',
548522
type: Type.Reject,
549-
notifiers: EmailDistros('[email protected]'),
523+
notifiers: Distros.Termination,
550524
},
551525
'Pending Termination Approval -> Back To Most Recent': {
552526
from: Step.PendingTerminationApproval,
@@ -558,7 +532,7 @@ export const ProjectWorkflow = defineWorkflow({
558532
),
559533
label: 'Will Not Terminate',
560534
type: Type.Neutral,
561-
notifiers: EmailDistros('[email protected]'),
535+
notifiers: Distros.Termination,
562536
},
563537

564538
// Finalizing Completion
@@ -567,14 +541,14 @@ export const ProjectWorkflow = defineWorkflow({
567541
to: BackToActive,
568542
label: 'Still Working',
569543
type: Type.Neutral,
570-
notifiers: EmailDistros('[email protected]'),
544+
notifiers: Distros.Closing,
571545
},
572546
'Finalizing Completion -> Completed': {
573547
from: Step.FinalizingCompletion,
574548
to: Step.Completed,
575549
label: 'Complete 🎉',
576550
type: Type.Approve,
577551
conditions: RequireOngoingEngagementsToBeFinalizingCompletion,
578-
notifiers: EmailDistros('[email protected]'),
552+
notifiers: Distros.Closing,
579553
},
580554
});

src/components/project/workflow/transitions/notifiers.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ResolveParams } from './dynamic-step';
88
type Notifier = TransitionNotifier<ResolveParams>;
99

1010
export const TeamMembers: Notifier = {
11-
description: 'The project members',
11+
description: 'Project members',
1212
async resolve({ project, moduleRef }) {
1313
return await moduleRef
1414
.get(ProjectMemberRepository, { strict: false })
@@ -17,7 +17,9 @@ export const TeamMembers: Notifier = {
1717
};
1818

1919
export const TeamMembersWithRole = (...roles: Role[]): Notifier => ({
20-
description: 'The project members',
20+
description: `Project members with one of these roles: ${roles
21+
.map((r) => Role.entry(r).label)
22+
.join(', ')}`,
2123
async resolve({ project, moduleRef }) {
2224
return await moduleRef
2325
.get(ProjectMemberRepository, { strict: false })
@@ -26,21 +28,21 @@ export const TeamMembersWithRole = (...roles: Role[]): Notifier => ({
2628
});
2729

2830
export const FinancialApprovers: Notifier = {
29-
description: 'All financial approvers according to the project type',
31+
description: 'Financial approvers for the project type',
3032
async resolve({ project, moduleRef }) {
3133
const repo = moduleRef.get(FinancialApproverRepository, { strict: false });
3234
const approvers = await repo.read(project.type);
3335
return approvers.map((approver) => approver.user);
3436
},
3537
};
3638

37-
export const EmailDistros = (...emails: string[]): Notifier => ({
38-
description: `These email addresses: ${emails.join(', ')}`,
39+
export const EmailDistro = (email: string): Notifier => ({
40+
description: email,
3941
resolve({ moduleRef }) {
4042
const config = moduleRef.get(ConfigService, { strict: false });
4143
if (!config.email.notifyDistributionLists) {
4244
return [];
4345
}
44-
return emails.map((email) => ({ email }));
46+
return { email };
4547
},
4648
});

0 commit comments

Comments
 (0)