2026-04-12 23:01:47 +07:00
|
|
|
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
|
|
|
|
import * as React from 'react';
|
2025-03-28 21:46:10 +07:00
|
|
|
import {
|
2026-04-12 23:01:47 +07:00
|
|
|
Plus,
|
|
|
|
|
UsersRound,
|
|
|
|
|
UserMinus,
|
|
|
|
|
UserCog,
|
|
|
|
|
RefreshCcw,
|
|
|
|
|
Pencil,
|
|
|
|
|
Trash2,
|
|
|
|
|
MoreHorizontal,
|
|
|
|
|
} from 'lucide-react';
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@imphnen-frontend-service/ui/atoms';
|
|
|
|
|
import { BackofficeWrapper } from '@imphnen-frontend-service/ui/organisms';
|
2026-04-05 17:08:42 +07:00
|
|
|
import {
|
|
|
|
|
useUserList,
|
|
|
|
|
useGachaItemList,
|
|
|
|
|
useDeleteGachaItem,
|
|
|
|
|
TGachaItemDto,
|
2026-04-12 23:01:47 +07:00
|
|
|
} from '@imphnen-frontend-service/service';
|
|
|
|
|
import { toast } from 'sonner';
|
|
|
|
|
import { DeleteConfirmDialog } from '../../components/list-helpers';
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2026-04-11 17:04:14 +07:00
|
|
|
export const Route = createFileRoute('/_authenticated/dashboard')({
|
|
|
|
|
component: DashboardPage,
|
2026-04-12 23:01:47 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
type StatCardProps = {
|
|
|
|
|
icon: React.ComponentType<{ className?: string }>;
|
|
|
|
|
label: string;
|
|
|
|
|
value: React.ReactNode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function StatCard({ icon: Icon, label, value }: StatCardProps) {
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardContent className="flex items-center gap-4 pt-6">
|
|
|
|
|
<div className="grid size-11 shrink-0 place-items-center rounded-md bg-primary-100 text-primary-600">
|
|
|
|
|
<Icon className="size-5" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="text-2xl font-semibold leading-tight text-foreground">
|
|
|
|
|
{value}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-xs text-muted-foreground">{label}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-11 17:04:14 +07:00
|
|
|
|
|
|
|
|
function DashboardPage() {
|
2026-04-12 23:01:47 +07:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [deleteId, setDeleteId] = React.useState<string | null>(null);
|
2025-03-31 22:36:37 +07:00
|
|
|
|
2026-04-12 23:01:47 +07:00
|
|
|
const { data: usersData } = useUserList({ per_page: 1 });
|
|
|
|
|
const { data: gachaItemsData } = useGachaItemList({ per_page: 9 });
|
|
|
|
|
const deleteItem = useDeleteGachaItem();
|
2026-04-05 17:08:42 +07:00
|
|
|
|
2026-04-12 23:01:47 +07:00
|
|
|
const totalUsers = usersData?.meta?.total ?? 0;
|
|
|
|
|
const gachaItems: TGachaItemDto[] = gachaItemsData?.data ?? [];
|
2026-04-05 17:08:42 +07:00
|
|
|
|
2026-04-11 22:02:57 +07:00
|
|
|
const handleDelete = async (id: string) => {
|
|
|
|
|
try {
|
2026-04-12 23:01:47 +07:00
|
|
|
await deleteItem.mutateAsync(id);
|
|
|
|
|
toast.success('Item berhasil dihapus');
|
|
|
|
|
setDeleteId(null);
|
2026-04-11 22:02:57 +07:00
|
|
|
} catch (error) {
|
2026-04-12 23:01:47 +07:00
|
|
|
console.log(error);
|
|
|
|
|
toast.error('Item gagal dihapus');
|
2026-04-05 17:08:42 +07:00
|
|
|
}
|
2026-04-12 23:01:47 +07:00
|
|
|
};
|
2026-04-05 17:08:42 +07:00
|
|
|
|
2025-03-27 07:46:15 +07:00
|
|
|
return (
|
2026-04-12 23:01:47 +07:00
|
|
|
<BackofficeWrapper
|
|
|
|
|
title="Gacha Dashboard"
|
|
|
|
|
description="Ringkasan statistik & daftar item gacha"
|
|
|
|
|
>
|
|
|
|
|
<section className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
|
|
|
<StatCard
|
|
|
|
|
icon={UsersRound}
|
|
|
|
|
label="Participants"
|
|
|
|
|
value={totalUsers.toLocaleString('id-ID')}
|
|
|
|
|
/>
|
|
|
|
|
<StatCard
|
|
|
|
|
icon={RefreshCcw}
|
|
|
|
|
label="Gacha Items"
|
|
|
|
|
value={(gachaItemsData?.meta?.total ?? 0).toLocaleString('id-ID')}
|
|
|
|
|
/>
|
|
|
|
|
<StatCard icon={UserCog} label="Redeem" value="—" />
|
|
|
|
|
<StatCard icon={UserMinus} label="Inactive Users" value="—" />
|
|
|
|
|
</section>
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2026-04-12 23:01:47 +07:00
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<CardTitle>Gacha Items</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Daftar item yang tersedia di gacha
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</div>
|
|
|
|
|
<Button
|
|
|
|
|
size="md"
|
|
|
|
|
onClick={() => navigate({ to: '/dashboard/create' })}
|
|
|
|
|
>
|
|
|
|
|
<Plus className="size-4" />
|
|
|
|
|
Tambah Item
|
|
|
|
|
</Button>
|
2025-03-31 00:30:05 +07:00
|
|
|
</div>
|
2026-04-12 23:01:47 +07:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{gachaItems.length === 0 ? (
|
|
|
|
|
<p className="py-8 text-center text-sm text-muted-foreground">
|
|
|
|
|
Belum ada item gacha.
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<ul className="grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3">
|
|
|
|
|
{gachaItems.map((item) => (
|
|
|
|
|
<li
|
|
|
|
|
key={item.id}
|
|
|
|
|
className="flex items-start justify-between gap-3 rounded-md border border-neutral-200 p-4 transition-colors hover:border-primary-200 hover:bg-primary-50/40"
|
|
|
|
|
>
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<h3 className="truncate text-sm font-semibold text-primary-700">
|
|
|
|
|
{item.name}
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="mt-0.5 font-mono text-xs text-muted-foreground">
|
|
|
|
|
{item.id}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button variant="text" size="icon" aria-label="Actions">
|
|
|
|
|
<MoreHorizontal className="size-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onSelect={() =>
|
|
|
|
|
navigate({
|
|
|
|
|
to: '/dashboard/$id',
|
|
|
|
|
params: { id: item.id },
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Pencil />
|
|
|
|
|
<span>Edit</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
variant="destructive"
|
|
|
|
|
onSelect={() => setDeleteId(item.id)}
|
|
|
|
|
>
|
|
|
|
|
<Trash2 />
|
|
|
|
|
<span>Hapus</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2025-03-27 14:31:30 +07:00
|
|
|
|
2026-04-12 23:01:47 +07:00
|
|
|
<DeleteConfirmDialog
|
|
|
|
|
open={!!deleteId}
|
|
|
|
|
onOpenChange={(o) => !o && setDeleteId(null)}
|
|
|
|
|
onConfirm={() => deleteId && handleDelete(deleteId)}
|
|
|
|
|
title="Hapus item gacha ini?"
|
|
|
|
|
/>
|
|
|
|
|
</BackofficeWrapper>
|
|
|
|
|
);
|
2026-04-11 17:04:14 +07:00
|
|
|
}
|