diff --git a/client/src/App/App.jsx b/client/src/App/App.jsx
index 4cf5b5d35..c2bfc0a7d 100644
--- a/client/src/App/App.jsx
+++ b/client/src/App/App.jsx
@@ -214,7 +214,9 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline
path="/tech/*"
element={
-
+
+
+
}
>
diff --git a/client/src/components/dms-allocations-summary-ap/dms-allocations-summary-ap.component.jsx b/client/src/components/dms-allocations-summary-ap/dms-allocations-summary-ap.component.jsx
index b4fc66577..abbde7277 100644
--- a/client/src/components/dms-allocations-summary-ap/dms-allocations-summary-ap.component.jsx
+++ b/client/src/components/dms-allocations-summary-ap/dms-allocations-summary-ap.component.jsx
@@ -1,62 +1,77 @@
import { SyncOutlined } from "@ant-design/icons";
import { Button, Card, Form, Input, Table } from "antd";
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useState, useContext } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { pageLimit } from "../../utils/config";
+import SocketContext from "../../contexts/SocketIO/socketContext.jsx"; // Import SocketContext
const mapStateToProps = createStructuredSelector({
- //currentUser: selectCurrentUser
bodyshop: selectBodyshop
});
-const mapDispatchToProps = (dispatch) => ({
- //setUserLanguage: language => dispatch(setUserLanguage(language))
-});
+export default connect(mapStateToProps)(DmsAllocationsSummaryAp);
-export default connect(mapStateToProps, mapDispatchToProps)(DmsAllocationsSummaryAp);
-
-export function DmsAllocationsSummaryAp({ socket, bodyshop, billids, title }) {
+export function DmsAllocationsSummaryAp({ bodyshop, billids, title }) {
const { t } = useTranslation();
const [allocationsSummary, setAllocationsSummary] = useState([]);
+ const { socket } = useContext(SocketContext);
useEffect(() => {
- socket.on("ap-export-success", (billid) => {
+ if (!socket) return;
+
+ const handleSuccess = async (billid) => {
setAllocationsSummary((allocationsSummary) =>
allocationsSummary.map((a) => {
if (a.billid !== billid) return a;
return { ...a, status: "Successful" };
})
);
- });
- socket.on("ap-export-failure", ({ billid, error }) => {
- allocationsSummary.map((a) => {
- if (a.billid !== billid) return a;
- return { ...a, status: error };
- });
- });
- if (socket.disconnected) socket.connect();
- return () => {
- socket.removeListener("ap-export-success");
- socket.removeListener("ap-export-failure");
- //socket.disconnect();
+ try {
+ await new Promise((resolve, reject) => {
+ socket.emit("clear-dms-session", (response) => {
+ if (response && response.status === "ok") {
+ resolve();
+ } else {
+ reject(new Error("Failed to clear DMS session"));
+ }
+ });
+ });
+ } catch (error) {
+ console.error("Failed to clear DMS session", error);
+ }
};
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+
+ const handleFailure = ({ billid, error }) => {
+ setAllocationsSummary((allocationsSummary) =>
+ allocationsSummary.map((a) => {
+ if (a.billid !== billid) return a;
+ return { ...a, status: error };
+ })
+ );
+ };
+
+ socket.on("ap-export-success", handleSuccess);
+ socket.on("ap-export-failure", handleFailure);
+
+ return () => {
+ socket.off("ap-export-success", handleSuccess);
+ socket.off("ap-export-failure", handleFailure);
+ };
+ }, [socket]);
useEffect(() => {
- if (socket.connected) {
+ if (socket && socket.connected) {
socket.emit("pbs-calculate-allocations-ap", billids, (ack) => {
setAllocationsSummary(ack);
-
socket.allocationsSummary = ack;
});
}
}, [socket, socket.connected, billids]);
- console.log(allocationsSummary);
+
const columns = [
{
title: t("general.labels.status"),
@@ -68,35 +83,40 @@ export function DmsAllocationsSummaryAp({ socket, bodyshop, billids, title }) {
dataIndex: ["Posting", "Reference"],
key: "reference"
},
-
{
title: t("jobs.fields.dms.lines"),
dataIndex: "Lines",
key: "Lines",
render: (text, record) => (
-
- | {t("bills.fields.invoice_number")} |
- {t("bodyshop.fields.dms.dms_acctnumber")} |
- {t("jobs.fields.dms.amount")} |
-
- {record.Posting.Lines.map((l, idx) => (
-
- | {l.InvoiceNumber} |
- {l.Account} |
- {l.Amount} |
+
+
+ | {t("bills.fields.invoice_number")} |
+ {t("bodyshop.fields.dms.dms_acctnumber")} |
+ {t("jobs.fields.dms.amount")} |
- ))}
+
+
+ {record.Posting.Lines.map((l, idx) => (
+
+ | {l.InvoiceNumber} |
+ {l.Account} |
+ {l.Amount} |
+
+ ))}
+
)
}
];
const handleFinish = async (values) => {
- socket.emit(`pbs-export-ap`, {
- billids,
- txEnvelope: values
- });
+ if (socket) {
+ socket.emit("pbs-export-ap", {
+ billids,
+ txEnvelope: values
+ });
+ }
};
return (
@@ -105,7 +125,9 @@ export function DmsAllocationsSummaryAp({ socket, bodyshop, billids, title }) {
extra={