ok
This commit is contained in:
@@ -108,7 +108,7 @@ const ProfileImage = styled.img`
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
object-fit: contain;
|
||||
object-fit: cover;
|
||||
cursor: pointer;
|
||||
z-index: 199;
|
||||
animation: ${(props) => {
|
||||
|
||||
@@ -13,10 +13,6 @@ import MultiSwitch from "react-multi-switch-toggle";
|
||||
import DailyCharts from '../components/DailyCharts.js';
|
||||
import PeriodCharts from '../components/PeriodCharts.js';
|
||||
|
||||
import Coupon from "../components/Coupon.js";
|
||||
|
||||
import CreateCouponPage from "./CreateCoupon.js";
|
||||
|
||||
const RoundedRectangle = ({
|
||||
onClick,
|
||||
title,
|
||||
@@ -312,7 +308,7 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
filterTexts[["yesterday", "weekly", "monthly", "yearly"].indexOf(filter)];
|
||||
|
||||
const [resetKey, setResetKey] = useState(0); // A key to force re-render
|
||||
const [texts, setTexts] = useState(['Buat bisnis']); // initially show only first 3 texts
|
||||
const [texts, setTexts] = useState([]); // initially show only first 3 texts
|
||||
const [fullTexts, setFullTexts] = useState(null); // initially show only first 3 texts
|
||||
const [fullTextsVisible, setFullTextsVisible] = useState(null); // initially show only first 3 texts
|
||||
|
||||
@@ -322,27 +318,27 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
let updatedFullTexts;
|
||||
if (otherCafes.length === 0) {
|
||||
// Only include the role-specific option if user.roleId is 1
|
||||
updatedFullTexts = user.roleId == 1 ? [["Buat Bisnis", 0]] : [];
|
||||
updatedFullTexts = user.roleId == 1 ? [[0]] : [];
|
||||
setSelectedCafeId(-1);
|
||||
} else if (otherCafes.length === 1) {
|
||||
updatedFullTexts = [
|
||||
[otherCafes[0].cafeIdentifyName || otherCafes[0].username, otherCafes[0].cafeId || otherCafes[0].user_id],
|
||||
// Only add the "Buat Bisnis" option for user.roleId == 1
|
||||
...(user.roleId == 1 ? [["Buat Bisnis", -1]] : [])
|
||||
|
||||
...(user.roleId == 1 ? [[-1]] : [])
|
||||
];
|
||||
|
||||
|
||||
setSelectedCafeId(otherCafes[0].cafeId); // Get the cafeId (second part of the pair)
|
||||
} else {
|
||||
updatedFullTexts = [
|
||||
["semua", 0], // First entry is "semua"
|
||||
...otherCafes.map(item => [item.cafeIdentifyName || item.username, item.cafeId || item.user_id]), // Map over cafes to get name and cafeId pairs
|
||||
// Only add "Buat Bisnis +" option for user.roleId == 1
|
||||
...(user.roleId == 1 ? [["Buat Bisnis +", -1]] : [])
|
||||
|
||||
...(user.roleId == 1 ? [] : [])
|
||||
];
|
||||
|
||||
|
||||
setSelectedCafeId(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
setFullTexts(updatedFullTexts); // Set fullTexts with the original structure
|
||||
// Set fullTextsVisible to an array of names only
|
||||
@@ -408,24 +404,24 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair)
|
||||
}
|
||||
let nextSelectedId = selectedItem[1]
|
||||
|
||||
|
||||
console.log(analytics)
|
||||
if (user && user.roleId === 0 && analytics) {
|
||||
// Filter the analytics items based on user_id
|
||||
if(selectedItem[1] != 0 && selectedItem[1] != -1){
|
||||
const filteredData = analytics.items.filter(
|
||||
(data) => data.user_id === 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([])
|
||||
if (selectedItem[1] != 0 && selectedItem[1] != -1) {
|
||||
const filteredData = analytics.items.filter(
|
||||
(data) => data.user_id === 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
|
||||
@@ -455,8 +451,8 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
} else {
|
||||
setModal('loading');
|
||||
const create = await createCafe(itemName);
|
||||
setModal("message", {
|
||||
captMessage: create ? 'Berhasil membuat cafe' : 'Gagal membuat cafe'
|
||||
setModal("message", {
|
||||
captMessage: create ? 'Berhasil membuat cafe' : 'Gagal membuat cafe'
|
||||
});
|
||||
|
||||
// Add a 2-second delay before proceeding
|
||||
@@ -602,7 +598,7 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
{!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && (
|
||||
<RoundedRectangle
|
||||
title={"Kunjungi bisnis"}
|
||||
width= {`calc(${'100%'} - 10px)`}
|
||||
width={`calc(${'100%'} - 10px)`}
|
||||
height='10px'
|
||||
onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName}
|
||||
marginBottom={'0px'}
|
||||
@@ -720,77 +716,6 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
}
|
||||
</div>
|
||||
}
|
||||
{!forCafe && selectedCafeId == -1 && user.roleId == 1 &&
|
||||
<div style={{
|
||||
textAlign: "center",
|
||||
}}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexWrap: "wrap",
|
||||
justifyContent: "center",
|
||||
padding: "20px",
|
||||
}}
|
||||
>
|
||||
|
||||
<RoundedRectangle
|
||||
title={"Masukkan nama bisnis"}
|
||||
width="calc(100% - 10px)"
|
||||
>
|
||||
<input
|
||||
value={itemName}
|
||||
onChange={(e) => setItemName(e.target.value)}
|
||||
style={{
|
||||
width: '70%',
|
||||
fontSize: '25px',
|
||||
borderRadius: '7px',
|
||||
border: '1px solid black'
|
||||
}}
|
||||
/>
|
||||
</RoundedRectangle>
|
||||
|
||||
|
||||
<RoundedRectangle
|
||||
title={"Buat Bisnis"}
|
||||
width="calc(100% - 10px)"
|
||||
onClick={handleClick}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
{!forCafe &&
|
||||
<>
|
||||
<div className={`${styles.couponContainer}`}>
|
||||
<div>
|
||||
{!forCafe &&
|
||||
<div className={styles.dateSelectorWrapper} style={{ fontSize: '13px' }}>
|
||||
<div
|
||||
className={`${styles.dateSelector} ${styles.dateSelectorActive}`} style={{ position: 'relative', width: 'calc(32vw - 30px)' }}
|
||||
>
|
||||
<div style={{ position: 'absolute', bottom: 0, left: '10%', right: '10%', borderBottom: `1px solid green` }}></div>
|
||||
<div
|
||||
style={{ color: 'black' }}>
|
||||
Voucher
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ padding: '25px', paddingTop: '0', paddingBottom: '0' }}>
|
||||
{/* <h1>{couponList.length}</h1> */}
|
||||
{couponList && couponList.map((coupon) => {
|
||||
return <Coupon
|
||||
code={coupon?.code || null}
|
||||
value={coupon?.discountValue}
|
||||
period={coupon?.discountPeriods}
|
||||
expiration={coupon?.discountEndDate}
|
||||
/>
|
||||
})}
|
||||
<button className={`${styles.addCoupon}`} onClick={() => setModal('claim-coupon')}>Tambahkan Voucher</button>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user