2026-04-11 22:02:57 +07:00
|
|
|
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
2025-03-28 21:46:10 +07:00
|
|
|
import {
|
|
|
|
|
PlusOutlined,
|
|
|
|
|
ReloadOutlined,
|
|
|
|
|
UsergroupAddOutlined,
|
|
|
|
|
UsergroupDeleteOutlined,
|
|
|
|
|
UserSwitchOutlined,
|
2026-04-11 22:02:57 +07:00
|
|
|
DeleteOutlined,
|
2026-04-11 17:04:14 +07:00
|
|
|
} from '@ant-design/icons'
|
|
|
|
|
import { Button } from '@imphnen-frontend-service/ui/atoms'
|
2026-04-11 22:02:57 +07:00
|
|
|
import { Fragment, useState } from 'react'
|
2026-04-05 17:08:42 +07:00
|
|
|
import {
|
|
|
|
|
useUserList,
|
|
|
|
|
useGachaItemList,
|
|
|
|
|
useDeleteGachaItem,
|
|
|
|
|
TGachaItemDto,
|
2026-04-11 17:04:14 +07:00
|
|
|
} from '@imphnen-frontend-service/service'
|
2026-04-11 22:02:57 +07:00
|
|
|
import { toast } from 'sonner'
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2026-04-11 17:04:14 +07:00
|
|
|
export const Route = createFileRoute('/_authenticated/dashboard')({
|
|
|
|
|
component: DashboardPage,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function DashboardPage() {
|
2026-04-11 22:02:57 +07:00
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const [deleteId, setDeleteId] = useState<string | null>(null)
|
2025-03-31 22:36:37 +07:00
|
|
|
|
2026-04-11 17:04:14 +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-11 17:04:14 +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 {
|
|
|
|
|
await deleteItem.mutateAsync(id)
|
|
|
|
|
toast.success('Item berhasil dihapus')
|
|
|
|
|
setDeleteId(null)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error)
|
|
|
|
|
toast.error('Item gagal dihapus')
|
2026-04-05 17:08:42 +07:00
|
|
|
}
|
2026-04-11 17:04:14 +07:00
|
|
|
}
|
2026-04-05 17:08:42 +07:00
|
|
|
|
2025-03-27 07:46:15 +07:00
|
|
|
return (
|
2025-03-31 00:30:05 +07:00
|
|
|
<Fragment>
|
|
|
|
|
<main className="w-full px-[48px] py-[40px] flex flex-col gap-8">
|
|
|
|
|
<header className="bg-white py-4 px-8 rounded-lg shadow p-4">
|
|
|
|
|
<h1 className="text-p2 font-semibold">Dashboard</h1>
|
|
|
|
|
</header>
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2025-03-31 00:30:05 +07:00
|
|
|
<div className="flex justify-between gap-[40px] p-8 bg-white rounded-md">
|
|
|
|
|
<div className="w-full flex flex-col gap-[40px]">
|
|
|
|
|
<section>
|
|
|
|
|
<h2 className="text-p2 font-medium text-primary-500 mb-8">
|
|
|
|
|
Summary
|
2025-03-27 13:35:13 +07:00
|
|
|
</h2>
|
2025-03-31 00:30:05 +07:00
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
|
|
|
<div className="bg-white rounded-lg shadow-sm py-4 px-6 flex items-center border border-neutral-100">
|
|
|
|
|
<div className="mr-4 text-primary-500 bg-primary-100 p-[8px] rounded-md">
|
|
|
|
|
<UsergroupAddOutlined className="text-[20px]" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-05 17:08:42 +07:00
|
|
|
<h3 className="text-p1 font-semibold">{totalUsers}</h3>
|
2025-03-31 00:30:05 +07:00
|
|
|
<p className="text-label1 text-neutral-500">Participants</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2025-03-31 00:30:05 +07:00
|
|
|
<div className="bg-white rounded-lg shadow-sm py-4 px-6 flex items-center border border-neutral-100">
|
|
|
|
|
<div className="mr-4 text-primary-500 bg-primary-100 p-[8px] rounded-md">
|
|
|
|
|
<ReloadOutlined className="text-[20px]" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-05 17:08:42 +07:00
|
|
|
<h3 className="text-p1 font-semibold">{gachaItemsData?.meta?.total ?? 0}</h3>
|
2025-03-31 00:30:05 +07:00
|
|
|
<p className="text-label1 text-neutral-500">
|
2026-04-05 17:08:42 +07:00
|
|
|
Gacha Items
|
2025-03-31 00:30:05 +07:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="bg-white rounded-lg shadow-sm py-4 px-6 flex items-center border border-neutral-100">
|
|
|
|
|
<div className="mr-4 text-primary-500 bg-primary-100 p-[8px] rounded-md">
|
|
|
|
|
<UserSwitchOutlined className="text-[20px]" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-05 17:08:42 +07:00
|
|
|
<h3 className="text-p1 font-semibold">-</h3>
|
2025-03-31 00:30:05 +07:00
|
|
|
<p className="text-label1 text-neutral-500">Redeem</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="bg-white rounded-lg shadow-sm py-4 px-6 flex items-center border border-neutral-100">
|
|
|
|
|
<div className="mr-4 text-primary-500 bg-primary-100 p-[8px] rounded-md">
|
|
|
|
|
<UsergroupDeleteOutlined className="text-[20px]" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-05 17:08:42 +07:00
|
|
|
<h3 className="text-p1 font-semibold">-</h3>
|
2025-03-31 00:30:05 +07:00
|
|
|
<p className="text-label1 text-neutral-500">
|
|
|
|
|
Inactive Users
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section className="flex flex-col gap-8">
|
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
|
<h2 className="text-p2 font-medium text-primary-500">
|
|
|
|
|
Gacha Items
|
|
|
|
|
</h2>
|
2025-03-31 01:33:18 +07:00
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="items-end gap-3"
|
2026-04-11 22:02:57 +07:00
|
|
|
onClick={() => navigate({ to: '/dashboard/create' })}
|
2025-03-31 01:33:18 +07:00
|
|
|
>
|
2025-03-31 00:30:05 +07:00
|
|
|
<span>Tambah Item</span>
|
|
|
|
|
<PlusOutlined className="text-[16px]" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-4 max-h-140 overflow-auto">
|
2026-04-05 17:08:42 +07:00
|
|
|
{gachaItems.map((item) => (
|
2025-03-31 00:30:05 +07:00
|
|
|
<div
|
2026-04-05 17:08:42 +07:00
|
|
|
key={item.id}
|
2025-04-05 09:36:49 +07:00
|
|
|
className="bg-white overflow-clip rounded-lg shadow-sm flex justify-between border border-neutral-100"
|
2025-03-31 00:30:05 +07:00
|
|
|
>
|
2025-04-05 09:36:49 +07:00
|
|
|
<div className="flex flex-col py-4 px-6 gap-[8px]">
|
2025-03-31 00:30:05 +07:00
|
|
|
<div>
|
|
|
|
|
<h3 className="text-p3 text-primary-500 font-medium">
|
2026-04-05 17:08:42 +07:00
|
|
|
{item.name}
|
2025-03-31 00:30:05 +07:00
|
|
|
</h3>
|
2025-04-05 09:36:49 +07:00
|
|
|
<div className="flex items-center justify-start gap-10 text-label2 text-gray-500 mt-1">
|
2026-04-05 17:08:42 +07:00
|
|
|
<span>{item.id}</span>
|
2025-03-31 00:30:05 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-start gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-[10px] text-neutral-500 p-0 font-normal hover:bg-transparent hover:text-primary-500"
|
2026-04-11 22:02:57 +07:00
|
|
|
onClick={() => navigate({ to: '/dashboard/$id', params: { id: item.id } })}
|
2025-03-31 00:30:05 +07:00
|
|
|
>
|
|
|
|
|
Edit
|
|
|
|
|
</Button>
|
2026-04-11 22:02:57 +07:00
|
|
|
{deleteId === item.id ? (
|
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
|
<span className="text-[10px] text-neutral-400">Yakin?</span>
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-[10px] text-red-500 p-0 font-normal hover:bg-transparent hover:text-red-700"
|
|
|
|
|
onClick={() => handleDelete(item.id)}
|
|
|
|
|
>
|
|
|
|
|
Ya
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-[10px] text-neutral-500 p-0 font-normal hover:bg-transparent"
|
|
|
|
|
onClick={() => setDeleteId(null)}
|
|
|
|
|
>
|
|
|
|
|
Batal
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-[10px] text-red-500 p-0 font-normal hover:bg-transparent hover:text-red-700"
|
|
|
|
|
onClick={() => setDeleteId(item.id)}
|
|
|
|
|
>
|
|
|
|
|
Delete
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-03-27 13:35:13 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-03-31 00:30:05 +07:00
|
|
|
|
2026-04-05 17:08:42 +07:00
|
|
|
<img src="gacha-clip.webp" alt={item.name} />
|
2025-03-27 13:35:13 +07:00
|
|
|
</div>
|
2025-03-31 00:30:05 +07:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
2025-03-27 14:31:30 +07:00
|
|
|
|
2025-03-31 00:30:05 +07:00
|
|
|
<img
|
|
|
|
|
src="gacha.webp"
|
|
|
|
|
alt=""
|
|
|
|
|
className="rounded-lg hidden xl:block xl:min-w-[436px] h-auto object-cover"
|
|
|
|
|
/>
|
2025-03-27 07:46:15 +07:00
|
|
|
</div>
|
2025-03-31 00:30:05 +07:00
|
|
|
</main>
|
|
|
|
|
</Fragment>
|
2026-04-11 17:04:14 +07:00
|
|
|
)
|
|
|
|
|
}
|