diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index 904f8ed..ee80b26 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -1,6 +1,6 @@ import { Field, Form, Formik } from "formik"; import React, { useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import * as Yup from "yup"; import usersService from "../../services/UsersService"; import { tableReload } from "../../store/TableReloads"; @@ -43,7 +43,7 @@ const validationSchema = Yup.object().shape({ function AddJob({ popUpHandler, categories }) { const ApiCall = new usersService(); - + const { walletDetails } = useSelector((state) => state.walletDetails); let dispatch = useDispatch(); let [currency, setCurrency] = useState({ @@ -90,6 +90,11 @@ function AddJob({ popUpHandler, categories }) { }); }; + const getWalletDetail = (currency) => { + let { result_list } = walletDetails; + return result_list?.filter((item) => item.country === currency); + }; + // FUNCTION TO HANDLE ADD JOB FORM const handleAddJob = (values, helpers) => { let reqData = { @@ -102,6 +107,16 @@ function AddJob({ popUpHandler, categories }) { category: values.category?.join("@"), }; + let walletChecker = getWalletDetail(reqData.country); + if (reqData.price > walletChecker[0]?.amount) { + setRequestStatus({ + loading: false, + status: false, + message: "Insufficient Balance", + }); + return; + } + setRequestStatus({ loading: true, status: false, message: "" }); ApiCall.jobManagerCreateJob(reqData) .then((res) => { @@ -164,7 +179,11 @@ function AddJob({ popUpHandler, categories }) { className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold flex item-center gap-1" > Currency - {props.errors.country && props.touched.country && {props.errors.country}} + {props.errors.country && props.touched.country && ( + + {props.errors.country} + + )}