-
-
Save MonteLogic/c07c5ad350f97152b5c9c2f7bb9c37f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 'use client'; | |
| import React, { useState } from 'react'; | |
| import Button from '../button'; | |
| import { FormSections } from './FormSections'; | |
| import { | |
| FormData, | |
| WorkExperience, | |
| ReferenceCheck, | |
| Education, | |
| License, | |
| CertificationType, | |
| MachinesUsed, | |
| } from './types'; | |
| import { generateHealthcarePDF } from '#/healthcare'; | |
| import ChevronDropdownMenu from './ChevronDropdownMenu'; | |
| export const HealthcareProfileForm: React.FC = () => { | |
| const [formData, setFormData] = useState<FormData>({ | |
| // Personal Information | |
| name: '', | |
| email: '', | |
| profession: '', | |
| address: '', | |
| phoneHome: '', | |
| phoneMobile: '', | |
| // Education | |
| education: [], | |
| // Licenses/Certifications | |
| licenses: [], | |
| // Specialty Certifications | |
| certificationTypes: [], | |
| // Work Experience (multiple entries) | |
| workExperiences: [], | |
| // | |
| machinesUsed: [], | |
| // Reference Check | |
| referenceChecks: [], | |
| }); | |
| const handleInputChange = ( | |
| e: React.ChangeEvent<HTMLInputElement>, | |
| section?: string, | |
| index?: number, | |
| ) => { | |
| const { name, value } = e.target; | |
| setFormData((prev) => { | |
| if (section && typeof index === 'number') { | |
| return { | |
| ...prev, | |
| // @ts-ignore | |
| [section]: prev[section].map((item: any, i: number) => | |
| i === index ? { ...item, [name]: value } : item, | |
| ), | |
| }; | |
| } else { | |
| return { ...prev, [name]: value }; | |
| } | |
| }); | |
| }; | |
| const addWorkExperience = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| workExperiences: [...prev.workExperiences, {} as WorkExperience], | |
| })); | |
| }; | |
| const addReferenceCheck = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| referenceChecks: [...prev.referenceChecks, {} as ReferenceCheck], | |
| })); | |
| }; | |
| const addEducation = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| education: [...prev.education, {} as Education], | |
| })); | |
| }; | |
| const addLicense = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| licenses: [...prev.licenses, {} as License], | |
| })); | |
| }; | |
| const addCertification = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| certificationTypes: [...prev.certificationTypes, {} as CertificationType], | |
| })); | |
| }; | |
| const addMachinesUsed = () => { | |
| setFormData((prev) => ({ | |
| ...prev, | |
| machinesUsed: [...prev.machinesUsed, {} as MachinesUsed], | |
| })); | |
| }; | |
| const handleGeneratePDF = () => { | |
| console.log(103, formData); | |
| generateHealthcarePDF(formData); | |
| setHasUnsavedChanges(false); | |
| }; | |
| // type issues: | |
| const fillWithExampleData = (exampleData: any) => { | |
| setFormData(exampleData); | |
| setHasUnsavedChanges(true); | |
| }; | |
| const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); | |
| return ( | |
| <> | |
| <ChevronDropdownMenu | |
| onFillData={(data) => setFormData(data)} | |
| currentFormData={formData} | |
| /> | |
| <div className="space-y-8"> | |
| <FormSections | |
| formData={formData} | |
| setFormData={setFormData} | |
| handleInputChange={handleInputChange} | |
| addWorkExperience={addWorkExperience} | |
| addMachinesUsed={addMachinesUsed} | |
| addReferenceCheck={addReferenceCheck} | |
| addEducation={addEducation} | |
| addLicense={addLicense} | |
| addCertification={addCertification} | |
| setHasUnsavedChanges={setHasUnsavedChanges} | |
| /> | |
| <Button | |
| onClick={handleGeneratePDF} | |
| className="w-full justify-center rounded-md bg-green-500 px-4 py-2 text-sm font-bold text-white hover:bg-green-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75" | |
| > | |
| Generate Healthcare Profile PDF | |
| </Button> | |
| </div> | |
| </> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment