Clear error on cancel (#2107)

This commit is contained in:
Presley Pizzo
2022-06-07 11:02:20 -04:00
committed by GitHub
parent cc30d42473
commit b4645b2d11
2 changed files with 10 additions and 3 deletions

View File

@ -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 ?? ""}

View File

@ -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" }
@ -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"],
@ -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: [
{
@ -283,7 +286,8 @@ export const usersMachine = createMachine(
}),
clearCreateUserError: assign((context: UsersContext) => ({
...context,
createUserError: undefined,
createUserErrorMessage: undefined,
createUserFormErrors: undefined,
})),
clearSuspendUserError: assign({
suspendUserError: (_) => undefined,