Skip to content

Commit 01684d1

Browse files
committed
feat: suspense recent borrows
1 parent 2352041 commit 01684d1

File tree

21 files changed

+141
-154
lines changed

21 files changed

+141
-154
lines changed

app/(protected)/admin/books/import/layout.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import { Alert, AlertDescription } from '@/components/ui/alert'
2-
import { Badge } from '@/components/ui/badge'
32
import {
43
Breadcrumb,
54
BreadcrumbItem,
65
BreadcrumbLink,
76
BreadcrumbList,
87
BreadcrumbSeparator,
98
} from '@/components/ui/breadcrumb'
10-
import { Button } from '@/components/ui/button'
11-
import { Verify } from '@/lib/firebase/firebase'
12-
import { Download, FileText } from 'lucide-react'
9+
import { FileText } from 'lucide-react'
1310
import { DownloadTemplateButton } from '@/components/books/DownloadTemplateButton'
1411
import { cookies } from 'next/headers'
1512

1613
export default async function BorrowDetailsLayout({
1714
children,
18-
params,
1915
}: Readonly<{
2016
children: React.ReactNode
2117
params: Promise<{}>
2218
}>) {
23-
const headers = await Verify({ from: `/admin/books/import` })
24-
2519
const cookieStore = await cookies()
2620
const cookieName = process.env.LIBRARY_COOKIE_NAME as string
2721
const libraryId = cookieStore.get(cookieName)?.value

app/(protected)/admin/books/import/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { FormUploadCSV } from '@/components/books/csv-upload-form'
2-
import { Button } from '@/components/ui/button'
32
import {
43
Card,
54
CardContent,
65
CardDescription,
76
CardHeader,
87
CardTitle,
98
} from '@/components/ui/card'
10-
import { RefreshCw, Upload } from 'lucide-react'
119

1210
export default function ImportBooksPage() {
1311
return (

app/(protected)/admin/borrows/[id]/page.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IsLoggedIn, Verify } from '@/lib/firebase/firebase'
2-
import { getBorrow, getListBorrows } from '@/lib/api/borrow'
3-
import { Borrow } from '@/lib/types/borrow'
2+
import { getBorrow } from '@/lib/api/borrow'
43
import { redirect, RedirectType } from 'next/navigation'
54
import { DetailBorrow } from '@/components/borrows/DetailBorrow'
65
import { Button } from '@/components/ui/button'
@@ -32,28 +31,8 @@ export default async function BorrowDetailsPage({
3231
redirect(`/login?from=${encodeURIComponent(from)}`, RedirectType.replace)
3332
}
3433

35-
let prevBorrows: Borrow[] = []
36-
const [prevBorrowsRes] = await Promise.all([
37-
getListBorrows(
38-
{
39-
subscription_id: borrowRes.data.subscription.id,
40-
sort_in: 'asc',
41-
limit: 20,
42-
},
43-
{
44-
headers,
45-
}
46-
),
47-
])
48-
49-
if ('error' in prevBorrowsRes) {
50-
prevBorrows = []
51-
} else {
52-
prevBorrows = prevBorrowsRes.data
53-
}
54-
5534
return (
56-
<DetailBorrow borrow={borrowRes.data} prevBorrows={prevBorrows}>
35+
<DetailBorrow borrow={borrowRes.data}>
5736
<div className="bottom-0 sticky py-2 grid md:grid-cols-2 gap-2">
5837
{borrowRes.data.returning ? (
5938
<BtnUndoReturn

app/(protected)/admin/dashboard/page.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99

1010
import { SITE_NAME } from '@/lib/consts'
1111
import type { Metadata, Route } from 'next'
12-
import { LibrarySelector } from '@/components/dashboard/LibrarySelector'
1312
import { DateRangeSelector } from '@/components/dashboard/DateRangeSelector'
1413
import { IsLoggedIn } from '@/lib/firebase/firebase'
1514
import { redirect, RedirectType } from 'next/navigation'
@@ -78,17 +77,6 @@ export default async function DashboardPage({
7877
return <div>{libsRes.error}</div>
7978
}
8079

81-
async function onLibraryChange(libraryID: string) {
82-
'use server'
83-
84-
const p = await searchParams
85-
// @ts-expect-error: skip and imit are not used now
86-
const sp = new URLSearchParams(p)
87-
sp.set('library_id', libraryID)
88-
89-
redirect(('./?' + sp.toString()) as Route, RedirectType.replace)
90-
}
91-
9280
const fromDate = parse(from, 'dd-MM-yyyy', new Date())
9381
const toDate = parse(to, 'dd-MM-yyyy', new Date())
9482

@@ -125,16 +113,8 @@ export default async function DashboardPage({
125113
</Breadcrumb>
126114

127115
<div className="grid my-4 grid-cols-1 gap-4 md:grid-cols-2">
128-
<LibrarySelector
129-
libs={libsRes.data.filter((lib) =>
130-
claims.librarease.admin_libs
131-
.concat(claims.librarease.staff_libs)
132-
.includes(lib.id)
133-
)}
134-
lib={libID!}
135-
onChangeAction={onLibraryChange}
136-
/>
137116
<DateRangeSelector
117+
className="col-span-2"
138118
range={{ from: fromDate, to: toDate }}
139119
onChangeAction={onDateRangeChange}
140120
/>

app/(protected)/admin/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default async function LibraryDashboard() {
5555
}
5656

5757
return (
58-
<main className="min-h-screen p-8">
58+
<main className="min-h-[calc(100vh-4rem)] p-8">
5959
<div className="max-w-2xl mx-auto space-y-4">
6060
<div className="flex justify-between items-center">
6161
<h1 className="text-2xl font-bold">Librarease</h1>

app/(protected)/admin/staffs/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Verify } from '@/lib/firebase/firebase'
2828
import Link from 'next/link'
2929
import type { Metadata } from 'next'
3030
import { SITE_NAME } from '@/lib/consts'
31+
import { DateTime } from '@/components/common/DateTime'
3132

3233
export const metadata: Metadata = {
3334
title: `Staffs · ${SITE_NAME}`,
@@ -105,7 +106,7 @@ export default async function Staffs({
105106
<TableHead>User</TableHead>
106107
<TableHead>Library</TableHead>
107108
<TableHead>Role</TableHead>
108-
<TableHead>Registered At</TableHead>
109+
<TableHead>Joined At</TableHead>
109110
</TableRow>
110111
</TableHeader>
111112
<TableBody>
@@ -117,7 +118,9 @@ export default async function Staffs({
117118
<TableCell>
118119
<Badge variant="outline">{s.role}</Badge>
119120
</TableCell>
120-
<TableCell>{s.created_at}</TableCell>
121+
<TableCell>
122+
<DateTime dateTime={s.created_at} />
123+
</TableCell>
121124
</TableRow>
122125
))}
123126
</TableBody>

app/(protected)/admin/users/page.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {
2323
TableRow,
2424
} from '@/components/ui/table'
2525
import { getListUsers } from '@/lib/api/user'
26-
import { formatDate } from '@/lib/utils'
2726
import Link from 'next/link'
2827
import type { Metadata } from 'next'
2928
import { SITE_NAME } from '@/lib/consts'
3029
import { cookies } from 'next/headers'
3130
import { Badge } from '@/components/ui/badge'
31+
import { DateTime } from '@/components/common/DateTime'
3232

3333
export const metadata: Metadata = {
3434
title: `Users · ${SITE_NAME}`,
@@ -100,19 +100,23 @@ export default async function Users({
100100
{/* <TableCaption>List of books available in the library.</TableCaption> */}
101101
<TableHeader>
102102
<TableRow>
103-
<TableHead>ID</TableHead>
104103
<TableHead>Name</TableHead>
105104
<TableHead>Email</TableHead>
106-
<TableHead>Created At</TableHead>
105+
<TableHead>ID</TableHead>
106+
<TableHead>Joined At</TableHead>
107107
</TableRow>
108108
</TableHeader>
109109
<TableBody>
110110
{res.data.map((u) => (
111111
<TableRow key={u.id}>
112-
<TableCell>{u.id}</TableCell>
113112
<TableCell>{u.name}</TableCell>
114113
<TableCell>{u.email}</TableCell>
115-
<TableCell>{formatDate(u.created_at)}</TableCell>
114+
<TableCell>
115+
<pre>{u.id}</pre>
116+
</TableCell>
117+
<TableCell>
118+
<DateTime dateTime={u.created_at} />
119+
</TableCell>
116120
</TableRow>
117121
))}
118122
</TableBody>
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IsLoggedIn, Verify } from '@/lib/firebase/firebase'
2-
import { getBorrow, getListBorrows } from '@/lib/api/borrow'
3-
import { Borrow } from '@/lib/types/borrow'
2+
import { getBorrow } from '@/lib/api/borrow'
43
import { redirect, RedirectType } from 'next/navigation'
54
import { DetailBorrow } from '@/components/borrows/DetailBorrow'
65

@@ -26,25 +25,5 @@ export default async function BorrowDetailsPage({
2625
redirect(`/login?from=${encodeURIComponent(from)}`, RedirectType.replace)
2726
}
2827

29-
let prevBorrows: Borrow[] = []
30-
const [prevBorrowsRes] = await Promise.all([
31-
getListBorrows(
32-
{
33-
subscription_id: borrowRes.data.subscription.id,
34-
sort_in: 'asc',
35-
limit: 20,
36-
},
37-
{
38-
headers,
39-
}
40-
),
41-
])
42-
43-
if ('error' in prevBorrowsRes) {
44-
prevBorrows = []
45-
} else {
46-
prevBorrows = prevBorrowsRes.data
47-
}
48-
49-
return <DetailBorrow borrow={borrowRes.data} prevBorrows={prevBorrows} />
28+
return <DetailBorrow borrow={borrowRes.data} />
5029
}

app/(protected)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default async function ProtectedLayout({
4949
Librarease
5050
</Link>
5151
{me && (
52-
<div className="inline-flex gap-2">
52+
<div className="inline-flex gap-2 items-baseline">
5353
{libraries.length > 0 && activeLibrary ? (
5454
<LibrarySwitch
5555
libraries={libraries}

components/books/DetailBook.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const DetailBook: React.FC<
3535
>
3636
{status}
3737
</Badge>
38-
<Badge variant="outline">book.genre</Badge>
38+
{/* <Badge variant="outline">book.genre</Badge> */}
3939
</div>
4040
</div>
4141

@@ -57,7 +57,7 @@ export const DetailBook: React.FC<
5757
<Library className="size-4" />
5858
<p>
5959
<span className="font-medium">Library:&nbsp;</span>
60-
<Link href={`/libraries/${book.library.id}`}>
60+
<Link href={`/libraries/${book.library.id}`} className="link">
6161
{book.library.name}
6262
</Link>
6363
</p>
@@ -69,7 +69,7 @@ export const DetailBook: React.FC<
6969
<CardTitle>Description</CardTitle>
7070
</CardHeader>
7171
<CardContent>
72-
<p className="text-sm leading-relaxed">book.description</p>
72+
{/* <p className="text-sm leading-relaxed">book.description</p> */}
7373
</CardContent>
7474
</Card>
7575
</div>

0 commit comments

Comments
 (0)