feat: manage page
This commit is contained in:
parent
2b4ed75d72
commit
a2bc9d0d5f
@ -11,6 +11,10 @@ const nextConfig = {
|
|||||||
source: '/search',
|
source: '/search',
|
||||||
destination: '/books',
|
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',
|
name: 'Hold Request',
|
||||||
iconSrc: '/images/mail.svg',
|
iconSrc: '/images/mail.svg',
|
||||||
value: totalHoldNotifications,
|
value: totalHoldNotifications,
|
||||||
href: '#',
|
href: '/manage',
|
||||||
ctaText: 'Answer Requests',
|
ctaText: 'Answer Requests',
|
||||||
shouldAnimate: totalHoldNotifications > 0,
|
shouldAnimate: totalHoldNotifications > 0,
|
||||||
},
|
},
|
||||||
@ -120,7 +120,7 @@ const UserFeed = async (props: Props) => {
|
|||||||
name: 'Loaned Out',
|
name: 'Loaned Out',
|
||||||
iconSrc: '/images/book-loan.svg',
|
iconSrc: '/images/book-loan.svg',
|
||||||
value: outBoundLoanCount,
|
value: outBoundLoanCount,
|
||||||
href: '#',
|
href: '/manage',
|
||||||
ctaText: 'Handle Returns',
|
ctaText: 'Handle Returns',
|
||||||
shouldAnimate: false,
|
shouldAnimate: false,
|
||||||
},
|
},
|
||||||
@ -128,7 +128,7 @@ const UserFeed = async (props: Props) => {
|
|||||||
name: 'Currently Holding',
|
name: 'Currently Holding',
|
||||||
iconSrc: '/images/book-shelf.svg',
|
iconSrc: '/images/book-shelf.svg',
|
||||||
value: currentlyHoldingCount,
|
value: currentlyHoldingCount,
|
||||||
href: '#',
|
href: '/manage',
|
||||||
ctaText: 'Loan Out',
|
ctaText: 'Loan Out',
|
||||||
shouldAnimate: false,
|
shouldAnimate: false,
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ type ListProps = {
|
|||||||
onUpdate: () => Promise<void>
|
onUpdate: () => Promise<void>
|
||||||
}
|
}
|
||||||
const BorrowedBooksList = (props: ListProps) => {
|
const BorrowedBooksList = (props: ListProps) => {
|
||||||
const { rows } = props
|
const { rows, onUpdate } = props
|
||||||
|
|
||||||
const [returningBookId, setReturningBookId] = useState(0)
|
const [returningBookId, setReturningBookId] = useState(0)
|
||||||
|
|
||||||
@ -54,11 +54,11 @@ const BorrowedBooksList = (props: ListProps) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await props.onUpdate()
|
await onUpdate()
|
||||||
setReturningBookId(0)
|
setReturningBookId(0)
|
||||||
toast('Book was returned, awaiting owner verification.')
|
toast('Book was returned, awaiting owner verification.')
|
||||||
},
|
},
|
||||||
[returningBookId, setReturningBookId],
|
[returningBookId, setReturningBookId, onUpdate],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -172,7 +172,7 @@ const BorrowedBooks = (props: Props) => {
|
|||||||
|
|
||||||
const updatedUserBorrows = await getUserBorrows({ userId: user.id })
|
const updatedUserBorrows = await getUserBorrows({ userId: user.id })
|
||||||
setBorrows(updatedUserBorrows)
|
setBorrows(updatedUserBorrows)
|
||||||
}, [borrows, setBorrows])
|
}, [setBorrows, user])
|
||||||
|
|
||||||
const rows: Row[] = useMemo(
|
const rows: Row[] = useMemo(
|
||||||
() =>
|
() =>
|
||||||
|
@ -27,6 +27,7 @@ export const resetPassword = async (props: Props): Promise<boolean> => {
|
|||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user