This commit is contained in:
insvrgent
2025-02-03 17:48:48 +07:00
parent 8676621fe2
commit 66f73bc1ba
5 changed files with 84 additions and 22 deletions

View File

@@ -110,6 +110,7 @@ const RoundedRectangle = ({
const App = ({ forCafe = true, cafeId = -1,
handleClose, otherCafes, coupons, setModal, user }) => {
const [modalStatus, setModalStatus] = useState(null);
const [selectedCafeId, setSelectedCafeId] = useState(cafeId);
const [analytics, setAnalytics] = useState({});
const [loading, setLoading] = useState(true);
@@ -306,7 +307,7 @@ const App = ({ forCafe = true, cafeId = -1,
if (otherCafes.length === 0) {
updatedFullTexts = [["Buat bisnis", 0]];
setSelectedCafeId(0);
setSelectedCafeId(-1);
} else if (otherCafes.length === 1) {
updatedFullTexts = [
[otherCafes[0].name || otherCafes[0].username, otherCafes[0].cafeId || otherCafes[0].userId],
@@ -393,6 +394,39 @@ const App = ({ forCafe = true, cafeId = -1,
// // We could add logic here if needed for side effects
// }, [selectedSwitch]);
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const handleClick = async () => {
if (user?.roleId === 0) {
setModal('loading');
const create = await createCoupon(itemName);
if (!create) {
setModalStatus('failed');
}
// Add a 2-second delay before proceeding
await delay(2000);
handleClose();
setModalStatus(null); // Reset status
window.location.reload(); // Reload the page
return;
} else {
setModal('loading');
const create = await createCafe(itemName);
if (!create) {
setModalStatus('failed');
}
// Add a 2-second delay before proceeding
await delay(2000);
handleClose();
setModalStatus(null); // Reset status
window.location.reload(); // Reload the page
}
};
return (
<div style={{
position: forCafe ? 'fixed' : 'relative',
@@ -484,24 +518,24 @@ const App = ({ forCafe = true, cafeId = -1,
invert={false}
loading={loading}
/>
<h1>{segments[0]?.itemName}</h1>
{((analytics?.itemSales &&
analytics?.itemSales.length > 0) || (!analytics?.itemSales && segments.length > 0)) && (
<RoundedRectangle
title={"Item favorit"}
value={analytics?.itemSales[0] != undefined ? analytics?.itemSales[0]?.itemName
: segments[0].itemName}
loading={loading}
/>
)}
{(!analytics?.itemSales ||
analytics?.itemSales.length === 0) && (
analytics?.itemSales.length > 0) || (!analytics?.itemSales && segments.length > 0)) ? (
<RoundedRectangle
title={"Item favorit"}
value={analytics?.itemSales?.length > 0 && analytics?.itemSales[0] != undefined ? analytics?.itemSales[0]?.itemName
: segments[0].itemName}
loading={loading}
/>
)
:
(
<RoundedRectangle
title={"Item favorit"}
value={"-"}
loading={loading}
/>
)}
)
}
{!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && (
<RoundedRectangle
title={"Kunjungi bisnis"}
@@ -670,7 +704,7 @@ const App = ({ forCafe = true, cafeId = -1,
<RoundedRectangle
title={user?.roleId === 0 ? "Buat Voucher" : "Buat Bisnis"}
width="calc(100% - 10px)"
onClick={() => (user?.roleId === 0 ? createCoupon(itemName) : createCafe(itemName))}
onClick={handleClick}
/>
</div>
</div>