@@ -25,6 +25,8 @@ export const Language = {
25
25
deleteUserError : "Error deleting user." ,
26
26
activateUserSuccess : "Successfully activated the user." ,
27
27
activateUserError : "Error activating user." ,
28
+ markUserDormantSuccess : "Successfully marked the user account as dormant." ,
29
+ markUserDormantError : "Error marking user account as dormant." ,
28
30
resetUserPasswordSuccess : "Successfully updated the user password." ,
29
31
resetUserPasswordError : "Error on resetting the user password." ,
30
32
updateUserRolesSuccess : "Successfully updated the user roles." ,
@@ -48,6 +50,10 @@ export interface UsersContext {
48
50
userIdToActivate ?: TypesGen . User [ "id" ]
49
51
usernameToActivate ?: TypesGen . User [ "username" ]
50
52
activateUserError ?: Error | unknown
53
+ // Mark user dormant
54
+ userIdToMarkDormant ?: TypesGen . User [ "id" ]
55
+ usernameToMarkDormant ?: TypesGen . User [ "username" ]
56
+ markUserDormantError ?: Error | unknown
51
57
// Reset user password
52
58
userIdToResetPassword ?: TypesGen . User [ "id" ]
53
59
resetUserPasswordError ?: Error | unknown
@@ -86,6 +92,14 @@ export type UsersEvent =
86
92
}
87
93
| { type : "CONFIRM_USER_ACTIVATION" }
88
94
| { type : "CANCEL_USER_ACTIVATION" }
95
+ // Mark as dormant events
96
+ | {
97
+ type : "MARK_USER_DORMANT"
98
+ userId : TypesGen . User [ "id" ]
99
+ username : TypesGen . User [ "username" ]
100
+ }
101
+ | { type : "CONFIRM_USER_DORMANT" }
102
+ | { type : "CANCEL_USER_DORMANT" }
89
103
// Reset password events
90
104
| { type : "RESET_USER_PASSWORD" ; userId : TypesGen . User [ "id" ] }
91
105
| { type : "CONFIRM_USER_PASSWORD_RESET" }
@@ -125,6 +139,9 @@ export const usersMachine =
125
139
activateUser : {
126
140
data : TypesGen . User
127
141
}
142
+ markUserDormant : {
143
+ data : TypesGen . User
144
+ }
128
145
updateUserPassword : {
129
146
data : undefined
130
147
}
@@ -187,6 +204,10 @@ export const usersMachine =
187
204
target : "confirmUserActivation" ,
188
205
actions : "assignUserToActivate" ,
189
206
} ,
207
+ MARK_USER_DORMANT : {
208
+ target : "confirmUserDormant" ,
209
+ actions : "assignUserToMarkDormant" ,
210
+ } ,
190
211
RESET_USER_PASSWORD : {
191
212
target : "confirmUserPasswordReset" ,
192
213
actions : [
@@ -230,6 +251,16 @@ export const usersMachine =
230
251
} ,
231
252
} ,
232
253
} ,
254
+ confirmUserDormant : {
255
+ on : {
256
+ CONFIRM_USER_DORMANT : {
257
+ target : "markingUserDormant" ,
258
+ } ,
259
+ CANCEL_USER_DORMANT : {
260
+ target : "idle" ,
261
+ } ,
262
+ } ,
263
+ } ,
233
264
suspendingUser : {
234
265
entry : "clearSuspendUserError" ,
235
266
invoke : {
@@ -293,6 +324,28 @@ export const usersMachine =
293
324
] ,
294
325
} ,
295
326
} ,
327
+ markingUserDormant : {
328
+ entry : "clearMarkUserDormantError" ,
329
+ invoke : {
330
+ src : "markUserDormant" ,
331
+ id : "markUserDormant" ,
332
+ onDone : [
333
+ {
334
+ target : "gettingUsers" ,
335
+ actions : "displayMarkUserDormantSuccess" ,
336
+ } ,
337
+ ] ,
338
+ onError : [
339
+ {
340
+ target : "idle" ,
341
+ actions : [
342
+ "assignMarkUserDormantError" ,
343
+ "displayMarkUserDormantErrorMessage" ,
344
+ ] ,
345
+ } ,
346
+ ] ,
347
+ } ,
348
+ } ,
296
349
confirmUserPasswordReset : {
297
350
on : {
298
351
CONFIRM_USER_PASSWORD_RESET : {
@@ -382,6 +435,12 @@ export const usersMachine =
382
435
383
436
return API . activateUser ( context . userIdToActivate )
384
437
} ,
438
+ markUserDormant : ( context ) => {
439
+ if ( ! context . userIdToMarkDormant ) {
440
+ throw new Error ( "userIdToMarkDormant is undefined" )
441
+ }
442
+ return API . markUserDormant ( context . userIdToMarkDormant )
443
+ } ,
385
444
resetUserPassword : ( context ) => {
386
445
if ( ! context . userIdToResetPassword ) {
387
446
throw new Error ( "userIdToResetPassword is undefined" )
@@ -413,6 +472,8 @@ export const usersMachine =
413
472
usernameToDelete : ( _ ) => undefined ,
414
473
userIdToActivate : ( _ ) => undefined ,
415
474
usernameToActivate : ( _ ) => undefined ,
475
+ userIdToMarkDormant : ( _ ) => undefined ,
476
+ usernameToMarkDormant : ( _ ) => undefined ,
416
477
userIdToResetPassword : ( _ ) => undefined ,
417
478
userIdToUpdateRoles : ( _ ) => undefined ,
418
479
} ) ,
@@ -438,6 +499,10 @@ export const usersMachine =
438
499
userIdToActivate : ( _ , event ) => event . userId ,
439
500
usernameToActivate : ( _ , event ) => event . username ,
440
501
} ) ,
502
+ assignUserToMarkDormant : assign ( {
503
+ userIdToMarkDormant : ( _ , event ) => event . userId ,
504
+ usernameToMarkDormant : ( _ , event ) => event . username ,
505
+ } ) ,
441
506
assignUserIdToResetPassword : assign ( {
442
507
userIdToResetPassword : ( _ , event ) => event . userId ,
443
508
} ) ,
@@ -457,6 +522,9 @@ export const usersMachine =
457
522
assignActivateUserError : assign ( {
458
523
activateUserError : ( _ , event ) => event . data ,
459
524
} ) ,
525
+ assignMarkUserDormantError : assign ( {
526
+ markUserDormantError : ( _ , event ) => event . data ,
527
+ } ) ,
460
528
assignResetUserPasswordError : assign ( {
461
529
resetUserPasswordError : ( _ , event ) => event . data ,
462
530
} ) ,
@@ -477,6 +545,9 @@ export const usersMachine =
477
545
clearActivateUserError : assign ( {
478
546
activateUserError : ( _ ) => undefined ,
479
547
} ) ,
548
+ clearMarkUserDormantError : assign ( {
549
+ markUserDormantError : ( _ ) => undefined ,
550
+ } ) ,
480
551
clearResetUserPasswordError : assign ( {
481
552
resetUserPasswordError : ( _ ) => undefined ,
482
553
} ) ,
@@ -513,6 +584,16 @@ export const usersMachine =
513
584
)
514
585
displayError ( message )
515
586
} ,
587
+ displayMarkUserDormantSuccess : ( ) => {
588
+ displaySuccess ( Language . markUserDormantSuccess )
589
+ } ,
590
+ displayMarkUserDormantErrorMessage : ( context ) => {
591
+ const message = getErrorMessage (
592
+ context . markUserDormantError ,
593
+ Language . markUserDormantError ,
594
+ )
595
+ displayError ( message )
596
+ } ,
516
597
displayResetPasswordSuccess : ( ) => {
517
598
displaySuccess ( Language . resetUserPasswordSuccess )
518
599
} ,
0 commit comments