Skip to content

Commit

Permalink
fix(app): supervisedBy unassigned resolved (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: Roland Schläfli <[email protected]>
  • Loading branch information
mxmlnwbr and rschlaefli authored Dec 13, 2023
1 parent 0a849f2 commit 3f16447
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/ProposalMeta.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IconDefinition, faFilePdf } from '@fortawesome/free-regular-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { format, parseISO } from 'date-fns'
import { useSession } from 'next-auth/react'
import Link from 'next/link'
import { useMemo } from 'react'
import { ProposalDetails } from 'src/types/app'

interface ProposalMetaProps {
Expand All @@ -12,7 +14,20 @@ const FileTypeIconMap: Record<string, IconDefinition> = {
'application/pdf': faFilePdf,
}
export default function ProposalMeta({ proposalDetails }: ProposalMetaProps) {
const { data: session } = useSession()

const supervisedBy = useMemo(() => {
if (session?.user?.email && proposalDetails?.supervisedBy?.length > 0) {
return proposalDetails.supervisedBy[0].supervisor.name
} else if (proposalDetails?.supervisedBy.name) {
return proposalDetails.supervisedBy.name
} else {
return 'Unassigned'
}
}, [session, proposalDetails])

if (!proposalDetails) return null

return (
<div className="p-4">
<h1 className="text-base font-bold">{proposalDetails.title}</h1>
Expand Down Expand Up @@ -51,7 +66,7 @@ export default function ProposalMeta({ proposalDetails }: ProposalMetaProps) {
)}
<div className="text-base">
<div className="font-bold">Supervised By</div>
<div>{proposalDetails.supervisedBy?.name ?? 'Unassigned'}</div>
<div>{supervisedBy}</div>
</div>

{proposalDetails.typeKey === 'STUDENT' && (
Expand All @@ -68,7 +83,7 @@ export default function ProposalMeta({ proposalDetails }: ProposalMetaProps) {
</div>

{proposalDetails.typeKey === 'STUDENT' && (
<div className="text-sm flex flex-row gap-6 mt-4">
<div className="flex flex-row gap-6 mt-4 text-sm">
{proposalDetails.attachments.map((attachment: any) => (
<Link
key={attachment.id}
Expand Down

0 comments on commit 3f16447

Please sign in to comment.