Skip to content

Commit 41a9fe8

Browse files
committed
feat: dashboard skip & limit
1 parent b6482e0 commit 41a9fe8

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

app/(protected)/dashboard/page.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { LibrarySelector } from '@/components/dashboard/LibrarySelector'
1919
import { DateRangeSelector } from '@/components/dashboard/DateRangeSelector'
2020
import { IsLoggedIn } from '@/lib/firebase/firebase'
2121
import { redirect, RedirectType } from 'next/navigation'
22-
import { format, subMonths, parse } from 'date-fns'
22+
import { format, subMonths, parse, startOfDay, endOfDay } from 'date-fns'
2323
import { getListLibraries } from '@/lib/api/library'
2424
import { DateRange } from 'react-day-picker'
2525

@@ -41,14 +41,6 @@ export default async function DashboardPage({
4141
const claims = await IsLoggedIn()
4242
if (!claims) redirect('/login?from=/dashboard')
4343

44-
const {
45-
library_id,
46-
from,
47-
to,
48-
// limit = 5,
49-
// skip,
50-
} = await searchParams
51-
5244
if (
5345
claims.librarease.role === 'USER' &&
5446
!claims.librarease.admin_libs.length &&
@@ -57,10 +49,12 @@ export default async function DashboardPage({
5749
redirect('/', RedirectType.replace)
5850
}
5951

52+
const { library_id, from, to, limit = 5, skip = 0 } = await searchParams
53+
6054
if (!to || !from) {
6155
const now = new Date()
6256
const to = format(now, 'dd-MM-yyyy')
63-
const from = format(subMonths(now, 4), 'dd-MM-yyyy')
57+
const from = format(subMonths(now, 1), 'dd-MM-yyyy')
6458
const libID = claims.librarease.admin_libs.concat(
6559
claims.librarease.staff_libs
6660
)
@@ -76,10 +70,10 @@ export default async function DashboardPage({
7670

7771
const [res, libsRes] = await Promise.all([
7872
getAnalysis({
79-
skip: 0,
80-
limit: 5,
81-
from: parse(from, 'dd-MM-yyyy', new Date()).toJSON(),
82-
to: parse(to, 'dd-MM-yyyy', new Date()).toJSON(),
73+
skip,
74+
limit,
75+
from: startOfDay(parse(from, 'dd-MM-yyyy', new Date())).toJSON(),
76+
to: endOfDay(parse(to, 'dd-MM-yyyy', new Date())).toJSON(),
8377
library_id,
8478
}),
8579
getListLibraries({ limit: 5 }),

components/dashboard/MonthlyRevenueChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function MonthlyRevenueChart({ data }: { data: Analysis['revenue'] }) {
5151
return (
5252
<Card>
5353
<CardHeader>
54-
<CardTitle>Monthly Revenue</CardTitle>
54+
<CardTitle>Total Revenue</CardTitle>
5555
<CardDescription>
5656
{from} - {to}
5757
</CardDescription>

components/dashboard/MontlyBorrowChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function MontlyBorrowChart({ data }: { data: Analysis['borrowing'] }) {
4747
return (
4848
<Card>
4949
<CardHeader>
50-
<CardTitle>Monthly Borrows</CardTitle>
50+
<CardTitle>Total Borrows</CardTitle>
5151
<CardDescription>
5252
{from} - {to}
5353
</CardDescription>

0 commit comments

Comments
 (0)