Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE - chore: removing old chat code and cleaning up complexity #14811

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react"
import { graphql } from "react-relay"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { ArticleSeriesFragmentContainer } from "../ArticleSeries"
import { ArticleSeriesFragmentContainer } from "Apps/Article/Components/ArticleSeries"

jest.unmock("react-relay")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react"
import { graphql } from "react-relay"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { ArticleVideoFragmentContainer } from "../ArticleVideo"
import { ArticleVideoFragmentContainer } from "Apps/Article/Components/ArticleVideo"

jest.unmock("react-relay")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react"
import { graphql } from "react-relay"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { ArticlesIndexArticlesPaginationContainer } from "../ArticlesIndexArticles"
import { ArticlesIndexArticlesPaginationContainer } from "Apps/Articles/Components/ArticlesIndexArticles"

jest.unmock("react-relay")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { screen } from "@testing-library/react"
import { ArtistInsightBadgesFragmentContainer } from "../ArtistInsightBadges"
import { ArtistInsightBadgesFragmentContainer } from "Apps/Artist/Components/ArtistInsights/ArtistInsightBadges"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { graphql } from "react-relay"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { graphql } from "react-relay"
import { screen } from "@testing-library/react"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { ArtistRelatedGeneCategoriesFragmentContainer } from "../ArtistRelatedGeneCategories"
import { ArtistRelatedGeneCategoriesFragmentContainer } from "Apps/Artist/Routes/Overview/Components/ArtistRelatedGeneCategories"

jest.unmock("react-relay")

Expand Down
11 changes: 6 additions & 5 deletions src/Apps/Artwork/Components/ArtworkChatBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ interface ArtworkChatBubbleProps {
artwork: ArtworkChatBubble_artwork$data
}

const ArtworkChatBubble: FC<React.PropsWithChildren<ArtworkChatBubbleProps>> = ({ artwork }) => {
const ArtworkChatBubble: FC<React.PropsWithChildren<
ArtworkChatBubbleProps
>> = ({ artwork }) => {
const {
isAcquireable,
isInquireable,
isOfferable,
listPrice,
isInAuction,
saleArtwork,
} = artwork

Expand All @@ -33,7 +34,7 @@ const ArtworkChatBubble: FC<React.PropsWithChildren<ArtworkChatBubbleProps>> = (
}
}, [listPrice])

if (!getENV("SALESFORCE_CHAT_ENABLED")) {
if (!getENV("SALESFORCE_MESSAGE_ENABLED")) {
return null
}

Expand All @@ -47,7 +48,7 @@ const ArtworkChatBubble: FC<React.PropsWithChildren<ArtworkChatBubbleProps>> = (
) {
return (
<Media greaterThan="xs">
<SalesforceWrapper isInAuction={isInAuction} />
<SalesforceWrapper />
</Media>
)
}
Expand All @@ -61,7 +62,7 @@ const ArtworkChatBubble: FC<React.PropsWithChildren<ArtworkChatBubbleProps>> = (

return (
<Media greaterThan="xs">
<SalesforceWrapper isInAuction={isInAuction} />
<SalesforceWrapper />
</Media>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/Auction/__tests__/AuctionApp.jest.enzyme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion src/Apps/Order/OrderApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const OrderApp: FC<React.PropsWithChildren<OrderAppProps>> = props => {
return null
}

if (!getENV("SALESFORCE_CHAT_ENABLED")) {
if (!getENV("SALESFORCE_MESSAGE_ENABLED")) {
return null
}

Expand Down
12 changes: 9 additions & 3 deletions src/Apps/Order/__tests__/OrderApp.jest.enzyme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -684,22 +684,28 @@ 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
expect(subject.find("SalesforceWrapper")).toHaveLength(1)
})

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 } } } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen, fireEvent, waitFor } from "@testing-library/react"
import { graphql } from "react-relay"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { useUpdateMyUserProfile } from "Utils/Hooks/Mutations/useUpdateMyUserProfile"
import { SettingsEditProfileAboutYouFragmentContainer } from "../SettingsEditProfileAboutYou"
import { SettingsEditProfileAboutYouFragmentContainer } from "Apps/Settings/Routes/EditProfile/Components/SettingsEditProfileAboutYou"

jest.unmock("react-relay")
jest.mock("Utils/Hooks/Mutations/useUpdateMyUserProfile")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react"
import { graphql } from "react-relay"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { SmsSecondFactorRefetchContainer } from "../index"
import { SmsSecondFactorRefetchContainer } from "Apps/Settings/Routes/EditSettings/Components/SettingsEditSettingsTwoFactor/TwoFactorAuthentication/Components/SmsSecondFactor/index"

jest.unmock("react-relay")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { OnboardingOrderedSetFragmentContainer } from "../OnboardingOrderedSet"
import { OnboardingOrderedSetFragmentContainer } from "Components/Onboarding/Components/OnboardingOrderedSet"
import { graphql } from "react-relay"
import { screen } from "@testing-library/react"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OnboardingSearchResultsFragmentContainer } from "../OnboardingSearchResults"
import { OnboardingSearchResultsFragmentContainer } from "Components/Onboarding/Components/OnboardingSearchResults"
import { graphql } from "react-relay"
import { screen } from "@testing-library/react"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
Expand Down
124 changes: 22 additions & 102 deletions src/Components/SalesforceWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,8 @@ import { useLoadScript } from "Utils/Hooks/useLoadScript"
import { useAppendStylesheet } from "Utils/Hooks/useAppendStylesheet"
import { useEffect } from "react"

interface SalesforceWrapperProps {
isInAuction?: boolean | null
}

export const SalesforceWrapper: React.FC<React.PropsWithChildren<SalesforceWrapperProps>> = ({
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) {
serviceName = getENV("SALESFORCE_MESSAGE_SERVICE_NAME")
chatURL = getENV("SALESFORCE_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"
)
}
}
export const SalesforceWrapper: React.FC<{}> = _props => {
const chatURL = getENV("SALESFORCE_MESSAGE_INSTANCE_URL")

useAppendStylesheet({
id: "salesforce-chat-styles",
Expand All @@ -60,77 +28,29 @@ export const SalesforceWrapper: React.FC<React.PropsWithChildren<SalesforceWrapp
`,
})

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"),
getENV("SALESFORCE_MESSAGE_SERVICE_NAME"),
getENV("SALESFORCE_MESSAGE_INSTANCE_URL"),
{
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?.()
}
}, [])

Expand Down
13 changes: 0 additions & 13 deletions src/Server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions src/Server/setup_sharify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/Typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 0 additions & 13 deletions src/Typings/sharify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down