@@ -16,7 +16,9 @@ export const Language = {
1616 createUserSuccess : "Successfully created user." ,
1717 createUserError : "Error on creating the user." ,
1818 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." ,
2022 resetUserPasswordSuccess : "Successfully updated the user password." ,
2123 resetUserPasswordError : "Error on resetting the user password." ,
2224 updateUserRolesSuccess : "Successfully updated the user roles." ,
@@ -32,6 +34,9 @@ export interface UsersContext {
3234 // Suspend user
3335 userIdToSuspend ?: TypesGen . User [ "id" ]
3436 suspendUserError ?: Error | unknown
37+ // Activate user
38+ userIdToActivate ?: TypesGen . User [ "id" ]
39+ activateUserError ?: Error | unknown
3540 // Reset user password
3641 userIdToResetPassword ?: TypesGen . User [ "id" ]
3742 resetUserPasswordError ?: Error | unknown
@@ -49,6 +54,10 @@ export type UsersEvent =
4954 | { type : "SUSPEND_USER" ; userId : TypesGen . User [ "id" ] }
5055 | { type : "CONFIRM_USER_SUSPENSION" }
5156 | { 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" }
5261 // Reset password events
5362 | { type : "RESET_USER_PASSWORD" ; userId : TypesGen . User [ "id" ] }
5463 | { type : "CONFIRM_USER_PASSWORD_RESET" }
@@ -72,6 +81,9 @@ export const usersMachine = createMachine(
7281 suspendUser : {
7382 data : TypesGen . User
7483 }
84+ activateUser : {
85+ data : TypesGen . User
86+ }
7587 updateUserPassword : {
7688 data : undefined
7789 }
@@ -92,6 +104,10 @@ export const usersMachine = createMachine(
92104 target : "confirmUserSuspension" ,
93105 actions : [ "assignUserIdToSuspend" ] ,
94106 } ,
107+ ACTIVATE_USER : {
108+ target : "confirmUserActivation" ,
109+ actions : [ "assignUserIdToActivate" ] ,
110+ } ,
95111 RESET_USER_PASSWORD : {
96112 target : "confirmUserPasswordReset" ,
97113 actions : [ "assignUserIdToResetPassword" , "generateRandomPassword" ] ,
@@ -150,6 +166,12 @@ export const usersMachine = createMachine(
150166 CANCEL_USER_SUSPENSION : "idle" ,
151167 } ,
152168 } ,
169+ confirmUserActivation : {
170+ on : {
171+ CONFIRM_USER_ACTIVATION : "activatingUser" ,
172+ CANCEL_USER_ACTIVATION : "idle" ,
173+ } ,
174+ } ,
153175 suspendingUser : {
154176 entry : "clearSuspendUserError" ,
155177 invoke : {
@@ -166,6 +188,22 @@ export const usersMachine = createMachine(
166188 } ,
167189 } ,
168190 } ,
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+ } ,
169207 confirmUserPasswordReset : {
170208 on : {
171209 CONFIRM_USER_PASSWORD_RESET : "resettingUserPassword" ,
@@ -223,6 +261,13 @@ export const usersMachine = createMachine(
223261
224262 return API . suspendUser ( context . userIdToSuspend )
225263 } ,
264+ activateUser : ( context ) => {
265+ if ( ! context . userIdToActivate ) {
266+ throw new Error ( "userIdToActivate is undefined" )
267+ }
268+
269+ return API . activateUser ( context . userIdToActivate )
270+ } ,
226271 resetUserPassword : ( context ) => {
227272 if ( ! context . userIdToResetPassword ) {
228273 throw new Error ( "userIdToResetPassword is undefined" )
@@ -258,6 +303,9 @@ export const usersMachine = createMachine(
258303 assignUserIdToSuspend : assign ( {
259304 userIdToSuspend : ( _ , event ) => event . userId ,
260305 } ) ,
306+ assignUserIdToActivate : assign ( {
307+ userIdToActivate : ( _ , event ) => event . userId ,
308+ } ) ,
261309 assignUserIdToResetPassword : assign ( {
262310 userIdToResetPassword : ( _ , event ) => event . userId ,
263311 } ) ,
@@ -278,6 +326,9 @@ export const usersMachine = createMachine(
278326 assignSuspendUserError : assign ( {
279327 suspendUserError : ( _ , event ) => event . data ,
280328 } ) ,
329+ assignActivateUserError : assign ( {
330+ activateUserError : ( _ , event ) => event . data ,
331+ } ) ,
281332 assignResetUserPasswordError : assign ( {
282333 resetUserPasswordError : ( _ , event ) => event . data ,
283334 } ) ,
@@ -292,6 +343,9 @@ export const usersMachine = createMachine(
292343 clearSuspendUserError : assign ( {
293344 suspendUserError : ( _ ) => undefined ,
294345 } ) ,
346+ clearActivateUserError : assign ( {
347+ activateUserError : ( _ ) => undefined ,
348+ } ) ,
295349 clearResetUserPasswordError : assign ( {
296350 resetUserPasswordError : ( _ ) => undefined ,
297351 } ) ,
@@ -308,6 +362,13 @@ export const usersMachine = createMachine(
308362 const message = getErrorMessage ( context . suspendUserError , Language . suspendUserError )
309363 displayError ( message )
310364 } ,
365+ displayActivateSuccess : ( ) => {
366+ displaySuccess ( Language . activateUserSuccess )
367+ } ,
368+ displayActivatedErrorMessage : ( context ) => {
369+ const message = getErrorMessage ( context . activateUserError , Language . activateUserError )
370+ displayError ( message )
371+ } ,
311372 displayResetPasswordSuccess : ( ) => {
312373 displaySuccess ( Language . resetUserPasswordSuccess )
313374 } ,
0 commit comments