ok
This commit is contained in:
108
src/App.js
108
src/App.js
@@ -115,9 +115,9 @@ function App() {
|
|||||||
items: cafe.items.filter((item) =>
|
items: cafe.items.filter((item) =>
|
||||||
filteredData.some((filtered) =>
|
filteredData.some((filtered) =>
|
||||||
filtered.itemList.some(
|
filtered.itemList.some(
|
||||||
(i) => i.itemId === item.itemId && i.availability
|
(i) => i.itemId === item.itemId && i.availability,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -156,30 +156,6 @@ function App() {
|
|||||||
// console.error("Error handling notifications:", error);
|
// console.error("Error handling notifications:", error);
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
useEffect(() => {
|
|
||||||
const askNotificationPermission = async () => {
|
|
||||||
let permission = Notification.permission;
|
|
||||||
if (permission === "default") {
|
|
||||||
setModal("req_notification");
|
|
||||||
}
|
|
||||||
if (permission === "granted") await resetNotificationSubscription();
|
|
||||||
|
|
||||||
permission = await Notification.requestPermission();
|
|
||||||
if (permission === "granted") {
|
|
||||||
await subscribeUser();
|
|
||||||
} else if (permission === "denied") {
|
|
||||||
setModal("blocked_notification");
|
|
||||||
console.error("Notification permission denied.");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if ("serviceWorker" in navigator) {
|
|
||||||
window.addEventListener("load", async () => {
|
|
||||||
await askNotificationPermission();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (socket == null) return;
|
if (socket == null) return;
|
||||||
|
|
||||||
@@ -245,11 +221,13 @@ function App() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("checkUserTokenRes", async (data) => {
|
socket.on("checkUserTokenRes", async (data) => {
|
||||||
|
console.log(data)
|
||||||
if (data.status !== 200) {
|
if (data.status !== 200) {
|
||||||
removeLocalStorage("auth");
|
removeLocalStorage("auth");
|
||||||
setDeviceType("guestDevice");
|
setDeviceType("guestDevice");
|
||||||
} else {
|
} else {
|
||||||
setUser(data.data.user);
|
setUser(data.data.user);
|
||||||
|
console.log('setting user')
|
||||||
if (
|
if (
|
||||||
data.data.user.password == "unsetunsetunset" &&
|
data.data.user.password == "unsetunsetunset" &&
|
||||||
localStorage.getItem("settings")
|
localStorage.getItem("settings")
|
||||||
@@ -332,19 +310,79 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to close the modal
|
// Function to close the modal
|
||||||
const closeModal = () => {
|
const closeModal = (closeTheseContent = []) => {
|
||||||
setIsModalOpen(false);
|
if (
|
||||||
document.body.style.overflow = "auto";
|
closeTheseContent.length === 0 ||
|
||||||
|
closeTheseContent.includes(modalContent)
|
||||||
|
) {
|
||||||
|
setIsModalOpen(false);
|
||||||
|
document.body.style.overflow = "auto";
|
||||||
|
|
||||||
const queryParams = new URLSearchParams(location.search);
|
const queryParams = new URLSearchParams(location.search);
|
||||||
|
|
||||||
// Remove the 'modal' parameter
|
// Remove the 'modal' parameter
|
||||||
queryParams.delete("modal");
|
queryParams.delete("modal");
|
||||||
|
|
||||||
// Update the URL without the 'modal' parameter
|
// Update the URL without the 'modal' parameter
|
||||||
navigate({ search: queryParams.toString() }, { replace: true });
|
navigate({ search: queryParams.toString() }, { replace: true });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const askNotificationPermission = async () => {
|
||||||
|
let permission = Notification.permission;
|
||||||
|
|
||||||
|
// Check current permission
|
||||||
|
if (permission === "default") {
|
||||||
|
setModal("req_notification");
|
||||||
|
|
||||||
|
// Request permission and wait for the result
|
||||||
|
permission = await Notification.requestPermission();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If permission is already granted, reset subscriptions
|
||||||
|
if (permission === "granted") {
|
||||||
|
await resetNotificationSubscription();
|
||||||
|
closeModal(["req_notification", "denied_notification"]);
|
||||||
|
} else if (permission === "denied") {
|
||||||
|
setModal("blocked_notification");
|
||||||
|
console.error("Notification permission denied.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continuously check until permission is granted
|
||||||
|
while (permission !== "granted") {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second
|
||||||
|
const permissionn = Notification.permission;
|
||||||
|
|
||||||
|
if (permissionn === "granted") {
|
||||||
|
closeModal(["req_notification", "denied_notification"]);
|
||||||
|
await resetNotificationSubscription();
|
||||||
|
break;
|
||||||
|
} else if (permissionn === "denied") {
|
||||||
|
setModal("blocked_notification");
|
||||||
|
console.error("Notification permission denied.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleLoad = async () => {
|
||||||
|
while (modalContent !== "transaction_pending" || modalContent !== "transaction_confirmed") {
|
||||||
|
if (user != null && (user.roleId < 3 || user.roleId > 2)) {
|
||||||
|
await askNotificationPermission();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
handleLoad();
|
||||||
|
if ("serviceWorker" in navigator) {
|
||||||
|
window.addEventListener("load", handleLoad);
|
||||||
|
|
||||||
|
// Cleanup the event listener on component unmount
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("load", handleLoad);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<header className="App-header">
|
<header className="App-header">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export async function confirmTransaction(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return false;
|
return false;
|
||||||
@@ -37,7 +37,7 @@ export async function declineTransaction(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -61,7 +61,7 @@ export async function cancelTransaction(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
@@ -86,7 +86,7 @@ export async function handleClaimHasPaid(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -111,7 +111,7 @@ export async function handleConfirmHasPaid(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -135,7 +135,7 @@ export async function getTransaction(transactionId) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -160,7 +160,7 @@ export async function getTransactions(shopId, demand) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -179,7 +179,7 @@ export const handlePaymentFromClerk = async (
|
|||||||
user_email,
|
user_email,
|
||||||
payment_type,
|
payment_type,
|
||||||
serving_type,
|
serving_type,
|
||||||
tableNo
|
tableNo,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const token = getLocalStorage("auth");
|
const token = getLocalStorage("auth");
|
||||||
@@ -208,7 +208,7 @@ export const handlePaymentFromClerk = async (
|
|||||||
tableNo,
|
tableNo,
|
||||||
transactions: structuredItems,
|
transactions: structuredItems,
|
||||||
}),
|
}),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -233,7 +233,7 @@ export const handlePaymentFromGuestSide = async (
|
|||||||
user_email,
|
user_email,
|
||||||
payment_type,
|
payment_type,
|
||||||
serving_type,
|
serving_type,
|
||||||
tableNo
|
tableNo,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const token = getLocalStorage("authGuestSide");
|
const token = getLocalStorage("authGuestSide");
|
||||||
@@ -262,7 +262,7 @@ export const handlePaymentFromGuestSide = async (
|
|||||||
tableNo,
|
tableNo,
|
||||||
transactions: structuredItems,
|
transactions: structuredItems,
|
||||||
}),
|
}),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
const res = await response.json();
|
const res = await response.json();
|
||||||
console.log(res);
|
console.log(res);
|
||||||
@@ -289,7 +289,7 @@ export const handlePaymentFromGuestDevice = async (
|
|||||||
serving_type,
|
serving_type,
|
||||||
tableNo,
|
tableNo,
|
||||||
notes,
|
notes,
|
||||||
socketId
|
socketId,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const token = getLocalStorage("auth");
|
const token = getLocalStorage("auth");
|
||||||
@@ -319,7 +319,7 @@ export const handlePaymentFromGuestDevice = async (
|
|||||||
notes: notes,
|
notes: notes,
|
||||||
socketId,
|
socketId,
|
||||||
}),
|
}),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -364,7 +364,7 @@ const getHeaders = (method = "GET") => {
|
|||||||
export const getFavourite = async (cafeId) => {
|
export const getFavourite = async (cafeId) => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${API_BASE_URL}/transaction/get-favourite/${cafeId}`,
|
`${API_BASE_URL}/transaction/get-favourite/${cafeId}`,
|
||||||
getHeaders()
|
getHeaders(),
|
||||||
);
|
);
|
||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
@@ -377,7 +377,7 @@ export const getAnalytics = async (cafeId, filter) => {
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
@@ -385,7 +385,7 @@ export const getAnalytics = async (cafeId, filter) => {
|
|||||||
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}`,
|
||||||
getHeaders()
|
getHeaders(),
|
||||||
);
|
);
|
||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user