Skip to content

Commit 32030a7

Browse files
committed
feat: subscription & membership info in borrow detail
1 parent 4ecc5a8 commit 32030a7

File tree

3 files changed

+98
-10
lines changed

3 files changed

+98
-10
lines changed

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

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@ import Link from 'next/link'
1010
import { Verify } from '@/lib/firebase/firebase'
1111
import { getBorrow } from '@/lib/api/borrow'
1212
import { Badge } from '@/components/ui/badge'
13-
import { formatDate, getBorrowStatus, isBorrowDue } from '@/lib/utils'
13+
import {
14+
formatDate,
15+
getBorrowStatus,
16+
getSubscriptionStatus,
17+
isBorrowDue,
18+
isSubscriptionActive,
19+
} from '@/lib/utils'
1420
import { BtnReturnBook } from '@/components/borrows/BtnReturnBorrow'
1521
import Image from 'next/image'
1622
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
1723
import {
24+
Book,
1825
Calendar,
1926
CalendarCheck,
2027
CalendarClock,
2128
CalendarX,
29+
Clock,
30+
CreditCard,
2231
Gavel,
2332
Library,
33+
Tally5,
2434
User,
2535
UserCog,
2636
} from 'lucide-react'
@@ -122,12 +132,19 @@ export default async function BorrowDetailsPage({
122132
<User className="h-4 w-4" />
123133
<p>
124134
<span className="font-medium">Name:&nbsp;</span>
135+
{/* <Link href={`/users/${borrowRes.data.subscription.user.id}`}> */}
125136
{borrowRes.data.subscription.user.name}
137+
{/* </Link> */}
126138
</p>
127139
<Library className="h-4 w-4" />
128140
<p>
129141
<span className="font-medium">Library:&nbsp;</span>
130-
{borrowRes.data.subscription.membership.library.name}
142+
<Link
143+
className="link"
144+
href={`/libraries/${borrowRes.data.subscription.membership.library.id}`}
145+
>
146+
{borrowRes.data.subscription.membership.library.name}
147+
</Link>
131148
</p>
132149
{/* <CreditCard className="h-4 w-4" />
133150
<p>
@@ -168,17 +185,21 @@ export default async function BorrowDetailsPage({
168185
<p>
169186
<span className="font-medium">Fine Expected:&nbsp;</span>
170187
{differenceInDays(
171-
new Date(),
188+
borrowRes.data.returning
189+
? new Date(borrowRes.data.returning.returned_at)
190+
: new Date(),
172191
new Date(borrowRes.data.due_at)
173192
) +
174193
' x ' +
175-
borrowRes.data.subscription.fine_per_day +
194+
(borrowRes.data.subscription.fine_per_day ?? 0) +
176195
' = ' +
177196
differenceInDays(
178-
new Date(),
197+
borrowRes.data.returning
198+
? new Date(borrowRes.data.returning.returned_at)
199+
: new Date(),
179200
new Date(borrowRes.data.due_at)
180201
) *
181-
borrowRes.data.subscription.fine_per_day +
202+
(borrowRes.data.subscription.fine_per_day ?? 0) +
182203
' Pts'}
183204
</p>
184205
<CalendarX className="h-4 w-4 text-destructive" />
@@ -217,6 +238,69 @@ export default async function BorrowDetailsPage({
217238
</CardContent>
218239
</Card> */}
219240

241+
<Card>
242+
<CardHeader>
243+
<div className="flex justify-between items-center">
244+
<CardTitle className="text-lg line-clamp-2">
245+
Membership Information
246+
</CardTitle>
247+
248+
<Badge
249+
variant={
250+
isSubscriptionActive(borrowRes.data.subscription)
251+
? 'default'
252+
: 'secondary'
253+
}
254+
className="capitalize"
255+
>
256+
{getSubscriptionStatus(borrowRes.data.subscription)}
257+
</Badge>
258+
</div>
259+
</CardHeader>
260+
<CardContent className="grid gap-2 grid-cols-[max-content,1fr] md:grid-cols-[max-content,1fr,max-content,1fr] items-center">
261+
<CreditCard className="h-4 w-4" />
262+
<p>
263+
<span className="font-medium">Membership:&nbsp;</span>
264+
<Link
265+
href={`/subscriptions/${borrowRes.data.subscription.id}`}
266+
className="link"
267+
>
268+
{borrowRes.data.subscription.membership.name}
269+
</Link>
270+
</p>
271+
<Clock className="h-4 w-4" />
272+
<p>
273+
<span className="font-medium">Expires:&nbsp;</span>
274+
{formatDate(borrowRes.data.subscription.expires_at)}
275+
</p>
276+
<CalendarClock className="h-4 w-4" />
277+
<p>
278+
<span className="font-medium">Borrow Period:&nbsp;</span>
279+
{borrowRes.data.subscription.loan_period} D
280+
</p>
281+
<Tally5 className="h-4 w-4" />
282+
<p>
283+
<span className="font-medium">Usage Limit:&nbsp;</span>
284+
{borrowRes.data.subscription.usage_limit ?? '-'}
285+
</p>
286+
<Book className="h-4 w-4" />
287+
<p>
288+
<span className="font-medium">Active Borrow Limit:&nbsp;</span>
289+
{borrowRes.data.subscription.active_loan_limit ?? '-'}
290+
</p>
291+
<Gavel className="h-4 w-4" />
292+
<p>
293+
<span className="font-medium">Fine per Day:&nbsp;</span>
294+
{borrowRes.data.subscription.fine_per_day ?? '-'} Pts
295+
</p>
296+
<Calendar className="h-4 w-4" />
297+
<p>
298+
<span className="font-medium">Purchased At:&nbsp;</span>
299+
{formatDate(borrowRes.data.subscription.created_at)}
300+
</p>
301+
</CardContent>
302+
</Card>
303+
220304
{!borrowRes.data.returning && (
221305
<div className="bottom-0 sticky py-2">
222306
<BtnReturnBook

app/globals.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ body {
9696
* {
9797
@apply border-border outline-ring/50;
9898
}
99+
99100
body {
100101
@apply bg-background text-foreground;
101102
}
103+
}
104+
105+
@layer utilities {
106+
.link {
107+
@apply underline decoration-dotted underline-offset-4;
108+
}
102109
}

components/subscriptions/CardSubscription.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from '@/lib/utils'
88
import { formatDistanceToNowStrict } from 'date-fns'
99
import { Badge } from '../ui/badge'
10-
import Link from 'next/link'
1110

1211
export const Cardsubscription: React.FC<{ subscription: Subscription }> = ({
1312
subscription,
@@ -16,9 +15,7 @@ export const Cardsubscription: React.FC<{ subscription: Subscription }> = ({
1615
<Card>
1716
<CardHeader>
1817
<div className="flex justify-between items-center">
19-
<CardTitle className="text-lg line-clamp-2">
20-
<Link href={`/subscriptions/${subscription.id}`}>Subscription</Link>
21-
</CardTitle>
18+
<CardTitle className="text-lg line-clamp-2">Subscription</CardTitle>
2219

2320
<Badge
2421
variant={

0 commit comments

Comments
 (0)