Initial commit device-management
tests / ci (push) Has been cancelled

This commit is contained in:
Wian Drs
2026-08-25 09:42:00 +07:00
commit 1e80be180e
1159 changed files with 149545 additions and 0 deletions
@@ -0,0 +1,85 @@
import { Form, Head, Link } from '@inertiajs/react';
import InputError from '@/components/input-error';
import { TenantAdminNav } from '@/components/tenant-admin-nav';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
type Props = {
tenant: { id: number; name: string };
};
export default function UserCreate({ tenant }: Props) {
const base = `/administration/tenants/${tenant.id}/users`;
return (
<>
<Head title="Tambah User" />
<div className="mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 p-4 md:p-6">
<div>
<h1 className="text-2xl font-semibold">Tambah User</h1>
<p className="text-sm text-muted-foreground">
{tenant.name}
</p>
</div>
<TenantAdminNav tenantId={tenant.id} />
<Form action={base} method="post">
{({ processing, errors }) => (
<Card>
<CardHeader>
<CardTitle>Informasi Akun</CardTitle>
</CardHeader>
<CardContent className="grid gap-5 md:grid-cols-2">
<div className="grid gap-2">
<Label>Nama</Label>
<Input name="name" required />
<InputError message={errors.name} />
</div>
<div className="grid gap-2">
<Label>Email</Label>
<Input name="email" type="email" required />
<InputError message={errors.email} />
</div>
<div className="grid gap-2">
<Label>Password</Label>
<Input
name="password"
type="password"
required
/>
<InputError message={errors.password} />
</div>
<div className="grid gap-2">
<Label>Konfirmasi Password</Label>
<Input
name="password_confirmation"
type="password"
required
/>
</div>
<div className="rounded-lg border bg-muted/40 px-4 py-3 text-sm md:col-span-2">
Akun baru otomatis menggunakan role baku{' '}
<strong>Tenant User</strong>.
</div>
<div className="flex justify-end gap-3 md:col-span-2">
<Button variant="outline" asChild>
<Link href={base}>Batal</Link>
</Button>
<Button disabled={processing}>
Buat User
</Button>
</div>
</CardContent>
</Card>
)}
</Form>
</div>
</>
);
}
UserCreate.layout = {
breadcrumbs: [
{ title: 'Users', href: '#' },
{ title: 'Tambah', href: '#' },
],
};
@@ -0,0 +1,137 @@
import { Form, Head, Link, usePage } from '@inertiajs/react';
import InputError from '@/components/input-error';
import { TenantAdminNav } from '@/components/tenant-admin-nav';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
type Role = { id: number; name: string };
type Props = {
tenant: { id: number; name: string };
managedUser: { id: number; name: string; email: string; roles: Role[] };
};
export default function UserEdit({ tenant, managedUser }: Props) {
const base = `/administration/tenants/${tenant.id}/users`;
const { flash } = usePage().props as unknown as {
flash: { success?: string };
};
return (
<>
<Head title={`Edit ${managedUser.name}`} />
<div className="mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 p-4 md:p-6">
<div>
<h1 className="text-2xl font-semibold">Edit User</h1>
<p className="text-sm text-muted-foreground">
{tenant.name}
</p>
</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>
)}
<Form action={`${base}/${managedUser.id}`} method="put">
{({ processing, errors }) => (
<Card>
<CardHeader>
<CardTitle>Profil dan Role</CardTitle>
</CardHeader>
<CardContent className="grid gap-5 md:grid-cols-2">
<div className="grid gap-2">
<Label>Nama</Label>
<Input
name="name"
defaultValue={managedUser.name}
required
/>
<InputError message={errors.name} />
</div>
<div className="grid gap-2">
<Label>Email</Label>
<Input
name="email"
type="email"
defaultValue={managedUser.email}
required
/>
<InputError message={errors.email} />
</div>
<div className="rounded-lg border bg-muted/40 px-4 py-3 text-sm md:col-span-2">
Role sistem:{' '}
<strong>
{managedUser.roles[0]?.name ??
'Tenant User'}
</strong>
. Role bersifat baku dan tidak dapat diubah.
</div>
<div className="flex justify-end gap-3 md:col-span-2">
<Button variant="outline" asChild>
<Link href={base}>Kembali</Link>
</Button>
<Button disabled={processing}>
Simpan
</Button>
</div>
</CardContent>
</Card>
)}
</Form>
<Form
action={`${base}/${managedUser.id}/password`}
method="put"
resetOnSuccess
>
{({ processing, errors }) => (
<Card>
<CardHeader>
<CardTitle>Reset Password</CardTitle>
<CardDescription>
Semua token API user akan dicabut.
</CardDescription>
</CardHeader>
<CardContent className="grid gap-5 md:grid-cols-2">
<div className="grid gap-2">
<Label>Password Baru</Label>
<Input
name="password"
type="password"
required
/>
<InputError message={errors.password} />
</div>
<div className="grid gap-2">
<Label>Konfirmasi Password</Label>
<Input
name="password_confirmation"
type="password"
required
/>
</div>
<div className="md:col-span-2">
<Button disabled={processing}>
Reset Password
</Button>
</div>
</CardContent>
</Card>
)}
</Form>
</div>
</>
);
}
UserEdit.layout = {
breadcrumbs: [
{ title: 'Users', href: '#' },
{ title: 'Edit', href: '#' },
],
};
@@ -0,0 +1,167 @@
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: '#' },
],
};