168 lines
8.2 KiB
TypeScript
168 lines
8.2 KiB
TypeScript
import { Form, Head, Link, usePage } from '@inertiajs/react';
|
|
import { Plus } from 'lucide-react';
|
|
import { TenantAdminNav } from '@/components/tenant-admin-nav';
|
|
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; name: string };
|
|
type Role = { id: number; name: string };
|
|
type User = {
|
|
id: number;
|
|
uuid: string;
|
|
name: string;
|
|
email: string;
|
|
is_active: boolean;
|
|
roles: Role[];
|
|
created_at: string;
|
|
};
|
|
type Props = { tenant: Tenant; users: { data: User[]; total: number } };
|
|
|
|
export default function UserIndex({ tenant, users }: Props) {
|
|
const { auth, flash } = usePage().props as unknown as {
|
|
auth: { user: { is_platform_admin: boolean }; permissions: string[] };
|
|
flash: { success?: string };
|
|
};
|
|
const can = (permission: string) =>
|
|
auth.user.is_platform_admin || auth.permissions.includes(permission);
|
|
const base = `/administration/tenants/${tenant.id}/users`;
|
|
|
|
return (
|
|
<>
|
|
<Head title={`Users · ${tenant.name}`} />
|
|
<div className="flex flex-1 flex-col gap-6 p-4 md:p-6">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-2xl font-semibold">Users</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
{tenant.name}
|
|
</p>
|
|
</div>
|
|
{can('user.create') && (
|
|
<Button asChild>
|
|
<Link href={`${base}/create`}>
|
|
<Plus /> Tambah User
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
<TenantAdminNav tenantId={tenant.id} />
|
|
{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>{users.total} User</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">User</th>
|
|
<th>Role</th>
|
|
<th>Status</th>
|
|
<th className="text-right">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{users.data.map((user) => (
|
|
<tr
|
|
key={user.uuid}
|
|
className="border-b last:border-0"
|
|
>
|
|
<td className="py-3">
|
|
<div className="font-medium">
|
|
{user.name}
|
|
</div>
|
|
<div className="text-xs text-muted-foreground">
|
|
{user.email}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
{user.roles.map((role) => (
|
|
<Badge
|
|
key={role.id}
|
|
variant="secondary"
|
|
>
|
|
{role.name}
|
|
</Badge>
|
|
))}
|
|
</td>
|
|
<td>
|
|
<Badge
|
|
variant={
|
|
user.is_active
|
|
? 'default'
|
|
: 'secondary'
|
|
}
|
|
>
|
|
{user.is_active
|
|
? 'Aktif'
|
|
: 'Nonaktif'}
|
|
</Badge>
|
|
</td>
|
|
<td className="text-right">
|
|
<div className="flex justify-end gap-2">
|
|
{can('user.update') && (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
asChild
|
|
>
|
|
<Link
|
|
href={`${base}/${user.id}/edit`}
|
|
>
|
|
Edit
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
{can('user.update') && (
|
|
<Form
|
|
action={`${base}/${user.id}/toggle-active`}
|
|
method="patch"
|
|
>
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
>
|
|
{user.is_active
|
|
? 'Nonaktifkan'
|
|
: 'Aktifkan'}
|
|
</Button>
|
|
</Form>
|
|
)}
|
|
{can('user.delete') && (
|
|
<Form
|
|
action={`${base}/${user.id}`}
|
|
method="delete"
|
|
>
|
|
<Button
|
|
size="sm"
|
|
variant="destructive"
|
|
>
|
|
Hapus
|
|
</Button>
|
|
</Form>
|
|
)}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
UserIndex.layout = {
|
|
breadcrumbs: [
|
|
{ title: 'Tenants', href: '/administration/tenants' },
|
|
{ title: 'Users', href: '#' },
|
|
],
|
|
};
|