Skip to content

Commit c70dd93

Browse files
committed
feat: borrow page lost tab
1 parent 67602f7 commit c70dd93

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

app/(protected)/admin/borrows/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default async function Borrows({
4545
const sp = await searchParams
4646
const skip = Number(sp?.skip ?? 0)
4747
const limit = Number(sp?.limit ?? 20)
48-
const status = sp?.status as 'active' | 'overdue' | 'returned'
48+
const status = sp?.status as 'active' | 'overdue' | 'returned' | 'lost'
4949

5050
const headers = await Verify({
5151
from: '/admin/borrows',
@@ -134,6 +134,7 @@ export default async function Borrows({
134134
{ name: 'Active', href: '/admin/borrows?status=active' },
135135
{ name: 'Overdue', href: '/admin/borrows?status=overdue' },
136136
{ name: 'Returned', href: '/admin/borrows?status=returned' },
137+
{ name: 'Lost', href: '/admin/borrows?status=lost' },
137138
]}
138139
activeHref={`/admin/borrows${status ? `?status=${status}` : ''}`}
139140
/>

app/(protected)/borrows/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default async function Borrows({
4040
const skip = Number(sp?.skip ?? 0)
4141
const limit = Number(sp?.limit ?? 20)
4242
const library_id = sp?.library_id
43-
const status = sp?.status as 'active' | 'overdue' | 'returned'
43+
const status = sp?.status as 'active' | 'overdue' | 'returned' | 'lost'
4444

4545
const headers = await Verify({
4646
from: '/borrows',
@@ -111,6 +111,7 @@ export default async function Borrows({
111111
{ name: 'Active', href: '/borrows?status=active' },
112112
{ name: 'Overdue', href: '/borrows?status=overdue' },
113113
{ name: 'Returned', href: '/borrows?status=returned' },
114+
{ name: 'Lost', href: '/borrows?status=lost' },
114115
]}
115116
activeHref={`/borrows${status ? `?status=${status}` : ''}`}
116117
/>

components/borrows/FormBorrow.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { zodResolver } from '@hookform/resolvers/zod'
3333
import { createBorrow } from '@/lib/api/borrow'
3434
import {
3535
Command,
36-
// CommandEmpty,
3736
CommandGroup,
3837
CommandInput,
3938
CommandItem,
@@ -42,7 +41,6 @@ import {
4241
import {
4342
Form,
4443
FormControl,
45-
// FormDescription,
4644
FormField,
4745
FormItem,
4846
FormLabel,
@@ -102,10 +100,13 @@ export const FormBorrow: React.FC<FormBorrowProps> = (props) => {
102100

103101
function onSubmit(data: z.infer<typeof FormSchema>) {
104102
createBorrow(data)
105-
.then(console.log)
106-
.then(() => {
103+
.then((res) => {
104+
if ('error' in res) {
105+
toast.error(res.error)
106+
return
107+
}
107108
toast('Borrow created successfully')
108-
router.push('/borrows')
109+
router.push(`/admin/borrows/${res.data.id}`)
109110
})
110111
.catch((e) => {
111112
toast.error(e?.error)

components/borrows/TabLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const TabLink = <T extends string>({
1515
return (
1616
<div
1717
className={cn(
18-
'inline-flex gap-2 w-fit items-center justify-center rounded-lg bg-muted text-muted-foreground p-[3px]',
18+
'inline-flex gap-2 w-fit items-center justify-center rounded-lg bg-muted text-muted-foreground p-[3px] flex-wrap',
1919
className
2020
)}
2121
>

lib/api/borrow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type GetListBorrowsQuery = QueryParams<
99
is_active?: boolean
1010
is_expired?: boolean
1111
library_id?: string
12-
status?: 'active' | 'overdue' | 'returned'
12+
status?: 'active' | 'overdue' | 'returned' | 'lost'
1313
user_id?: string
1414
}
1515
>
@@ -33,6 +33,8 @@ export const getListBorrows = async (
3333
url.searchParams.append('is_overdue', 'true')
3434
} else if (status === 'returned') {
3535
url.searchParams.append('is_returned', 'true')
36+
} else if (status === 'lost') {
37+
url.searchParams.append('is_lost', 'true')
3638
}
3739
}
3840

0 commit comments

Comments
 (0)