Spaces and pages: - Spaces inside workspaces, open or private, with admin/editor/commenter/viewer roles that cascade from the workspace role (rules in internal/access) - Page tree per space with fractional position keys, move with cycle checks, trash that hides whole subtrees, restore and permanent delete - OpenAPI, TypeScript client, and web app sidebar tree with drag-and-drop, page, space, trash and space settings views (EN + PL) Design system: - Tokens, type scale, radii and shadows from the design kit in @docwell/ui/theme.css; Inter, Source Serif 4 and JetBrains Mono bundled - Vue ports of Button, TextField, Badge, Callout, Icon, Breadcrumbs, SlashMenu and PageTreeItem, plus Logo; favicons and web manifest - Web app and admin panel restyled on the new tokens, in light and dark Also: fix the Vite dev server crashing on /config.json, and stop tracking the local Design/ and docs/ folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
4.0 KiB
Vue
97 lines
4.0 KiB
Vue
<script setup lang="ts">
|
|
import type { Organization } from "@docwell/api-client";
|
|
import { DwButton, DwCallout } from "@docwell/ui";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { useI18n } from "vue-i18n";
|
|
import { useApi } from "../../api";
|
|
import FormField from "../../components/FormField.vue";
|
|
import PageShell from "../../components/PageShell.vue";
|
|
import { useFormErrors } from "../../composables/useFormErrors";
|
|
import { useRuntimeConfig } from "../../platform";
|
|
import { useAuthStore } from "../../stores/auth";
|
|
import { useWorkspacesStore } from "../../stores/workspaces";
|
|
|
|
// Adapts to who is looking (same model as DriverVault's OrgManager):
|
|
// - no organization: create one and become its admin;
|
|
// - org admin: rename it, or delete it as its last member (back to a plain user);
|
|
// - org member: see which organization they belong to;
|
|
// - superadmin: organizations are managed in the admin panel.
|
|
// The server enforces all of this; the page only mirrors it.
|
|
const api = useApi();
|
|
const auth = useAuthStore();
|
|
const workspaces = useWorkspacesStore();
|
|
const config = useRuntimeConfig();
|
|
const { t } = useI18n();
|
|
const errors = useFormErrors();
|
|
|
|
const role = computed(() => auth.user?.role ?? "user");
|
|
const hasOrg = computed(() => !!auth.user?.organization);
|
|
const org = ref<Organization | null>(null);
|
|
const name = ref("");
|
|
const busy = ref(false);
|
|
const adminUrl = computed(() => `${config.apiUrl}/admin/`);
|
|
|
|
async function loadOrg() {
|
|
org.value = null;
|
|
if (role.value === "admin" && hasOrg.value) {
|
|
org.value = (await api.orgs.list().catch(() => []))[0] ?? null;
|
|
name.value = org.value?.name ?? "";
|
|
}
|
|
}
|
|
onMounted(loadOrg);
|
|
|
|
async function run(action: () => Promise<unknown>) {
|
|
busy.value = true;
|
|
errors.reset();
|
|
try {
|
|
await action();
|
|
await auth.reload();
|
|
await Promise.all([loadOrg(), workspaces.load()]);
|
|
} catch (e) {
|
|
errors.show(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
const create = () => run(() => api.orgs.create(name.value));
|
|
const rename = () => run(() => api.orgs.rename(org.value!.id, name.value));
|
|
function remove() {
|
|
if (!org.value || !confirm(t("org.confirmDelete", { name: org.value.name }))) return;
|
|
run(() => api.orgs.remove(org.value!.id));
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<PageShell :title="$t('org.title')" :subtitle="$t(`org.subtitle.${role === 'superadmin' ? 'superadmin' : hasOrg ? role : 'none'}`)">
|
|
<DwCallout v-if="errors.message.value" tone="danger" size="ui">{{ errors.message.value }}</DwCallout>
|
|
|
|
<section v-if="role === 'superadmin'" class="dw-card">
|
|
<a :href="adminUrl" class="dw-link">{{ $t("org.openAdmin") }}</a>
|
|
</section>
|
|
|
|
<form v-else-if="!hasOrg" class="space-y-4 dw-card" @submit.prevent="create">
|
|
<FormField v-model="name" :label="$t('org.name')" required :error="errors.fields.value.name" />
|
|
<p class="text-ui-sm text-ink-muted">{{ $t("org.createHint") }}</p>
|
|
<DwButton type="submit" variant="primary" :disabled="busy || !name.trim()">{{ $t("org.create") }}</DwButton>
|
|
</form>
|
|
|
|
<section v-else-if="role === 'admin' && org" class="space-y-4 dw-card">
|
|
<form class="space-y-4" @submit.prevent="rename">
|
|
<FormField v-model="name" :label="$t('org.name')" required :error="errors.fields.value.name" />
|
|
<p class="text-ui-sm text-ink-muted">{{ $t("org.counts", { members: org.members, workspaces: org.workspaces }) }}</p>
|
|
<DwButton type="submit" variant="primary" :disabled="busy || !name.trim() || name.trim() === org.name">{{ $t("common.save") }}</DwButton>
|
|
</form>
|
|
<div class="border-t border-line pt-4">
|
|
<h2 class="text-ui-lg">{{ $t("org.dangerTitle") }}</h2>
|
|
<p class="mt-1 text-ui-sm text-ink-muted">{{ $t("org.deleteHint") }}</p>
|
|
<DwButton variant="secondary" class="mt-3 !text-danger" :disabled="busy" @click="remove">{{ $t("org.delete") }}</DwButton>
|
|
</div>
|
|
</section>
|
|
|
|
<section v-else class="dw-card">
|
|
<p class="text-ui-md">{{ $t("org.memberOf", { name: auth.user?.organizationName }) }}</p>
|
|
</section>
|
|
</PageShell>
|
|
</template>
|