This commit is contained in:
zadit
2024-11-01 11:33:26 +07:00
parent 5a2b9b2f86
commit 32e8ebd69b
20 changed files with 812 additions and 509 deletions

View File

@@ -10,7 +10,7 @@ import {
import "../App.css";
import { getImageUrl, createItem, updateItem } from "../helpers/itemHelper.js";
import { getImageUrl, createItem, updateItem, moveItemType } from "../helpers/itemHelper.js";
import SearchInput from "../components/SearchInput";
import ItemTypeLister from "../components/ItemTypeLister";
import { MusicPlayer } from "../components/MusicPlayer";
@@ -30,6 +30,7 @@ function CafePage({
welcomePageConfig,
shopName,
shopOwnerId,
setShopItems,
shopItems,
shopClerks,
socket,
@@ -149,6 +150,40 @@ function CafePage({
document.body.style.overflow = "auto";
};
const moveItemTypeHandler = async (itemTypeId, direction, index) => {
const previousItems = [...shopItems];
// Update local state immediately
const newItems = [...shopItems];
let targetIndex;
if (direction === 'up' && index > 0) {
targetIndex = index - 1;
} else if (direction === 'down' && index < newItems.length - 1) {
targetIndex = index + 1;
}
console.log(index);
console.log(targetIndex);
if (targetIndex !== undefined) {
// Swap items
[newItems[index], newItems[targetIndex]] = [newItems[targetIndex], newItems[index]];
newItems[index].order = targetIndex;
newItems[targetIndex].order = index;
setShopItems(newItems);
// Call the API to move the item type
try {
await moveItemType(itemTypeId, previousItems[targetIndex].itemTypeId, index, targetIndex);
} catch (error) {
console.error('Error moving item type:', error);
// Revert the changes if the backend fails
setShopItems(previousItems);
}
}
};
if (loading)
return (
<div className="Loader">
@@ -204,6 +239,7 @@ function CafePage({
shopOwnerId={shopOwnerId}
shopId={shopId}
itemTypes={shopItems}
setShopItems={setShopItems}
isEditMode={isEditMode}
onFilterChange={(e) => setFilterId(e)}
filterId={filterId}
@@ -217,8 +253,10 @@ function CafePage({
(itemType) =>
filterId == 0 || itemType.itemTypeId === filterId
)
.map((itemType) => (
.map((itemType, index) => (
<ItemLister
index={index}
indexTotal={shopItems.length}
shopId={shopId}
shopOwnerId={shopOwnerId}
user={user}
@@ -226,8 +264,11 @@ function CafePage({
itemTypeId={itemType.itemTypeId}
typeName={itemType.name}
typeImage={itemType.image}
setShopItems={setShopItems}
itemList={itemType.itemList}
typeVisibility={itemType.visibility}
moveItemTypeUp={(e)=>moveItemTypeHandler(e,'up', index)}
moveItemTypeDown={(e)=>moveItemTypeHandler(e, 'down', index)}
isEditMode={isEditMode}
beingEditedType={beingEditedType}
setBeingEditedType={setBeingEditedType}

View File

@@ -150,7 +150,7 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
return (
<div className={styles.Invoice}>
<div style={{ marginTop: "30px" }}></div>
<h2 className={styles["Invoice-title"]}>Cart</h2>
<h2 className={styles["Invoice-title"]}>Keranjang</h2>
<div style={{ marginTop: "30px" }}></div>
<div className={styles.RoundedRectangle}>
{cartItems.map((itemType) => (
@@ -165,7 +165,7 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
{table.tableNo != null && (
<div className={styles.OrderTypeContainer}>
<span htmlFor="orderType">Serve to table {table.tableNo}</span>
<span htmlFor="orderType">Diantar ke meja {table.tableNo}</span>
{/* <select
id="orderType"
value={orderType}
@@ -193,7 +193,7 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
)}
<div className={styles.NoteContainer}>
<span>Note :</span>
<span>Catatan :</span>
<span></span>
</div>
@@ -201,7 +201,7 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
<textarea
ref={textareaRef}
className={styles.NoteInput}
placeholder="Add a note..."
placeholder="Tambahkan catatan..."
/>
</div>
<div className={styles.TotalContainer}>
@@ -211,21 +211,21 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
</div>
<div className={styles.PaymentOption}>
<div className={styles.TotalContainer}>
<span>Payment Option</span>
<span>Opsi pembayaran</span>
<span></span>
</div>
<button className={styles.PayButton} onClick={() => handlePay(false)}>
{isPaymentLoading ? (
<ColorRing height="50" width="50" color="white" />
) : (
"Cashless"
"Nontunai"
)}
</button>
<div className={styles.Pay2Button} onClick={() => handlePay(true)}>
{isPaymentLoading ? (
<ColorRing height="12" width="12" color="white" />
) : (
"Cash"
"Tunai"
)}
</div>
</div>

View File

@@ -80,6 +80,31 @@ const Dashboard = ({ user, setModal }) => {
});
}
};
// function calculateCafeMetrics(cafes) {
// let totalIncomeThisMonth = 0;
// let totalIncomeLastMonth = 0;
// cafes.forEach(cafe => {
// const currentIncome = cafe.totalIncome;
// const growth = cafe.growthIncome / 100;
// // Hitung keuntungan bulan lalu
// const lastMonthIncome = currentIncome / (1 + growth);
// // Tambahkan ke total
// totalIncomeThisMonth += currentIncome;
// totalIncomeLastMonth += lastMonthIncome;
// });
// // Hitung growth total
// const totalGrowth = ((totalIncomeThisMonth - totalIncomeLastMonth) / totalIncomeLastMonth) * 100;
// return {
// totalIncomeThisMonth,
// totalIncomeLastMonth: totalIncomeLastMonth.toFixed(2),
// totalGrowth: totalGrowth.toFixed(2)
// };
// }
return (
<>
@@ -100,7 +125,9 @@ const Dashboard = ({ user, setModal }) => {
onClick={() => navigate("/" + item.cafeId)}
className={styles.rectangle}
>
{item.name || item.username}
<h1>{item.name || item.username}</h1>
<div><h1>{item.report.totalIncome}</h1><h1>{item.report.totalIncome}</h1></div>
</div>
))}
{user && user.roleId < 1 ? (

View File

@@ -211,10 +211,11 @@ const App = ({ cafeId,
right: 0,
backgroundColor: 'rgb(207, 207, 207)'}}
>
<h2 className={styles["Transactions-title"]}>Reports</h2>
<div style={{ textAlign: "center" }}>
<h2 className={styles["Transactions-title"]}>Laporan</h2>
<div style={{ textAlign: "center",
marginTop: '30px' }}>
<MultiSwitch
texts={["Yesterday", "This week", "This Month", "This year"]}
texts={["kemarin", "minggu ini", "bulan ini", "tahun ini"]}
selectedSwitch={["daily", "weekly", "monthly", "yearly"].indexOf(
filter
)}

View File

@@ -43,7 +43,7 @@ function SearchResult({ user, shopItems, sendParam }) {
return (
<div className="App">
<header className="App-header">
<Header HeaderText={"Search"} />
<Header HeaderText={"Pencarian"} />
<div style={{ marginTop: "5px" }}></div>
<SearchInput
shopId={shopId}

View File

@@ -229,7 +229,7 @@ export default function Transactions({
: handleDecline(transaction.transactionId)
}
>
{isPaymentOpen ? "back" : "cancel"}
{isPaymentOpen ? "kembali" : "batalkan"}
</h5>
</div>
)}