Files
archie/ui/src/settings/OrganisationsPage.vue
T

62 lines
2.1 KiB
Vue

<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";
import { errors } from "@/copy/errors";
import { describeError } from "@/lib/api";
/**
* 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 = describeError(cause, errors.common.unknown);
}
});
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>