feat: add views field to news response schema and update dashboard pages

This commit is contained in:
Ardeman 2025-03-24 15:45:43 +08:00
parent 1c33eba834
commit 65f7bbe0aa
4 changed files with 29 additions and 15 deletions

View File

@ -23,6 +23,7 @@ export const newsResponseSchema = z.object({
created_at: z.string(), created_at: z.string(),
updated_at: z.string(), updated_at: z.string(),
author: authorSchema, author: authorSchema,
views: z.number(),
}) })
const dataResponseSchema = z.object({ const dataResponseSchema = z.object({
data: z.array(newsResponseSchema), data: z.array(newsResponseSchema),

View File

@ -14,7 +14,7 @@ import { Button } from '~/components/ui/button'
import { UiTable } from '~/components/ui/table' import { UiTable } from '~/components/ui/table'
import { TitleDashboard } from '~/components/ui/title-dashboard' import { TitleDashboard } from '~/components/ui/title-dashboard'
import type { loader } from '~/routes/_admin.lg-admin._dashboard.advertisements._index' import type { loader } from '~/routes/_admin.lg-admin._dashboard.advertisements._index'
import { formatDate } from '~/utils/formatter' import { formatDate, formatNumberWithPeriods } from '~/utils/formatter'
export const AdvertisementsPage = () => { export const AdvertisementsPage = () => {
const loaderData = useRouteLoaderData<typeof loader>( const loaderData = useRouteLoaderData<typeof loader>(
@ -70,6 +70,7 @@ export const AdvertisementsPage = () => {
/> />
) )
}, },
5: (value: number) => formatNumberWithPeriods(value),
6: (value: string, _type: unknown, data: TAdResponse) => ( 6: (value: string, _type: unknown, data: TAdResponse) => (
<div className="flex space-x-2"> <div className="flex space-x-2">
<Button <Button

View File

@ -16,7 +16,7 @@ import { Button } from '~/components/ui/button'
import { UiTable } from '~/components/ui/table' import { UiTable } from '~/components/ui/table'
import { TitleDashboard } from '~/components/ui/title-dashboard' import { TitleDashboard } from '~/components/ui/title-dashboard'
import type { loader } from '~/routes/_admin.lg-admin._dashboard.contents._index' import type { loader } from '~/routes/_admin.lg-admin._dashboard.contents._index'
import { formatDate } from '~/utils/formatter' import { formatDate, formatNumberWithPeriods } from '~/utils/formatter'
export const ContentsPage = () => { export const ContentsPage = () => {
const loaderData = useRouteLoaderData<typeof loader>( const loaderData = useRouteLoaderData<typeof loader>(
@ -48,17 +48,20 @@ export const ContentsPage = () => {
title: 'Penulis', title: 'Penulis',
data: 'author', data: 'author',
}, },
{ title: 'Judul', data: 'title', className: 'text-sm' }, { title: 'Judul', data: 'title' },
{ {
title: 'Kategori', title: 'Kategori',
data: 'categories', data: 'categories',
className: 'text-xs',
}, },
{ title: 'Tag', data: 'tags', className: 'text-xs' }, { title: 'Tag', data: 'tags' },
{ {
title: 'Subscription', title: 'Subscription',
data: 'is_premium', data: 'is_premium',
}, },
{
title: 'Jumlah Pembaca',
data: 'views',
},
{ {
title: 'Action', title: 'Action',
data: 'id', data: 'id',
@ -72,9 +75,17 @@ export const ContentsPage = () => {
<div className="text-sm text-[#7C7C7C]">ID: {value.id.slice(0, 8)}</div> <div className="text-sm text-[#7C7C7C]">ID: {value.id.slice(0, 8)}</div>
</> </>
), ),
4: (value: TCategoryResponse[]) => 3: (value: string) => <span className="text-sm">{value}</span>,
value.map((item) => item.name).join(', '), 4: (value: TCategoryResponse[]) => (
5: (value: TTagResponse[]) => value.map((item) => item.name).join(', '), <span className="text-xs">
{value.map((item) => item.name).join(', ')}
</span>
),
5: (value: TTagResponse[]) => (
<span className="text-xs">
{value.map((item) => item.name).join(', ')}
</span>
),
6: (value: string) => 6: (value: string) =>
value ? ( value ? (
<div className="rounded-full bg-[#FFFCAF] px-2 text-center text-[#DBCA6E]"> <div className="rounded-full bg-[#FFFCAF] px-2 text-center text-[#DBCA6E]">
@ -85,7 +96,8 @@ export const ContentsPage = () => {
Normal Normal
</div> </div>
), ),
7: (value: string, _type: unknown, data: TNewsResponse) => ( 7: (value: number) => formatNumberWithPeriods(value),
8: (value: string, _type: unknown, data: TNewsResponse) => (
<div className="flex space-x-2"> <div className="flex space-x-2">
<Button <Button
as="a" as="a"

View File

@ -1,11 +1,11 @@
import { ChartBarIcon, ChartPieIcon } from '@heroicons/react/24/solid' import { ChartBarIcon, ChartPieIcon } from '@heroicons/react/24/solid'
export const REPORT = [ export const REPORT = [
{ title: 'Total User', amount: 10_800, icon: ChartBarIcon }, { title: 'Total User', amount: 8, icon: ChartBarIcon },
{ title: 'Total User Subscribe', amount: 5000, icon: ChartBarIcon }, { title: 'Total User Subscribe', amount: 0, icon: ChartBarIcon },
{ {
title: 'Total Nilai Subscribe', title: 'Total Nilai Subscribe',
amount: 250_000_000, amount: 0,
icon: ChartBarIcon, icon: ChartBarIcon,
currency: 'Rp. ', currency: 'Rp. ',
}, },
@ -14,12 +14,12 @@ export const REPORT = [
export const HISTORY = [ export const HISTORY = [
{ {
title: 'Total Content Biasa', title: 'Total Content Biasa',
amount: 2890, amount: 7,
icon: ChartPieIcon, icon: ChartPieIcon,
}, },
{ {
title: 'Total Content Premium', title: 'Total Content Premium',
amount: 274, amount: 3,
icon: ChartPieIcon, icon: ChartPieIcon,
}, },
] ]