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 <CreateUserForm
formErrors={createUserFormErrors} formErrors={createUserFormErrors}
onSubmit={(user: TypesGen.CreateUserRequest) => usersSend({ type: "CREATE", user })} onSubmit={(user: TypesGen.CreateUserRequest) => usersSend({ type: "CREATE", user })}
onCancel={() => navigate("/users")} onCancel={() => {
usersSend("CANCEL_CREATE_USER")
navigate("/users")
}}
isLoading={usersState.hasTag("loading")} isLoading={usersState.hasTag("loading")}
error={genericError} error={genericError}
myOrgId={myOrgId ?? ""} myOrgId={myOrgId ?? ""}

View File

@ -44,6 +44,7 @@ export interface UsersContext {
export type UsersEvent = export type UsersEvent =
| { type: "GET_USERS" } | { type: "GET_USERS" }
| { type: "CREATE"; user: TypesGen.CreateUserRequest } | { type: "CREATE"; user: TypesGen.CreateUserRequest }
| { type: "CANCEL_CREATE_USER" }
// Suspend events // Suspend events
| { type: "SUSPEND_USER"; userId: TypesGen.User["id"] } | { type: "SUSPEND_USER"; userId: TypesGen.User["id"] }
| { type: "CONFIRM_USER_SUSPENSION" } | { type: "CONFIRM_USER_SUSPENSION" }
@ -86,6 +87,7 @@ export const usersMachine = createMachine(
on: { on: {
GET_USERS: "gettingUsers", GET_USERS: "gettingUsers",
CREATE: "creatingUser", CREATE: "creatingUser",
CANCEL_CREATE_USER: { actions: ["clearCreateUserError"] },
SUSPEND_USER: { SUSPEND_USER: {
target: "confirmUserSuspension", target: "confirmUserSuspension",
actions: ["assignUserIdToSuspend"], actions: ["assignUserIdToSuspend"],
@ -120,12 +122,13 @@ export const usersMachine = createMachine(
tags: "loading", tags: "loading",
}, },
creatingUser: { creatingUser: {
entry: "clearCreateUserError",
invoke: { invoke: {
src: "createUser", src: "createUser",
id: "createUser", id: "createUser",
onDone: { onDone: {
target: "idle", target: "idle",
actions: ["displayCreateUserSuccess", "redirectToUsersPage", "clearCreateUserError"], actions: ["displayCreateUserSuccess", "redirectToUsersPage"],
}, },
onError: [ onError: [
{ {
@ -283,7 +286,8 @@ export const usersMachine = createMachine(
}), }),
clearCreateUserError: assign((context: UsersContext) => ({ clearCreateUserError: assign((context: UsersContext) => ({
...context, ...context,
createUserError: undefined, createUserErrorMessage: undefined,
createUserFormErrors: undefined,
})), })),
clearSuspendUserError: assign({ clearSuspendUserError: assign({
suspendUserError: (_) => undefined, suspendUserError: (_) => undefined,