205 lines
9.9 KiB
TypeScript
205 lines
9.9 KiB
TypeScript
import { Head, Link, usePage } from '@inertiajs/react';
|
|
import { Building2, Plus, Users } from 'lucide-react';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
type Tenant = {
|
|
id: number;
|
|
uuid: string;
|
|
name: string;
|
|
slug: string;
|
|
is_active: boolean;
|
|
users_count: number;
|
|
created_at: string;
|
|
installations: {
|
|
deployment_type: string;
|
|
domain?: string;
|
|
status: string;
|
|
}[];
|
|
licenses: { plan: string; status: string; expires_at: string }[];
|
|
};
|
|
type PageLink = { url: string | null; label: string; active: boolean };
|
|
type Props = { tenants: { data: Tenant[]; links: PageLink[]; total: number } };
|
|
|
|
export default function TenantIndex({ tenants }: Props) {
|
|
const { flash } = usePage().props as unknown as {
|
|
flash: { success?: string };
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Head title="Tenants" />
|
|
<div className="flex flex-1 flex-col gap-6 p-4 md:p-6">
|
|
<div className="flex flex-col justify-between gap-3 sm:flex-row sm:items-center">
|
|
<div>
|
|
<h1 className="text-2xl font-semibold">Tenants</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Kelola organisasi yang menggunakan platform.
|
|
</p>
|
|
</div>
|
|
<Button asChild>
|
|
<Link href="/administration/tenants/create">
|
|
<Plus /> Tambah Tenant
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
{flash.success && (
|
|
<div className="rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
|
{flash.success}
|
|
</div>
|
|
)}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Building2 className="size-5" /> {tenants.total}{' '}
|
|
Tenant
|
|
</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="overflow-x-auto">
|
|
<table className="w-full min-w-3xl text-sm">
|
|
<thead>
|
|
<tr className="border-b text-left text-muted-foreground">
|
|
<th className="py-3">Tenant</th>
|
|
<th>Status</th>
|
|
<th>Instalasi</th>
|
|
<th>Paket</th>
|
|
<th>Users</th>
|
|
<th>Dibuat</th>
|
|
<th className="text-right">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{tenants.data.map((tenant) => (
|
|
<tr
|
|
key={tenant.uuid}
|
|
className="border-b last:border-0"
|
|
>
|
|
<td className="py-4">
|
|
<div className="font-medium">
|
|
{tenant.name}
|
|
</div>
|
|
<div className="text-xs text-muted-foreground">
|
|
{tenant.slug}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<Badge
|
|
variant={
|
|
tenant.is_active
|
|
? 'default'
|
|
: 'secondary'
|
|
}
|
|
>
|
|
{tenant.is_active
|
|
? 'Aktif'
|
|
: 'Nonaktif'}
|
|
</Badge>
|
|
</td>
|
|
<td>
|
|
<div className="font-medium">
|
|
{tenant.licenses[0]?.plan ??
|
|
'-'}
|
|
</div>
|
|
<div className="text-xs text-muted-foreground">
|
|
{tenant.licenses[0]?.status ??
|
|
'belum ada'}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<div className="font-medium">
|
|
{tenant.installations[0]
|
|
?.deployment_type ===
|
|
'self_hosted'
|
|
? 'Server Tenant'
|
|
: 'RADIQ Cloud'}
|
|
</div>
|
|
<div className="text-xs text-muted-foreground">
|
|
{tenant.installations[0]
|
|
?.domain ??
|
|
tenant.installations[0]
|
|
?.status ??
|
|
'-'}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<span className="inline-flex items-center gap-1">
|
|
<Users className="size-4" />{' '}
|
|
{tenant.users_count}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
{new Date(
|
|
tenant.created_at,
|
|
).toLocaleDateString('id-ID')}
|
|
</td>
|
|
<td className="text-right">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
asChild
|
|
>
|
|
<Link
|
|
href={`/administration/tenants/${tenant.id}/edit`}
|
|
>
|
|
Kelola
|
|
</Link>
|
|
</Button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
{tenants.data.length === 0 && (
|
|
<tr>
|
|
<td
|
|
colSpan={7}
|
|
className="py-12 text-center text-muted-foreground"
|
|
>
|
|
Belum ada tenant. Buat tenant
|
|
pertama untuk mulai.
|
|
</td>
|
|
</tr>
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
<div className="mt-4 flex flex-wrap gap-2">
|
|
{tenants.links.map((link) => (
|
|
<Button
|
|
key={link.label}
|
|
variant={
|
|
link.active ? 'default' : 'outline'
|
|
}
|
|
size="sm"
|
|
disabled={!link.url}
|
|
asChild={!!link.url}
|
|
>
|
|
{link.url ? (
|
|
<Link
|
|
href={link.url}
|
|
dangerouslySetInnerHTML={{
|
|
__html: link.label,
|
|
}}
|
|
/>
|
|
) : (
|
|
<span
|
|
dangerouslySetInnerHTML={{
|
|
__html: link.label,
|
|
}}
|
|
/>
|
|
)}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
TenantIndex.layout = {
|
|
breadcrumbs: [
|
|
{ title: 'Administration', href: '/administration/tenants' },
|
|
{ title: 'Tenants', href: '/administration/tenants' },
|
|
],
|
|
};
|