feat(ui): organisations are created and opened from Instance settings

This commit is contained in:
sam committed 2026-11-13 13:03:43 +11:00
1 parent e6a2a16bba
commit c26eeda939
4 files changed
+77 -25

No files matched your search

+1 -1
View File
@@ -84,7 +84,7 @@ const settings: NavSpec = {
"/settings/status",
],
},
{ paths: ["/settings/authentication"] },
{ paths: ["/settings/organisations", "/settings/authentication"] },
],
};
+11 -24
View File
@@ -4,22 +4,16 @@ import { storeToRefs } from "pinia";
import { computed, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import NewOrgDialog from "./NewOrgDialog.vue";
import { Button } from "@/components/ui/button";
import { useOrgStore } from "@/stores/org";
/**
* The Organisation area's frame: the org every section below is about, and the
* switcher an instance admin uses to point it elsewhere.
* The Organisation area's frame: the org every section below is about. The
* topbar switches the org you act in; an instance admin opens any other org
* from Instance > Organisations.
*/
const orgStore = useOrgStore();
const { homeOrg, instanceAdmin, org, orgs } = storeToRefs(orgStore);
const { homeOrg, org } = storeToRefs(orgStore);
const error = ref("");
// Policies and models act on the caller's own org server-side, so an instance
@@ -43,20 +37,13 @@ onMounted(async () => {
<template>
<div>
<!-- The org is named once: the switcher for an instance admin, a plain
label for everyone else. -->
<div v-if="instanceAdmin" class="mb-4 flex flex-wrap items-center gap-2">
<Select :model-value="org?.id" @update:model-value="(id) => orgStore.viewOrg(String(id))">
<SelectTrigger class="w-72" aria-label="Organisation">
<SelectValue placeholder="Organisation" />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="o in orgs" :key="o.id" :value="o.id">{{ o.name }}</SelectItem>
</SelectContent>
</Select>
<NewOrgDialog />
<!-- The topbar names the org you act in. Only an instance admin who
opened another org from Instance > Organisations needs it named here,
with the way back. -->
<div v-if="org && away" class="mb-4 flex flex-wrap items-center gap-2">
<p class="text-title font-semibold tracking-[-0.01em]">{{ org.name }}</p>
<Button variant="ghost" size="sm" @click="orgStore.viewOrg(homeOrg)">Back to your organisation</Button>
</div>
<p v-else-if="org" class="mb-4 text-title font-semibold tracking-[-0.01em]">{{ org.name }}</p>
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
+6
View File
@@ -166,6 +166,12 @@ const routes = [
section: "settings",
},
},
{
path: "/settings/organisations",
name: "settings-organisations",
component: () => import("@/settings/OrganisationsPage.vue"),
meta: { navPath: "/settings", settings: true, label: "Organisations", section: "settings" },
},
{
path: "/settings/authentication",
name: "authentication",
+59
View File
@@ -0,0 +1,59 @@
<script setup lang="ts">
import { storeToRefs } from "pinia";
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import PageHeader from "@/base/PageHeader.vue";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/ui/item";
import NewOrgDialog from "@/org/NewOrgDialog.vue";
import { useOrgStore } from "@/stores/org";
/**
* The instance's tenants. Creating an org is an instance decision, so it lives
* here rather than inside an org; opening one points the Organisation area at
* it without changing the org the dashboard acts in.
*/
const orgStore = useOrgStore();
const { homeOrg, orgs } = storeToRefs(orgStore);
const router = useRouter();
const error = ref("");
onMounted(async () => {
try {
await orgStore.loadOrg();
} catch (cause) {
error.value = String((cause as Error).message || cause);
}
});
function open(id: string): void {
orgStore.viewOrg(id);
void router.push("/org");
}
</script>
<template>
<div>
<PageHeader title="Organisations"><NewOrgDialog /></PageHeader>
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
<Empty v-else-if="!orgs.length"><EmptyHeader><EmptyTitle>No organisations</EmptyTitle></EmptyHeader></Empty>
<ItemGroup v-else class="gap-2">
<Item v-for="o in orgs" :key="o.id" variant="outline" size="sm">
<ItemContent>
<ItemTitle>
{{ o.name }}
<Badge v-if="o.id === homeOrg" variant="secondary">Current</Badge>
</ItemTitle>
<ItemDescription class="font-mono">{{ o.id }}</ItemDescription>
</ItemContent>
<ItemActions>
<Button variant="outline" size="sm" @click="open(o.id)">Open</Button>
</ItemActions>
</Item>
</ItemGroup>
</div>
</template>