ДИЗАЙН - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: состояние workspace policy в onboarding
This commit is contained in:
parent
e009915e34
commit
8ec762f790
|
|
@ -4,7 +4,7 @@
|
|||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
// plane imports
|
||||
import { useTranslation } from "@plane/i18n";
|
||||
|
|
@ -21,6 +21,9 @@ import { useInstance } from "@/hooks/store/use-instance";
|
|||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
// wrappers
|
||||
import { AuthenticationWrapper } from "@/lib/wrappers/authentication-wrapper";
|
||||
import { WorkspaceService, type NodeDCWorkspacePolicy } from "@/services/workspace.service";
|
||||
|
||||
const workspaceService = new WorkspaceService();
|
||||
|
||||
const CreateWorkspacePage = observer(function CreateWorkspacePage() {
|
||||
const { t } = useTranslation();
|
||||
|
|
@ -36,8 +39,39 @@ const CreateWorkspacePage = observer(function CreateWorkspacePage() {
|
|||
slug: "",
|
||||
organization_size: "",
|
||||
});
|
||||
const [workspacePolicy, setWorkspacePolicy] = useState<NodeDCWorkspacePolicy | null>(null);
|
||||
const [workspacePolicyLoading, setWorkspacePolicyLoading] = useState(true);
|
||||
// derived values
|
||||
const isWorkspaceCreationDisabled = config?.is_workspace_creation_disabled ?? false;
|
||||
const isWorkspaceCreationDeniedByNodeDC = Boolean(workspacePolicy?.enabled && !workspacePolicy.can_create_workspace);
|
||||
const shouldBlockWorkspaceCreation = isWorkspaceCreationDisabled || isWorkspaceCreationDeniedByNodeDC;
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
workspaceService
|
||||
.getNodeDCWorkspacePolicy()
|
||||
.then((policy) => {
|
||||
if (mounted) setWorkspacePolicy(policy);
|
||||
})
|
||||
.catch(() => {
|
||||
if (mounted) {
|
||||
setWorkspacePolicy({
|
||||
enabled: false,
|
||||
can_create_workspace: true,
|
||||
mode: "unavailable",
|
||||
reason: "NODE.DC workspace policy is unavailable.",
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (mounted) setWorkspacePolicyLoading(false);
|
||||
});
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// methods
|
||||
const getMailtoHref = () => {
|
||||
|
|
@ -60,7 +94,17 @@ const CreateWorkspacePage = observer(function CreateWorkspacePage() {
|
|||
<div className="relative z-10 flex min-h-screen w-screen flex-col overflow-hidden overflow-y-auto bg-canvas px-8 pt-10 pb-12">
|
||||
<AuthHeaderBase pageTitle={t("workspace_creation.heading")} />
|
||||
<main className="grid flex-1 place-items-center py-8">
|
||||
{isWorkspaceCreationDisabled ? (
|
||||
{workspacePolicyLoading ? (
|
||||
<section className="nodedc-auth-shell flex flex-col items-start justify-center gap-4">
|
||||
<div className="space-y-3">
|
||||
<h1 className="m-0 text-30 font-semibold leading-tight text-primary">Работайте во всех измерениях.</h1>
|
||||
<p className="m-0 text-28 font-semibold leading-tight text-secondary">Проверяем доступ к workspace.</p>
|
||||
</div>
|
||||
<p className="m-0 text-14 leading-6 text-secondary">
|
||||
Сверяем платформенную policy NODE.DC перед созданием рабочего пространства.
|
||||
</p>
|
||||
</section>
|
||||
) : shouldBlockWorkspaceCreation ? (
|
||||
<section className="nodedc-auth-shell flex flex-col items-center justify-center gap-4 text-center">
|
||||
<img
|
||||
src={WorkspaceCreationDisabled}
|
||||
|
|
@ -68,10 +112,14 @@ const CreateWorkspacePage = observer(function CreateWorkspacePage() {
|
|||
alt="Workspace creation disabled"
|
||||
/>
|
||||
<h1 className="m-0 text-24 font-semibold text-primary">
|
||||
{t("workspace_creation.errors.creation_disabled.title")}
|
||||
{isWorkspaceCreationDeniedByNodeDC
|
||||
? "Workspace создаёт администратор."
|
||||
: t("workspace_creation.errors.creation_disabled.title")}
|
||||
</h1>
|
||||
<p className="m-0 text-14 leading-6 text-secondary">
|
||||
{t("workspace_creation.errors.creation_disabled.description")}
|
||||
{isWorkspaceCreationDeniedByNodeDC
|
||||
? workspacePolicy?.reason || "Дождитесь назначения в рабочее пространство администратором NODE.DC."
|
||||
: t("workspace_creation.errors.creation_disabled.description")}
|
||||
</p>
|
||||
<div className="mt-6 flex w-full flex-col gap-3">
|
||||
<Button variant="primary" className="nodedc-auth-primary-button" onClick={() => router.back()}>
|
||||
|
|
|
|||
|
|
@ -35,6 +35,13 @@ import type {
|
|||
// services
|
||||
import { APIService } from "@/services/api.service";
|
||||
|
||||
export interface NodeDCWorkspacePolicy {
|
||||
enabled: boolean;
|
||||
can_create_workspace: boolean;
|
||||
mode: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export class WorkspaceService extends APIService {
|
||||
constructor() {
|
||||
super(API_BASE_URL);
|
||||
|
|
@ -95,6 +102,14 @@ export class WorkspaceService extends APIService {
|
|||
});
|
||||
}
|
||||
|
||||
async getNodeDCWorkspacePolicy(): Promise<NodeDCWorkspacePolicy> {
|
||||
return this.get("/api/nodedc/workspace-policy/")
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
async updateWorkspace(workspaceSlug: string, data: Partial<IWorkspace>): Promise<IWorkspace> {
|
||||
return this.patch(`/api/workspaces/${workspaceSlug}/`, data)
|
||||
.then((response) => response?.data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue