From 9f61c1590faadfa65b1b852a78915cfe6024de68 Mon Sep 17 00:00:00 2001 From: mxmlnwbr <71628027+mxmlnwbr@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:46:37 +0100 Subject: [PATCH] feat(app): Proposal filtering (#7) Co-authored-by: Roland Schlaefli --- src/components/ProposalStatusForm.tsx | 7 +- src/components/StudentProposals.tsx | 64 ++++- src/components/SupervisorProposals.tsx | 7 +- ...useLocalStorage.tsx => useLocalStorage.ts} | 0 src/lib/hooks/useUserRole.ts | 18 ++ src/pages/index.tsx | 83 +++--- src/server/routers/_app.ts | 251 +++++++++++------- src/types/{app.d.ts => app.ts} | 19 +- 8 files changed, 290 insertions(+), 159 deletions(-) rename src/lib/hooks/{useLocalStorage.tsx => useLocalStorage.ts} (100%) create mode 100644 src/lib/hooks/useUserRole.ts rename src/types/{app.d.ts => app.ts} (60%) diff --git a/src/components/ProposalStatusForm.tsx b/src/components/ProposalStatusForm.tsx index eb86f95..26ceeef 100644 --- a/src/components/ProposalStatusForm.tsx +++ b/src/components/ProposalStatusForm.tsx @@ -1,6 +1,6 @@ import { useSessionStorage } from '@uidotdev/usehooks' import { Tabs, UserNotification } from '@uzh-bf/design-system' -import type { Session } from 'next-auth' +import { useSession } from 'next-auth/react' import { ProposalDetails } from 'src/types/app' import AcceptProposalForm from './AcceptProposalForm' // Import AcceptProposalForm and other form components import DeclineProposalForm from './DeclineProposalForm' @@ -8,16 +8,17 @@ import RejectProposalForm from './RejectProposalForm' import TentativeAcceptProposalForm from './TentativeAcceptProposalForm' interface ProposalStatusFormProps { proposalDetails: ProposalDetails - session: Session | null } export default function ProposalStatusForm({ proposalDetails, - session, }: ProposalStatusFormProps) { + const { data: session } = useSession() + const [providedFeedback, setProvidedFeedback] = useSessionStorage< null | string >(proposalDetails.id, null) + if ( (proposalDetails?.typeKey === 'STUDENT' && proposalDetails?.statusKey === 'MATCHED_TENTATIVE') || diff --git a/src/components/StudentProposals.tsx b/src/components/StudentProposals.tsx index f98a8c1..293ee30 100644 --- a/src/components/StudentProposals.tsx +++ b/src/components/StudentProposals.tsx @@ -1,27 +1,72 @@ -import { H2, H3 } from '@uzh-bf/design-system' -import { RefObject } from 'react' +import { H2, H3, Select } from '@uzh-bf/design-system' +import * as R from 'ramda' +import { RefObject, useMemo } from 'react' +import { ProposalDetails, ProposalStatusFilter } from 'src/types/app' import ProposalCard from './ProposalCard' interface StudentProposalsProps { - data: any - groupedStudentProposals: any + data: ProposalDetails[] selectedProposal: string | null setSelectedProposal: (proposalId: string | null) => void - setDisplayMode: (displayMode: string) => void buttonRef: RefObject + filters: { + status: ProposalStatusFilter + } + setFilters: (filters: { status: ProposalStatusFilter }) => void } export default function StudentProposals({ data, - groupedStudentProposals, selectedProposal, setSelectedProposal, - setDisplayMode, buttonRef, + filters, + setFilters, }: StudentProposalsProps) { + const groupedStudentProposals = useMemo(() => { + if (!data) return {} + + return R.groupBy( + (p) => p.topicArea.name, + R.sortBy( + R.prop('title'), + data.filter( + (proposal: ProposalDetails) => proposal.typeKey === 'STUDENT' + ) + ) + ) + }, [data]) + return (
-

Student Proposals

+
+

Student Proposals

+