import {useState, useEffect} from 'react' import { Button, InputCompOne, Stepper } from '../../shared/index'; import {Formik, Form} from 'formik' import * as Yup from "yup"; import { getEmployersList } from '../../../core/apiRequest'; type Props = { handleNextStep:(value:{})=>any } // type EmployerProps = { // loading?: boolean, // data?: Array<{[index:string]: string}> | {[index:string]: Array<{[index:string]: string}> } // } const initialValues = { job_title: "", name: "", sector: "", industry: "", resumption_date: "", email:"", annual_income: "", monthly_salary: "", salary_payment_date: "", employment_id: "", highest_eductaion: "", employer_uid: "", isChecked: false }; // To get the validation schema const validationSchema = Yup.object().shape({ isChecked: Yup.bool(), // use bool instead of boolean // .oneOf([true, false], "You must accept the terms and conditions"), job_title: Yup.string() .required("Required"), name: Yup.string().when('isChecked', { is: true, then: () => Yup.string().required('required'), otherwise: () => Yup.string(), }), sector: Yup.string().when('isChecked', { is: true, then: () => Yup.string().required('required'), }), industry: Yup.string().when('isChecked', { is: true, then: () => Yup.string().required('required'), }), resumption_date: Yup.string() .required("Required"), email: Yup.string().when('isChecked', { is: true, then: () => Yup.string().required('required'), }) .email("Invalid"), annual_income: Yup.string() .required("Required") .test("no-e", "Invalid", (value:any) => { if (value && /^[0-9]*$/.test(value) == false) { return false; } return true; }), monthly_salary: Yup.string() .required("Required") .test("no-e", "Invalid", (value:any) => { if (value && /^[0-9]*$/.test(value) == false) { return false; } return true; }), salary_payment_date: Yup.string() .required("Required"), employment_id: Yup.string() .required("Required"), highest_eductaion: Yup.string() .required("Required"), employer_uid: Yup.string().when('isChecked', { is: false, then: () => Yup.string().required('required'), }), }); export default function DashboardHomeEmploymentInfo({handleNextStep}:Props) { const [employersList, setEmployersList] = useState({ loading: true, data: [] }) //FUNCTION TO HANDLE SUBMIT const handleSubmit = (values:any) => { // Remember to changed the checked value's name if(values.employer_uid){ let employer_uid = values.employer_uid delete values.employer_uid handleNextStep({employer_uid, employment: values}) }else{ handleNextStep({employment: values}) } }; useEffect(()=>{ getEmployersList().then(res => { setEmployersList({loading:false, data:res?.data}) }).catch(err => { console.log(err) setEmployersList({loading:false, data:[]}) }) },[]) return (
{(props)=>(

Employment Informaton

Check here if employer is not on the list

Name: {'Name'}
)}
); } interface SelectOption { loading: boolean; data: {value: string; label: string}[] } const jobSector: SelectOption = { loading: false, data: [ { value: "", label: "Please Select" }, { value: "private (non academic)", label: "Private (non academic)" }, ] } const industry: SelectOption = { loading: false, data: [ { value: "", label: "Please Select" }, { value: "engineering", label: "Engineering" }, ] } const highestEductaion: SelectOption = { loading: false, data: [ { value: "", label: "Please Select" }, { value: "b.sc + professional qualification", label: "B.Sc + Professional Qualification" }, ] }