From 16fd35df831b200c35cce9dfcce066ab3dc90028 Mon Sep 17 00:00:00 2001 From: Ebube Date: Mon, 26 Jun 2023 17:48:00 +0100 Subject: [PATCH 1/2] . --- src/components/AddJob/AddJob.jsx | 103 +++++++++++----------- src/components/Partials/Layout.jsx | 3 +- src/services/UsersService.js | 134 ++++++++++++++++------------- 3 files changed, 128 insertions(+), 112 deletions(-) diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index 799dd2e..2168e53 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -14,8 +14,14 @@ const validationSchema = Yup.object().shape({ .max(25, "Maximum 25 characters") .required("Country is required"), price: Yup.number() - .typeError("you must specify a number") + .typeError("Invalid number") .min(1, "Price must be greater than 0") + .test("no-e", "Invalid number", (value) => { + if (value && /\d+e/.test(value)) { + return false; + } + return true; + }) .required("Price is required"), title: Yup.string() .min(3, "Minimum 3 characters") @@ -42,15 +48,16 @@ function AddJob({ popUpHandler, categories }) { let { userDetails } = useSelector((state) => state.userDetails); - let [country, setCountry] = useState({ + const [numberValue, setNumberValue] = useState(""); + let [currency, setCurrency] = useState({ loading: true, status: false, - data: [], - }); // To Hold the array of country getUserCountry returns + data: null, + }); // To Hold the array of currency getUserCurrency returns let initialValues = { // initial values for formik - country: userDetails.country, + currency: "", price: "", title: "", description: "", @@ -65,25 +72,7 @@ function AddJob({ popUpHandler, categories }) { message: "", }); // Holds state when submit button is pressed - // FUNCTION TO GET COUNTRY - const getUserCountry = () => { - setCountry((prev) => ({ ...prev, loading: true })); - ApiCall.getSignupCountryData() - .then((res) => { - if (res.data.internal_return < 1) { - setCountry({ loading: false, status: true, data: [] }); - return; - } - setCountry({ - loading: false, - status: true, - data: res.data.signup_country, - }); - }) - .catch((err) => { - setCountry({ loading: false, status: false, data: [] }); - }); - }; + // FUNCTION TO GET Currency // FUNCTION TO HANDLE ADD JOB FORM const handleAddJob = (values, helpers) => { @@ -113,7 +102,7 @@ function AddJob({ popUpHandler, categories }) { setRequestStatus({ loading: false, status: false, - message: "Opps! soemthing went wrong. Try Again", + message: "Opps! something went wrong. Try Again", }); }) .finally(() => { @@ -124,9 +113,31 @@ function AddJob({ popUpHandler, categories }) { }; useEffect(() => { - getUserCountry(); + const getUserCurrency = () => { + setCurrency((prev) => ({ ...prev, loading: true })); + ApiCall.getUserWallets() + .then((res) => { + if (res.data.internal_return < 0) { + setCurrency({ loading: false, status: true, data: [] }); + return; + } + console.log("Res for currency >> ", res); + + setCurrency({ + loading: false, + status: true, + data: res.data.result_list, + }); + }) + .catch((err) => { + setCurrency({ loading: false, status: false, data: [] }); + }); + }; + getUserCurrency(); }, []); + console.log("Currency >> ", currency.data); + return (
{/* inputs starts here */} - {/* country */}