feature/IO-3182-Phone-Number-Consent - Checkpoint
This commit is contained in:
@@ -8,6 +8,7 @@ import ChatPopupComponent from "../chat-popup/chat-popup.component";
|
||||
import "./chat-affix.styles.scss";
|
||||
import { registerMessagingHandlers, unregisterMessagingHandlers } from "./registerMessagingSocketHandlers";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
|
||||
import { GET_PHONE_NUMBER_CONSENT } from "../../graphql/consent.queries.js";
|
||||
|
||||
export function ChatAffixContainer({ bodyshop, chatVisible }) {
|
||||
const { t } = useTranslation();
|
||||
@@ -34,16 +35,59 @@ export function ChatAffixContainer({ bodyshop, chatVisible }) {
|
||||
|
||||
SubscribeToTopicForFCMNotification();
|
||||
|
||||
//Register WS handlers
|
||||
// Register WebSocket handlers
|
||||
if (socket && socket.connected) {
|
||||
registerMessagingHandlers({ socket, client });
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (socket && socket.connected) {
|
||||
// Handle consent-changed events
|
||||
const handleConsentChanged = ({ bodyshopId, phone_number, consent_status }) => {
|
||||
try {
|
||||
client.cache.writeQuery(
|
||||
{
|
||||
query: GET_PHONE_NUMBER_CONSENT,
|
||||
variables: { bodyshopid: bodyshopId, phone_number }
|
||||
},
|
||||
(data) => {
|
||||
if (!data?.phone_number_consent?.[0]) {
|
||||
return {
|
||||
phone_number_consent: [
|
||||
{
|
||||
__typename: "phone_number_consent",
|
||||
id: null,
|
||||
bodyshopid: bodyshopId,
|
||||
phone_number,
|
||||
consent_status,
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
consent_updated_at: new Date().toISOString(),
|
||||
history: []
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
return {
|
||||
phone_number_consent: [
|
||||
{
|
||||
...data.phone_number_consent[0],
|
||||
consent_status,
|
||||
consent_updated_at: new Date().toISOString()
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error updating consent cache:", error);
|
||||
}
|
||||
};
|
||||
|
||||
socket.on("consent-changed", handleConsentChanged);
|
||||
|
||||
return () => {
|
||||
socket.off("consent-changed", handleConsentChanged);
|
||||
unregisterMessagingHandlers({ socket });
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}, [bodyshop, socket, t, client]);
|
||||
|
||||
if (!bodyshop || !bodyshop.messagingservicesid) return <></>;
|
||||
|
||||
Reference in New Issue
Block a user