Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4645b2

Browse files
authored
Clear error on cancel (#2107)
1 parent cc30d42 commit b4645b2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

site/src/pages/UsersPage/CreateUserPage/CreateUserPage.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export const CreateUserPage: React.FC = () => {
3131
<CreateUserForm
3232
formErrors={createUserFormErrors}
3333
onSubmit={(user: TypesGen.CreateUserRequest) => usersSend({ type: "CREATE", user })}
34-
onCancel={() => navigate("/users")}
34+
onCancel={() => {
35+
usersSend("CANCEL_CREATE_USER")
36+
navigate("/users")
37+
}}
3538
isLoading={usersState.hasTag("loading")}
3639
error={genericError}
3740
myOrgId={myOrgId ?? ""}

site/src/xServices/users/usersXService.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface UsersContext {
4444
export type UsersEvent =
4545
| { type: "GET_USERS" }
4646
| { type: "CREATE"; user: TypesGen.CreateUserRequest }
47+
| { type: "CANCEL_CREATE_USER" }
4748
// Suspend events
4849
| { type: "SUSPEND_USER"; userId: TypesGen.User["id"] }
4950
| { type: "CONFIRM_USER_SUSPENSION" }
@@ -86,6 +87,7 @@ export const usersMachine = createMachine(
8687
on: {
8788
GET_USERS: "gettingUsers",
8889
CREATE: "creatingUser",
90+
CANCEL_CREATE_USER: { actions: ["clearCreateUserError"] },
8991
SUSPEND_USER: {
9092
target: "confirmUserSuspension",
9193
actions: ["assignUserIdToSuspend"],
@@ -120,12 +122,13 @@ export const usersMachine = createMachine(
120122
tags: "loading",
121123
},
122124
creatingUser: {
125+
entry: "clearCreateUserError",
123126
invoke: {
124127
src: "createUser",
125128
id: "createUser",
126129
onDone: {
127130
target: "idle",
128-
actions: ["displayCreateUserSuccess", "redirectToUsersPage", "clearCreateUserError"],
131+
actions: ["displayCreateUserSuccess", "redirectToUsersPage"],
129132
},
130133
onError: [
131134
{
@@ -283,7 +286,8 @@ export const usersMachine = createMachine(
283286
}),
284287
clearCreateUserError: assign((context: UsersContext) => ({
285288
...context,
286-
createUserError: undefined,
289+
createUserErrorMessage: undefined,
290+
createUserFormErrors: undefined,
287291
})),
288292
clearSuspendUserError: assign({
289293
suspendUserError: (_) => undefined,

0 commit comments

Comments
 (0)