Skip to content

Commit

Permalink
Clear error on cancel (#2107)
Browse files Browse the repository at this point in the history
  • Loading branch information
presleyp committed Jun 7, 2022
1 parent cc30d42 commit b4645b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion site/src/pages/UsersPage/CreateUserPage/CreateUserPage.tsx
Expand Up @@ -31,7 +31,10 @@ export const CreateUserPage: React.FC = () => {
<CreateUserForm
formErrors={createUserFormErrors}
onSubmit={(user: TypesGen.CreateUserRequest) => usersSend({ type: "CREATE", user })}
onCancel={() => navigate("/users")}
onCancel={() => {
usersSend("CANCEL_CREATE_USER")
navigate("/users")
}}
isLoading={usersState.hasTag("loading")}
error={genericError}
myOrgId={myOrgId ?? ""}
Expand Down
8 changes: 6 additions & 2 deletions site/src/xServices/users/usersXService.ts
Expand Up @@ -44,6 +44,7 @@ export interface UsersContext {
export type UsersEvent =
| { type: "GET_USERS" }
| { type: "CREATE"; user: TypesGen.CreateUserRequest }
| { type: "CANCEL_CREATE_USER" }
// Suspend events
| { type: "SUSPEND_USER"; userId: TypesGen.User["id"] }
| { type: "CONFIRM_USER_SUSPENSION" }
Expand Down Expand Up @@ -86,6 +87,7 @@ export const usersMachine = createMachine(
on: {
GET_USERS: "gettingUsers",
CREATE: "creatingUser",
CANCEL_CREATE_USER: { actions: ["clearCreateUserError"] },
SUSPEND_USER: {
target: "confirmUserSuspension",
actions: ["assignUserIdToSuspend"],
Expand Down Expand Up @@ -120,12 +122,13 @@ export const usersMachine = createMachine(
tags: "loading",
},
creatingUser: {
entry: "clearCreateUserError",
invoke: {
src: "createUser",
id: "createUser",
onDone: {
target: "idle",
actions: ["displayCreateUserSuccess", "redirectToUsersPage", "clearCreateUserError"],
actions: ["displayCreateUserSuccess", "redirectToUsersPage"],
},
onError: [
{
Expand Down Expand Up @@ -283,7 +286,8 @@ export const usersMachine = createMachine(
}),
clearCreateUserError: assign((context: UsersContext) => ({
...context,
createUserError: undefined,
createUserErrorMessage: undefined,
createUserFormErrors: undefined,
})),
clearSuspendUserError: assign({
suspendUserError: (_) => undefined,
Expand Down

0 comments on commit b4645b2

Please sign in to comment.