mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
Switch to using creation mode in XState
still problems in tests
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { useActor } from "@xstate/react"
|
||||
import React, { useContext } from "react"
|
||||
import { useNavigate } from "react-router"
|
||||
import { Navigate } from "react-router"
|
||||
import { CreateUserRequest } from "../../../api/typesGenerated"
|
||||
import { CreateUserForm } from "../../../components/CreateUserForm/CreateUserForm"
|
||||
import { XServiceContext } from "../../../xServices/StateContext"
|
||||
@ -13,17 +13,19 @@ export const CreateUserPage = () => {
|
||||
const xServices = useContext(XServiceContext)
|
||||
const [usersState, usersSend] = useActor(xServices.usersXService)
|
||||
const { createUserError, createUserFormErrors } = usersState.context
|
||||
const navigate = useNavigate()
|
||||
// There is no field for organization id in Community Edition, so handle its field error like a generic error
|
||||
const genericError = (createUserError || createUserFormErrors?.organization_id) ? Language.unknownError : undefined
|
||||
const genericError = createUserError || createUserFormErrors?.organization_id ? Language.unknownError : undefined
|
||||
|
||||
return (
|
||||
<CreateUserForm
|
||||
if (usersState.matches("creationMode")){
|
||||
return <CreateUserForm
|
||||
formErrors={createUserFormErrors}
|
||||
onSubmit={(user: CreateUserRequest) => usersSend({ type: "CREATE", user })}
|
||||
onCancel={() => navigate("/users")}
|
||||
onCancel={() => {usersSend("EXIT_CREATION_MODE")}}
|
||||
isLoading={usersState.hasTag("loading")}
|
||||
error={genericError}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
// on cancel or success, redirect
|
||||
return <Navigate to="/users"/>
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user