Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | import React from "react";
import ResourceHistorySection from "@/components/diff/ResourceHistorySection/ResourceHistorySection";
import { Link, useParams } from "react-router-dom";
import { useQuery } from "@tanstack/react-query";
import { useApiHandler } from "@/services/useApiHandler";
import { QUERY_KEYS } from "@/services/query_keys";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import SubPage from "@/components/page/SubPage/SubPage";
import {
Building2,
Calendar,
Bot,
Wrench,
FolderKanban,
Settings,
Users,
} from "lucide-react";
import {
MetaItem,
Skeleton,
} from "@/components/detail";
import { parseServerDate } from "@/util/time";
// ─── Primitives ───────────────────────────────────────────────────────────────
const NavCard: React.FC<{
icon: React.ElementType;
label: string;
description: string;
to: string;
}> = ({ icon: Icon, label, description, to }) => (
<Link
to={to}
className="flex items-start gap-3 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-500 hover:shadow-sm transition-all"
>
<div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
<Icon className="size-4 text-gray-600 dark:text-gray-300" />
</div>
<div className="min-w-0">
<div className="text-sm font-semibold text-gray-800 dark:text-gray-200">
{label}
</div>
<div className="text-xs text-gray-400 dark:text-gray-500 mt-0.5 leading-relaxed">
{description}
</div>
</div>
</Link>
);
// ─── OrganisationViewer ───────────────────────────────────────────────────────
const OrganisationViewer: React.FC = () => {
const { getApiHandler } = useApiHandler();
const { organisationId } = useParams();
const {
data: organisation,
error,
isLoading,
} = useQuery({
queryKey: [QUERY_KEYS.GET.ORGANISATION_BY_ID, organisationId],
queryFn: async () => {
if (!organisationId) return null;
return getApiHandler().organisation_router.id(atob(organisationId));
},
enabled: !!organisationId,
});
if (!organisationId)
return <div className="p-4 text-red-500">Invalid organisation ID.</div>;
if (error)
return <div className="p-4 text-red-500">Error: {error.toString()}</div>;
const navItems = organisationId
? [
{
icon: FolderKanban,
label: "Projects",
description: "View all projects within this organisation.",
to: APP_ROUTES.ORGANISATION.projects.replace(
ROUTE_PARAMS.ORGANISATION.id,
organisationId,
),
},
{
icon: Bot,
label: "Agents",
description: "Manage LLM agents scoped to this organisation.",
to: APP_ROUTES.ORGANISATION.agents.replace(
ROUTE_PARAMS.ORGANISATION.id,
organisationId,
),
},
{
icon: Settings,
label: "Settings",
description: "Configure organisation-level preferences.",
to: APP_ROUTES.ORGANISATION.settings.replace(
ROUTE_PARAMS.ORGANISATION.id,
organisationId,
),
},
]
: [];
return (
<SubPage
title={
isLoading ? (
<Skeleton className="h-7 w-48" />
) : (
(organisation?.name ?? "—")
)
}
title_icon={
<Building2 className="size-12 text-gray-400 dark:text-gray-500" />
}
links={[]}
>
{/* Metadata strip */}
<div className="grid grid-cols-2 sm:grid-cols-3 gap-5 p-5 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm mb-6">
{isLoading ? (
Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="flex flex-col gap-1.5">
<Skeleton className="h-3 w-16" />
<Skeleton className="h-4 w-24" />
</div>
))
) : (
<>
<MetaItem
icon={Building2}
label="Type"
value={
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-emerald-50 dark:bg-emerald-950/40 text-emerald-700 dark:text-emerald-300 border border-emerald-200 dark:border-emerald-800">
Organisation
</span>
}
/>
<MetaItem
icon={Users}
label="Sign-in organisation"
value={
organisation?.auth0_org_id ? (
<span className="font-mono text-xs">
{organisation.auth0_org_id}
</span>
) : (
<span className="text-gray-400 dark:text-gray-500 italic font-normal">
Not linked
</span>
)
}
/>
<MetaItem
icon={Calendar}
label="Created"
value={
organisation?.created_at
? parseServerDate(organisation.created_at).toLocaleDateString(
undefined,
{
year: "numeric",
month: "short",
day: "numeric",
},
)
: "—"
}
/>
</>
)}
</div>
{/* Navigation cards */}
{!isLoading && (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
{navItems.map((item) => (
<NavCard key={item.label} {...item} />
))}
</div>
)}
{isLoading && (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
{Array.from({ length: 4 }).map((_, i) => (
<div
key={i}
className="animate-pulse rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4 flex items-start gap-3"
>
<div className="size-8 rounded-lg bg-gray-200 dark:bg-gray-700 shrink-0" />
<div className="flex-1 space-y-2">
<div className="h-4 w-24 rounded bg-gray-200 dark:bg-gray-700" />
<div className="h-3 w-full rounded bg-gray-200 dark:bg-gray-700" />
</div>
</div>
))}
</div>
)}
<ResourceHistorySection
source={getApiHandler().organisation_router}
resourceId={organisationId ? atob(organisationId) : null}
queryKey={QUERY_KEYS.GET.ORGANISATION_HISTORY}
fieldLabels={{ name: "Name", auth0_org_id: "Sign-in organisation" }}
/>
</SubPage>
);
};
export default OrganisationViewer;
|