Only returns User Country as Default Country in Add Job Page

This commit is contained in:
victorAnumudu
2023-05-18 16:12:14 +01:00
parent 6803059ee5
commit 24f3a40a43
+31 -33
View File
@@ -4,6 +4,8 @@ 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";
@@ -31,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 = {
@@ -48,10 +50,12 @@ function AddJob() {
const ApiCall = new usersService();
const navigate = useNavigate();
let {userDetails} = useSelector((state)=> state.userDetails)
let [pageLoading, setPageLoading] = useState(true); // State used for knowing when the page is mounting
let [country, setCountry] = useState({
loading: false,
loading: true,
status: false,
data: [],
}); // To Hold the array of country getUserCountry returns
@@ -85,7 +89,7 @@ function AddJob() {
// 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({
@@ -149,16 +153,17 @@ function AddJob() {
<div className="xl:flex xl:space-x-7 mb-6">
<div className="field w-full mb-6 xl:mb-0">
{/* <InputCom
fieldClass="px-6"
label="Country"
labelClass='tracking-wide'
inputBg = 'bg-slate-100'
type="text"
name="country"
// placeholder="Select Country"
value={props.values.country}
inputHandler={props.handleChange}
/> */}
fieldClass="px-6 cursor-not-allowed"
label="Country"
labelClass='tracking-wide'
inputBg = 'bg-slate-100'
type="text"
name="country"
disable={true}
value={country.loading ? 'loading' : country.data ? country.data : 'no country found!'}
inputHandler={(e)=> setCountry((prev) => ({...prev, data:e.target.value}))}
/> */}
<label
htmlFor="country"
className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block"
@@ -182,15 +187,19 @@ function AddJob() {
<option className="text-slate-500 text-lg" value="">
Select...
</option>
{country.data.map((item, index) => (
<option
key={index}
className="text-slate-500 text-lg"
value={item[0]}
>
{item[1]}
</option>
))}
{country.data.map((item, index) => {
if(item[0] == userDetails.country){
return (
<option
key={index}
className="text-slate-500 text-lg"
value={item[0]}
>
{item[1]}
</option>
)
}
})}
</>
) : (
<option className="text-slate-500 text-lg" value="">
@@ -272,17 +281,6 @@ function AddJob() {
{/* Details */}
<div className="field w-full mb-6">
{/* <InputCom
fieldClass="px-6"
label="Job Delivery Details"
labelClass='tracking-wide'
inputBg = 'bg-slate-100'
type="text"
name="details"
// placeholder="Please Enter Detail Description of Job"
value={props.values.details}
inputHandler={props.handleChange}
/> */}
<label
htmlFor="Job Delivery Details"
className='className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block"'