Switch to using creation mode in XState

still problems in tests
This commit is contained in:
Presley
2022-04-27 18:18:07 +00:00
parent 30b8799bc2
commit cf8442fa4b
5 changed files with 54 additions and 40 deletions

View File

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