Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(app): store provided feedback in session storage #5

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@trpc/next": "10.37.1",
"@trpc/react-query": "10.37.1",
"@trpc/server": "10.37.1",
"@uidotdev/usehooks": "^2.4.1",
"@uzh-bf/design-system": "2.0.12",
"axios": "1.5.1",
"cross-fetch": "3.1.5",
Expand Down
6 changes: 4 additions & 2 deletions src/components/AcceptProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ interface AcceptProposalFormProps {
proposalName: string
proposalId: string
supervisorEmail: string
setValue: (value: string) => void
}

export default function AcceptProposalForm({
proposalName,
proposalId,
supervisorEmail,
setValue,
}: AcceptProposalFormProps) {
rschlaefli marked this conversation as resolved.
Show resolved Hide resolved
const SignupSchema = Yup.object().shape({
comment: Yup.string().required('Required'),
Expand All @@ -36,9 +38,9 @@ export default function AcceptProposalForm({
}}
validationSchema={SignupSchema}
onSubmit={async (values, { resetForm }) => {
await submitFeedback.mutateAsync(values)

setValue('ACCEPT')
resetForm()
await submitFeedback.mutateAsync(values)
toast.success('Proposal accepted successfully!')
}}
>
Expand Down
6 changes: 4 additions & 2 deletions src/components/DeclineProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ interface DeclineProposalFormProps {
proposalName: string
proposalId: string
supervisorEmail: string
setValue: (value: string) => void
}

export default function DeclineProposalForm({
proposalName,
proposalId,
supervisorEmail,
setValue,
}: DeclineProposalFormProps) {
const SignupSchema = Yup.object().shape({
reason: Yup.string().required('Required'),
Expand All @@ -39,9 +41,9 @@ export default function DeclineProposalForm({
}}
validationSchema={SignupSchema}
onSubmit={async (values, { resetForm }) => {
await submitFeedback.mutateAsync(values)

resetForm()
setValue('DECLINE')
await submitFeedback.mutateAsync(values)
toast.success('Proposal declined successfully!')
}}
>
Expand Down
18 changes: 15 additions & 3 deletions src/components/ProposalStatusForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSessionStorage } from '@uidotdev/usehooks'
import { Tabs } from '@uzh-bf/design-system'
import type { Session } from 'next-auth'
import { ProposalDetails } from 'src/types/app'
Expand All @@ -14,9 +15,13 @@ export default function ProposalStatusForm({
proposalDetails,
session,
}: ProposalStatusFormProps) {
const [providedFeedback, setProvidedFeedback] = useSessionStorage<
null | string
>(proposalDetails.id, null)
if (
proposalDetails?.typeKey === 'STUDENT' &&
proposalDetails?.statusKey === 'MATCHED_TENTATIVE'
(proposalDetails?.typeKey === 'STUDENT' &&
proposalDetails?.statusKey === 'MATCHED_TENTATIVE') ||
providedFeedback === 'ACCEPT_TENTATIVE'
) {
return (
<>
Expand Down Expand Up @@ -44,6 +49,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
<Tabs.TabContent
Expand All @@ -58,6 +64,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
</Tabs>
Expand All @@ -67,7 +74,8 @@ export default function ProposalStatusForm({
} else if (
(proposalDetails?.typeKey === 'STUDENT' &&
proposalDetails?.statusKey === 'MATCHED') ||
proposalDetails?.receivedFeedbacks?.length > 0
proposalDetails?.receivedFeedbacks?.length > 0 ||
providedFeedback
) {
return (
<div className="p-4 bg-yellow-100">
mxmlnwbr marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -102,6 +110,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
<Tabs.TabContent
Expand All @@ -116,6 +125,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
<Tabs.TabContent
Expand All @@ -130,6 +140,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
<Tabs.TabContent
Expand All @@ -144,6 +155,7 @@ export default function ProposalStatusForm({
proposalName={proposalDetails?.title}
proposalId={proposalDetails?.id}
supervisorEmail={session?.user?.email as string}
setValue={setProvidedFeedback}
/>
</Tabs.TabContent>
</Tabs>
Expand Down
6 changes: 4 additions & 2 deletions src/components/RejectProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ interface RejectProposalFormProps {
proposalName: string
proposalId: string
supervisorEmail: string
setValue: (value: string) => void
}

export default function RejectProposalForm({
proposalName,
proposalId,
supervisorEmail,
setValue,
}: RejectProposalFormProps) {
const SignupSchema = Yup.object().shape({
reason: Yup.string().required('Required'),
Expand All @@ -39,9 +41,9 @@ export default function RejectProposalForm({
}}
validationSchema={SignupSchema}
onSubmit={async (values, { resetForm }) => {
await submitFeedback.mutateAsync(values)

resetForm()
setValue('REJECT')
await submitFeedback.mutateAsync(values)
toast.success('Proposal rejected successfully!')
}}
>
Expand Down
6 changes: 4 additions & 2 deletions src/components/TentativeAcceptProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ interface TentativeAcceptProposalFormProps {
proposalName: string
proposalId: string
supervisorEmail: string
setValue: (value: string) => void
}

export default function TentativeAcceptProposalForm({
proposalName,
proposalId,
supervisorEmail,
setValue,
}: TentativeAcceptProposalFormProps) {
const SignupSchema = Yup.object().shape({
comment: Yup.string().required('Required'),
Expand All @@ -36,9 +38,9 @@ export default function TentativeAcceptProposalForm({
}}
validationSchema={SignupSchema}
onSubmit={async (values, { resetForm }) => {
await submitFeedback.mutateAsync(values)

resetForm()
setValue('ACCEPT_TENTATIVE')
await submitFeedback.mutateAsync(values)
toast.success('Proposal tentatively accepted successfully!')
}}
>
Expand Down