This commit is contained in:
insvrgent
2025-02-06 10:32:18 +07:00
parent e2b0ef1046
commit 3e5d795153
3 changed files with 57 additions and 7 deletions

View File

@@ -402,14 +402,22 @@ export const getReports = async (cafeId, filter) => {
); );
return response.json(); return response.json();
}; };
export const getAnalytics = async (filter) => {
const response = await fetch( export const getAnalytics = async (filter, selectedCafeId) => {
API_BASE_URL + "/transaction/get-analytics" + "?type=" + filter, // Start the URL with the filter type query
getHeaders('POST') let url = API_BASE_URL + "/transaction/get-analytics" + "?type=" + filter;
);
// Only add selectedCafeId to the query string if it's not null
if (selectedCafeId !== null) {
url += "&cafeId=" + selectedCafeId;
}
// Fetch with the updated URL
const response = await fetch(url, getHeaders('POST'));
return response.json(); return response.json();
}; };
export const getIncome = async (cafeId) => { export const getIncome = async (cafeId) => {
const response = await fetch( const response = await fetch(
`${API_BASE_URL}/transaction/get-income/${cafeId}`, `${API_BASE_URL}/transaction/get-income/${cafeId}`,

View File

@@ -266,9 +266,10 @@
border: 1px solid #ccc; border: 1px solid #ccc;
margin-top: 5px; margin-top: 5px;
margin-bottom: 15px; margin-bottom: 15px;
text-transform: lowercase; text-transform: none; /* Remove lowercase transformation */
} }
.usernameInputError { .usernameInputError {
width: 250px; width: 250px;
height: 55px; height: 55px;

View File

@@ -127,9 +127,12 @@ const App = ({ forCafe = true, cafeId = -1,
try { try {
setLoading(true); setLoading(true);
// Fetch the analytics data with the selected filter // Fetch the analytics data with the selected filter
const analyticsData = (selectedCafeId !== '' && selectedCafeId !== 0) let analyticsData = null;
if(user.roleId == 1)
analyticsData = (selectedCafeId !== '' && selectedCafeId !== 0)
? await getReports(selectedCafeId, filter) ? await getReports(selectedCafeId, filter)
: await getAnalytics(filter); : await getAnalytics(filter);
else analyticsData = await getAnalytics(filter, selectedCafeId);
console.log(analyticsData); console.log(analyticsData);
if (analyticsData) setAnalytics(analyticsData); if (analyticsData) setAnalytics(analyticsData);
@@ -657,6 +660,44 @@ 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>
}
{user?.roleId == 1 && {user?.roleId == 1 &&
<> <>
<div className={`${styles.couponContainer}`}> <div className={`${styles.couponContainer}`}>