From a2bc9d0d5f868539cecde97d24d07310d64c3c6a Mon Sep 17 00:00:00 2001 From: ysandler Date: Mon, 5 May 2025 10:46:51 -0500 Subject: [PATCH] feat: manage page --- next.config.mjs | 4 + src/app/(frontend)/manage/page.client.tsx | 17 +++++ src/app/(frontend)/manage/page.tsx | 89 +++++++++++++++++++++++ src/components/Feed/UserFeed.tsx | 6 +- src/components/Manage/BorrowedBooks.tsx | 8 +- src/serverActions/ResetPassword.ts | 1 + 6 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 src/app/(frontend)/manage/page.client.tsx create mode 100644 src/app/(frontend)/manage/page.tsx diff --git a/next.config.mjs b/next.config.mjs index ee65b13..63d5822 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -11,6 +11,10 @@ const nextConfig = { source: '/search', destination: '/books', }, + { + source: '/profile', + destination: '/manage', + }, ] }, } diff --git a/src/app/(frontend)/manage/page.client.tsx b/src/app/(frontend)/manage/page.client.tsx new file mode 100644 index 0000000..2bac0cc --- /dev/null +++ b/src/app/(frontend)/manage/page.client.tsx @@ -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 | null + borrows: PaginatedDocs | null + user: User | null +} +const ManagePageClient = (props: Props) => { + const { repos, borrows, user } = props + return +} + +export default ManagePageClient diff --git a/src/app/(frontend)/manage/page.tsx b/src/app/(frontend)/manage/page.tsx new file mode 100644 index 0000000..9ba0b0f --- /dev/null +++ b/src/app/(frontend)/manage/page.tsx @@ -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 | 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 + + let userBorrows: PaginatedDocs | 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 ( + <> + + + + ) +} + +export default ManagePage diff --git a/src/components/Feed/UserFeed.tsx b/src/components/Feed/UserFeed.tsx index 257aaaf..87382f1 100644 --- a/src/components/Feed/UserFeed.tsx +++ b/src/components/Feed/UserFeed.tsx @@ -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, }, diff --git a/src/components/Manage/BorrowedBooks.tsx b/src/components/Manage/BorrowedBooks.tsx index 21a374a..4bade05 100644 --- a/src/components/Manage/BorrowedBooks.tsx +++ b/src/components/Manage/BorrowedBooks.tsx @@ -36,7 +36,7 @@ type ListProps = { onUpdate: () => Promise } 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( () => diff --git a/src/serverActions/ResetPassword.ts b/src/serverActions/ResetPassword.ts index 4462233..d3a033f 100644 --- a/src/serverActions/ResetPassword.ts +++ b/src/serverActions/ResetPassword.ts @@ -27,6 +27,7 @@ export const resetPassword = async (props: Props): Promise => { }) return true } catch (err) { + console.log(err) return false } }