From 1a50788730af02b43c68a9747e7092dfbd8893c8 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Thu, 18 May 2023 14:18:26 +0100 Subject: [PATCH] Disabled input field of country on add Job page --- src/components/AddJob/AddJob.jsx | 91 +++++++++++++++++--------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index 6e35d2a..05f4d74 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -4,14 +4,16 @@ import InputCom from "../Helpers/Inputs/InputCom"; import LoadingSpinner from "../Spinners/LoadingSpinner"; import usersService from "../../services/UsersService"; +import { useSelector } from "react-redux"; + import { Form, Formik } from "formik"; import * as Yup from "yup"; const validationSchema = Yup.object().shape({ - country: Yup.string() - .min(1, "Minimum 3 characters") - .max(25, "Maximum 25 characters") - .required("Country is required"), + // country: Yup.string() + // .min(1, "Minimum 3 characters") + // .max(25, "Maximum 25 characters") + // .required("Country is required"), price: Yup.number() .typeError("you must specify a number") .min(1, "Price must be greater than 0") @@ -36,7 +38,7 @@ const validationSchema = Yup.object().shape({ let initialValues = { // initial values for formik - country: "", + // country: "", price: 0, title: "", description: "", @@ -48,13 +50,16 @@ function AddJob() { const ApiCall = new usersService(); const navigate = useNavigate(); + let {userDetails} = useSelector((state)=> state.userDetails) + console.log(userDetails, userDetails.country) + let [pageLoading, setPageLoading] = useState(true); // State used for knowing when the page is mounting - let [country, setCountry] = useState({ - loading: false, - status: false, - data: [], - }); // To Hold the array of country getUserCountry returns + // let [country, setCountry] = useState({ + // loading: false, + // status: false, + // data: [], + // }); // To Hold the array of country getUserCountry returns let [requestStatus, setRequestStatus] = useState({ loading: false, @@ -63,29 +68,29 @@ function AddJob() { }); // 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: [] }); - }); - }; + // 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 HANDLE ADD JOB FORM const handleAddJob = (values, helpers) => { setRequestStatus({ loading: true, status: false, message: "" }); - ApiCall.jobManagerCreateJob(values) + ApiCall.jobManagerCreateJob({...values, country:userDetails.country}) .then((res) => { if (res.data.internal_return < 1) { setRequestStatus({ @@ -120,7 +125,7 @@ function AddJob() { useEffect(() => { setPageLoading(false); - getUserCountry(); + // getUserCountry(); }, []); return pageLoading.loading ? ( @@ -148,18 +153,18 @@ function AddJob() { {/* country */}
- {/* */} -
{/* Price */} -- 2.34.1