2026-04-11 17:04:14 +07:00
|
|
|
import { createFileRoute } from '@tanstack/react-router'
|
2025-03-28 21:46:10 +07:00
|
|
|
import {
|
|
|
|
|
PlusOutlined,
|
|
|
|
|
ReloadOutlined,
|
|
|
|
|
UsergroupAddOutlined,
|
|
|
|
|
UsergroupDeleteOutlined,
|
|
|
|
|
UserSwitchOutlined,
|
2026-04-11 17:04:14 +07:00
|
|
|
} from '@ant-design/icons'
|
|
|
|
|
import { Button } from '@imphnen-frontend-service/ui/atoms'
|
|
|
|
|
import { FC, Fragment, ReactElement, useRef, useState } from 'react'
|
|
|
|
|
import ModalAddItem from './_components/dashboard/modal-add-item'
|
|
|
|
|
import ModalEditItem from './_components/dashboard/modal-edit-item'
|
|
|
|
|
import ModalDeleteItem from './_components/dashboard/modal-delete-item'
|
|
|
|
|
import { useQueryState } from '@imphnen-frontend-service/utils'
|
2026-04-05 17:08:42 +07:00
|
|
|
import {
|
|
|
|
|
useUserList,
|
|
|
|
|
useGachaItemList,
|
|
|
|
|
useCreateGachaItem,
|
|
|
|
|
useUpdateGachaItem,
|
|
|
|
|
useDeleteGachaItem,
|
|
|
|
|
TGachaItemDto,
|
2026-04-11 17:04:14 +07:00
|
|
|
} from '@imphnen-frontend-service/service'
|
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() {
|
|
|
|
|
const [showModalAddItem, setShowModalAddItem] = useState(false)
|
|
|
|
|
const [showModalEditItem, setShowModalEditItem] = useState(false)
|
|
|
|
|
const [showModalDeleteItem, setShowModalDeleteItem] = useState(false)
|
|
|
|
|
const [selectedItem, setSelectedItem] = useState<TGachaItemDto | null>(null)
|
|
|
|
|
const pendingFormData = useRef<any>(null)
|
2025-03-31 00:30:05 +07:00
|
|
|
|
2025-03-31 22:36:37 +07:00
|
|
|
const {
|
|
|
|
|
step: currentStep,
|
|
|
|
|
nextStep,
|
|
|
|
|
prevStep,
|
|
|
|
|
resetStep,
|
|
|
|
|
} = useQueryState('step', {
|
|
|
|
|
defaultValue: 1,
|
|
|
|
|
maxValue: 2,
|
|
|
|
|
minValue: 1,
|
2026-04-11 17:04:14 +07:00
|
|
|
})
|
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 createItem = useCreateGachaItem()
|
|
|
|
|
const updateItem = useUpdateGachaItem()
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const handleAdd = async (): Promise<boolean> => {
|
|
|
|
|
if (pendingFormData.current) {
|
2026-04-11 17:04:14 +07:00
|
|
|
const { itemName, quantity } = pendingFormData.current
|
2026-04-05 17:08:42 +07:00
|
|
|
await createItem.mutateAsync({
|
|
|
|
|
item_code: (itemName as string).toLowerCase().replace(/\s+/g, '-'),
|
|
|
|
|
name: itemName,
|
|
|
|
|
description: '',
|
|
|
|
|
rarity: 'common',
|
|
|
|
|
type_: 'physical',
|
|
|
|
|
category: 'merchandise',
|
|
|
|
|
value: 0,
|
|
|
|
|
weight: 1,
|
|
|
|
|
stock: quantity ?? 1,
|
|
|
|
|
is_limited: false,
|
2026-04-11 17:04:14 +07:00
|
|
|
})
|
2026-04-05 17:08:42 +07:00
|
|
|
}
|
2026-04-11 17:04:14 +07:00
|
|
|
return true
|
|
|
|
|
}
|
2026-04-05 17:08:42 +07:00
|
|
|
|
|
|
|
|
const handleEdit = async (): Promise<boolean> => {
|
|
|
|
|
if (selectedItem && pendingFormData.current) {
|
2026-04-11 17:04:14 +07:00
|
|
|
const { itemName, quantity } = pendingFormData.current
|
2026-04-05 17:08:42 +07:00
|
|
|
await updateItem.mutateAsync({
|
|
|
|
|
id: selectedItem.id,
|
|
|
|
|
data: { name: itemName, stock: quantity },
|
2026-04-11 17:04:14 +07:00
|
|
|
})
|
2026-04-05 17:08:42 +07:00
|
|
|
}
|
2026-04-11 17:04:14 +07:00
|
|
|
return true
|
|
|
|
|
}
|
2026-04-05 17:08:42 +07:00
|
|
|
|
|
|
|
|
const handleDelete = async (): Promise<boolean> => {
|
|
|
|
|
if (selectedItem) {
|
2026-04-11 17:04:14 +07:00
|
|
|
await deleteItem.mutateAsync(selectedItem.id)
|
2026-04-05 17:08:42 +07:00
|
|
|
}
|
2026-04-11 17:04:14 +07:00
|
|
|
return true
|
|
|
|
|
}
|
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"
|
|
|
|
|
onClick={() => setShowModalAddItem(true)}
|
|
|
|
|
>
|
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-05 17:08:42 +07:00
|
|
|
onClick={() => {
|
2026-04-11 17:04:14 +07:00
|
|
|
setSelectedItem(item)
|
|
|
|
|
setShowModalEditItem(true)
|
2026-04-05 17:08:42 +07:00
|
|
|
}}
|
2025-03-31 00:30:05 +07:00
|
|
|
>
|
|
|
|
|
Edit
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-[10px] text-red-500 p-0 font-normal hover:bg-transparent hover:text-red-700"
|
2026-04-05 17:08:42 +07:00
|
|
|
onClick={() => {
|
2026-04-11 17:04:14 +07:00
|
|
|
setSelectedItem(item)
|
|
|
|
|
setShowModalDeleteItem(true)
|
2026-04-05 17:08:42 +07:00
|
|
|
}}
|
2025-03-31 00:30:05 +07:00
|
|
|
>
|
|
|
|
|
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>
|
2025-03-27 07:46:15 +07:00
|
|
|
|
2025-03-31 01:33:18 +07:00
|
|
|
<ModalAddItem
|
2025-03-31 22:36:37 +07:00
|
|
|
currentStep={currentStep}
|
2025-03-31 01:33:18 +07:00
|
|
|
isOpen={showModalAddItem}
|
|
|
|
|
onClose={() => setShowModalAddItem(false)}
|
2025-03-31 22:36:37 +07:00
|
|
|
nextStep={nextStep}
|
|
|
|
|
prevStep={prevStep}
|
|
|
|
|
resetStep={resetStep}
|
2026-04-05 17:08:42 +07:00
|
|
|
handleAddItem={handleAdd}
|
2026-04-11 17:04:14 +07:00
|
|
|
onDataCapture={(data) => { pendingFormData.current = data }}
|
2025-03-31 01:33:18 +07:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<ModalEditItem
|
2025-03-31 22:36:37 +07:00
|
|
|
currentStep={currentStep}
|
2025-03-31 01:33:18 +07:00
|
|
|
isOpen={showModalEditItem}
|
|
|
|
|
onClose={() => setShowModalEditItem(false)}
|
2025-03-31 22:36:37 +07:00
|
|
|
nextStep={nextStep}
|
|
|
|
|
prevStep={prevStep}
|
|
|
|
|
resetStep={resetStep}
|
2026-04-05 17:08:42 +07:00
|
|
|
handleEditItem={handleEdit}
|
|
|
|
|
initialValues={selectedItem ? { itemName: selectedItem.name } : undefined}
|
2026-04-11 17:04:14 +07:00
|
|
|
onDataCapture={(data) => { pendingFormData.current = data }}
|
2025-03-31 01:33:18 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-03-31 00:30:05 +07:00
|
|
|
<ModalDeleteItem
|
|
|
|
|
isOpen={showModalDeleteItem}
|
|
|
|
|
onClose={() => setShowModalDeleteItem(false)}
|
2026-04-11 17:04:14 +07:00
|
|
|
handleDeleteItem={async () => { await handleDelete(); return true }}
|
2025-03-31 00:30:05 +07:00
|
|
|
/>
|
|
|
|
|
</Fragment>
|
2026-04-11 17:04:14 +07:00
|
|
|
)
|
|
|
|
|
}
|