mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat: workspace quotas (#4184)
This commit is contained in:
@ -1,21 +1,32 @@
|
||||
import { useActor, useMachine } from "@xstate/react"
|
||||
import { User } from "api/typesGenerated"
|
||||
import { shallowEqual, useActor, useMachine, useSelector } from "@xstate/react"
|
||||
import { FeatureNames } from "api/types"
|
||||
import { useOrganizationId } from "hooks/useOrganizationId"
|
||||
import { FC, useContext, useState } from "react"
|
||||
import { FC, useContext } from "react"
|
||||
import { Helmet } from "react-helmet-async"
|
||||
import { useNavigate, useParams } from "react-router-dom"
|
||||
import { pageTitle } from "util/page"
|
||||
import { createWorkspaceMachine } from "xServices/createWorkspace/createWorkspaceXService"
|
||||
import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors"
|
||||
import { XServiceContext } from "xServices/StateContext"
|
||||
import { CreateWorkspaceErrors, CreateWorkspacePageView } from "./CreateWorkspacePageView"
|
||||
|
||||
const CreateWorkspacePage: FC = () => {
|
||||
const xServices = useContext(XServiceContext)
|
||||
const organizationId = useOrganizationId()
|
||||
const { template } = useParams()
|
||||
const templateName = template ? template : ""
|
||||
const navigate = useNavigate()
|
||||
const featureVisibility = useSelector(
|
||||
xServices.entitlementsXService,
|
||||
selectFeatureVisibility,
|
||||
shallowEqual,
|
||||
)
|
||||
const workspaceQuotaEnabled = featureVisibility[FeatureNames.WorkspaceQuota]
|
||||
|
||||
const [authState] = useActor(xServices.authXService)
|
||||
const { me } = authState.context
|
||||
const [createWorkspaceState, send] = useMachine(createWorkspaceMachine, {
|
||||
context: { organizationId, templateName },
|
||||
context: { organizationId, templateName, workspaceQuotaEnabled, owner: me ?? null },
|
||||
actions: {
|
||||
onCreateWorkspace: (_, event) => {
|
||||
navigate(`/@${event.data.owner_name}/${event.data.name}`)
|
||||
@ -31,14 +42,11 @@ const CreateWorkspacePage: FC = () => {
|
||||
getTemplatesError,
|
||||
createWorkspaceError,
|
||||
permissions,
|
||||
workspaceQuota,
|
||||
getWorkspaceQuotaError,
|
||||
owner,
|
||||
} = createWorkspaceState.context
|
||||
|
||||
const xServices = useContext(XServiceContext)
|
||||
const [authState] = useActor(xServices.authXService)
|
||||
const { me } = authState.context
|
||||
|
||||
const [owner, setOwner] = useState<User | null>(me ?? null)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
@ -53,14 +61,21 @@ const CreateWorkspacePage: FC = () => {
|
||||
templates={templates}
|
||||
selectedTemplate={selectedTemplate}
|
||||
templateSchema={templateSchema}
|
||||
workspaceQuota={workspaceQuota}
|
||||
createWorkspaceErrors={{
|
||||
[CreateWorkspaceErrors.GET_TEMPLATES_ERROR]: getTemplatesError,
|
||||
[CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR]: getTemplateSchemaError,
|
||||
[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]: createWorkspaceError,
|
||||
[CreateWorkspaceErrors.GET_WORKSPACE_QUOTA_ERROR]: getWorkspaceQuotaError,
|
||||
}}
|
||||
canCreateForUser={permissions?.createWorkspaceForUser}
|
||||
defaultWorkspaceOwner={me ?? null}
|
||||
setOwner={setOwner}
|
||||
owner={owner}
|
||||
setOwner={(user) => {
|
||||
send({
|
||||
type: "SELECT_OWNER",
|
||||
owner: user,
|
||||
})
|
||||
}}
|
||||
onCancel={() => {
|
||||
navigate("/templates")
|
||||
}}
|
||||
|
Reference in New Issue
Block a user