feat: manage page
This commit is contained in:
parent
2b4ed75d72
commit
a2bc9d0d5f
@ -11,6 +11,10 @@ const nextConfig = {
|
||||
source: '/search',
|
||||
destination: '/books',
|
||||
},
|
||||
{
|
||||
source: '/profile',
|
||||
destination: '/manage',
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
17
src/app/(frontend)/manage/page.client.tsx
Normal file
17
src/app/(frontend)/manage/page.client.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
'use client'
|
||||
|
||||
import Manage from '@/components/Manage/Manage'
|
||||
import { Checkout, Repository, User } from '@/payload-types'
|
||||
import { PaginatedDocs } from 'payload'
|
||||
|
||||
type Props = {
|
||||
repos: PaginatedDocs<Repository> | null
|
||||
borrows: PaginatedDocs<Checkout> | null
|
||||
user: User | null
|
||||
}
|
||||
const ManagePageClient = (props: Props) => {
|
||||
const { repos, borrows, user } = props
|
||||
return <Manage repos={repos} borrows={borrows} user={user} />
|
||||
}
|
||||
|
||||
export default ManagePageClient
|
89
src/app/(frontend)/manage/page.tsx
Normal file
89
src/app/(frontend)/manage/page.tsx
Normal file
@ -0,0 +1,89 @@
|
||||
import { headers as getHeaders } from 'next/headers.js'
|
||||
import { getPayload, PaginatedDocs } from 'payload'
|
||||
import { Checkout, Repository } from '@/payload-types'
|
||||
import config from '@/payload.config'
|
||||
import ManagePageClient from './page.client'
|
||||
import { PageBreadCrumb, Route } from '@/components/PageBreadCrumb'
|
||||
|
||||
const breadcrumRoutes: Route[] = [
|
||||
{
|
||||
label: 'Home',
|
||||
href: '/',
|
||||
},
|
||||
{
|
||||
label: 'Manage',
|
||||
href: '/manage',
|
||||
},
|
||||
]
|
||||
|
||||
const ManagePage = async () => {
|
||||
const headers = await getHeaders()
|
||||
const payloadConfig = await config
|
||||
const payload = await getPayload({ config: payloadConfig })
|
||||
const { user } = await payload.auth({ headers })
|
||||
|
||||
let userRepos: PaginatedDocs<Repository> | null = null
|
||||
if (user?.id)
|
||||
userRepos = (await payload.find({
|
||||
collection: 'repositories',
|
||||
depth: 3,
|
||||
limit: 10,
|
||||
select: {
|
||||
name: true,
|
||||
abbreviation: true,
|
||||
image: true,
|
||||
description: true,
|
||||
dateOpenToPublic: true,
|
||||
holdRequests: true,
|
||||
},
|
||||
where: {
|
||||
'owner.id': {
|
||||
equals: user.id,
|
||||
},
|
||||
},
|
||||
joins: {
|
||||
holdRequests: {
|
||||
limit: 100,
|
||||
},
|
||||
},
|
||||
})) as PaginatedDocs<Repository>
|
||||
|
||||
let userBorrows: PaginatedDocs<Checkout> | null = null
|
||||
if (user?.id)
|
||||
userBorrows = await payload.find({
|
||||
collection: 'checkouts',
|
||||
depth: 3,
|
||||
limit: 10,
|
||||
select: {
|
||||
id: true,
|
||||
copy: true,
|
||||
dateDue: true,
|
||||
ownerVerifiedReturnedDate: true,
|
||||
loaneeReturnedDate: true,
|
||||
},
|
||||
sort: 'dateDue',
|
||||
where: {
|
||||
and: [
|
||||
{
|
||||
isReturned: {
|
||||
not_equals: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
'user.id': {
|
||||
equals: user.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageBreadCrumb routes={breadcrumRoutes} />
|
||||
<ManagePageClient repos={userRepos} borrows={userBorrows} user={user} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default ManagePage
|
@ -112,7 +112,7 @@ const UserFeed = async (props: Props) => {
|
||||
name: 'Hold Request',
|
||||
iconSrc: '/images/mail.svg',
|
||||
value: totalHoldNotifications,
|
||||
href: '#',
|
||||
href: '/manage',
|
||||
ctaText: 'Answer Requests',
|
||||
shouldAnimate: totalHoldNotifications > 0,
|
||||
},
|
||||
@ -120,7 +120,7 @@ const UserFeed = async (props: Props) => {
|
||||
name: 'Loaned Out',
|
||||
iconSrc: '/images/book-loan.svg',
|
||||
value: outBoundLoanCount,
|
||||
href: '#',
|
||||
href: '/manage',
|
||||
ctaText: 'Handle Returns',
|
||||
shouldAnimate: false,
|
||||
},
|
||||
@ -128,7 +128,7 @@ const UserFeed = async (props: Props) => {
|
||||
name: 'Currently Holding',
|
||||
iconSrc: '/images/book-shelf.svg',
|
||||
value: currentlyHoldingCount,
|
||||
href: '#',
|
||||
href: '/manage',
|
||||
ctaText: 'Loan Out',
|
||||
shouldAnimate: false,
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ type ListProps = {
|
||||
onUpdate: () => Promise<void>
|
||||
}
|
||||
const BorrowedBooksList = (props: ListProps) => {
|
||||
const { rows } = props
|
||||
const { rows, onUpdate } = props
|
||||
|
||||
const [returningBookId, setReturningBookId] = useState(0)
|
||||
|
||||
@ -54,11 +54,11 @@ const BorrowedBooksList = (props: ListProps) => {
|
||||
return
|
||||
}
|
||||
|
||||
await props.onUpdate()
|
||||
await onUpdate()
|
||||
setReturningBookId(0)
|
||||
toast('Book was returned, awaiting owner verification.')
|
||||
},
|
||||
[returningBookId, setReturningBookId],
|
||||
[returningBookId, setReturningBookId, onUpdate],
|
||||
)
|
||||
|
||||
return (
|
||||
@ -172,7 +172,7 @@ const BorrowedBooks = (props: Props) => {
|
||||
|
||||
const updatedUserBorrows = await getUserBorrows({ userId: user.id })
|
||||
setBorrows(updatedUserBorrows)
|
||||
}, [borrows, setBorrows])
|
||||
}, [setBorrows, user])
|
||||
|
||||
const rows: Row[] = useMemo(
|
||||
() =>
|
||||
|
@ -27,6 +27,7 @@ export const resetPassword = async (props: Props): Promise<boolean> => {
|
||||
})
|
||||
return true
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user