From 120450fd7c7e672acf5a409853d02a6e6a213a8f Mon Sep 17 00:00:00 2001 From: "fredy.siswanto" Date: Tue, 4 Mar 2025 00:21:14 +0700 Subject: [PATCH] feat: implement UiTable component and refactor dashboard pages to use it --- app/components/ui/table.tsx | 42 ++++++ app/data/contents.ts | 28 ++++ app/pages/dashboard-advertisements/index.tsx | 148 +++++++++++++------ app/pages/dashboard-contents/index.tsx | 62 ++++---- app/pages/dashboard-subscriptions/index.tsx | 57 +++---- 5 files changed, 228 insertions(+), 109 deletions(-) create mode 100644 app/components/ui/table.tsx diff --git a/app/components/ui/table.tsx b/app/components/ui/table.tsx new file mode 100644 index 0000000..ca22ed5 --- /dev/null +++ b/app/components/ui/table.tsx @@ -0,0 +1,42 @@ +import DT, { type Config, type ConfigColumns } from 'datatables.net-dt' +import DataTable from 'datatables.net-react' +import React from 'react' + +export type UiTableProperties = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data: any[] + columns: ConfigColumns[] + slots?: any // eslint-disable-line @typescript-eslint/no-explicit-any + options?: Config + title: string +} + +export const UiTable: React.FC = ({ + data, + columns, + slots, + options, + title, +}) => { + DataTable.use(DT) + return ( +
+

{title}

+
+ +
+
+ ) +} diff --git a/app/data/contents.ts b/app/data/contents.ts index 9e45504..921ca77 100644 --- a/app/data/contents.ts +++ b/app/data/contents.ts @@ -1,8 +1,11 @@ import type { TNews } from '~/types/news' type TBanner = { + id: number urlImage: string alt: string link: string + status: 'active' | 'draft' | 'inactive' + createdAt?: string } export const DUMMY_DESCRIPTION = 'Berita Terhangat hari ini' @@ -155,18 +158,43 @@ export const KAJIAN: TNews = { export const BANNER: TBanner[] = [ { + id: 1, urlImage: '/images/banner.png', alt: 'banner', link: '/category/spotlight', + status: 'active', + createdAt: '2021-08-01', }, { + id: 2, urlImage: 'https://placehold.co/1000x65.png', alt: 'banner', + status: 'draft', link: '/#', + createdAt: '2021-08-01', }, { + id: 3, + urlImage: 'https://placehold.co/1000x65.png', + alt: 'banner', + status: 'draft', + link: '/#', + createdAt: '2021-08-01', + }, + { + id: 4, urlImage: '/images/banner.png', alt: 'banner', link: '/#', + status: 'active', + createdAt: '2021-08-01', + }, + { + id: 5, + urlImage: '/images/banner.png', + alt: 'banner', + link: '/#', + status: 'inactive', + createdAt: '2021-08-01', }, ] diff --git a/app/pages/dashboard-advertisements/index.tsx b/app/pages/dashboard-advertisements/index.tsx index e103a1e..3016786 100644 --- a/app/pages/dashboard-advertisements/index.tsx +++ b/app/pages/dashboard-advertisements/index.tsx @@ -1,12 +1,17 @@ import { Field, Input, Label } from '@headlessui/react' import { useState } from 'react' +import { twMerge } from 'tailwind-merge' import { PlusIcon } from '~/components/icons/plus' +import { UiTable } from '~/components/ui/table' +import { TitleDashboard } from '~/components/ui/title-dashboard' +import { BANNER } from '~/data/contents' type BannerUploadProperties = { onBannerChange?: (file: File | undefined) => void onLinkChange?: (link: string) => void } +type TStatusColors = 'draft' | 'active' | 'inactive' export const AdvertisementsPage = ({ onBannerChange, @@ -27,55 +32,106 @@ export const AdvertisementsPage = ({ onLinkChange?.(newLink) } - return ( -
- {banner && ( -
-
- Banner Preview -
+ const dataBanner = BANNER + const dataColumns = [ + { title: 'No', data: 'id' }, + { title: 'Banner', data: 'urlImage' }, + { title: 'Link', data: 'link' }, + { title: 'Tgl Create', data: 'createdAt' }, + { title: 'Status', data: 'status' }, + ] + const dataSlot = { + 1: (value: string) => { + return ( +
+ {`banner
- )} - - - - - + {status} + + ) + }, + } - - - - + return ( +
+ +
+
+ + + + + + + + + + +
+ {banner && ( +
+
+ Banner Preview +
+
+ )} +
+
) } diff --git a/app/pages/dashboard-contents/index.tsx b/app/pages/dashboard-contents/index.tsx index 299e1c7..3717775 100644 --- a/app/pages/dashboard-contents/index.tsx +++ b/app/pages/dashboard-contents/index.tsx @@ -4,13 +4,15 @@ import DataTable from 'datatables.net-react' import { SearchIcon } from '~/components/icons/search' import { Button } from '~/components/ui/button' +import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' import { CONTENTS } from './data' export const ContentsPage = () => { DataTable.use(DT) - const columns = [ + const dataTable = CONTENTS + const dataColumns = [ { title: 'No', data: 'id' }, { title: 'Tanggal Kontent', data: 'createdAt' }, { title: 'Nama Penulis', data: 'author' }, @@ -30,6 +32,27 @@ export const ContentsPage = () => { data: 'id', }, ] + const dataSlot = { + 6: (value: string | number) => { + return ( + + ) + }, + } + const dataOptions = { + paging: true, + searching: true, + ordering: true, + info: true, + // scrollY: '50vh', + } return (
@@ -62,35 +85,14 @@ export const ContentsPage = () => {
-
-

Daftar Content

- { - return ( - - ) - }, - }} - options={{ - paging: true, - searching: true, - ordering: true, - info: true, - // scrollY: '50vh', - }} - > -
+ +
) } diff --git a/app/pages/dashboard-subscriptions/index.tsx b/app/pages/dashboard-subscriptions/index.tsx index 0de1f47..e251c7e 100644 --- a/app/pages/dashboard-subscriptions/index.tsx +++ b/app/pages/dashboard-subscriptions/index.tsx @@ -5,6 +5,7 @@ import { useState } from 'react' import { SearchIcon } from '~/components/icons/search' import { Button } from '~/components/ui/button' +import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' import { SUBSCRIPTIONS, SUBSETTINGS } from './data' @@ -91,23 +92,17 @@ export const SubscriptionsPage = () => { -
-

- Daftar Subscription -

- - -
+ )} @@ -156,22 +151,18 @@ export const SubscriptionsPage = () => { -
-

- Daftar Subscription -

- -
+ + )}