From 3a15c0d945c5864682a8027e7594e20b1466fea8 Mon Sep 17 00:00:00 2001 From: Ardeman Date: Sat, 8 Mar 2025 00:45:05 +0800 Subject: [PATCH] feat: enhance category schema with sequence and description fields, and update dashboard display --- app/apis/common/get-categories.ts | 2 ++ app/pages/dashboard-categories/index.tsx | 28 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/apis/common/get-categories.ts b/app/apis/common/get-categories.ts index c074cee..778e58d 100644 --- a/app/apis/common/get-categories.ts +++ b/app/apis/common/get-categories.ts @@ -6,6 +6,8 @@ export const categoryResponseSchema = z.object({ id: z.string(), name: z.string(), code: z.string(), + sequence: z.number().nullable(), + description: z.string().nullable(), }) const categoriesResponseSchema = z.object({ data: z.array(categoryResponseSchema), diff --git a/app/pages/dashboard-categories/index.tsx b/app/pages/dashboard-categories/index.tsx index f3ee82e..163e64c 100644 --- a/app/pages/dashboard-categories/index.tsx +++ b/app/pages/dashboard-categories/index.tsx @@ -2,6 +2,7 @@ import DT from 'datatables.net-dt' import DataTable from 'datatables.net-react' import { Link, useRouteLoaderData } from 'react-router' +import type { TCategoryResponse } from '~/apis/common/get-categories' import { Button } from '~/components/ui/button' import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' @@ -13,26 +14,33 @@ export const CategoriesPage = () => { const categoriesData = loaderData?.dataCategories DataTable.use(DT) - const dataTable = categoriesData + const dataTable = categoriesData?.sort((a, b) => { + if (a.sequence === null) return 1 + if (b.sequence === null) return -1 + return a.sequence - b.sequence + }) const dataColumns = [ { title: 'No', render: ( data: unknown, type: unknown, - row: unknown, + row: TCategoryResponse, meta: { row: number }, ) => { - return meta.row + 1 + return `
${meta.row + 1}
${ + row.sequence === null + ? '' + : `
Urutan: ${row.sequence}
` + }` }, }, { - title: 'Nama', - data: 'name', + title: 'Kategori', }, { - title: 'Kode', - data: 'code', + title: 'Deskripsi', + data: 'description', }, { title: 'Action', @@ -40,6 +48,12 @@ export const CategoriesPage = () => { }, ] const dataSlot = { + 1: (_value: unknown, _type: unknown, data: TCategoryResponse) => ( +
+
{data.name}
+
Kode: {data.code}
+
+ ), 3: (value: string) => (