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

feat: implement Proposal Application Acceptance Workflow #12

Merged
merged 20 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 31 additions & 2 deletions src/components/ApplicationDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Button, Modal, Prose } from '@uzh-bf/design-system'
import { add, format, parseISO } from 'date-fns'
import { useState } from 'react'
import toast from 'react-hot-toast'
import { trpc } from 'src/lib/trpc'
import { ApplicationDetails } from 'src/types/app'

function ApplicationDetailsModal({ row }: { row: ApplicationDetails }) {
function ApplicationDetailsModal({
row,
isProposalOpen,
setIsProposalOpen,
}: {
row: ApplicationDetails
isProposalOpen: boolean
setIsProposalOpen: (isOpen: boolean) => void
}) {
const FileTypeIconMap: Record<string, IconDefinition> = {
'application/pdf': faFilePdf,
}
const [isOpen, setIsOpen] = useState(false)

const acceptApplication = trpc.acceptProposalApplication.useMutation()

return (
<Modal
title={`Application by ${row?.fullName}`}
Expand Down Expand Up @@ -39,7 +51,24 @@ function ApplicationDetailsModal({ row }: { row: ApplicationDetails }) {
</div>
<div>
<h1 className="text-base font-bold">Status:</h1>
<p className="pb-2 text-base">{row?.statusKey}</p>
<p className="pb-2 text-base">
{isProposalOpen ? row?.statusKey : 'Please Refresh Page'}
{isProposalOpen && row?.statusKey === 'OPEN' ? (
<Button
onClick={async () => {
setIsProposalOpen(false)
await acceptApplication.mutateAsync({
proposalId: row.proposalId,
proposalApplicationId: row.id,
applicantEmail: row.email,
})
toast.success('Application accepted successfully!')
rschlaefli marked this conversation as resolved.
Show resolved Hide resolved
}}
>
ACCEPT (Non Reversible)
</Button>
) : null}
</p>
<h1 className="text-base font-bold">Working Period:</h1>
<p className="pb-2 text-base">
{format(parseISO(row.plannedStartAt), 'dd.MM.Y')} -{' '}
Expand Down
9 changes: 8 additions & 1 deletion src/components/ProposalApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { H2, Table } from '@uzh-bf/design-system'
import { add, format, parseISO } from 'date-fns'
import { useState } from 'react'
import { ApplicationDetails, ProposalDetails } from 'src/types/app'
import ApplicationDetailsModal from './ApplicationDetailsModal'
import ApplicationForm from './ApplicationForm'
Expand All @@ -15,6 +16,8 @@ export default function ProposalApplication({
isStudent,
isSupervisor,
}: ProposalApplicationProps) {
const [isProposalOpen, setIsProposalOpen] = useState<boolean>(true)
mxmlnwbr marked this conversation as resolved.
Show resolved Hide resolved

if (proposalDetails?.typeKey === 'SUPERVISOR') {
return (
<div className="p-4">
mxmlnwbr marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -66,7 +69,11 @@ export default function ProposalApplication({
label: 'Details',
accessor: 'details',
transformer: ({ row }) => (
<ApplicationDetailsModal row={row} />
<ApplicationDetailsModal
row={row}
isProposalOpen={isProposalOpen}
setIsProposalOpen={setIsProposalOpen}
/>
),
},
]}
Expand Down
15 changes: 15 additions & 0 deletions src/server/routers/_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ export const appRouter = router({
.mutation(async ({ ctx, input }) => {
const res = await axios.post(process.env.APPLICATION_URL as string, input)
}),

acceptProposalApplication: publicProcedure
.input(
z.object({
proposalId: z.string(),
proposalApplicationId: z.string(),
applicantEmail: z.string().email(),
})
)
.mutation(async ({ ctx, input }) => {
const res = await axios.post(
process.env.APPLICATION_ACCEPTANCE_URL as string,
input
mxmlnwbr marked this conversation as resolved.
Show resolved Hide resolved
)
rschlaefli marked this conversation as resolved.
Show resolved Hide resolved
}),
})

export type AppRouter = typeof appRouter