diff --git a/src/components/TransactionPage/index.js b/src/components/TransactionPage/index.js
index 2166836..14e9682 100644
--- a/src/components/TransactionPage/index.js
+++ b/src/components/TransactionPage/index.js
@@ -50,8 +50,10 @@ const TransactionPage = () => {
useEffect(() => {
// get the transactions value
if (!state?.user?.id) return;
+ console.log("hit?");
socket.emit("transactions");
socket.on("transactionsData", (value) => {
+ console.log({ value });
setTransactions(value);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
From 06095ad2d8e2c65d09f5268f55e17d905ea06d05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E1=B4=B9=E1=B5=83=E1=B5=88=E1=B5=89=20=E1=B5=92=E2=81=BF?=
=?UTF-8?q?=20=E1=B4=B1=E1=B5=83=CA=B3=E1=B5=97=CA=B0=20=E1=B5=87=CA=B8=20?=
=?UTF-8?q?=CA=B0=E1=B5=98=E1=B5=90=E1=B5=83=E2=81=BF=CB=A2?=
<39050604+EXPITC@users.noreply.github.com>
Date: Thu, 22 Jun 2023 04:37:48 +0700
Subject: [PATCH 2/3] chore: fix naming button map
+ src/components/Map/index.js
+ Change "waiting for the transaction to be approved" when transaction
in the state.
+ Change button text to "Finish Order".
---
src/components/Map/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/components/Map/index.js b/src/components/Map/index.js
index c54ff12..152d53c 100644
--- a/src/components/Map/index.js
+++ b/src/components/Map/index.js
@@ -380,7 +380,7 @@ const Map = ({ toggle, far, setLocEdit, updateLoc, startLoc, cart }) => {
Delivery Time
{toMinutes(duration)} Minutes
{otwOrder ? (
-
+
) : (
)}
From 1126e1d332ade308bad6fe3a011530654ba4147d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E1=B4=B9=E1=B5=83=E1=B5=88=E1=B5=89=20=E1=B5=92=E2=81=BF?=
=?UTF-8?q?=20=E1=B4=B1=E1=B5=83=CA=B3=E1=B5=97=CA=B0=20=E1=B5=87=CA=B8=20?=
=?UTF-8?q?=CA=B0=E1=B5=98=E1=B5=90=E1=B5=83=E2=81=BF=CB=A2?=
<39050604+EXPITC@users.noreply.github.com>
Date: Thu, 22 Jun 2023 05:18:38 +0700
Subject: [PATCH 3/3] feat: add realtime data to order
+ src/components/
-|CartPage/index.js
-|Map/index.js
-|TransactionPage/index.js
+ Add realtime data for user while waiting order to accept order to finish.
---
src/components/CartPage/index.js | 9 ++++++++-
src/components/Map/index.js | 23 +++++++++++++++++++++--
src/components/TransactionPage/index.js | 5 ++++-
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/src/components/CartPage/index.js b/src/components/CartPage/index.js
index 35cb830..85afeab 100644
--- a/src/components/CartPage/index.js
+++ b/src/components/CartPage/index.js
@@ -286,7 +286,14 @@ const CartPage = () => {
{open && (
)}
- {far &&
}
+ {far && (
+
+ )}
{isLoading ? (
diff --git a/src/components/Map/index.js b/src/components/Map/index.js
index 152d53c..a9345ef 100644
--- a/src/components/Map/index.js
+++ b/src/components/Map/index.js
@@ -11,7 +11,15 @@ import socketIo from "../../utils/socket";
import toMinutes from "../../utils/toMinutes";
import axios from "axios";
-const Map = ({ toggle, far, setLocEdit, updateLoc, startLoc, cart }) => {
+const Map = ({
+ toggle,
+ far,
+ setLocEdit,
+ updateLoc,
+ startLoc,
+ cart,
+ transId,
+}) => {
const [viewState, setViewState] = useState(false);
const { state } = useContext(UserContext);
const { user } = state;
@@ -222,14 +230,25 @@ const Map = ({ toggle, far, setLocEdit, updateLoc, startLoc, cart }) => {
setOtwOrder(data);
});
+ if (transId) {
+ socket.emit("subTrans", transId);
+ socket.on("confirmTransaction", () => {
+ socket.emit("onTheWay", user.id);
+ socket.on("otwData", (data) => {
+ setOtwOrder(data);
+ });
+ });
+ }
+
socket.on("connect_error", (err) => {
console.error(err.message);
});
return () => {
+ if (transId) socket.emit("unsubTrans", transId);
socket.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [user?.id]);
+ }, [user?.id, transId]);
return (
diff --git a/src/components/TransactionPage/index.js b/src/components/TransactionPage/index.js
index 14e9682..cee14d0 100644
--- a/src/components/TransactionPage/index.js
+++ b/src/components/TransactionPage/index.js
@@ -61,8 +61,9 @@ const TransactionPage = () => {
const handleApprove = (id) => {
// socket.emit("otw");
+ socket.on("subTrans", id);
socket.emit("accept", id);
- // setRefresh(!refresh);
+
socket.on("acceptData", (data) => {
if (!data[1][0]) return;
setTransactions((prev) => {
@@ -72,6 +73,8 @@ const TransactionPage = () => {
});
});
});
+
+ socket.on("unsubTrans", id);
};
const handleCancel = (id) => {
socket.emit("cancel", id);