@@ -16,7 +16,9 @@ export const Language = {
16
16
createUserSuccess :"Successfully created user." ,
17
17
createUserError :"Error on creating the user." ,
18
18
suspendUserSuccess :"Successfully suspended the user." ,
19
- suspendUserError :"Error on suspending the user." ,
19
+ suspendUserError :"Error suspending user." ,
20
+ activateUserSuccess :"Successfully activated the user." ,
21
+ activateUserError :"Error activating user." ,
20
22
resetUserPasswordSuccess :"Successfully updated the user password." ,
21
23
resetUserPasswordError :"Error on resetting the user password." ,
22
24
updateUserRolesSuccess :"Successfully updated the user roles." ,
@@ -32,6 +34,9 @@ export interface UsersContext {
32
34
// Suspend user
33
35
userIdToSuspend ?:TypesGen . User [ "id" ]
34
36
suspendUserError ?:Error | unknown
37
+ // Activate user
38
+ userIdToActivate ?:TypesGen . User [ "id" ]
39
+ activateUserError ?:Error | unknown
35
40
// Reset user password
36
41
userIdToResetPassword ?:TypesGen . User [ "id" ]
37
42
resetUserPasswordError ?:Error | unknown
@@ -49,6 +54,10 @@ export type UsersEvent =
49
54
| { type :"SUSPEND_USER" ; userId :TypesGen . User [ "id" ] }
50
55
| { type :"CONFIRM_USER_SUSPENSION" }
51
56
| { type :"CANCEL_USER_SUSPENSION" }
57
+ // Activate events
58
+ | { type :"ACTIVATE_USER" ; userId :TypesGen . User [ "id" ] }
59
+ | { type :"CONFIRM_USER_ACTIVATION" }
60
+ | { type :"CANCEL_USER_ACTIVATION" }
52
61
// Reset password events
53
62
| { type :"RESET_USER_PASSWORD" ; userId :TypesGen . User [ "id" ] }
54
63
| { type :"CONFIRM_USER_PASSWORD_RESET" }
@@ -72,6 +81,9 @@ export const usersMachine = createMachine(
72
81
suspendUser :{
73
82
data :TypesGen . User
74
83
}
84
+ activateUser :{
85
+ data :TypesGen . User
86
+ }
75
87
updateUserPassword :{
76
88
data :undefined
77
89
}
@@ -92,6 +104,10 @@ export const usersMachine = createMachine(
92
104
target :"confirmUserSuspension" ,
93
105
actions :[ "assignUserIdToSuspend" ] ,
94
106
} ,
107
+ ACTIVATE_USER :{
108
+ target :"confirmUserActivation" ,
109
+ actions :[ "assignUserIdToActivate" ] ,
110
+ } ,
95
111
RESET_USER_PASSWORD :{
96
112
target :"confirmUserPasswordReset" ,
97
113
actions :[ "assignUserIdToResetPassword" , "generateRandomPassword" ] ,
@@ -150,6 +166,12 @@ export const usersMachine = createMachine(
150
166
CANCEL_USER_SUSPENSION :"idle" ,
151
167
} ,
152
168
} ,
169
+ confirmUserActivation :{
170
+ on :{
171
+ CONFIRM_USER_ACTIVATION :"activatingUser" ,
172
+ CANCEL_USER_ACTIVATION :"idle" ,
173
+ } ,
174
+ } ,
153
175
suspendingUser :{
154
176
entry :"clearSuspendUserError" ,
155
177
invoke :{
@@ -166,6 +188,22 @@ export const usersMachine = createMachine(
166
188
} ,
167
189
} ,
168
190
} ,
191
+ activatingUser :{
192
+ entry :"clearActivateUserError" ,
193
+ invoke :{
194
+ src :"activateUser" ,
195
+ id :"activateUser" ,
196
+ onDone :{
197
+ // Update users list
198
+ target :"gettingUsers" ,
199
+ actions :[ "displayActivateSuccess" ] ,
200
+ } ,
201
+ onError :{
202
+ target :"idle" ,
203
+ actions :[ "assignActivateUserError" , "displayActivatedErrorMessage" ] ,
204
+ } ,
205
+ } ,
206
+ } ,
169
207
confirmUserPasswordReset :{
170
208
on :{
171
209
CONFIRM_USER_PASSWORD_RESET :"resettingUserPassword" ,
@@ -223,6 +261,13 @@ export const usersMachine = createMachine(
223
261
224
262
return API . suspendUser ( context . userIdToSuspend )
225
263
} ,
264
+ activateUser :( context ) => {
265
+ if ( ! context . userIdToActivate ) {
266
+ throw new Error ( "userIdToActivate is undefined" )
267
+ }
268
+
269
+ return API . activateUser ( context . userIdToActivate )
270
+ } ,
226
271
resetUserPassword :( context ) => {
227
272
if ( ! context . userIdToResetPassword ) {
228
273
throw new Error ( "userIdToResetPassword is undefined" )
@@ -258,6 +303,9 @@ export const usersMachine = createMachine(
258
303
assignUserIdToSuspend :assign ( {
259
304
userIdToSuspend :( _ , event ) => event . userId ,
260
305
} ) ,
306
+ assignUserIdToActivate :assign ( {
307
+ userIdToActivate :( _ , event ) => event . userId ,
308
+ } ) ,
261
309
assignUserIdToResetPassword :assign ( {
262
310
userIdToResetPassword :( _ , event ) => event . userId ,
263
311
} ) ,
@@ -278,6 +326,9 @@ export const usersMachine = createMachine(
278
326
assignSuspendUserError :assign ( {
279
327
suspendUserError :( _ , event ) => event . data ,
280
328
} ) ,
329
+ assignActivateUserError :assign ( {
330
+ activateUserError :( _ , event ) => event . data ,
331
+ } ) ,
281
332
assignResetUserPasswordError :assign ( {
282
333
resetUserPasswordError :( _ , event ) => event . data ,
283
334
} ) ,
@@ -292,6 +343,9 @@ export const usersMachine = createMachine(
292
343
clearSuspendUserError :assign ( {
293
344
suspendUserError :( _ ) => undefined ,
294
345
} ) ,
346
+ clearActivateUserError :assign ( {
347
+ activateUserError :( _ ) => undefined ,
348
+ } ) ,
295
349
clearResetUserPasswordError :assign ( {
296
350
resetUserPasswordError :( _ ) => undefined ,
297
351
} ) ,
@@ -308,6 +362,13 @@ export const usersMachine = createMachine(
308
362
const message = getErrorMessage ( context . suspendUserError , Language . suspendUserError )
309
363
displayError ( message )
310
364
} ,
365
+ displayActivateSuccess :( ) => {
366
+ displaySuccess ( Language . activateUserSuccess )
367
+ } ,
368
+ displayActivatedErrorMessage :( context ) => {
369
+ const message = getErrorMessage ( context . activateUserError , Language . activateUserError )
370
+ displayError ( message )
371
+ } ,
311
372
displayResetPasswordSuccess :( ) => {
312
373
displaySuccess ( Language . resetUserPasswordSuccess )
313
374
} ,