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