From 1a50788730af02b43c68a9747e7092dfbd8893c8 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Thu, 18 May 2023 14:18:26 +0100 Subject: [PATCH 1/2] 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 From 07c72b5459113321f769426f07f4fd97bce35578 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Thu, 18 May 2023 15:58:48 +0100 Subject: [PATCH 2/2] error display name for timeline_days changed --- src/components/AddJob/AddJob.jsx | 71 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index 05f4d74..05fda87 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -33,7 +33,7 @@ const validationSchema = Yup.object().shape({ timeline_days: Yup.number() .typeError("you must specify a number") .min(1, "Price must be greater than 0") - .required("Price is required"), + .required("Timeline is required"), }); let initialValues = { @@ -51,15 +51,14 @@ function AddJob() { 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: true, + status: false, + data: '', + }); // To Hold the array of country getUserCountry returns let [requestStatus, setRequestStatus] = useState({ loading: false, @@ -68,24 +67,24 @@ 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?.find(item => item[0]==userDetails.country)[1], + }); + }) + .catch((err) => { + setCountry({ loading: false, status: false, data: '' }); + }); + }; // FUNCTION TO HANDLE ADD JOB FORM const handleAddJob = (values, helpers) => { @@ -125,7 +124,7 @@ function AddJob() { useEffect(() => { setPageLoading(false); - // getUserCountry(); + getUserCountry(); }, []); return pageLoading.loading ? ( @@ -161,8 +160,9 @@ function AddJob() { type="text" name="country" disable={true} - // placeholder="Select Country" - value={userDetails.country} + value={country.loading ? 'loading' : country.data ? country.data : 'no country found!'} + // inputHandler={(e)=> setCountry((prev) => ({...prev, data:e.target.value}))} + /> {/*