feat: Add create workspace page (#1589)

This commit is contained in:
Kyle Carberry
2022-05-19 15:51:10 -05:00
committed by GitHub
parent 4afc66faf5
commit 3be356095f
17 changed files with 652 additions and 380 deletions

View File

@ -0,0 +1,39 @@
import { useMachine } from "@xstate/react"
import React from "react"
import { useNavigate } from "react-router"
import { useParams } from "react-router-dom"
import { createWorkspace } from "../../api/api"
import { templateMachine } from "../../xServices/template/templateXService"
import { CreateWorkspacePageView } from "./CreateWorkspacePageView"
const CreateWorkspacePage: React.FC = () => {
const { template } = useParams()
const [templateState] = useMachine(templateMachine, {
context: {
name: template,
},
})
const navigate = useNavigate()
const loading = templateState.hasTag("loading")
if (!templateState.context.template || !templateState.context.templateSchema) {
return null
}
return (
<CreateWorkspacePageView
template={templateState.context.template}
templateSchema={templateState.context.templateSchema}
loading={loading}
onCancel={() => navigate("/templates")}
onSubmit={async (req) => {
if (!templateState.context.template) {
throw new Error("template isn't valid")
}
const workspace = await createWorkspace(templateState.context.template.organization_id, req)
navigate("/workspaces/" + workspace.id)
}}
/>
)
}
export default CreateWorkspacePage