-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split up into components with props (#2)
Co-authored-by: Roland Schlaefli <[email protected]>
- Loading branch information
1 parent
2075836
commit ba3cf3f
Showing
22 changed files
with
690 additions
and
481 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Ref } from 'react' | ||
|
||
interface CreateProposalProps { | ||
displayMode: string | ||
ref: Ref<HTMLIFrameElement> | ||
} | ||
|
||
export default function CreateProposal({ | ||
displayMode, | ||
ref, | ||
}: CreateProposalProps) { | ||
if (displayMode === 'createSupervisor') { | ||
return ( | ||
<iframe | ||
ref={ref} | ||
className="rounded" | ||
width="100%" | ||
height="1400px" | ||
src={process.env.NEXT_PUBLIC_FORMS_URL_PUBLISH} | ||
></iframe> | ||
) | ||
} else if (displayMode === 'createStudent') { | ||
return ( | ||
<iframe | ||
ref={ref} | ||
className="rounded" | ||
width="100%" | ||
height="1400px" | ||
src={process.env.NEXT_PUBLIC_FORMS_URL_SUBMIT} | ||
></iframe> | ||
) | ||
} | ||
return null | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Button } from '@uzh-bf/design-system' | ||
import { RefObject } from 'react' | ||
|
||
interface NewProposalButtonProps { | ||
isSupervisor: boolean | ||
displayMode: string | ||
setDisplayMode: (displayMode: string) => void | ||
setSelectedProposal: (proposalId: string | null) => void | ||
buttonRef: RefObject<HTMLButtonElement> | ||
} | ||
|
||
export default function NewProposalButton({ | ||
isSupervisor, | ||
displayMode, | ||
setDisplayMode, | ||
setSelectedProposal, | ||
buttonRef, | ||
}: NewProposalButtonProps) { | ||
const handleButtonClick = () => { | ||
setSelectedProposal(null) | ||
isSupervisor | ||
? setDisplayMode('createSupervisor') | ||
: setDisplayMode('createStudent') | ||
buttonRef?.current?.scrollIntoView({ | ||
behavior: 'smooth', | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<Button | ||
active={ | ||
displayMode === 'createSupervisor' || displayMode === 'createStudent' | ||
} | ||
onClick={handleButtonClick} | ||
> | ||
New Proposal | ||
</Button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { | ||
IconDefinition, | ||
faFilePdf, | ||
faMessage, | ||
} from '@fortawesome/free-regular-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { H2, Table } from '@uzh-bf/design-system' | ||
import { add, format, parseISO } from 'date-fns' | ||
import { ProposalDetails } from 'src/types/app' | ||
import { IterableElement } from 'type-fest' | ||
import ApplicationForm from './ApplicationForm' | ||
|
||
interface ProposalApplicationProps { | ||
proposalDetails: ProposalDetails | ||
isStudent: boolean | ||
isSupervisor: boolean | ||
} | ||
|
||
export default function ProposalApplication({ | ||
proposalDetails, | ||
isStudent, | ||
isSupervisor, | ||
}: ProposalApplicationProps) { | ||
const FileTypeIconMap: Record<string, IconDefinition> = { | ||
'application/pdf': faFilePdf, | ||
} | ||
if (proposalDetails?.typeKey === 'SUPERVISOR') { | ||
return ( | ||
<div className="p-4"> | ||
{isStudent && ( | ||
<ApplicationForm | ||
key={proposalDetails.id} | ||
proposalName={proposalDetails.title} | ||
proposalId={proposalDetails.id} | ||
/> | ||
)} | ||
{isSupervisor && ( | ||
<div className="pt-4"> | ||
<H2>Applications</H2> | ||
{proposalDetails?.applications?.length === 0 && | ||
'No applications for this proposal...'} | ||
{proposalDetails?.applications?.length > 0 && ( | ||
<Table<IterableElement<(typeof proposalDetails)['applications']>> | ||
className={{ | ||
root: 'text-xs', | ||
tableHeader: 'text-sm', | ||
}} | ||
columns={[ | ||
{ | ||
label: 'Date', | ||
accessor: 'createdAt', | ||
transformer: ({ row }) => | ||
format(parseISO(row.createdAt), 'dd.MM.Y'), | ||
}, | ||
{ | ||
label: 'Status', | ||
accessor: 'status', | ||
sortable: true, | ||
transformer: ({ row }) => <div>{row.statusKey}</div>, | ||
}, | ||
{ | ||
label: 'Working Period', | ||
accessor: 'plannedStartAt', | ||
sortable: true, | ||
transformer: ({ row }) => | ||
`${format( | ||
parseISO(row.plannedStartAt), | ||
'd.M.Y' | ||
)} - ${format( | ||
add(parseISO(row.plannedStartAt), { months: 6 }), | ||
'd.M.Y' | ||
)}`, | ||
}, | ||
{ | ||
label: 'Name', | ||
accessor: 'fullName', | ||
sortable: true, | ||
transformer: ({ row }) => ( | ||
<a | ||
href={`mailto:${row.email}`} | ||
target="_blank" | ||
className="flex flex-row items-center gap-2 hover:text-orange-700" | ||
rel="noreferrer" | ||
> | ||
<FontAwesomeIcon icon={faMessage} /> | ||
{row.fullName} | ||
</a> | ||
), | ||
}, | ||
{ | ||
label: 'Motivation', | ||
accessor: 'motivation', | ||
transformer: ({ row }) => ( | ||
<div className="text-xs break-all">{row.motivation}</div> | ||
), | ||
}, | ||
{ | ||
label: 'Attachments', | ||
accessor: 'attachments', | ||
transformer: ({ row }) => ( | ||
<div> | ||
{row.attachments?.map((attachment: any) => ( | ||
<a | ||
href={attachment.href} | ||
target="_blank" | ||
key={attachment.id} | ||
className="hover:text-orange-700" | ||
rel="noreferrer" | ||
> | ||
<div className="flex flex-row items-center gap-2"> | ||
<FontAwesomeIcon | ||
icon={FileTypeIconMap[attachment.type]} | ||
/> | ||
{attachment.name} | ||
</div> | ||
</a> | ||
))} | ||
</div> | ||
), | ||
}, | ||
]} | ||
data={proposalDetails.applications} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} else { | ||
return null | ||
} | ||
} |
Oops, something went wrong.