This commit is contained in:
insvrgent
2025-02-07 06:46:24 +07:00
parent 3e5d795153
commit ebf9f89089

View File

@@ -112,6 +112,7 @@ const RoundedRectangle = ({
const App = ({ forCafe = true, cafeId = -1,
handleClose, otherCafes, coupons, setModal, user }) => {
const [couponList, setCouponList] = useState(coupons);
const [modalStatus, setModalStatus] = useState(null);
const [selectedCafeId, setSelectedCafeId] = useState(cafeId);
const [analytics, setAnalytics] = useState({});
@@ -386,11 +387,33 @@ const App = ({ forCafe = true, cafeId = -1,
// Get the cafeId from the selected text based on the index
const selectedText = texts[index]; // Get the selected name from the texts array
let unSelectedText;
if (texts[index - 1] != undefined) unSelectedText = texts[index - 1]; // Get the selected name from the texts array
const selectedItem = fullTexts.find(item => item[0] === selectedText); // Find the corresponding full item
const unSelectedItem = fullTexts.find(item => item[0] === unSelectedText); // Find the corresponding full item
if (selectedItem) {
setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair)
}
if(selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon', {}, () => {setSelectedSwitch(0);setSelectedCafeId(0)});
let nextSelectedId = selectedItem[1]
if (selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon', {}, () => { setSelectedSwitch(1); setSelectedCafeId(unSelectedItem[1]); nextSelectedId=unSelectedItem[1] });
console.log(analytics)
if (user && user.roleId === 0 && analytics) {
// Filter the analytics items based on userId
if(selectedItem[1] != 0 && selectedItem[1] != -1){
const filteredData = analytics.items.filter(
(data) => data.userId === nextSelectedId
);
// Extract coupons from the filtered data
const couponsToAdd = filteredData.flatMap((data) => data.coupons);
// Log the coupons to be added
console.log(couponsToAdd);
// Assuming setCouponList is a function that updates the coupon list
setCouponList(couponsToAdd || []);
}
else setCouponList([])
}
setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render
};
@@ -698,8 +721,6 @@ const App = ({ forCafe = true, cafeId = -1,
</div>
</div>
}
{user?.roleId == 1 &&
<>
<div className={`${styles.couponContainer}`}>
{forCafe && <div style={{ marginTop: '49px', marginRight: '10px' }} onClick={handleClose}><svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 512 512"><path d="M48,256c0,114.87,93.13,208,208,208s208-93.13,208-208S370.87,48,256,48,48,141.13,48,256Zm212.65-91.36a16,16,0,0,1,.09,22.63L208.42,240H342a16,16,0,0,1,0,32H208.42l52.32,52.73A16,16,0,1,1,238,347.27l-79.39-80a16,16,0,0,1,0-22.54l79.39-80A16,16,0,0,1,260.65,164.64Z" /></svg></div>}
<div>
@@ -719,8 +740,8 @@ const App = ({ forCafe = true, cafeId = -1,
</div>
</div>
<div style={{ padding: '25px', paddingTop: '0', paddingBottom: '0' }}>
{coupons && coupons.map((coupon) => {
{/* <h1>{couponList.length}</h1> */}
{couponList && couponList.map((coupon) => {
return <Coupon
code={coupon?.code || null}
value={coupon?.discountValue}
@@ -730,8 +751,6 @@ const App = ({ forCafe = true, cafeId = -1,
})}
<button className={`${styles.addCoupon}`} onClick={() => setModal('claim-coupon')}>Tambahkan Voucher</button>
</div>
</>
}
</div>
);
};