import {useEffect, useState} from 'react' import {useLocation, useNavigate} from 'react-router-dom' import { Button, InputCompOne } from "../../shared"; import {Formik, Form} from 'formik' import * as Yup from "yup"; import { RouteHandler } from '../../../router/routes'; import { getLoanDetail } from '../../../core/apiRequest'; import CustomSpinner from '../../CustomSpinner'; interface LoanDetail { loan_amount: string; payment_month: string; sales_agent: string; [key: string]: any; // to accommodate any additional properties } // interface InitialValues { // loan_amount: string; // payment_month: string; // sales_agent: string; // } const initialValues = { loan_amount: "", payment_month: "", sales_agent: "", }; // To get the validation schema const validationSchema = Yup.object().shape({ payment_month: Yup.string() .required("Required"), loan_amount: Yup.string() .required("Required") .test("no-e", "Invalid", (value:any) => { if (value && /^[0-9]*$/.test(value) == false) { return false; } return true; }), sales_agent: Yup.string() }); type LocationState = { application_uid: string } export default function ReferenceDetails() { const location = useLocation() const navigate = useNavigate() // const applicationUID = location?.state?.application_uid const stateExist = location?.state as LocationState //FUNCTION TO HANDLE SUBMIT const handleSubmit = (values:{}) => { // handleNextStep(values) console.log(values) }; const [loanDetail, setLoanDetail] = useState<{loading:boolean, data:LoanDetail}>({ loading: true, data: { loan_amount: '', payment_month: '', sales_agent: '', }, }) useEffect(()=>{ if(!stateExist){ navigate(RouteHandler.dashboardHome) return } getLoanDetail({application_uid:stateExist.application_uid}).then(res => { setLoanDetail({loading:false, data:res?.data?.loan}) }).catch(err => { console.log(err) setLoanDetail((prev:any) => ({...prev, loading:false})) }) },[]) // const formInitialValue:LoanDetail = (loanDetail.loading) ? initialValues : loanDetail?.data const formInitialValue = (loanDetail.loading || Object.keys(loanDetail?.data)?.length < 1) ? initialValues : {...initialValues, ...loanDetail?.data} return ( <> {loanDetail.loading ?
:
{(props)=>(

Loan Details

)}
} ); } // interface SelectOption { // loading: boolean; // data: {value: string; // label: string}[] // } // const paymentMonth: SelectOption = { // loading: false, // data: [ // { value: "", label: "Please Select" }, // { value: "6", label: "6 Months" }, // { value: "12", label: "12 Months" }, // { value: "18", label: "18 Months" }, // { value: "24", label: "24 Months" }, // ] // }