diff --git a/src/components/JAF/JAF.tsx b/src/components/JAF/JAF.tsx index d4d2b0c..bdc7b29 100644 --- a/src/components/JAF/JAF.tsx +++ b/src/components/JAF/JAF.tsx @@ -115,7 +115,7 @@ function JAF() { job: { role: values.role, description: values.description, - //attachment: values.attachment,//file + attachment: values.attachment,//file skills: values.skills, location: values.location, noOfVacancies: values.noOfVacancies, @@ -154,7 +154,7 @@ function JAF() { contact: "+91 " + values.phoneNumber, landline: values.landline, }, - //attachment: values.attachment,//file + attachment: values.attachment,//file others: values.jobOthers, skills: values.skills, location: values.location, diff --git a/src/components/JAF/JobDetails.tsx b/src/components/JAF/JobDetails.tsx index 2c11a91..b95f91f 100644 --- a/src/components/JAF/JobDetails.tsx +++ b/src/components/JAF/JobDetails.tsx @@ -25,24 +25,6 @@ const ReactQuill = dynamic(() => import('react-quill'), { ssr: false }); const { TextArea } = Input; -const props: UploadProps = { - name: "attachment", - action: "https://run.mocky.io/v3/435e224c-44fb-4773-9faf-380c5e6a2188", - headers: { - authorization: "authorization-text", - }, - onChange(info: any) { - if (info.file.status !== "uploading") { - console.log(info.file, info.fileList); - } - if (info.file.status === "done") { - message.success(`${info.file.name} file uploaded successfully`); - } else if (info.file.status === "error") { - message.error(`${info.file.name} file upload failed.`); - } - }, -}; - type StepProps = { errors: FormikErrors; values: FormikValues; @@ -50,11 +32,21 @@ type StepProps = { setFieldValue: (field: string, value: any) => void; }; +const getBase64 = (file: File): Promise => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => resolve(reader.result as string); + reader.onerror = (error) => reject(error); + }); +}; + const JobDetails = ({ errors, values, handleChange, setFieldValue }: StepProps) => { const [form] = Form.useForm(); const [skills, setSkills] = useState([]); const [skillInput, setSkillInput] = useState(""); + const [fileList, setFileList] = useState([]); const [testType, setTestType] = useState([]); const [seasonType, setSeasonType] = useState(""); @@ -70,6 +62,28 @@ const JobDetails = ({ errors, values, handleChange, setFieldValue }: StepProps) setSkillInput(e.target.value); }; + const handleFileChange = async (info: any) => { + if (info.file.status !== 'uploading') { + console.log('Uploading:', info.file, info.fileList); + } + if (info.file.status === "done") { + const file = info.file.originFileObj; + try { + const base64String = await getBase64(file); + console.log(`Base64 string length: ${base64String.length}`); + console.log(`Base64 string: ${base64String.substring(0, 50)}...`); + setFieldValue("attachment", base64String); + message.success(`${info.file.name} file uploaded successfully`); + } catch (error) { + message.error("File conversion to Base64 failed."); + } + } else if (info.file.status === "error") { + message.error(`${info.file.name} file upload failed.`); + } + + setFileList(info.fileList); + }; + const addSkill = () => { if (skillInput) { const updatedSkills = [...skills, skillInput]; @@ -305,7 +319,10 @@ const JobDetails = ({ errors, values, handleChange, setFieldValue }: StepProps) - +