From eacfae19f0566a8c9d9a440a97f8bd70a1560971 Mon Sep 17 00:00:00 2001 From: ebube Date: Tue, 28 Nov 2023 07:26:34 -0800 Subject: [PATCH] Currency Bug Fix --- src/components/AddJob/AddJob.jsx | 141 ++++++++++++++++--------------- 1 file changed, 74 insertions(+), 67 deletions(-) diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index 0bfb873..6aaa71b 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -38,7 +38,7 @@ const validationSchema = Yup.object().shape({ .typeError("you must specify a number") .min(1, "Price must be greater than 0") .required("Timeline is required"), - category: Yup.string().min(1, "Select at least one checkbox"), + category: Yup.array().min(1, "Select at least one checkbox"), }); function AddJob({ popUpHandler, categories }) { @@ -48,24 +48,30 @@ function AddJob({ popUpHandler, categories }) { let dispatch = useDispatch(); - const getWalletDetail = (country) => { // A FUNCTION TO GET USER BALANCE BASED ON COUNTRY SELECTED + const getWalletDetail = (countryParams) => { + // A FUNCTION TO GET USER BALANCE BASED ON COUNTRY SELECTED const walletChecker = walletDetails?.data.find( - (item) => item.country === country + (item) => item.country === countryParams ); - return walletChecker ? walletChecker.code : ""; + return walletChecker + ? { + description: walletChecker.description, + country: walletChecker.country, + } + : ""; }; - const walletAmount = getWalletDetail(userDetails.country); // GETTING USER BALANCE BASED ON COUNTRY SELECTED + const walletAmount = getWalletDetail(userDetails.country); // GETTING USER BALANCE BASED ON COUNTRY SELECTED let initialValues = { // initial values for formik - country: walletAmount, + country: walletAmount?.description, price: "", title: "", description: "", job_detail: "", timeline_days: "", - category: "", + category: [], }; let [requestStatus, setRequestStatus] = useState({ @@ -74,18 +80,25 @@ function AddJob({ popUpHandler, categories }) { message: "", }); // Holds state when submit button is pressed + // const getWalletDetail = (country) => { // A FUNCTION TO GET USER BALANCE BASED ON COUNTRY SELECTED + // const walletChecker = walletDetails?.data.find( + // (item) => item.country === country + // ); + // return walletChecker ? walletChecker.amount : 0; + // }; const handleAddJob = async (values, helpers) => { const reqData = { - country: values?.country, + country: walletAmount?.country, price: Number(values.price) * 100, title: values?.title, description: values?.description, job_detail: values?.job_detail, timeline_days: values?.timeline_days, - category: values.category, + category: values.category?.join("@"), }; + // const walletAmount = getWalletDetail(reqData.country); // GETTING USER BALANCE BASED ON COUNTRY SELECTED // if (reqData.price > walletAmount) { // setRequestStatus({ @@ -138,7 +151,7 @@ function AddJob({ popUpHandler, categories }) { }; return ( -
+
- +
{/* Price */} @@ -233,7 +246,7 @@ function AddJob({ popUpHandler, categories }) { {/* Details */}
-
+
-
- -
-
+