Skip to content

Commit 60d7009

Browse files
committed
fix: borrow and return changes
1 parent 7989192 commit 60d7009

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

components/borrows/BtnReturnBorrow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export const BtnReturnBook: React.FC<
2626
if (confirm) clearTimeout(confirm)
2727
}
2828

29-
if (borrow.returned_at)
29+
if (borrow.returning)
3030
return (
3131
<Button {...props} variant="secondary" disabled>
32-
{formatDate(borrow.returned_at)}
32+
{formatDate(borrow.returning.returned_at)}
3333
</Button>
3434
)
3535

components/borrows/CardBorrow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const checkIsDue = (borrow: Borrow) => {
2727
}
2828

2929
const getBorrowStatus = (borrow: Borrow) => {
30-
if (borrow.returned_at) return 'returned'
30+
if (borrow.returning?.returned_at) return 'returned'
3131

3232
return checkIsDue(borrow) ? 'overdue' : 'active'
3333
}
@@ -39,7 +39,7 @@ export const CardBorrow: React.FC<{ borrow: Borrow }> = ({ borrow }) => {
3939
<Card
4040
key={borrow.id}
4141
className={clsx('relative', {
42-
'bg-destructive/5': isDue && !borrow.returned_at,
42+
'bg-destructive/5': isDue && !borrow.returning?.returned_at,
4343
})}
4444
>
4545
<CardHeader>

lib/api/borrow.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ export const createBorrow = async (
6161
}
6262

6363
export const returnBorrow = async (
64-
data: Pick<Borrow, 'id' | 'returned_at'>,
64+
data: Pick<Borrow, 'id'> & {
65+
returned_at: string
66+
},
6567
init?: RequestInit
6668
): GetBorrowResponse => {
67-
const response = await fetch(`${BORROW_URL}/${data.id}`, {
69+
const response = await fetch(`${BORROW_URL}/${data.id}/return`, {
6870
...init,
6971
method: 'PUT',
7072
body: JSON.stringify(data),

lib/types/borrow.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type Borrow = WithCommon<{
99
staff_id: string
1010
borrowed_at: string
1111
due_at: string
12-
returned_at?: string
12+
returning?: Return
1313
book: Pick<Book, 'id' | 'title' | 'code'>
1414
subscription: Pick<
1515
Subscription,
@@ -23,3 +23,9 @@ export type BorrowDetail = Omit<Borrow, 'book' | 'subscription' | 'staff'> & {
2323
subscription: SubscriptionDetail
2424
staff: Staff
2525
}
26+
27+
type Return = WithCommon<{
28+
borrowing_id: string
29+
returned_at: string
30+
staff: Pick<Staff, 'id' | 'name'>
31+
}>

0 commit comments

Comments
 (0)