An Optimized version
This commit was merged in pull request #398.
This commit is contained in:
@@ -90,14 +90,15 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWalletDetail = (currency) => {
|
const getWalletDetail = (country) => {
|
||||||
let { result_list } = walletDetails;
|
const walletChecker = walletDetails.result_list.find(
|
||||||
return result_list?.filter((item) => item.country === currency);
|
(item) => item.country === country
|
||||||
|
);
|
||||||
|
return walletChecker ? walletChecker.amount : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FUNCTION TO HANDLE ADD JOB FORM
|
const handleAddJob = async (values, helpers) => {
|
||||||
const handleAddJob = (values, helpers) => {
|
const reqData = {
|
||||||
let reqData = {
|
|
||||||
country: values?.country,
|
country: values?.country,
|
||||||
price: Number(values.price) * 100,
|
price: Number(values.price) * 100,
|
||||||
title: values?.title,
|
title: values?.title,
|
||||||
@@ -107,30 +108,34 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
category: values.category?.join("@"),
|
category: values.category?.join("@"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let walletChecker = getWalletDetail(reqData.country);
|
const walletAmount = getWalletDetail(reqData.country);
|
||||||
if (reqData.price > walletChecker[0]?.amount) {
|
if (reqData.price > walletAmount) {
|
||||||
setRequestStatus({
|
setRequestStatus({
|
||||||
loading: false,
|
loading: false,
|
||||||
status: false,
|
status: false,
|
||||||
message: "Insufficient Balance",
|
message: "Insufficient Balance",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setRequestStatus({ loading: false, status: false, message: "" });
|
||||||
|
}, 1500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setRequestStatus({ loading: true, status: false, message: "" });
|
setRequestStatus({ loading: true, status: false, message: "" });
|
||||||
ApiCall.jobManagerCreateJob(reqData)
|
|
||||||
.then((res) => {
|
try {
|
||||||
if (res.data.internal_return < 1) {
|
const res = await ApiCall.jobManagerCreateJob(reqData);
|
||||||
setRequestStatus({
|
if (res.data.internal_return < 1) {
|
||||||
loading: false,
|
setRequestStatus({
|
||||||
status: false,
|
loading: false,
|
||||||
message: "Could not complete your request at the moment",
|
status: false,
|
||||||
});
|
message: "Could not complete your request at the moment",
|
||||||
setTimeout(() => {
|
});
|
||||||
popUpHandler();
|
setTimeout(() => {
|
||||||
}, 1500);
|
popUpHandler();
|
||||||
return;
|
}, 1500);
|
||||||
}
|
} else {
|
||||||
setRequestStatus({
|
setRequestStatus({
|
||||||
loading: false,
|
loading: false,
|
||||||
status: true,
|
status: true,
|
||||||
@@ -140,19 +145,18 @@ function AddJob({ popUpHandler, categories }) {
|
|||||||
dispatch(tableReload({ type: "JOBTABLE" }));
|
dispatch(tableReload({ type: "JOBTABLE" }));
|
||||||
popUpHandler();
|
popUpHandler();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
setRequestStatus({
|
setRequestStatus({
|
||||||
loading: false,
|
loading: false,
|
||||||
status: false,
|
status: false,
|
||||||
message: "Opps! something went wrong. Try Again",
|
message: "Oops! Something went wrong. Try Again",
|
||||||
});
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
setRequestStatus({ loading: false, status: false, message: "" });
|
|
||||||
}, 5000);
|
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => {
|
||||||
|
setRequestStatus({ loading: false, status: false, message: "" });
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user