@@ -10,15 +10,22 @@ import Link from 'next/link'
1010import { Verify } from '@/lib/firebase/firebase'
1111import { getBorrow } from '@/lib/api/borrow'
1212import { Badge } from '@/components/ui/badge'
13- import { getBorrowStatus } from '@/lib/utils'
14- import { CardBorrow } from '@/components/borrows/CardBorrow'
15- import { CardBook } from '@/components/books/CardBook'
16- import { Carduser } from '@/components/users/CardUser'
17- import { Cardstaff } from '@/components/staffs/CardStaff'
18- import { Cardsubscription } from '@/components/subscriptions/CardSubscription'
19- import { CardMembership } from '@/components/memberships/CardMembership'
13+ import { formatDate , getBorrowStatus , isBorrowDue } from '@/lib/utils'
2014import { BtnReturnBook } from '@/components/borrows/BtnReturnBorrow'
2115import Image from 'next/image'
16+ import { Card , CardContent , CardHeader , CardTitle } from '@/components/ui/card'
17+ import {
18+ Calendar ,
19+ CalendarCheck ,
20+ CalendarClock ,
21+ CalendarX ,
22+ Gavel ,
23+ Library ,
24+ User ,
25+ UserCog ,
26+ } from 'lucide-react'
27+ import clsx from 'clsx'
28+ import { differenceInDays } from 'date-fns'
2229
2330export default async function BorrowDetailsPage ( {
2431 params,
@@ -36,6 +43,10 @@ export default async function BorrowDetailsPage({
3643 return < div > { JSON . stringify ( borrowRes . message ) } </ div >
3744 }
3845
46+ const isDue = isBorrowDue ( borrowRes . data )
47+
48+ // const progressPercent = getBorrowProgressPercent(borrowRes.data)
49+
3950 // const cookieStore = await cookies()
4051 // const sessionName = process.env.SESSION_COOKIE_NAME as string
4152 // const session = cookieStore.get(sessionName)
@@ -78,23 +89,134 @@ export default async function BorrowDetailsPage({
7889 </ Badge >
7990 </ div >
8091
81- < div className = "grid grid-cols-1 md:grid-cols-3 gap-4" >
82- { borrowRes . data . book ?. cover && (
83- < Image
84- src = { borrowRes . data . book . cover }
85- alt = { borrowRes . data . book . title + "'s cover" }
86- width = { 256 }
87- height = { 256 }
88- className = "rounded-lg w-56 h-auto place-self-center row-span-2"
89- />
90- ) }
91- < CardBorrow borrow = { borrowRes . data } />
92- < CardBook book = { borrowRes . data . book } />
93- < Carduser user = { borrowRes . data . subscription . user } />
94- < Cardstaff staff = { borrowRes . data . staff } />
95- < Cardsubscription subscription = { borrowRes . data . subscription } />
96- < CardMembership membership = { borrowRes . data . subscription . membership } />
92+ < div className = "grid grid-cols-1 md:grid-cols-2 gap-4" >
93+ < Card className = "md:row-span-2" >
94+ < CardHeader >
95+ < CardTitle > Book Information</ CardTitle >
96+ </ CardHeader >
97+ < CardContent className = "grid md:grid-cols-2 gap-4" >
98+ < Image
99+ src = { borrowRes . data . book ?. cover ?? '/book-placeholder.svg' }
100+ alt = { borrowRes . data . book . title + "'s cover" }
101+ width = { 256 }
102+ height = { 256 }
103+ className = "shadow-md rounded-lg w-56 h-auto place-self-center row-span-2"
104+ />
105+ < div >
106+ < h2 className = "text-xl font-semibold" >
107+ { borrowRes . data . book . title }
108+ </ h2 >
109+ < p className = "text-gray-600" > { borrowRes . data . book . author } </ p >
110+ < p className = "text-sm text-gray-500" >
111+ { borrowRes . data . book . code }
112+ </ p >
113+ </ div >
114+ </ CardContent >
115+ </ Card >
116+
117+ < Card >
118+ < CardHeader >
119+ < CardTitle > User Information</ CardTitle >
120+ </ CardHeader >
121+ < CardContent className = "grid gap-2 grid-cols-[max-content,1fr] items-center" >
122+ < User className = "h-4 w-4" />
123+ < p >
124+ < span className = "font-medium" > Name: </ span >
125+ { borrowRes . data . subscription . user . name }
126+ </ p >
127+ < Library className = "h-4 w-4" />
128+ < p >
129+ < span className = "font-medium" > Library: </ span >
130+ { borrowRes . data . subscription . membership . library . name }
131+ </ p >
132+ { /* <CreditCard className="h-4 w-4" />
133+ <p>
134+ <span className="font-medium">Membership: </span>
135+ {borrowRes.data.subscription.membership.name}
136+ </p>
137+ <Clock className="h-4 w-4" />
138+ <p>
139+ <span className="font-medium">Expires: </span>
140+ {formatDate(borrowRes.data.subscription.expires_at)}
141+ </p> */ }
142+ </ CardContent >
143+ </ Card >
144+
145+ < Card >
146+ < CardHeader >
147+ < CardTitle > Borrow Details</ CardTitle >
148+ </ CardHeader >
149+ < CardContent className = "grid gap-2 grid-cols-[max-content,1fr] items-center" >
150+ < UserCog className = "h-4 w-4 text-muted-foreground" />
151+ < p >
152+ < span className = "font-medium" > Staff: </ span >
153+ { borrowRes . data . staff . name }
154+
155+ { borrowRes . data . returning
156+ ? '/ ' + borrowRes . data . returning . staff . name
157+ : null }
158+ </ p >
159+
160+ < Calendar className = "h-4 w-4 text-muted-foreground" />
161+ < p >
162+ < span className = "font-medium" > Borrowed: </ span >
163+ { formatDate ( borrowRes . data . borrowed_at ) }
164+ </ p >
165+ { isDue ? (
166+ < >
167+ < Gavel className = "h-4 w-4 text-muted-foreground" />
168+ < p >
169+ < span className = "font-medium" > Fine Expected: </ span >
170+ { differenceInDays (
171+ new Date ( ) ,
172+ new Date ( borrowRes . data . due_at )
173+ ) +
174+ ' x ' +
175+ borrowRes . data . subscription . fine_per_day +
176+ ' = ' +
177+ differenceInDays (
178+ new Date ( ) ,
179+ new Date ( borrowRes . data . due_at )
180+ ) *
181+ borrowRes . data . subscription . fine_per_day +
182+ ' Pts' }
183+ </ p >
184+ < CalendarX className = "h-4 w-4 text-destructive" />
185+ </ >
186+ ) : (
187+ < CalendarClock className = "h-4 w-4 text-muted-foreground" />
188+ ) }
189+ < p className = { clsx ( { 'text-destructive' : isDue } ) } >
190+ < span className = "font-medium" > Due: </ span >
191+ { formatDate ( borrowRes . data . due_at ) }
192+ </ p >
193+ { borrowRes . data . returning ? (
194+ < >
195+ < CalendarCheck className = "h-4 w-4 text-muted-foreground" />
196+ < p >
197+ < span className = "font-medium" > Returned: </ span >
198+ { formatDate ( borrowRes . data . returning . returned_at ) }
199+ </ p >
200+ < Gavel className = "h-4 w-4 text-muted-foreground" />
201+ < p >
202+ < span className = "font-medium" > Fine Received: </ span >
203+ { borrowRes . data . returning . fine ?? '-' } Pts
204+ </ p >
205+ </ >
206+ ) : null }
207+ </ CardContent >
208+ </ Card >
97209 </ div >
210+
211+ { /* <Card>
212+ <CardHeader>
213+ <CardTitle>Progress</CardTitle>
214+ </CardHeader>
215+ <CardContent>
216+ <Progress value={progressPercent} />
217+ </CardContent>
218+ </Card> */ }
219+
98220 { ! borrowRes . data . returning && (
99221 < div className = "bottom-0 sticky py-2" >
100222 < BtnReturnBook
0 commit comments