@@ -286,44 +328,50 @@ export function MusicPlayer({ socket, shopId, user, isSpotifyNeedLogin }) {
))}
-
+
+
{currentSong.item && currentSong.item.name
- ? currentSong.item.name
- : "Awaiting the next hit"}
+ ? (viewing? currentSong.item.name:text)
+ :
+ viewing? messages[0]:text}
-
- {currentSong.item &&
- currentSong.item.album &&
- currentSong.item.album.images[0] &&
- currentSong.item.artists[0].name
- ? currentSong.item.artists[0].name
- : "Drop your hits below"}
-
-
-
- {formatTime(currentTime)}
+ {viewing && <>
+
+ {currentSong.item &&
+ currentSong.item.album &&
+ currentSong.item.album.images[0] &&
+ currentSong.item.artists[0].name
+ ? currentSong.item.artists[0].name
+ : "Drop your hits below"}
-
-
- {formatTime(trackLength)}
-
-
+
+
+ {formatTime(currentTime)}
+
+
+
+ {formatTime(trackLength)}
+
+
>
+ }
+ {viewing &&
+ <>
{expanded
- ? "collapse"
+ ? "︿"
: currentSong.item &&
- currentSong.item.album &&
- currentSong.item.album.images[0] &&
- currentSong.item.artists[0]
+ currentSong.item.album &&
+ currentSong.item.album.images[0] &&
+ currentSong.item.artists[0]
? "expand"
: "request your song"}
-
+
>
+}
);
}
diff --git a/src/components/TableList.js b/src/components/TableList.js
index ffabe4d..1dc1b63 100644
--- a/src/components/TableList.js
+++ b/src/components/TableList.js
@@ -1,6 +1,7 @@
-import React, { useState, useEffect } from "react";
+import React, {useState} from "react";
import QRCodeWithBackground from "./QR"; // Adjust path as needed
-const TableList = ({ shop, tables, onSelectTable, selectedTable }) => {
+
+const TableList = ({ shop, tables, onSelectTable, selectedTable, handleSetTableNo, handleAddTable }) => {
const [initialPos, setInitialPos] = useState({
left: shop.xposition,
top: shop.yposition,
@@ -21,16 +22,16 @@ const TableList = ({ shop, tables, onSelectTable, selectedTable }) => {
}
};
- const handleBackgroundUrlChange = (newUrl) => {
- setBgImageUrl(newUrl);
- };
-
const handleQrSave = (qrPosition, qrSize, bgImage) => {
setInitialPos(qrPosition);
setInitialSize(qrSize);
setBgImageUrl(bgImage);
};
+ const handleCreateTable = () => {
+ handleAddTable();
+ };
+
return (
{
/>
)}
+ {/* Add new table input */}
+
+
+
+
{tables &&
tables
.filter((table) => table.tableNo !== 0)
diff --git a/src/components/TablesPage.js b/src/components/TablesPage.js
index 995bdcf..30fdd7a 100644
--- a/src/components/TablesPage.js
+++ b/src/components/TablesPage.js
@@ -130,10 +130,10 @@ const TablesPage = ({ shop }) => {
};
const handleSave = async () => {
- if (newTable) {
+ // if (newTable) {
try {
const createdTable = await createTable(shop.cafeId, {
- ...newTable,
+ // ...newTable,
tableNo,
});
setTables([...tables, createdTable]);
@@ -143,28 +143,28 @@ const TablesPage = ({ shop }) => {
} catch (error) {
console.error("Error creating table:", error);
}
- } else if (selectedTable) {
- try {
- const updatedTable = await updateTable(shop.cafeId, {
- ...selectedTable,
- tableNo,
- });
- setTables(
- tables.map((table) =>
- table.tableId === updatedTable.tableId ? updatedTable : table
- )
- );
- setOriginalTables(
- tables.map((table) =>
- table.tableId === updatedTable.tableId ? updatedTable : table
- )
- );
- setSelectedTable(null);
- setTableNo(""); // Reset table name
- } catch (error) {
- console.error("Error updating table:", error);
- }
- }
+ // } else if (selectedTable) {
+ // try {
+ // const updatedTable = await updateTable(shop.cafeId, {
+ // ...selectedTable,
+ // tableNo,
+ // });
+ // setTables(
+ // tables.map((table) =>
+ // table.tableId === updatedTable.tableId ? updatedTable : table
+ // )
+ // );
+ // setOriginalTables(
+ // tables.map((table) =>
+ // table.tableId === updatedTable.tableId ? updatedTable : table
+ // )
+ // );
+ // setSelectedTable(null);
+ // setTableNo(""); // Reset table name
+ // } catch (error) {
+ // console.error("Error updating table:", error);
+ // }
+ // }
};
const handleSetTableNo = (event) => {
@@ -207,6 +207,8 @@ const TablesPage = ({ shop }) => {
tables={tables}
onSelectTable={handleSelect}
selectedTable={selectedTable}
+ handleSetTableNo={handleSetTableNo}
+ handleAddTable={handleSave}
/>
);
diff --git a/src/config.js b/src/config.js
index b717ef9..03bd13a 100644
--- a/src/config.js
+++ b/src/config.js
@@ -1,5 +1,5 @@
// src/config.js
-const API_BASE_URL = "https://wxf6vz-5000.csb.app"; // Replace with your actual backend URL
+const API_BASE_URL = 'https://9qc65z-5000.csb.app';
export default API_BASE_URL;
diff --git a/src/helpers/itemHelper.js b/src/helpers/itemHelper.js
index 16f8342..b95dad9 100644
--- a/src/helpers/itemHelper.js
+++ b/src/helpers/itemHelper.js
@@ -165,12 +165,19 @@ export async function updateItemAvalilability(itemId, isAvailable) {
throw error;
}
}
-
-export async function createItemType(shopId, name, selectedImage) {
+export async function createItemType(shopId, name, selectedImage, previewUrl) {
try {
const formData = new FormData();
formData.append("name", name);
- formData.append("image", selectedImage);
+
+ // Check if selectedImage is provided
+ if (selectedImage) {
+ formData.append("image", selectedImage);
+ } else if (previewUrl) {
+ // Remove the API_BASE_URL and any leading slashes from previewUrl
+ const processedPreviewUrl = previewUrl.replace(API_BASE_URL, "").replace(/^\/+/, "");
+ formData.append("sampleImage", processedPreviewUrl);
+ }
const response = await fetch(`${API_BASE_URL}/item/createType/${shopId}`, {
method: "POST",
@@ -192,6 +199,7 @@ export async function createItemType(shopId, name, selectedImage) {
throw error;
}
}
+
export async function updateItemType(
shopId,
itemTypeId,
diff --git a/src/helpers/userHelpers.js b/src/helpers/userHelpers.js
index 0430f37..a420179 100644
--- a/src/helpers/userHelpers.js
+++ b/src/helpers/userHelpers.js
@@ -193,12 +193,12 @@ export const getAllCafeOwner = async (formData) => {
}
};
-export const createCafeOwner = async (shopId, email, username, password) => {
+export const createCafeOwner = async (email, username, password) => {
const token = getLocalStorage("auth");
if (token) {
try {
const response = await fetch(
- API_BASE_URL + "/user/create-clerk/" + shopId,
+ API_BASE_URL + "/user/create-admin/" ,
{
method: "POST",
headers: {
@@ -276,6 +276,7 @@ export const createClerks = async (shopId, email, username, password) => {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
+ console.log(data)
return data;
} catch (error) {
console.error("Error getting clerk:", error);
diff --git a/src/pages/CafePage.js b/src/pages/CafePage.js
index fd8db40..9a9cc20 100644
--- a/src/pages/CafePage.js
+++ b/src/pages/CafePage.js
@@ -20,7 +20,7 @@ import Header from "../components/Header";
import { ThreeDots } from "react-loader-spinner";
-import { updateLocalStorage } from "../helpers/localStorageHelpers";
+import { updateLocalStorage, removeLocalStorage } from "../helpers/localStorageHelpers";
import { unsubscribeUser } from "../helpers/subscribeHelpers.js";
import WelcomePage from "./WelcomePage.js";
@@ -108,7 +108,7 @@ function CafePage({
};
const handleLogout = () => {
- updateLocalStorage("auth", "");
+ removeLocalStorage("auth");
unsubscribeUser();
navigate(0);
};
@@ -172,9 +172,12 @@ function CafePage({
setIsEditMode={(e) => setIsEditMode(e)}
isEditMode={isEditMode}
/>
-
-
-
+
-
- {filterId === 0 ? (
- <>
-
Music Req.
-
- >
- ) : (
-
- )}
-
+ {/*
*/}
{shopItems
.filter(
(itemType) =>
diff --git a/src/pages/Cart.js b/src/pages/Cart.js
index e2428f9..d2e93bd 100644
--- a/src/pages/Cart.js
+++ b/src/pages/Cart.js
@@ -163,9 +163,10 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
/>
))}
+{table.tableNo != null && (
- Order Type:
- */}
+ )}
{orderType === "serve" && table.length < 1 && (
Serve to:
diff --git a/src/pages/CreateClerk.js b/src/pages/CreateClerk.js
new file mode 100644
index 0000000..a7820c0
--- /dev/null
+++ b/src/pages/CreateClerk.js
@@ -0,0 +1,111 @@
+import React, { useState } from 'react';
+import { createClerks } from '../helpers/userHelpers'; // Adjust the import path as needed
+
+const CreateClerk = ({ shopId }) => {
+ const [email, setEmail] = useState('');
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+ const [loading, setLoading] = useState(false);
+ const [message, setMessage] = useState('');
+
+ const handleSubmit = async (event) => {
+ event.preventDefault();
+ setLoading(true);
+ setMessage('');
+
+ // Basic validation
+ if (!email || !username || !password) {
+ setMessage('All fields are required');
+ setLoading(false);
+ return;
+ }
+
+ try {
+ const create = await createClerks(shopId, email, username, password);
+
+ if(create) setMessage('Clerk created successfully');
+ else setMessage('failed')
+ } catch (error) {
+ setMessage('Error creating clerk');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+
+ );
+};
+
+// Basic styling to make it mobile-friendly
+const styles = {
+ container: {
+ width: '100%',
+ maxWidth: '400px',
+ margin: '0 auto',
+ padding: '20px',
+ boxSizing: 'border-box',
+ },
+ header: {
+ textAlign: 'center',
+ marginBottom: '20px',
+ },
+ form: {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '15px',
+ },
+ input: {
+ padding: '10px',
+ fontSize: '16px',
+ borderRadius: '5px',
+ border: '1px solid #ccc',
+ width: '100%',
+ boxSizing: 'border-box',
+ },
+ button: {
+ padding: '10px',
+ fontSize: '16px',
+ borderRadius: '5px',
+ border: 'none',
+ backgroundColor: '#28a745',
+ color: 'white',
+ cursor: 'pointer',
+ },
+ message: {
+ textAlign: 'center',
+ color: 'red',
+ marginTop: '10px',
+ },
+};
+
+export default CreateClerk;
diff --git a/src/pages/Dashboard.js b/src/pages/Dashboard.js
index 7a78a7b..02cd652 100644
--- a/src/pages/Dashboard.js
+++ b/src/pages/Dashboard.js
@@ -3,7 +3,7 @@ import styles from "./Dashboard.module.css"; // Import module CSS for styling
import Header from "../components/Header";
import { useNavigate } from "react-router-dom";
import AccountUpdateModal from "../components/AccountUpdateModal";
-import { updateLocalStorage } from "../helpers/localStorageHelpers";
+import { removeLocalStorage } from "../helpers/localStorageHelpers";
import { getAllCafeOwner, createCafeOwner } from "../helpers/userHelpers";
import { getOwnedCafes, createCafe, updateCafe } from "../helpers/cafeHelpers";
@@ -50,7 +50,7 @@ const Dashboard = ({ user, setModal }) => {
};
const handleLogout = () => {
- updateLocalStorage("auth", "");
+ removeLocalStorage("auth");
unsubscribeUser();
navigate(0);
};
@@ -58,9 +58,9 @@ const Dashboard = ({ user, setModal }) => {
const handleCreateItem = () => {
if (user.roleId < 1) {
// Create admin functionality
- createCafeOwner(newItem.name)
+ createCafeOwner(newItem.email, newItem.username, newItem.password)
.then(() => {
- setItems([...items, { name: newItem.name }]);
+ setItems([...items, { name: newItem.username }]);
setIsCreating(false);
setNewItem({ name: "", type: "" });
})
@@ -84,7 +84,7 @@ const Dashboard = ({ user, setModal }) => {
return (
<>