Skip to content

Commit

Permalink
Help Center: Avoid authenticating to Zendesk for free users (#97471)
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyweight authored Dec 13, 2024
1 parent c72ee5b commit e6ee88d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/help-center/src/components/help-center-smooch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const initSmooch = ( {
};

const HelpCenterSmooch: React.FC< { enableAuth: boolean } > = ( { enableAuth } ) => {
const { data: authData } = useAuthenticateZendeskMessaging( enableAuth, 'messenger' );
const { isEligibleForChat } = useChatStatus();
const { data: authData } = useAuthenticateZendeskMessaging(
enableAuth && isEligibleForChat,
'messenger'
);
const smoochRef = useRef< HTMLDivElement >( null );
const { isHelpCenterShown, isChatLoaded } = useSelect( ( select ) => {
const helpCenterSelect: HelpCenterSelect = select( HELP_CENTER_STORE );
Expand All @@ -51,7 +55,6 @@ const HelpCenterSmooch: React.FC< { enableAuth: boolean } > = ( { enableAuth } )
};
}, [] );

const { isEligibleForChat } = useChatStatus();
const { isMessagingScriptLoaded } = useLoadZendeskMessaging(
'zendesk_support_chat_key',
isHelpCenterShown && isEligibleForChat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const getPlaceholderAttachmentMessage = ( file: File ) => {
};

export const AttachmentButton: React.FC = () => {
const { chat, addMessage, trackEvent } = useOdieAssistantContext();
const { data: authData } = useAuthenticateZendeskMessaging( true, 'messenger' );
const { chat, addMessage, trackEvent, isUserEligibleForPaidSupport } = useOdieAssistantContext();
const { data: authData } = useAuthenticateZendeskMessaging(
isUserEligibleForPaidSupport,
'messenger'
);
const { isPending: isAttachingFile, mutateAsync: attachFileToConversation } =
useAttachFileToConversation();
const { zendeskClientId } = useSelect( ( select ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const VERSION = 'v1';
let isLoggedIn = false;

export function useAuthenticateZendeskMessaging(
enabled = true,
enabled = false,
type: ZendeskAuthType = 'zendesk'
) {
const currentEnvironment = config( 'env_id' );
Expand Down
4 changes: 2 additions & 2 deletions packages/zendesk-client/src/use-load-zendesk-messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { ZendeskConfigName } from './types';

export function useLoadZendeskMessaging(
keyConfigName: ZendeskConfigName,
enabled = true,
tryAuthenticating = true,
enabled = false,
tryAuthenticating = false,
shouldUseHelpCenterExperience = false
) {
const [ isMessagingScriptLoaded, setMessagingScriptLoaded ] = useState( false );
Expand Down

0 comments on commit e6ee88d

Please sign in to comment.