diff --git a/src/components/Dashboard/home/DashboardHomeEmploymentInfo.tsx b/src/components/Dashboard/home/DashboardHomeEmploymentInfo.tsx index b5d86d2..5bae263 100644 --- a/src/components/Dashboard/home/DashboardHomeEmploymentInfo.tsx +++ b/src/components/Dashboard/home/DashboardHomeEmploymentInfo.tsx @@ -1,12 +1,20 @@ +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: "", @@ -18,24 +26,37 @@ const initialValues = { monthly_salary: "", salary_payment_date: "", employment_id: "", - highest_eductaion: "" + highest_eductaion: "", + employer: "", + 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() - .required("Required"), - sector: Yup.string() - .required("Required"), - industry: 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() - .email("Invalid") - .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) => { @@ -58,16 +79,35 @@ const validationSchema = Yup.object().shape({ .required("Required"), highest_eductaion: Yup.string() .required("Required"), + employer: 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 handleNextStep({employment: values}) }; + useEffect(()=>{ + getEmployersList().then(res => { + setEmployersList({loading:false, data:res?.data}) + }).catch(err => { + console.log(err) + setEmployersList({loading:false, data:[]}) + }) + },[]) + return (
@@ -83,155 +123,188 @@ export default function DashboardHomeEmploymentInfo({handleNextStep}:Props) {

Employment Informaton

-
- - +
+
+
+ +
+ +

Check here if employer is not on the list

+
+
+ Name: {'Name'} +
+
+
+ + + + +
+
+ +
+ + +
+ + +
+
+ + +
+ +
+
+
-
- - -
-
- - -
-
- - -
-
- - -
- -
)} diff --git a/src/components/shared/InputCompOne.tsx b/src/components/shared/InputCompOne.tsx index 40d496a..ca9b296 100644 --- a/src/components/shared/InputCompOne.tsx +++ b/src/components/shared/InputCompOne.tsx @@ -17,7 +17,7 @@ export interface InputCompOneProps { selectValue?: string; input?: boolean; select?: boolean; - selectOptions?: {loading:boolean, data:{ value: string; label: string }[]}; + selectOptions?: {loading:boolean, data:{ [index: string]: string; }[]}; inputType?: string; inputClass?: string; parentInputClass?: string; @@ -25,6 +25,7 @@ export interface InputCompOneProps { parentClass?: string; maxLength?: number; error?: string; + disabled?: boolean } const InputCompOne = forwardRef( @@ -52,6 +53,7 @@ const InputCompOne = forwardRef( parentClass, maxLength, error, + disabled=false }, forwardedRef ) => { @@ -78,6 +80,7 @@ const InputCompOne = forwardRef( className={`px-4 ${floatLabel && 'peer pt-4 placeholder:text-transparent'} ${inputClass}`} maxLength={maxLength} id={label ? label : floatLabel} + disabled={disabled} /> {floatLabel &&