mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
Clear error on cancel (#2107)
This commit is contained in:
@ -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 ?? ""}
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user