gg
This commit is contained in:
@@ -332,6 +332,12 @@ const Header = ({
|
|||||||
</Child>
|
</Child>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{user.username !== undefined &&
|
||||||
|
(user.roleId === 1 || user.roleId === 2) && (
|
||||||
|
<Child onClick={() => setModal("update_stock")}>
|
||||||
|
update stock
|
||||||
|
</Child>
|
||||||
|
)}
|
||||||
{user.username !== undefined && user.roleId === 2 && (
|
{user.username !== undefined && user.roleId === 2 && (
|
||||||
<Child hasChildren>
|
<Child hasChildren>
|
||||||
connected guest sides
|
connected guest sides
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const Modal = ({ shopId, isOpen, onClose, modalContent }) => {
|
|||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
{modalContent === "edit_tables" && <TableMaps shopId={shopId} />}
|
{modalContent === "edit_tables" && <TableMaps shopId={shopId} />}
|
||||||
|
{modalContent === "new_transaction" && <TableMaps shopId={shopId} />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ const TableCanvas = ({ shopId }) => {
|
|||||||
context.textBaseline = "middle";
|
context.textBaseline = "middle";
|
||||||
context.fillText(
|
context.fillText(
|
||||||
table.tableId === (selectedTable?.tableId || newTable?.tableId)
|
table.tableId === (selectedTable?.tableId || newTable?.tableId)
|
||||||
? tableNo == 0
|
? tableNo === 0
|
||||||
? "clerk"
|
? "clerk"
|
||||||
: tableNo
|
: tableNo
|
||||||
: table.tableNo == 0
|
: table.tableNo === 0
|
||||||
? "clerk"
|
? "clerk"
|
||||||
: table.tableNo,
|
: table.tableNo,
|
||||||
table.xposition + rectWidth / 2,
|
table.xposition + rectWidth / 2,
|
||||||
@@ -257,9 +257,9 @@ const TableCanvas = ({ shopId }) => {
|
|||||||
const handleSetTableNo = (event) => {
|
const handleSetTableNo = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
// Prevent setting value to '0' or starting with '0'
|
// Prevent setting value to '0' or starting with '0'
|
||||||
// if (newValue === "" || /^[1-9][0-9]*$/.test(newValue)) {
|
if (newValue === "" || /^[1-9][0-9]*$/.test(newValue)) {
|
||||||
setTableNo(newValue);
|
setTableNo(newValue);
|
||||||
// }
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -333,6 +333,7 @@ const TableCanvas = ({ shopId }) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Table No"
|
placeholder="Table No"
|
||||||
value={tableNo}
|
value={tableNo}
|
||||||
|
disabled={tableNo === 0 ? "disabled" : ""}
|
||||||
onChange={handleSetTableNo}
|
onChange={handleSetTableNo}
|
||||||
style={{
|
style={{
|
||||||
marginRight: "10px",
|
marginRight: "10px",
|
||||||
@@ -376,8 +377,12 @@ const TableCanvas = ({ shopId }) => {
|
|||||||
}}
|
}}
|
||||||
onClick={() => handleSelect(table)}
|
onClick={() => handleSelect(table)}
|
||||||
>
|
>
|
||||||
Table {table.tableNo} - Position: ({table.xposition},{" "}
|
{
|
||||||
{table.yposition})
|
table.tableNo === 0
|
||||||
|
? "Clerk" // Display "Clerk" if tableNo is 0
|
||||||
|
: `Table ${table.tableNo}` // Display "Table {tableNo}" otherwise
|
||||||
|
}{" "}
|
||||||
|
- Position: ({table.xposition}, {table.yposition})
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -14,7 +14,55 @@ export async function getOwnedCafes(userId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${getAuthToken()}`,
|
Authorization: `Bearer ${getAuthToken()}`,
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch cart details");
|
||||||
|
}
|
||||||
|
|
||||||
|
const cafes = await response.json();
|
||||||
|
return cafes;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCafe(userId) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${API_BASE_URL}/cafe/get-cafe-by-ownerId/` + userId,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${getAuthToken()}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch cart details");
|
||||||
|
}
|
||||||
|
|
||||||
|
const cafes = await response.json();
|
||||||
|
return cafes;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCafe(userId) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${API_BASE_URL}/cafe/get-cafe-by-ownerId/` + userId,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${getAuthToken()}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export async function removeConnectedGuestSides(guestSideSessionId) {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
guestSideSessionId,
|
guestSideSessionId,
|
||||||
}),
|
}),
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const { message, guestSideList } = await response.json();
|
const { message, guestSideList } = await response.json();
|
||||||
@@ -168,6 +168,66 @@ export const getAllCafeOwner = async (formData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createCafeOwner = async (shopId, email, username, password) => {
|
||||||
|
const token = getLocalStorage("auth");
|
||||||
|
if (token) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
API_BASE_URL + "/user/create-clerk/" + shopId,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: email,
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error getting clerk:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteCafeOwner = async (shopId, email, username, password) => {
|
||||||
|
const token = getLocalStorage("auth");
|
||||||
|
if (token) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
API_BASE_URL + "/user/create-clerk/" + shopId,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: email,
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error getting clerk:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createClerks = async (shopId, email, username, password) => {
|
export const createClerks = async (shopId, email, username, password) => {
|
||||||
const token = getLocalStorage("auth");
|
const token = getLocalStorage("auth");
|
||||||
if (token) {
|
if (token) {
|
||||||
@@ -185,7 +245,7 @@ export const createClerks = async (shopId, email, username, password) => {
|
|||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
}),
|
}),
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import Header from "../components/Header";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import AccountUpdateModal from "../components/AccountUpdateModal";
|
import AccountUpdateModal from "../components/AccountUpdateModal";
|
||||||
import { updateLocalStorage } from "../helpers/localStorageHelpers";
|
import { updateLocalStorage } from "../helpers/localStorageHelpers";
|
||||||
import { getAllCafeOwner } from "../helpers/userHelpers";
|
import { getAllCafeOwner, createCafeOwner } from "../helpers/userHelpers";
|
||||||
import { getOwnedCafes } from "../helpers/cafeHelpers";
|
import { getOwnedCafes, createCafe, updateCafe } from "../helpers/cafeHelpers";
|
||||||
|
|
||||||
import { ThreeDots } from "react-loader-spinner";
|
import { ThreeDots } from "react-loader-spinner";
|
||||||
|
|
||||||
@@ -14,30 +14,32 @@ const Dashboard = ({ user, setModal }) => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
|
const [newItem, setNewItem] = useState({ name: "", type: "" });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user && user.roleId === 0) {
|
if (user && user.roleId === 0) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
// Example of calling getAllCafeOwner if roleId is 0
|
|
||||||
getAllCafeOwner()
|
getAllCafeOwner()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setItems(data); // Assuming getAllCafeOwners returns an array of cafe owners
|
setItems(data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching cafe owners:", error);
|
console.error("Error fetching cafe owners:", error);
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (user && user.roleId === 1) {
|
if (user && user.roleId === 1) {
|
||||||
// Example of calling getAllCafeOwner if roleId is 0
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
getOwnedCafes(user.userId)
|
getOwnedCafes(user.userId)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setItems(data); // Assuming getAllCafeOwners returns an array of cafe owners
|
setItems(data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching cafe owners:", error);
|
console.error("Error fetching owned cafes:", error);
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
@@ -51,6 +53,32 @@ const Dashboard = ({ user, setModal }) => {
|
|||||||
navigate(0);
|
navigate(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCreateItem = () => {
|
||||||
|
if (user.roleId < 1) {
|
||||||
|
// Create admin functionality
|
||||||
|
createCafeOwner(newItem.name)
|
||||||
|
.then(() => {
|
||||||
|
setItems([...items, { name: newItem.name }]);
|
||||||
|
setIsCreating(false);
|
||||||
|
setNewItem({ name: "", type: "" });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error creating admin:", error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Create cafe functionality
|
||||||
|
createCafe(newItem.name)
|
||||||
|
.then(() => {
|
||||||
|
setItems([...items, { name: newItem.name }]);
|
||||||
|
setIsCreating(false);
|
||||||
|
setNewItem({ name: "", type: "" });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error creating cafe:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header
|
<Header
|
||||||
@@ -74,9 +102,19 @@ const Dashboard = ({ user, setModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{user && user.roleId < 1 ? (
|
{user && user.roleId < 1 ? (
|
||||||
<div className={styles.rectangle}>Create Admin</div>
|
<div
|
||||||
|
className={styles.rectangle}
|
||||||
|
onClick={() => setIsCreating(true)}
|
||||||
|
>
|
||||||
|
Create Admin
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.rectangle}>Create Cafe</div>
|
<div
|
||||||
|
className={styles.rectangle}
|
||||||
|
onClick={() => setIsCreating(true)}
|
||||||
|
>
|
||||||
|
Create Cafe
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -88,6 +126,20 @@ const Dashboard = ({ user, setModal }) => {
|
|||||||
onClose={handleModalClose}
|
onClose={handleModalClose}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isCreating && (
|
||||||
|
<div className={styles.createModal}>
|
||||||
|
<h2>Create New {user.roleId < 1 ? "Admin" : "Cafe"}</h2>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={newItem.name}
|
||||||
|
onChange={(e) => setNewItem({ ...newItem, name: e.target.value })}
|
||||||
|
placeholder="Name"
|
||||||
|
/>
|
||||||
|
<button onClick={handleCreateItem}>Create</button>
|
||||||
|
<button onClick={() => setIsCreating(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user