@@ -6,46 +6,111 @@ import {
66 BreadcrumbPage ,
77 BreadcrumbSeparator ,
88} from "@/components/ui/breadcrumb" ;
9+ import { Button } from "@/components/ui/button" ;
10+ import {
11+ Pagination ,
12+ PaginationContent ,
13+ PaginationItem ,
14+ PaginationNext ,
15+ PaginationPrevious ,
16+ } from "@/components/ui/pagination" ;
17+ import {
18+ Table ,
19+ TableBody ,
20+ TableCell ,
21+ TableHead ,
22+ TableHeader ,
23+ TableRow ,
24+ } from "@/components/ui/table" ;
925import { getListStaffs } from "@/lib/api/staff" ;
1026import Link from "next/link" ;
1127
12- export default async function Staffs ( ) {
28+ export default async function Staffs ( {
29+ searchParams,
30+ } : {
31+ searchParams : Promise < {
32+ skip ?: number ;
33+ limit ?: number ;
34+ library_id ?: string ;
35+ } > ;
36+ } ) {
37+ const sp = await searchParams ;
38+ const skip = Number ( sp ?. skip ?? 0 ) ;
39+ const limit = Number ( sp ?. limit ?? 20 ) ;
40+ const library_id = sp ?. library_id ;
1341 const res = await getListStaffs ( {
1442 sort_by : "created_at" ,
1543 sort_in : "desc" ,
16- limit : 20 ,
44+ limit : limit ,
45+ skip : skip ,
46+ ...( library_id ? { library_id } : { } ) ,
1747 } ) ;
1848
1949 if ( "error" in res ) {
2050 console . log ( res ) ;
2151 return < div > { JSON . stringify ( res . message ) } </ div > ;
2252 }
2353
54+ const prevSkip = skip - limit > 0 ? skip - limit : 0 ;
55+
56+ const nextURL = `/staffs?skip=${ skip + limit } &limit=${ limit } ` ;
57+ const prevURL = `/staffs?skip=${ prevSkip } &limit=${ limit } ` ;
58+
2459 return (
2560 < div >
26- < h1 className = "text-2xl font-semibold" > Libraries</ h1 >
27- < Breadcrumb >
28- < BreadcrumbList >
29- < BreadcrumbItem >
30- < Link href = "/" passHref legacyBehavior >
31- < BreadcrumbLink > Home</ BreadcrumbLink >
32- </ Link >
33- </ BreadcrumbItem >
34- < BreadcrumbSeparator />
35-
36- < BreadcrumbItem >
37- < BreadcrumbPage > Staffs</ BreadcrumbPage >
38- </ BreadcrumbItem >
39- </ BreadcrumbList >
40- </ Breadcrumb >
41-
42- { res . data . map ( ( staff ) => (
43- < div key = { staff . id } >
44- < Link href = { `staffs/${ staff . id } ` } legacyBehavior >
45- { staff . name }
46- </ Link >
47- </ div >
48- ) ) }
61+ < h1 className = "text-2xl font-semibold" > Books</ h1 >
62+ < div className = "flex justify-between items-center" >
63+ < Breadcrumb >
64+ < BreadcrumbList >
65+ < BreadcrumbItem >
66+ < Link href = "/" passHref legacyBehavior >
67+ < BreadcrumbLink > Home</ BreadcrumbLink >
68+ </ Link >
69+ </ BreadcrumbItem >
70+ < BreadcrumbSeparator />
71+
72+ < BreadcrumbItem >
73+ < BreadcrumbPage > Staffs</ BreadcrumbPage >
74+ </ BreadcrumbItem >
75+ </ BreadcrumbList >
76+ </ Breadcrumb >
77+ < Button asChild >
78+ < Link href = "/staffs/new" > Register a Staff</ Link >
79+ </ Button >
80+ </ div >
81+
82+ < Table >
83+ { /* <TableCaption>List of books available in the library.</TableCaption> */ }
84+ < TableHeader >
85+ < TableRow >
86+ < TableHead > Name</ TableHead >
87+ < TableHead > User</ TableHead >
88+ < TableHead > Library</ TableHead >
89+ < TableHead > Registered At</ TableHead >
90+ </ TableRow >
91+ </ TableHeader >
92+ < TableBody >
93+ { res . data . map ( ( s ) => (
94+ < TableRow key = { s . id } >
95+ < TableCell > { s . name } </ TableCell >
96+ < TableCell > { s . user ?. name } </ TableCell >
97+ < TableCell > { s . library ?. name } </ TableCell >
98+ < TableCell > { s . created_at } </ TableCell >
99+ </ TableRow >
100+ ) ) }
101+ </ TableBody >
102+ </ Table >
103+
104+ < Pagination >
105+ < PaginationContent >
106+ < PaginationItem >
107+ < PaginationPrevious href = { prevURL } />
108+ </ PaginationItem >
109+ < PaginationItem >
110+ < PaginationNext href = { nextURL } />
111+ </ PaginationItem >
112+ </ PaginationContent >
113+ </ Pagination >
49114 </ div >
50115 ) ;
51116}
0 commit comments