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 | 1x 6x 1x 1x 1x 1x 2x 2x 2x 2x 2x 6x | import { encodeResourceId } from "@/components/detail";
import React, { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { Organisation } from "@/objects/Organisation";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import { Building2, Search, ChevronRight, Calendar } from "lucide-react";
import { parseServerDate } from "@/util/time";
export interface OrganisationsGridProps {
organisations: Organisation[];
loading?: boolean;
}
// ─── Skeleton card ────────────────────────────────────────────────────────────
const SkeletonCard: React.FC = () => (
<div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-5 space-y-3 animate-pulse">
<div className="flex items-start justify-between">
<div className="flex items-center gap-3">
<div className="size-9 rounded-lg bg-gray-200 dark:bg-gray-700" />
<div className="space-y-1.5">
<div className="h-4 w-40 rounded bg-gray-200 dark:bg-gray-700" />
<div className="h-3 w-24 rounded bg-gray-200 dark:bg-gray-700" />
</div>
</div>
</div>
<div className="h-3 w-full rounded bg-gray-200 dark:bg-gray-700" />
<div className="h-3 w-3/5 rounded bg-gray-200 dark:bg-gray-700" />
</div>
);
// ─── Organisation card ────────────────────────────────────────────────────────
const OrganisationCard: React.FC<{ organisation: Organisation }> = ({ organisation }) => {
const href = APP_ROUTES.ORGANISATION.home.replace(
ROUTE_PARAMS.ORGANISATION.id,
encodeResourceId(organisation.id),
);
return (
<Link
to={href}
className="group flex flex-col rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm hover:shadow-md hover:border-gray-300 dark:hover:border-gray-500 transition-all overflow-hidden"
>
<div className="flex-1 p-5 flex flex-col gap-4">
{/* Header */}
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-3 min-w-0">
<div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
<Building2 className="size-5 text-gray-600 dark:text-gray-300" />
</div>
<div className="min-w-0">
<div className="text-sm font-semibold text-gray-900 dark:text-gray-100 truncate">
{organisation.name}
</div>
<div className="flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500 mt-0.5">
<Calendar className="size-3" />
{organisation.created_at
? parseServerDate(organisation.created_at).toLocaleDateString(undefined, {
year: "numeric",
month: "short",
day: "numeric",
})
: "Organisation"}
</div>
</div>
</div>
<ChevronRight className="size-4 text-gray-300 dark:text-gray-600 shrink-0 mt-0.5 group-hover:text-gray-500 dark:group-hover:text-gray-400 transition-colors" />
</div>
{/* Linked sign-in organisation, by its id: the sign-in service is
not named on the page. */}
{organisation.auth0_org_id ? (
<span
title="Sign-in organisation"
className="self-start text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 font-mono"
>
{organisation.auth0_org_id}
</span>
) : (
<p className="text-xs text-gray-300 dark:text-gray-600 italic">
No sign-in organisation linked.
</p>
)}
</div>
</Link>
);
};
// ─── Empty state ──────────────────────────────────────────────────────────────
const EmptyState: React.FC<{ filtered: boolean }> = ({ filtered }) => (
<div className="col-span-3 flex flex-col items-center justify-center py-16 text-center">
<div className="p-4 rounded-full bg-gray-100 dark:bg-gray-700 mb-4">
<Building2 className="size-8 text-gray-400 dark:text-gray-500" />
</div>
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">
{filtered ? "No organisations match your search." : "No organisations yet."}
</p>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
{filtered
? "Try adjusting your search."
: "Create an organisation to collaborate with your team."}
</p>
</div>
);
// ─── OrganisationsGrid ────────────────────────────────────────────────────────
const OrganisationsGrid: React.FC<OrganisationsGridProps> = ({ organisations, loading }) => {
const [search, setSearch] = useState("");
const filtered = useMemo(() => {
const q = search.trim().toLowerCase();
Eif (!q) return organisations;
return organisations.filter((o) => o.name.toLowerCase().includes(q));
}, [organisations, search]);
return (
<div className="space-y-4">
{/* Toolbar */}
<div className="flex items-center gap-3">
<div className="relative w-full sm:w-64">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-gray-400 pointer-events-none" />
<input
type="text"
placeholder="Search organisations…"
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-full pl-8 pr-3 py-2 text-sm rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:focus:ring-gray-500"
/>
</div>
</div>
{/* Summary */}
{!loading && organisations.length > 0 && (
<p className="text-xs text-gray-400 dark:text-gray-500">
{filtered.length} of {organisations.length} organisation
{organisations.length !== 1 ? "s" : ""}
{search ? " (filtered)" : ""}
</p>
)}
{/* Grid */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{loading ? (
Array.from({ length: 6 }).map((_, i) => <SkeletonCard key={i} />)
) : filtered.length === 0 ? (
<EmptyState filtered={!!search} />
) : (
filtered.map((org) => <OrganisationCard key={org.id} organisation={org} />)
)}
</div>
</div>
);
};
export default OrganisationsGrid;
|