Skip to content

Commit

Permalink
Description of final report and final evaluation saved in store (#60)
Browse files Browse the repository at this point in the history
* Final report description saved in store

* Final evaluation description saved in store
  • Loading branch information
Emanuel-Palestino authored Dec 15, 2024
1 parent f648cb1 commit ae13c1f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
19 changes: 16 additions & 3 deletions app/_store/internship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type InternshipStore = {

reports: { [key: string]: PartialReport }
documentsDownloaded: { [key: string]: boolean }

finalReportDescription: string | undefined
finalEvaluationDescription: string | undefined
}

type InternshipActions = {
Expand All @@ -31,6 +34,8 @@ type InternshipActions = {
setCompanyData: (companyData: Company) => void
addReport: (key: string, report: PartialReport) => void
setDocumentDownloaded: (key: string, value: boolean) => void
setFinalReportDescription: (description: string) => void
setFinalEvaluationDescription: (description: string) => void
setData: (data: InternshipStore) => void
}

Expand All @@ -53,6 +58,9 @@ export const useInternshipStore = create<InternshipStoreState>()(

reports: {},

finalReportDescription: undefined,
finalEvaluationDescription: undefined,

setPersonalData: (personalData: Person) =>
set(() => ({ personalData, isPersonalDataComplete: true })),

Expand All @@ -65,9 +73,8 @@ export const useInternshipStore = create<InternshipStoreState>()(
setCompanyData: (companyData: Company) =>
set(() => ({ companyData, isCompanyDataComplete: true })),

addReport: (key, report) => {
set(() => ({ reports: { ...get().reports, [key]: report } }))
},
addReport: (key, report) =>
set(() => ({ reports: { ...get().reports, [key]: report } })),

documentsDownloaded: {},
setDocumentDownloaded(key, value) {
Expand All @@ -76,6 +83,12 @@ export const useInternshipStore = create<InternshipStoreState>()(
}))
},

setFinalReportDescription: (description: string) =>
set(() => ({ finalReportDescription: description })),

setFinalEvaluationDescription: (description: string) =>
set(() => ({ finalEvaluationDescription: description })),

setData: (data) => set(() => data),
}),
{
Expand Down
9 changes: 6 additions & 3 deletions app/estancias_profesionales/FinalEvaluationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const FinalEvaluationModal: FC<FinalEvaluationProps> = ({
companyData,
personalData,
studentData,
finalEvaluationDescription,
setFinalEvaluationDescription,
setDocumentDownloaded,
} = useInternshipStore()

Expand All @@ -46,7 +48,7 @@ const FinalEvaluationModal: FC<FinalEvaluationProps> = ({

const { handleSubmit, register, watch } = useForm<{ description: string }>({
defaultValues: {
description: "",
description: finalEvaluationDescription || "",
},
})

Expand All @@ -63,9 +65,10 @@ const FinalEvaluationModal: FC<FinalEvaluationProps> = ({
<ModalBody>
<form
id="final_evaluation_form"
onSubmit={handleSubmit(async () => {
await createPDF()
onSubmit={handleSubmit(async (data) => {
setFinalEvaluationDescription(data.description)
setDocumentDownloaded("final-evaluation", true)
await createPDF()
onClose()
})}
>
Expand Down
9 changes: 6 additions & 3 deletions app/estancias_profesionales/FinalReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const FinalReportModal: FC<FinalReportModalProps> = ({
personalData,
studentData,
reports,
finalReportDescription,
setFinalReportDescription,
setDocumentDownloaded,
} = useInternshipStore()

Expand All @@ -50,7 +52,7 @@ const FinalReportModal: FC<FinalReportModalProps> = ({
description: string
}>({
defaultValues: {
description: "",
description: finalReportDescription || "",
},
})

Expand Down Expand Up @@ -100,9 +102,10 @@ const FinalReportModal: FC<FinalReportModalProps> = ({
<ModalBody>
<form
id="final_report_form"
onSubmit={handleSubmit(async () => {
await createFinalReport()
onSubmit={handleSubmit(async (data) => {
setFinalReportDescription(data.description)
setDocumentDownloaded("final-report", true)
await createFinalReport()
onClose()
})}
>
Expand Down

0 comments on commit ae13c1f

Please sign in to comment.