This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
// The workspaces of the organization, and a form to create one (spec §3.1). A workspace is where
|
||||
// projects live and where a restricted group of people works apart from the rest of the
|
||||
// organization; creating one is for administrators (`tenancy.workspace.manage`), so the form is shown
|
||||
// to them and the kernel refuses everybody else regardless.
|
||||
|
||||
import { workspaceList } from "@conusai-kit/tenancy"
|
||||
import type { ReactElement } from "react"
|
||||
import { orFallback } from "../../../src/server/guard"
|
||||
import { holdsAtLeast, pageContext } from "../../../src/server/page"
|
||||
import { ProcedureForm } from "../../../src/ui/procedure-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function Workspaces({ params }: { params: Promise<{ org: string }> }): Promise<ReactElement> {
|
||||
const { org } = await params
|
||||
const page = await pageContext()
|
||||
const { caller, i18n, path } = page
|
||||
const { workspaces } = await orFallback(path, () => caller.call(workspaceList, { org }))
|
||||
const mayCreate = await holdsAtLeast(page, org, "admin")
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1>{i18n.message("workspace.list")}</h1>
|
||||
{workspaces.length === 0 ? (
|
||||
<p>{i18n.message("workspace.none")}</p>
|
||||
) : (
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{i18n.message("app.name")}</th>
|
||||
<th scope="col">{i18n.message("workspace.visibility")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{workspaces.map((workspace) => (
|
||||
<tr key={workspace.slug}>
|
||||
<td>
|
||||
<a href={`/${org}/${workspace.slug}`}>{workspace.name}</a>
|
||||
{workspace.isDefault ? ` (${i18n.message("workspace.default")})` : ""}
|
||||
</td>
|
||||
<td>
|
||||
{workspace.visibility === "org"
|
||||
? i18n.message("workspace.visibilityOrg")
|
||||
: i18n.message("workspace.visibilityRestricted")}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
|
||||
{mayCreate ? (
|
||||
<>
|
||||
<h2>{i18n.message("workspace.create")}</h2>
|
||||
<ProcedureForm
|
||||
procedure="tenancy.workspace.create"
|
||||
hidden={{ org }}
|
||||
submitLabel={i18n.message("app.create")}
|
||||
failedTemplate={i18n.message("app.failed")}
|
||||
fields={[
|
||||
{ name: "name", label: i18n.message("app.name"), required: true },
|
||||
{ name: "slug", label: i18n.message("app.slug"), required: true },
|
||||
{
|
||||
name: "visibility",
|
||||
label: i18n.message("workspace.visibility"),
|
||||
required: true,
|
||||
options: [
|
||||
{ value: "org", label: i18n.message("workspace.visibilityOrg") },
|
||||
{ value: "restricted", label: i18n.message("workspace.visibilityRestricted") },
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user