From e1bd04a85fa1692e6dfe2d8c8dba715f757c2ac5 Mon Sep 17 00:00:00 2001 From: Mitchell Henson Date: Tue, 5 Nov 2024 13:22:38 +0100 Subject: [PATCH 1/2] chore: removing old chat code and cleaning up complexity --- .../Artwork/Components/ArtworkChatBubble.tsx | 2 +- .../Auction/__tests__/AuctionApp.jest.tsx | 4 +- src/Apps/Order/OrderApp.tsx | 2 +- .../Order/__tests__/OrderApp.jest.enzyme.tsx | 12 +- src/Components/SalesforceWrapper.tsx | 120 ++++-------------- src/Server/config.ts | 13 -- src/Server/setup_sharify.ts | 13 -- src/Typings/global.d.ts | 1 - src/Typings/sharify.d.ts | 13 -- 9 files changed, 38 insertions(+), 142 deletions(-) diff --git a/src/Apps/Artwork/Components/ArtworkChatBubble.tsx b/src/Apps/Artwork/Components/ArtworkChatBubble.tsx index 6084b6389d4..4bb9ea5853d 100644 --- a/src/Apps/Artwork/Components/ArtworkChatBubble.tsx +++ b/src/Apps/Artwork/Components/ArtworkChatBubble.tsx @@ -33,7 +33,7 @@ const ArtworkChatBubble: FC = ({ artwork }) => { } }, [listPrice]) - if (!getENV("SALESFORCE_CHAT_ENABLED")) { + if (!getENV("SALESFORCE_MESSAGE_ENABLED")) { return null } diff --git a/src/Apps/Auction/__tests__/AuctionApp.jest.tsx b/src/Apps/Auction/__tests__/AuctionApp.jest.tsx index d58b1851754..99fc8304e2a 100644 --- a/src/Apps/Auction/__tests__/AuctionApp.jest.tsx +++ b/src/Apps/Auction/__tests__/AuctionApp.jest.tsx @@ -104,14 +104,14 @@ describe("AuctionApp", () => { }) it("embeds Salesforce widget", () => { - mockGetENV.mockImplementation(() => ({ SALESFORCE_CHAT_ENABLED: true })) + mockGetENV.mockImplementation(() => ({ SALESFORCE_MESSAGE_ENABLED: true })) const { wrapper } = getWrapper() expect(wrapper.find("SalesforceWrapper").exists()).toBeFalsy() }) it("does not embed Salesforce widget on mobile", () => { breakpoint = "xs" - mockGetENV.mockImplementation(() => ({ SALESFORCE_CHAT_ENABLED: true })) + mockGetENV.mockImplementation(() => ({ SALESFORCE_MESSAGE_ENABLED: true })) const { wrapper } = getWrapper() expect(wrapper.find("SalesforceWrapper").exists()).toBeFalsy() }) diff --git a/src/Apps/Order/OrderApp.tsx b/src/Apps/Order/OrderApp.tsx index 9d7cbb44a11..976ebb4cdc1 100644 --- a/src/Apps/Order/OrderApp.tsx +++ b/src/Apps/Order/OrderApp.tsx @@ -94,7 +94,7 @@ const OrderApp: FC = props => { return null } - if (!getENV("SALESFORCE_CHAT_ENABLED")) { + if (!getENV("SALESFORCE_MESSAGE_ENABLED")) { return null } diff --git a/src/Apps/Order/__tests__/OrderApp.jest.enzyme.tsx b/src/Apps/Order/__tests__/OrderApp.jest.enzyme.tsx index 48e80947962..17f51ac9f4b 100644 --- a/src/Apps/Order/__tests__/OrderApp.jest.enzyme.tsx +++ b/src/Apps/Order/__tests__/OrderApp.jest.enzyme.tsx @@ -684,7 +684,9 @@ describe("OrderApp", () => { describe("chat bubble", () => { it("shows the Salesforce chat integration button", () => { - mockGetENV.mockImplementation(() => ({ SALESFORCE_CHAT_ENABLED: true })) + mockGetENV.mockImplementation(() => ({ + SALESFORCE_MESSAGE_ENABLED: true, + })) const props = getProps() as any const subject = getWrapper({ props }) as any @@ -692,14 +694,18 @@ describe("OrderApp", () => { }) it("does not show the Salesforce chat integration button on mobile", () => { - mockGetENV.mockImplementation(() => ({ SALESFORCE_CHAT_ENABLED: true })) + mockGetENV.mockImplementation(() => ({ + SALESFORCE_MESSAGE_ENABLED: true, + })) const props = getProps() as any const subject = getWrapper({ props, breakpoint: "xs" }) as any expect(subject.find("SalesforceWrapper")).toHaveLength(0) }) it("does not show the Salesforce chat integration button if in a modal", () => { - mockGetENV.mockImplementation(() => ({ SALESFORCE_CHAT_ENABLED: true })) + mockGetENV.mockImplementation(() => ({ + SALESFORCE_MESSAGE_ENABLED: true, + })) const props = getProps() const subject = getWrapper({ props: { ...props, match: { location: { query: { isModal: true } } } }, diff --git a/src/Components/SalesforceWrapper.tsx b/src/Components/SalesforceWrapper.tsx index f04595115a4..ea6b6433519 100644 --- a/src/Components/SalesforceWrapper.tsx +++ b/src/Components/SalesforceWrapper.tsx @@ -10,37 +10,15 @@ interface SalesforceWrapperProps { export const SalesforceWrapper: React.FC = ({ isInAuction = false, }) => { - const salesforceMessageEnabled = getENV("SALESFORCE_MESSAGE_ENABLED") - let embeddedService = null - let buttonId = null - let ewsLiveAgentDevName = null let serviceName = null let chatURL = null - if (salesforceMessageEnabled) { - if (isInAuction) { - serviceName = getENV("SALESFORCE_AUCTION_MESSAGE_SERVICE_NAME") - chatURL = getENV("SALESFORCE_AUCTION_MESSAGE_INSTANCE_URL") - } else { - serviceName = getENV("SALESFORCE_COLLECTOR_MESSAGE_SERVICE_NAME") - chatURL = getENV("SALESFORCE_COLLECTOR_MESSAGE_INSTANCE_URL") - } + if (isInAuction) { + serviceName = getENV("SALESFORCE_AUCTION_MESSAGE_SERVICE_NAME") + chatURL = getENV("SALESFORCE_AUCTION_MESSAGE_INSTANCE_URL") } else { - if (isInAuction) { - embeddedService = getENV("SALESFORCE_CHAT_EMBEDDED_SERVICE_AUCTION_NAME") - buttonId = getENV("SALESFORCE_CHAT_AUCTION_BUTTON_ID") - ewsLiveAgentDevName = getENV( - "SALESFORCE_CHAT_AUCTION_ESW_LIVE_AGENT_DEV_NAME" - ) - } else { - embeddedService = getENV( - "SALESFORCE_CHAT_EMBEDDED_SERVICE_COLLECTOR_NAME" - ) - buttonId = getENV("SALESFORCE_CHAT_COLLECTOR_BUTTON_ID") - ewsLiveAgentDevName = getENV( - "SALESFORCE_CHAT_COLLECTOR_ESW_LIVE_AGENT_DEV_NAME" - ) - } + serviceName = getENV("SALESFORCE_COLLECTOR_MESSAGE_SERVICE_NAME") + chatURL = getENV("SALESFORCE_COLLECTOR_MESSAGE_INSTANCE_URL") } useAppendStylesheet({ @@ -65,77 +43,29 @@ export const SalesforceWrapper: React.FC = ({ `, }) - useLoadScript( - (() => { - if (salesforceMessageEnabled) { - return { - id: "salesforce-chat-script", - src: `${chatURL}/assets/js/bootstrap.min.js`, - removeOnUnmount: true, - onReady: () => { - if (window.embeddedservice_bootstrap?.settings) { - window.embeddedservice_bootstrap.settings.language = "en_US" - window.embeddedservice_bootstrap.init( - getENV("SALESFORCE_MESSAGE_ORG_ID"), - serviceName, - chatURL, - { - scrt2URL: getENV("SALESFORCE_MESSAGE_SCRT2_URL"), - } - ) - } - }, - } - } else { - return { - id: "salesforce-chat-script", - src: `${getENV( - "SALESFORCE_CHAT_INSTANCE_URL" - )}/embeddedservice/5.0/esw.min.js`, - removeOnUnmount: true, - onReady: () => { - if (window.embedded_svc?.settings) { - window.embedded_svc.settings.defaultMinimizedText = "Chat" - window.embedded_svc.settings.enabledFeatures = ["LiveAgent"] - window.embedded_svc.settings.entryFeature = "LiveAgent" - - window.embedded_svc.init( - getENV("SALESFORCE_CHAT_INSTANCE_URL"), - getENV("SALESFORCE_CHAT_HELP_URL"), - "https://service.force.com", - getENV("SALESFORCE_CHAT_ORG_ID"), - embeddedService, - { - baseLiveAgentContentURL: getENV( - "SALESFORCE_CHAT_LIVE_AGENT_CONTENT_URL" - ), - deploymentId: getENV("SALESFORCE_CHAT_DEPLOYMENT_ID"), - buttonId: buttonId, - baseLiveAgentURL: getENV("SALESFORCE_CHAT_LIVE_AGENT_URL"), - eswLiveAgentDevName: ewsLiveAgentDevName, - isOfflineSupportEnabled: true, - } - ) - } - }, - } + useLoadScript({ + id: "salesforce-chat-script", + src: `${chatURL}/assets/js/bootstrap.min.js`, + removeOnUnmount: true, + onReady: () => { + if (window.embeddedservice_bootstrap?.settings) { + window.embeddedservice_bootstrap.settings.language = "en_US" + window.embeddedservice_bootstrap.init( + getENV("SALESFORCE_MESSAGE_ORG_ID"), + serviceName, + chatURL, + { + scrt2URL: getENV("SALESFORCE_MESSAGE_SCRT2_URL"), + } + ) } - })() - ) + }, + }) useEffect(() => { - const salesforceMessageEnabled = getENV("SALESFORCE_MESSAGE_ENABLED") - - if (salesforceMessageEnabled) { - window.embeddedservice_bootstrap?.showHelpButton?.() - return () => { - window.embeddedservice_bootstrap?.hideHelpButton?.() - } - } else { - window.embedded_svc?.showHelpButton?.() - return () => { - window.embedded_svc?.hideHelpButton?.() - } + window.embeddedservice_bootstrap?.showHelpButton?.() + return () => { + window.embeddedservice_bootstrap?.hideHelpButton?.() } }, []) diff --git a/src/Server/config.ts b/src/Server/config.ts index 42602a6265d..e6a146ed4e9 100644 --- a/src/Server/config.ts +++ b/src/Server/config.ts @@ -85,19 +85,6 @@ export const RECAPTCHA_KEY: any = null export const S3_BUCKET: any = null export const S3_KEY: any = null export const S3_SECRET: any = null -export const SALESFORCE_CHAT_ENABLED: any = false -export const SALESFORCE_CHAT_INSTANCE_URL: any = null -export const SALESFORCE_CHAT_HELP_URL: any = null -export const SALESFORCE_CHAT_ORG_ID: any = null -export const SALESFORCE_CHAT_EMBEDDED_SERVICE_COLLECTOR_NAME: any = null -export const SALESFORCE_CHAT_EMBEDDED_SERVICE_AUCTION_NAME: any = null -export const SALESFORCE_CHAT_DEPLOYMENT_ID: any = null -export const SALESFORCE_CHAT_COLLECTOR_BUTTON_ID: any = null -export const SALESFORCE_CHAT_AUCTION_BUTTON_ID: any = null -export const SALESFORCE_CHAT_LIVE_AGENT_CONTENT_URL: any = null -export const SALESFORCE_CHAT_LIVE_AGENT_URL: any = null -export const SALESFORCE_CHAT_COLLECTOR_ESW_LIVE_AGENT_DEV_NAME: any = null -export const SALESFORCE_CHAT_AUCTION_ESW_LIVE_AGENT_DEV_NAME: any = null export const SALESFORCE_MESSAGE_ENABLED: any = false export const SALESFORCE_MESSAGE_ORG_ID: any = null export const SALESFORCE_MESSAGE_SCRT2_URL: any = null diff --git a/src/Server/setup_sharify.ts b/src/Server/setup_sharify.ts index 1a41455d379..f5bca7b4aaa 100644 --- a/src/Server/setup_sharify.ts +++ b/src/Server/setup_sharify.ts @@ -74,19 +74,6 @@ sharify.data = _.extend( "GRAPHQL_CACHE_TTL", "RESET_PASSWORD_TOKEN", "S3_BUCKET", - "SALESFORCE_CHAT_ENABLED", - "SALESFORCE_CHAT_INSTANCE_URL", - "SALESFORCE_CHAT_HELP_URL", - "SALESFORCE_CHAT_ORG_ID", - "SALESFORCE_CHAT_EMBEDDED_SERVICE_COLLECTOR_NAME", - "SALESFORCE_CHAT_EMBEDDED_SERVICE_AUCTION_NAME", - "SALESFORCE_CHAT_DEPLOYMENT_ID", - "SALESFORCE_CHAT_COLLECTOR_BUTTON_ID", - "SALESFORCE_CHAT_AUCTION_BUTTON_ID", - "SALESFORCE_CHAT_COLLECTOR_ESW_LIVE_AGENT_DEV_NAME", - "SALESFORCE_CHAT_AUCTION_ESW_LIVE_AGENT_DEV_NAME", - "SALESFORCE_CHAT_LIVE_AGENT_URL", - "SALESFORCE_CHAT_LIVE_AGENT_CONTENT_URL", "SALESFORCE_MESSAGE_ENABLED", "SALESFORCE_MESSAGE_ORG_ID", "SALESFORCE_MESSAGE_SCRT2_URL", diff --git a/src/Typings/global.d.ts b/src/Typings/global.d.ts index 70b906e9a62..58d2d8f6b0f 100644 --- a/src/Typings/global.d.ts +++ b/src/Typings/global.d.ts @@ -45,7 +45,6 @@ declare global { analytics: any braze?: typeof Braze desktopPageTimeTrackers: [{ path: string; reset: (path) => void }] - embedded_svc?: any embeddedservice_bootstrap?: any grecaptcha: any ReactNativeWebView?: { postMessage: (message: string) => void } diff --git a/src/Typings/sharify.d.ts b/src/Typings/sharify.d.ts index 625a72d4db9..79af68dd27a 100644 --- a/src/Typings/sharify.d.ts +++ b/src/Typings/sharify.d.ts @@ -80,19 +80,6 @@ declare module "sharify" { REQUEST_ID?: string RESET_PASSWORD_REDIRECT_TO: string RESET_PASSWORD_TOKEN: string - SALESFORCE_CHAT_ENABLED: boolean - SALESFORCE_CHAT_INSTANCE_URL: string - SALESFORCE_CHAT_HELP_URL: string - SALESFORCE_CHAT_ORG_ID: string - SALESFORCE_CHAT_EMBEDDED_SERVICE_COLLECTOR_NAME: string - SALESFORCE_CHAT_EMBEDDED_SERVICE_AUCTION_NAME: string - SALESFORCE_CHAT_DEPLOYMENT_ID: string - SALESFORCE_CHAT_LIVE_AGENT_URL: string - SALESFORCE_CHAT_COLLECTOR_BUTTON_ID: string - SALESFORCE_CHAT_AUCTION_BUTTON_ID: string - SALESFORCE_CHAT_COLLECTOR_ESW_LIVE_AGENT_DEV_NAME: string - SALESFORCE_CHAT_AUCTION_ESW_LIVE_AGENT_DEV_NAME: string - SALESFORCE_CHAT_LIVE_AGENT_CONTENT_URL: string SALESFORCE_MESSAGE_ENABLED: boolean SALESFORCE_MESSAGE_ORG_ID: string SALESFORCE_MESSAGE_SCRT2_URL: string From 1a64b1ddb3bb1ca02c325bd9002472ebd880a746 Mon Sep 17 00:00:00 2001 From: Mitchell Henson Date: Thu, 28 Nov 2024 16:58:25 +0100 Subject: [PATCH 2/2] chore: removed unused variable --- src/Apps/Artwork/Components/ArtworkChatBubble.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Apps/Artwork/Components/ArtworkChatBubble.tsx b/src/Apps/Artwork/Components/ArtworkChatBubble.tsx index 8d805ef09e5..f1dbc26a381 100644 --- a/src/Apps/Artwork/Components/ArtworkChatBubble.tsx +++ b/src/Apps/Artwork/Components/ArtworkChatBubble.tsx @@ -18,7 +18,6 @@ const ArtworkChatBubble: FC