@@ -19,6 +19,8 @@ import {
1919} from '@/components/ui/table'
2020import { getListBooks } from '@/lib/api/book'
2121import { getLibrary } from '@/lib/api/library'
22+ import { getListMemberships } from '@/lib/api/membership'
23+ import Image from 'next/image'
2224import Link from 'next/link'
2325
2426export default async function LibraryDetail ( {
@@ -27,9 +29,10 @@ export default async function LibraryDetail({
2729 params : Promise < { id : string } >
2830} ) {
2931 const { id } = await params
30- const [ libRes , bookRes ] = await Promise . all ( [
32+ const [ libRes , bookRes , memRes ] = await Promise . all ( [
3133 getLibrary ( { id } ) ,
32- getListBooks ( { limit : 20 , library_id : id } ) ,
34+ getListBooks ( { limit : 5 , library_id : id } ) ,
35+ getListMemberships ( { limit : 5 , library_id : id } ) ,
3336 ] )
3437
3538 if ( 'error' in libRes ) {
@@ -42,8 +45,13 @@ export default async function LibraryDetail({
4245 return < div > { JSON . stringify ( bookRes . message ) } </ div >
4346 }
4447
48+ if ( 'error' in memRes ) {
49+ console . log ( { memRes } )
50+ return < div > { JSON . stringify ( memRes . message ) } </ div >
51+ }
52+
4553 return (
46- < div >
54+ < div className = "space-y-2" >
4755 < h1 className = "text-2xl font-semibold" > { libRes . data . name } </ h1 >
4856 < Breadcrumb >
4957 < BreadcrumbList >
@@ -66,33 +74,85 @@ export default async function LibraryDetail({
6674 </ BreadcrumbList >
6775 </ Breadcrumb >
6876
69- < Table >
70- < TableCaption > List of books available in the library.</ TableCaption >
71- < TableHeader >
72- < TableRow >
73- < TableHead className = "w-[100px]" > Code</ TableHead >
74- < TableHead > Title</ TableHead >
75- < TableHead > Year</ TableHead >
76- < TableHead className = "text-right" > Author</ TableHead >
77- </ TableRow >
78- </ TableHeader >
79- < TableBody >
80- { bookRes . data . map ( ( book ) => (
81- < TableRow key = { book . id } >
82- < TableCell className = "font-medium" > { book . code } </ TableCell >
83- < TableCell > { book . title } </ TableCell >
84- < TableCell > { book . year } </ TableCell >
85- < TableCell className = "text-right" > { book . author } </ TableCell >
86- </ TableRow >
87- ) ) }
88- </ TableBody >
89- { /* <TableFooter>
90- <TableRow>
91- <TableCell colSpan={3}>Total</TableCell>
92- <TableCell className="text-right">$2,500.00</TableCell>
93- </TableRow>
94- </TableFooter> */ }
95- </ Table >
77+ < div className = "flex flex-col md:flex-row gap-4 py-2" >
78+ { libRes . data . logo && (
79+ < Image
80+ src = { libRes . data . logo }
81+ alt = { libRes . data . name }
82+ width = { 400 }
83+ height = { 400 }
84+ className = "rounded-lg w-auto h-auto"
85+ />
86+ ) }
87+ < div className = "" >
88+ < dl className = "grid gap-2" >
89+ < div className = "grid grid-cols-3" >
90+ < dt className = "font-medium" > Phone:</ dt >
91+ < dd className = "col-span-2" > { libRes . data . phone } </ dd >
92+ </ div >
93+ < div className = "grid grid-cols-3" >
94+ < dt className = "font-medium" > Email:</ dt >
95+ < dd className = "col-span-2" > { libRes . data . email } </ dd >
96+ </ div >
97+ < div className = "grid grid-cols-3" >
98+ < dt className = "font-medium" > Description:</ dt >
99+ < dd className = "col-span-2" > { libRes . data . description } </ dd >
100+ </ div >
101+ </ dl >
102+ </ div >
103+ </ div >
104+
105+ < div className = "grid md:grid-cols-2 gap-4" >
106+ < div className = "border border-gray-200 my-4" >
107+ < Table >
108+ < TableCaption > Latest added books from the library.</ TableCaption >
109+ < TableHeader >
110+ < TableRow >
111+ < TableHead className = "" > Code</ TableHead >
112+ < TableHead > Title</ TableHead >
113+ < TableHead > Year</ TableHead >
114+ < TableHead className = "text-right" > Author</ TableHead >
115+ </ TableRow >
116+ </ TableHeader >
117+ < TableBody >
118+ { bookRes . data . map ( ( book ) => (
119+ < TableRow key = { book . id } >
120+ < TableCell className = "font-medium" > { book . code } </ TableCell >
121+ < TableCell > { book . title } </ TableCell >
122+ < TableCell > { book . year } </ TableCell >
123+ < TableCell className = "text-right" > { book . author } </ TableCell >
124+ </ TableRow >
125+ ) ) }
126+ </ TableBody >
127+ </ Table >
128+ </ div >
129+
130+ < div className = "border border-gray-200 my-4" >
131+ < Table >
132+ < TableCaption >
133+ Latest added memberships from the library.
134+ </ TableCaption >
135+ < TableHeader >
136+ < TableRow >
137+ < TableHead > Name</ TableHead >
138+ < TableHead > Borrow Limit</ TableHead >
139+ < TableHead > Borrow Period</ TableHead >
140+ < TableHead > Price</ TableHead >
141+ </ TableRow >
142+ </ TableHeader >
143+ < TableBody >
144+ { memRes . data . map ( ( m ) => (
145+ < TableRow key = { m . id } >
146+ < TableCell className = "whitespace-nowrap" > { m . name } </ TableCell >
147+ < TableCell > { m . usage_limit ?? '-' } </ TableCell >
148+ < TableCell > { m . loan_period } D</ TableCell >
149+ < TableCell > { m . price ?? '-' } </ TableCell >
150+ </ TableRow >
151+ ) ) }
152+ </ TableBody >
153+ </ Table >
154+ </ div >
155+ </ div >
96156 </ div >
97157 )
98158}
0 commit comments