Compare commits

...

3 Commits

Author SHA1 Message Date
victorAnumudu f5575ecce5 disabled user country 2023-05-18 16:33:18 +01:00
victorAnumudu b5b95a9040 duplicate info removed 2023-05-18 16:15:37 +01:00
victorAnumudu 24f3a40a43 Only returns User Country as Default Country in Add Job Page 2023-05-18 16:12:14 +01:00
+52 -43
View File
@@ -4,6 +4,8 @@ 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";
@@ -31,31 +33,43 @@ const validationSchema = Yup.object().shape({
timeline_days: Yup.number() timeline_days: 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")
.required("Price is required"), .required("Timeline is required"),
}); });
let initialValues = { // let initialValues = {
// initial values for formik // // initial values for formik
country: "", // country: "NG",
price: 0, // price: 0,
title: "", // title: "",
description: "", // description: "",
job_detail: "", // job_detail: "",
timeline_days: "", // timeline_days: "",
}; // };
function AddJob() { function AddJob() {
const ApiCall = new usersService(); const ApiCall = new usersService();
const navigate = useNavigate(); const navigate = useNavigate();
let {userDetails} = useSelector((state)=> state.userDetails)
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: true,
status: false, status: false,
data: [], data: [],
}); // To Hold the array of country getUserCountry returns }); // To Hold the array of country getUserCountry returns
let initialValues = {
// initial values for formik
country: userDetails.country,
price: "",
title: "",
description: "",
job_detail: "",
timeline_days: "",
};
let [requestStatus, setRequestStatus] = useState({ let [requestStatus, setRequestStatus] = useState({
loading: false, loading: false,
status: false, status: false,
@@ -119,8 +133,8 @@ function AddJob() {
}; };
useEffect(() => { useEffect(() => {
setPageLoading(false);
getUserCountry(); getUserCountry();
setPageLoading(false);
}, []); }, []);
return pageLoading.loading ? ( return pageLoading.loading ? (
@@ -149,16 +163,17 @@ function AddJob() {
<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} value={country.loading ? 'loading' : country.data ? country.data : 'no country found!'}
inputHandler={props.handleChange} inputHandler={(e)=> setCountry((prev) => ({...prev, data:e.target.value}))}
/> */}
/> */}
<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"
@@ -168,6 +183,7 @@ function AddJob() {
<select <select
id="country" id="country"
name="country" name="country"
disabled
value={props.values.country} value={props.values.country}
className={`input-field p-2 mt-3 rounded-md placeholder:text-base text-dark-gray dark:text-white w-full h-10 bg-slate-100 dark:bg-[#11131F] focus:ring-0 focus:outline-none`} className={`input-field p-2 mt-3 rounded-md placeholder:text-base text-dark-gray dark:text-white w-full h-10 bg-slate-100 dark:bg-[#11131F] focus:ring-0 focus:outline-none`}
onChange={props.handleChange} onChange={props.handleChange}
@@ -182,15 +198,19 @@ function AddJob() {
<option className="text-slate-500 text-lg" value=""> <option className="text-slate-500 text-lg" value="">
Select... Select...
</option> </option>
{country.data.map((item, index) => ( {country.data.map((item, index) => {
<option if(item[0] == userDetails.country){
key={index} return (
className="text-slate-500 text-lg" <option
value={item[0]} key={index}
> className="text-slate-500 text-lg"
{item[1]} value={item[0]}
</option> >
))} {item[1]}
</option>
)
}
})}
</> </>
) : ( ) : (
<option className="text-slate-500 text-lg" value=""> <option className="text-slate-500 text-lg" value="">
@@ -214,7 +234,7 @@ function AddJob() {
inputBg="bg-slate-100" inputBg="bg-slate-100"
type="number" type="number"
name="price" name="price"
// placeholder="Please Enter Amount" placeholder="0"
value={props.values.price} value={props.values.price}
inputHandler={props.handleChange} inputHandler={props.handleChange}
blurHandler={props.handleBlur} blurHandler={props.handleBlur}
@@ -272,17 +292,6 @@ function AddJob() {
{/* Details */} {/* Details */}
<div className="field w-full mb-6"> <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 <label
htmlFor="Job Delivery Details" htmlFor="Job Delivery Details"
className='className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block"' className='className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold block"'