Skip to content

Commit 83e3df9

Browse files
committed
feat: authorize staffs route
1 parent a264aa9 commit 83e3df9

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
TableRow,
2525
} from '@/components/ui/table'
2626
import { getListStaffs } from '@/lib/api/staff'
27+
import { Verify } from '@/lib/firebase/firebase'
2728
import Link from 'next/link'
2829

2930
export default async function Staffs({
@@ -39,14 +40,24 @@ export default async function Staffs({
3940
const skip = Number(sp?.skip ?? 0)
4041
const limit = Number(sp?.limit ?? 20)
4142
const library_id = sp?.library_id
42-
const res = await getListStaffs({
43-
sort_by: 'created_at',
44-
sort_in: 'desc',
45-
limit: limit,
46-
skip: skip,
47-
...(library_id ? { library_id } : {}),
43+
44+
const headers = await Verify({
45+
from: '/staffs',
4846
})
4947

48+
const res = await getListStaffs(
49+
{
50+
sort_by: 'created_at',
51+
sort_in: 'desc',
52+
limit: limit,
53+
skip: skip,
54+
...(library_id ? { library_id } : {}),
55+
},
56+
{
57+
headers,
58+
}
59+
)
60+
5061
if ('error' in res) {
5162
console.log(res)
5263
return <div>{JSON.stringify(res.message)}</div>

app/(protected)/subscriptions/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '@/components/ui/table'
2525
import { getListSubs } from '@/lib/api/subscription'
2626
import { Verify } from '@/lib/firebase/firebase'
27+
import { formatDate } from '@/lib/utils'
2728
import Link from 'next/link'
2829

2930
export default async function Subscriptions({
@@ -111,10 +112,10 @@ export default async function Subscriptions({
111112
<TableCell>{s.membership?.name}</TableCell>
112113
<TableCell>{s.membership?.library?.name}</TableCell>
113114
<TableCell>
114-
<time dateTime={s.expires_at}>{s.expires_at}</time>
115+
<time dateTime={s.expires_at}>{formatDate(s.expires_at)}</time>
115116
</TableCell>
116117
<TableCell>
117-
<time dateTime={s.created_at}>{s.created_at}</time>
118+
<time dateTime={s.created_at}>{formatDate(s.created_at)}</time>
118119
</TableCell>
119120
<TableCell>{s.active_loan_limit}</TableCell>
120121
<TableCell>{s.loan_period} D</TableCell>

app/libraries/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
TableRow,
2424
} from '@/components/ui/table'
2525
import { getListLibraries } from '@/lib/api/library'
26+
import { formatDate } from '@/lib/utils'
2627
import Link from 'next/link'
2728

2829
export default async function Libraries({
@@ -94,8 +95,8 @@ export default async function Libraries({
9495
<TableCell>
9596
<Link href={`libraries/${lib.id}`}>{lib.name}</Link>
9697
</TableCell>
97-
<TableCell>{lib.created_at}</TableCell>
98-
<TableCell>{lib.updated_at}</TableCell>
98+
<TableCell>{formatDate(lib.created_at)}</TableCell>
99+
<TableCell>{formatDate(lib.updated_at)}</TableCell>
99100
</TableRow>
100101
))}
101102
</TableBody>

app/users/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
TableRow,
2424
} from '@/components/ui/table'
2525
import { getListUsers } from '@/lib/api/user'
26+
import { formatDate } from '@/lib/utils'
2627
import Link from 'next/link'
2728

2829
export default async function Users({
@@ -92,7 +93,7 @@ export default async function Users({
9293
<TableCell>{u.id}</TableCell>
9394
<TableCell>{u.name}</TableCell>
9495
<TableCell>{u.email}</TableCell>
95-
<TableCell>{u.created_at}</TableCell>
96+
<TableCell>{formatDate(u.created_at)}</TableCell>
9697
</TableRow>
9798
))}
9899
</TableBody>

components/borrows/FormNewBorrow.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,15 @@ export const FormNewBorrow: React.FC<{ token: string }> = ({ token }) => {
170170
const [staffs, setStaffs] = useState<Staff[]>([])
171171

172172
useEffect(() => {
173-
getListStaffs({
174-
limit: 20,
175-
name: staffQ,
176-
}).then((res) => {
173+
getListStaffs(
174+
{
175+
limit: 20,
176+
name: staffQ,
177+
},
178+
{
179+
headers,
180+
}
181+
).then((res) => {
177182
if ('error' in res) {
178183
toast({
179184
title: 'Error',

lib/api/staff.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const STAFF_URL = `${BASE_URL}/staffs`
77
type GetListStaffsQuery = QueryParams<Staff>
88
type GetListStaffsResponse = Promise<ResList<Staff>>
99
export const getListStaffs = async (
10-
query: GetListStaffsQuery
10+
query: GetListStaffsQuery,
11+
init?: RequestInit
1112
): GetListStaffsResponse => {
1213
const url = new URL(STAFF_URL)
1314
Object.entries(query).forEach(([key, value]) => {
@@ -16,7 +17,7 @@ export const getListStaffs = async (
1617
}
1718
})
1819

19-
const response = await fetch(url.toString())
20+
const response = await fetch(url.toString(), init)
2021
return response.json()
2122
}
2223

middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const config: MiddlewareConfig = {
1313
matcher: [
1414
'/subscriptions/:path*',
1515
'/borrows/:path*',
16+
'/staffs/:path*',
1617
'/libraries/([0-9a-fA-F-]{36})/edit',
1718
],
1819
}

0 commit comments

Comments
 (0)