This commit is contained in:
Vassshhh
2025-08-27 02:53:30 +07:00
parent dd0227ab80
commit e039fc8acc
2 changed files with 28 additions and 103 deletions

View File

@@ -108,7 +108,7 @@ const ProfileImage = styled.img`
width: 60px; width: 60px;
height: 60px; height: 60px;
border-radius: 50%; border-radius: 50%;
object-fit: contain; object-fit: cover;
cursor: pointer; cursor: pointer;
z-index: 199; z-index: 199;
animation: ${(props) => { animation: ${(props) => {

View File

@@ -13,10 +13,6 @@ import MultiSwitch from "react-multi-switch-toggle";
import DailyCharts from '../components/DailyCharts.js'; import DailyCharts from '../components/DailyCharts.js';
import PeriodCharts from '../components/PeriodCharts.js'; import PeriodCharts from '../components/PeriodCharts.js';
import Coupon from "../components/Coupon.js";
import CreateCouponPage from "./CreateCoupon.js";
const RoundedRectangle = ({ const RoundedRectangle = ({
onClick, onClick,
title, title,
@@ -312,7 +308,7 @@ const App = ({ forCafe = true, cafeId = -1,
filterTexts[["yesterday", "weekly", "monthly", "yearly"].indexOf(filter)]; filterTexts[["yesterday", "weekly", "monthly", "yearly"].indexOf(filter)];
const [resetKey, setResetKey] = useState(0); // A key to force re-render 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 [fullTexts, setFullTexts] = useState(null); // initially show only first 3 texts
const [fullTextsVisible, setFullTextsVisible] = 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; let updatedFullTexts;
if (otherCafes.length === 0) { if (otherCafes.length === 0) {
// Only include the role-specific option if user.roleId is 1 // 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); setSelectedCafeId(-1);
} else if (otherCafes.length === 1) { } else if (otherCafes.length === 1) {
updatedFullTexts = [ updatedFullTexts = [
[otherCafes[0].cafeIdentifyName || otherCafes[0].username, otherCafes[0].cafeId || otherCafes[0].user_id], [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) setSelectedCafeId(otherCafes[0].cafeId); // Get the cafeId (second part of the pair)
} else { } else {
updatedFullTexts = [ updatedFullTexts = [
["semua", 0], // First entry is "semua" ["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 ...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); setSelectedCafeId(0);
} }
setFullTexts(updatedFullTexts); // Set fullTexts with the original structure setFullTexts(updatedFullTexts); // Set fullTexts with the original structure
// Set fullTextsVisible to an array of names only // 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) setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair)
} }
let nextSelectedId = selectedItem[1] let nextSelectedId = selectedItem[1]
console.log(analytics) console.log(analytics)
if (user && user.roleId === 0 && analytics) { if (user && user.roleId === 0 && analytics) {
// Filter the analytics items based on user_id // Filter the analytics items based on user_id
if(selectedItem[1] != 0 && selectedItem[1] != -1){ if (selectedItem[1] != 0 && selectedItem[1] != -1) {
const filteredData = analytics.items.filter( const filteredData = analytics.items.filter(
(data) => data.user_id === nextSelectedId (data) => data.user_id === nextSelectedId
); );
// Extract coupons from the filtered data // Extract coupons from the filtered data
const couponsToAdd = filteredData.flatMap((data) => data.coupons); const couponsToAdd = filteredData.flatMap((data) => data.coupons);
// Log the coupons to be added // Log the coupons to be added
console.log(couponsToAdd); console.log(couponsToAdd);
// Assuming setCouponList is a function that updates the coupon list // Assuming setCouponList is a function that updates the coupon list
setCouponList(couponsToAdd || []); setCouponList(couponsToAdd || []);
} }
else setCouponList([]) else setCouponList([])
} }
setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render
@@ -455,8 +451,8 @@ const App = ({ forCafe = true, cafeId = -1,
} else { } else {
setModal('loading'); setModal('loading');
const create = await createCafe(itemName); const create = await createCafe(itemName);
setModal("message", { setModal("message", {
captMessage: create ? 'Berhasil membuat cafe' : 'Gagal membuat cafe' captMessage: create ? 'Berhasil membuat cafe' : 'Gagal membuat cafe'
}); });
// Add a 2-second delay before proceeding // Add a 2-second delay before proceeding
@@ -602,7 +598,7 @@ const App = ({ forCafe = true, cafeId = -1,
{!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && ( {!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && (
<RoundedRectangle <RoundedRectangle
title={"Kunjungi bisnis"} title={"Kunjungi bisnis"}
width= {`calc(${'100%'} - 10px)`} width={`calc(${'100%'} - 10px)`}
height='10px' height='10px'
onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName} onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName}
marginBottom={'0px'} marginBottom={'0px'}
@@ -720,77 +716,6 @@ const App = ({ forCafe = true, cafeId = -1,
} }
</div> </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> </div>
); );
}; };