Merge branch 'add-job-bug' of WrenchBoard/Users-Wrench into master
This commit is contained in:
@@ -11,7 +11,7 @@ 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("Currency is required"),
|
||||||
price: Yup.string()
|
price: Yup.string()
|
||||||
.typeError("Invalid number")
|
.typeError("Invalid number")
|
||||||
.min(1, "Price must be greater than 0")
|
.min(1, "Price must be greater than 0")
|
||||||
@@ -46,12 +46,6 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
const { walletDetails } = useSelector((state) => state.walletDetails);
|
const { walletDetails } = useSelector((state) => state.walletDetails);
|
||||||
let dispatch = useDispatch();
|
let dispatch = useDispatch();
|
||||||
|
|
||||||
let [currency, setCurrency] = useState({
|
|
||||||
loading: true,
|
|
||||||
status: false,
|
|
||||||
data: null,
|
|
||||||
}); // To Hold the array of currency getUserCurrency returns
|
|
||||||
|
|
||||||
let initialValues = {
|
let initialValues = {
|
||||||
// initial values for formik
|
// initial values for formik
|
||||||
country: "",
|
country: "",
|
||||||
@@ -69,29 +63,8 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
message: "",
|
message: "",
|
||||||
}); // Holds state when submit button is pressed
|
}); // Holds state when submit button is pressed
|
||||||
|
|
||||||
// FUNCTION TO GET Currency
|
const getWalletDetail = (country) => { // A FUNCTION TO GET USER BALANCE BASED ON COUNTRY SELECTED
|
||||||
const getUserCurrency = () => {
|
const walletChecker = walletDetails?.data.find(
|
||||||
setCurrency((prev) => ({ ...prev, loading: true }));
|
|
||||||
ApiCall.getUserWallets()
|
|
||||||
.then((res) => {
|
|
||||||
if (res.data.internal_return < 0) {
|
|
||||||
setCurrency({ loading: false, status: true, data: [] });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrency({
|
|
||||||
loading: false,
|
|
||||||
status: true,
|
|
||||||
data: res.data.result_list,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
setCurrency({ loading: false, status: false, data: [] });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getWalletDetail = (country) => {
|
|
||||||
const walletChecker = walletDetails.result_list.find(
|
|
||||||
(item) => item.country === country
|
(item) => item.country === country
|
||||||
);
|
);
|
||||||
return walletChecker ? walletChecker.amount : 0;
|
return walletChecker ? walletChecker.amount : 0;
|
||||||
@@ -108,7 +81,8 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
category: values.category?.join("@"),
|
category: values.category?.join("@"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const walletAmount = getWalletDetail(reqData.country);
|
const walletAmount = getWalletDetail(reqData.country); // GETTING USER BALANCE BASED ON COUNTRY SELECTED
|
||||||
|
|
||||||
if (reqData.price > walletAmount) {
|
if (reqData.price > walletAmount) {
|
||||||
setRequestStatus({
|
setRequestStatus({
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -159,10 +133,6 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getUserCurrency();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="add-job p-5 w-full bg-white rounded-md flex flex-col justify-between">
|
<div className="add-job p-5 w-full bg-white rounded-md flex flex-col justify-between">
|
||||||
<Formik
|
<Formik
|
||||||
@@ -197,16 +167,16 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
onChange={props.handleChange}
|
onChange={props.handleChange}
|
||||||
onBlur={props.handleBlur}
|
onBlur={props.handleBlur}
|
||||||
>
|
>
|
||||||
{currency.loading ? (
|
{walletDetails.loading ? (
|
||||||
<option className="text-slate-500 text-lg" value="">
|
<option className="text-slate-500 text-lg" value="">
|
||||||
Loading...
|
Loading...
|
||||||
</option>
|
</option>
|
||||||
) : currency.data.length ? (
|
) : walletDetails.data.length ? (
|
||||||
<>
|
<>
|
||||||
<option className="text-slate-500 text-lg" value="">
|
<option className="text-slate-500 text-lg" value="">
|
||||||
Select a currency
|
Select a currency
|
||||||
</option>
|
</option>
|
||||||
{currency.data?.map((item, index) => (
|
{walletDetails.data?.map((item, index) => (
|
||||||
<option
|
<option
|
||||||
key={index}
|
key={index}
|
||||||
className="text-slate-500 text-lg"
|
className="text-slate-500 text-lg"
|
||||||
@@ -384,6 +354,7 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
<option value="">Select Duration</option>
|
<option value="">Select Duration</option>
|
||||||
{publicArray.map(({ name, duration }, idx) => (
|
{publicArray.map(({ name, duration }, idx) => (
|
||||||
<option
|
<option
|
||||||
|
key={idx}
|
||||||
className="text-slate-500 text-lg"
|
className="text-slate-500 text-lg"
|
||||||
value={duration}
|
value={duration}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ const AuthRoute = ({ redirectPath = "/login", children }) => {
|
|||||||
.getRecentActivitiedData()
|
.getRecentActivitiedData()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// debugger;
|
// debugger;
|
||||||
if (res.data?.internal_return < 0) {
|
if (res?.data?.internal_return < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dispatch(recentActivitiesData(res.data));
|
dispatch(recentActivitiesData(res.data));
|
||||||
|
|||||||
Reference in New Issue
Block a user