Disabled input field of country on add Job page

This commit is contained in:
victorAnumudu
2023-05-18 14:18:26 +01:00
parent 6803059ee5
commit 1a50788730
+48 -43
View File
@@ -4,14 +4,16 @@ import InputCom from "../Helpers/Inputs/InputCom";
import LoadingSpinner from "../Spinners/LoadingSpinner"; import LoadingSpinner from "../Spinners/LoadingSpinner";
import usersService from "../../services/UsersService"; import usersService from "../../services/UsersService";
import { useSelector } from "react-redux";
import { Form, Formik } from "formik"; import { Form, Formik } from "formik";
import * as Yup from "yup"; import * as Yup from "yup";
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
country: Yup.string() // country: Yup.string()
.min(1, "Minimum 3 characters") // .min(1, "Minimum 3 characters")
.max(25, "Maximum 25 characters") // .max(25, "Maximum 25 characters")
.required("Country is required"), // .required("Country is required"),
price: Yup.number() price: Yup.number()
.typeError("you must specify a number") .typeError("you must specify a number")
.min(1, "Price must be greater than 0") .min(1, "Price must be greater than 0")
@@ -36,7 +38,7 @@ const validationSchema = Yup.object().shape({
let initialValues = { let initialValues = {
// initial values for formik // initial values for formik
country: "", // country: "",
price: 0, price: 0,
title: "", title: "",
description: "", description: "",
@@ -48,13 +50,16 @@ function AddJob() {
const ApiCall = new usersService(); const ApiCall = new usersService();
const navigate = useNavigate(); 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 [pageLoading, setPageLoading] = useState(true); // State used for knowing when the page is mounting
let [country, setCountry] = useState({ // let [country, setCountry] = useState({
loading: false, // loading: false,
status: false, // status: false,
data: [], // data: [],
}); // To Hold the array of country getUserCountry returns // }); // To Hold the array of country getUserCountry returns
let [requestStatus, setRequestStatus] = useState({ let [requestStatus, setRequestStatus] = useState({
loading: false, loading: false,
@@ -63,29 +68,29 @@ function AddJob() {
}); // Holds state when submit button is pressed }); // Holds state when submit button is pressed
// FUNCTION TO GET COUNTRY // FUNCTION TO GET COUNTRY
const getUserCountry = () => { // const getUserCountry = () => {
setCountry((prev) => ({ ...prev, loading: true })); // setCountry((prev) => ({ ...prev, loading: true }));
ApiCall.getSignupCountryData() // ApiCall.getSignupCountryData()
.then((res) => { // .then((res) => {
if (res.data.internal_return < 1) { // if (res.data.internal_return < 1) {
setCountry({ loading: false, status: true, data: [] }); // setCountry({ loading: false, status: true, data: [] });
return; // return;
} // }
setCountry({ // setCountry({
loading: false, // loading: false,
status: true, // status: true,
data: res.data.signup_country, // data: res.data.signup_country,
}); // });
}) // })
.catch((err) => { // .catch((err) => {
setCountry({ loading: false, status: false, data: [] }); // setCountry({ loading: false, status: false, data: [] });
}); // });
}; // };
// FUNCTION TO HANDLE ADD JOB FORM // FUNCTION TO HANDLE ADD JOB FORM
const handleAddJob = (values, helpers) => { const handleAddJob = (values, helpers) => {
setRequestStatus({ loading: true, status: false, message: "" }); setRequestStatus({ loading: true, status: false, message: "" });
ApiCall.jobManagerCreateJob(values) ApiCall.jobManagerCreateJob({...values, country:userDetails.country})
.then((res) => { .then((res) => {
if (res.data.internal_return < 1) { if (res.data.internal_return < 1) {
setRequestStatus({ setRequestStatus({
@@ -120,7 +125,7 @@ function AddJob() {
useEffect(() => { useEffect(() => {
setPageLoading(false); setPageLoading(false);
getUserCountry(); // getUserCountry();
}, []); }, []);
return pageLoading.loading ? ( return pageLoading.loading ? (
@@ -148,18 +153,18 @@ function AddJob() {
{/* country */} {/* country */}
<div className="xl:flex xl:space-x-7 mb-6"> <div className="xl:flex xl:space-x-7 mb-6">
<div className="field w-full mb-6 xl:mb-0"> <div className="field w-full mb-6 xl:mb-0">
{/* <InputCom <InputCom
fieldClass="px-6" fieldClass="px-6 cursor-not-allowed"
label="Country" label="Country"
labelClass='tracking-wide' labelClass='tracking-wide'
inputBg = 'bg-slate-100' inputBg = 'bg-slate-100'
type="text" type="text"
name="country" name="country"
// placeholder="Select Country" disable={true}
value={props.values.country} // placeholder="Select Country"
inputHandler={props.handleChange} value={userDetails.country}
/> */} />
<label {/* <label
htmlFor="country" htmlFor="country"
className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block" className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block"
> >
@@ -202,7 +207,7 @@ function AddJob() {
<p className="text-sm text-red-500"> <p className="text-sm text-red-500">
{props.errors.country} {props.errors.country}
</p> </p>
)} )} */}
</div> </div>
{/* Price */} {/* Price */}