working on clerk notification
This commit is contained in:
33
src/App.js
33
src/App.js
@@ -83,12 +83,7 @@ function App() {
|
|||||||
setShopItems(data);
|
setShopItems(data);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
// setLoading(false);
|
// setLoading(false);
|
||||||
socket.emit("join-room", { token: getLocalStorage("auth"), shopId });
|
// socket.emit("join-room", { token: getLocalStorage("auth"), shopId });
|
||||||
|
|
||||||
socket.on("joined-room", (response) => {
|
|
||||||
// const { isSpotifyNeedLogin } = response;
|
|
||||||
// setNeedSpotifyLogin(isSpotifyNeedLogin);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("transaction_created", () => {
|
socket.on("transaction_created", () => {
|
||||||
console.log("transaction created");
|
console.log("transaction created");
|
||||||
@@ -127,17 +122,19 @@ function App() {
|
|||||||
// }, [navigate, socket, shopId]);
|
// }, [navigate, socket, shopId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (getLocalStorage("auth")) {
|
if (socket == null) return;
|
||||||
console.log("emitting");
|
|
||||||
socket.emit("checkUserToken", {
|
if (getLocalStorage("authGuestSide")) {
|
||||||
token: getLocalStorage("auth"),
|
|
||||||
});
|
|
||||||
} else if (getLocalStorage("authGuestSide")) {
|
|
||||||
socket.emit("checkGuestSideToken", {
|
socket.emit("checkGuestSideToken", {
|
||||||
token: getLocalStorage("authGuestSide"),
|
token: getLocalStorage("authGuestSide"),
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log("emitting");
|
||||||
|
socket.emit("checkUserToken", {
|
||||||
|
token: getLocalStorage("auth"),
|
||||||
|
shopId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setDeviceType("guestDevice");
|
|
||||||
|
|
||||||
socket.on("transaction_created", async (data) => {
|
socket.on("transaction_created", async (data) => {
|
||||||
console.log("transaction notification");
|
console.log("transaction notification");
|
||||||
@@ -145,13 +142,11 @@ function App() {
|
|||||||
|
|
||||||
socket.on("checkUserTokenRes", async (data) => {
|
socket.on("checkUserTokenRes", async (data) => {
|
||||||
if (data.status !== 200) {
|
if (data.status !== 200) {
|
||||||
removeLocalStorage("authGuestSide");
|
|
||||||
removeLocalStorage("auth");
|
removeLocalStorage("auth");
|
||||||
console.log("auth failed");
|
setDeviceType("guestDevice");
|
||||||
|
console.log("guestDevice");
|
||||||
} else {
|
} else {
|
||||||
console.log("auth success");
|
console.log("auth success");
|
||||||
console.log(data.data.user);
|
|
||||||
|
|
||||||
setUser(data.data.user);
|
setUser(data.data.user);
|
||||||
if (data.data.user.cafeId == shopId) {
|
if (data.data.user.cafeId == shopId) {
|
||||||
const connectedGuestSides = await getConnectedGuestSides();
|
const connectedGuestSides = await getConnectedGuestSides();
|
||||||
@@ -166,7 +161,6 @@ function App() {
|
|||||||
socket.on("checkGuestSideTokenRes", (data) => {
|
socket.on("checkGuestSideTokenRes", (data) => {
|
||||||
if (data.status !== 200) {
|
if (data.status !== 200) {
|
||||||
removeLocalStorage("authGuestSide");
|
removeLocalStorage("authGuestSide");
|
||||||
removeLocalStorage("auth");
|
|
||||||
navigate("/guest-side");
|
navigate("/guest-side");
|
||||||
console.log("isntguestside");
|
console.log("isntguestside");
|
||||||
} else {
|
} else {
|
||||||
@@ -187,7 +181,7 @@ function App() {
|
|||||||
return () => {
|
return () => {
|
||||||
socket.off("signout-guest-session");
|
socket.off("signout-guest-session");
|
||||||
};
|
};
|
||||||
}, [navigate, socket]);
|
}, [socket, shopId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
@@ -257,6 +251,7 @@ function App() {
|
|||||||
<Cart
|
<Cart
|
||||||
sendParam={handleSetParam}
|
sendParam={handleSetParam}
|
||||||
totalItemsCount={totalItemsCount}
|
totalItemsCount={totalItemsCount}
|
||||||
|
deviceType={deviceType}
|
||||||
/>
|
/>
|
||||||
<Footer
|
<Footer
|
||||||
shopId={shopId}
|
shopId={shopId}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default function Footer({ shopId, cartItemsLength, selectedPage }) {
|
|||||||
|
|
||||||
{/* Cart Icon */}
|
{/* Cart Icon */}
|
||||||
<div onClick={goToCart} className={styles["footer-icon"]}>
|
<div onClick={goToCart} className={styles["footer-icon"]}>
|
||||||
{cartItemsLength !== "0" && (
|
{cartItemsLength != "0" && (
|
||||||
<div className={styles.circle}>{cartItemsLength}</div>
|
<div className={styles.circle}>{cartItemsLength}</div>
|
||||||
)}
|
)}
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const useNavigationHelpers = (params) => {
|
|||||||
`/${params}/invoice?orderType=${orderType}&tableNumber=${tableNumber}&email=${email}`,
|
`/${params}/invoice?orderType=${orderType}&tableNumber=${tableNumber}&email=${email}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
navigate(`/${params}/invoice?orderType=${orderType}}&email=${email}`);
|
navigate(`/${params}/invoice?orderType=${orderType}&email=${email}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import API_BASE_URL from "../config.js";
|
import API_BASE_URL from "../config.js";
|
||||||
import { getLocalStorage } from "./localStorageHelpers";
|
import { getLocalStorage, updateLocalStorage } from "./localStorageHelpers";
|
||||||
import { getItemsByCafeId } from "../helpers/cartHelpers.js";
|
import { getItemsByCafeId } from "../helpers/cartHelpers.js";
|
||||||
|
|
||||||
export const handlePaymentFromClerk = async (
|
export const handlePaymentFromClerk = async (
|
||||||
@@ -148,6 +148,8 @@ export const handlePaymentFromGuestDevice = async (
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
// Handle success response
|
// Handle success response
|
||||||
console.log("Transaction successful!");
|
console.log("Transaction successful!");
|
||||||
|
const data = await response.json();
|
||||||
|
updateLocalStorage("auth", data.auth);
|
||||||
// Optionally return response data or handle further actions upon success
|
// Optionally return response data or handle further actions upon success
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ function CafePage({
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [screenMessage, setScreenMessage] = useState("");
|
const [screenMessage, setScreenMessage] = useState("");
|
||||||
|
|
||||||
const [isSpotifyNeedLogin, setNeedSpotifyLogin] = useState(false);
|
const [isSpotifyNeedLogin, setNeedSpotifyLogin] = useState(true);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -67,6 +67,17 @@ function CafePage({
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, [shopItems]);
|
}, [shopItems]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchData() {
|
||||||
|
socket.on("joined-room", (response) => {
|
||||||
|
const { isSpotifyNeedLogin } = response;
|
||||||
|
setNeedSpotifyLogin(isSpotifyNeedLogin);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (socket) fetchData();
|
||||||
|
}, [socket]);
|
||||||
|
|
||||||
if (loading)
|
if (loading)
|
||||||
return (
|
return (
|
||||||
<div className="Loader">
|
<div className="Loader">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { getCartDetails } from "../helpers/itemHelper.js";
|
|||||||
import { getItemsByCafeId } from "../helpers/cartHelpers"; // Import getItemsByCafeId
|
import { getItemsByCafeId } from "../helpers/cartHelpers"; // Import getItemsByCafeId
|
||||||
import Modal from "../components/Modal"; // Import the reusable Modal component
|
import Modal from "../components/Modal"; // Import the reusable Modal component
|
||||||
|
|
||||||
export default function Cart({ sendParam, totalItemsCount }) {
|
export default function Cart({ sendParam, totalItemsCount, deviceType }) {
|
||||||
const { shopId } = useParams();
|
const { shopId } = useParams();
|
||||||
sendParam(shopId);
|
sendParam(shopId);
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ export default function Cart({ sendParam, totalItemsCount }) {
|
|||||||
itemList={itemType.itemList}
|
itemList={itemType.itemList}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
{deviceType != "guestDevice" && (
|
||||||
<div className={styles.EmailContainer}>
|
<div className={styles.EmailContainer}>
|
||||||
<label htmlFor="email">Email:</label>
|
<label htmlFor="email">Email:</label>
|
||||||
<input
|
<input
|
||||||
@@ -177,6 +177,7 @@ export default function Cart({ sendParam, totalItemsCount }) {
|
|||||||
className={styles.EmailInput}
|
className={styles.EmailInput}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
<div className={styles.OrderTypeContainer}>
|
<div className={styles.OrderTypeContainer}>
|
||||||
<span htmlFor="orderType">Order Type:</span>
|
<span htmlFor="orderType">Order Type:</span>
|
||||||
<select
|
<select
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export default function Invoice({ sendParam, deviceType }) {
|
|||||||
orderType,
|
orderType,
|
||||||
tableNumber,
|
tableNumber,
|
||||||
);
|
);
|
||||||
} else if (deviceType == "guestDevice") {
|
} else if (deviceType == "guestSide") {
|
||||||
const pay = await handlePaymentFromGuestSide(
|
const pay = await handlePaymentFromGuestSide(
|
||||||
shopId,
|
shopId,
|
||||||
email,
|
email,
|
||||||
|
|||||||
Reference in New Issue
Block a user