diff --git a/client/src/components/chat-affix/registerMessagingSocketHandlers.js b/client/src/components/chat-affix/registerMessagingSocketHandlers.js
index 6c6e96ad2..88e0ac9df 100644
--- a/client/src/components/chat-affix/registerMessagingSocketHandlers.js
+++ b/client/src/components/chat-affix/registerMessagingSocketHandlers.js
@@ -462,7 +462,7 @@ export const registerMessagingHandlers = ({ socket, client }) => {
logLocal("handlePhoneNumberOptedOut - Error", { error: error.message });
}
};
-
+
// New handler for phone number opt-in
const handlePhoneNumberOptedIn = async (data) => {
const { bodyshopid, phone_number } = data;
diff --git a/client/src/components/phone-number-consent/phone-number-consent.component.jsx b/client/src/components/phone-number-consent/phone-number-consent.component.jsx
index 7981a3db2..0df53ca30 100644
--- a/client/src/components/phone-number-consent/phone-number-consent.component.jsx
+++ b/client/src/components/phone-number-consent/phone-number-consent.component.jsx
@@ -1,11 +1,11 @@
import { useQuery } from "@apollo/client";
import { Input, Table } from "antd";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
-import { GET_PHONE_NUMBER_OPT_OUTS } from "../../graphql/phone-number-opt-out.queries";
+import { GET_PHONE_NUMBER_OPT_OUTS, SEARCH_OWNERS_BY_PHONE_NUMBERS } from "../../graphql/phone-number-opt-out.queries";
import PhoneNumberFormatter from "../../utils/PhoneFormatter";
import { TimeAgoFormatter } from "../../utils/DateFormatter";
@@ -20,11 +20,71 @@ const mapDispatchToProps = () => ({});
function PhoneNumberConsentList({ bodyshop, currentUser }) {
const { t } = useTranslation();
const [search, setSearch] = useState("");
- const { loading, data } = useQuery(GET_PHONE_NUMBER_OPT_OUTS, {
+
+ // Fetch opt-out phone numbers
+ const { loading: optOutLoading, data: optOutData } = useQuery(GET_PHONE_NUMBER_OPT_OUTS, {
variables: { bodyshopid: bodyshop.id, search: search ? `%${search}%` : undefined },
fetchPolicy: "network-only"
});
+ // Prepare phone numbers for owner query
+ const phoneNumbers = useMemo(() => {
+ return optOutData?.phone_number_opt_out?.map((item) => item.phone_number) || [];
+ }, [optOutData?.phone_number_opt_out]);
+ const allPhoneNumbers = useMemo(() => {
+ const normalized = phoneNumbers;
+ const withPlusOne = phoneNumbers.map((num) => `+1${num}`);
+ return [...normalized, ...withPlusOne].filter(Boolean);
+ }, [phoneNumbers]);
+
+ // Fetch owners for all phone numbers
+ const { loading: ownersLoading, data: ownersData } = useQuery(SEARCH_OWNERS_BY_PHONE_NUMBERS, {
+ variables: { bodyshopid: bodyshop.id, phone_numbers: allPhoneNumbers },
+ skip: allPhoneNumbers.length === 0 || !bodyshop.id,
+ fetchPolicy: "network-only"
+ });
+
+ // Format owner names for display
+ const formatOwnerName = (owner) => {
+ const parts = [];
+ if (owner.ownr_fn || owner.ownr_ln) {
+ parts.push([owner.ownr_fn, owner.ownr_ln].filter(Boolean).join(" "));
+ }
+ if (owner.ownr_co_nm) {
+ parts.push(owner.ownr_co_nm);
+ }
+ return parts.join(", ") || "-";
+ };
+
+ // Map phone numbers to their associated owners and identify phone field
+ const getAssociatedOwners = (phoneNumber) => {
+ if (!ownersData?.owners) return [];
+ const normalizedPhone = phoneNumber.replace(/^\+1/, "");
+ return ownersData.owners
+ .filter(
+ (owner) =>
+ owner.ownr_ph1 === phoneNumber ||
+ owner.ownr_ph2 === phoneNumber ||
+ owner.ownr_ph1 === normalizedPhone ||
+ owner.ownr_ph2 === normalizedPhone ||
+ owner.ownr_ph1 === `+1${phoneNumber}` ||
+ owner.ownr_ph2 === `+1${phoneNumber}`
+ )
+ .map((owner) => ({
+ ...owner,
+ phoneField:
+ [owner.ownr_ph1, owner.ownr_ph2].includes(phoneNumber) ||
+ [owner.ownr_ph1, owner.ownr_ph2].includes(normalizedPhone) ||
+ [owner.ownr_ph1, owner.ownr_ph2].includes(`+1${phoneNumber}`)
+ ? owner.ownr_ph1 === phoneNumber ||
+ owner.ownr_ph1 === normalizedPhone ||
+ owner.ownr_ph1 === `+1${phoneNumber}`
+ ? t("consent.phone_1")
+ : t("consent.phone_2")
+ : null
+ }));
+ };
+
const columns = [
{
title: t("consent.phone_number"),
@@ -32,6 +92,28 @@ function PhoneNumberConsentList({ bodyshop, currentUser }) {
render: (text) =>