Skip to content

Commit

Permalink
Fix Help Center site picker - include domain only sites (#91026)
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed May 22, 2024
1 parent 4630886 commit fd6505d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/help-center/src/data/use-support-availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import apiFetch from '@wordpress/api-fetch';
import wpcomRequest, { canAccessWpcomApis } from 'wpcom-proxy-request';
import { OtherSupportAvailability, ChatAvailability, EmailSupportStatus } from '../types';

// Bump me to invalidate the cache.
const VERSION = 1;

type ResponseType< T extends 'CHAT' | 'OTHER' | 'EMAIL' > = T extends 'CHAT'
? ChatAvailability
: T extends 'EMAIL'
Expand All @@ -19,7 +22,7 @@ export function useSupportAvailability< SUPPORT_TYPE extends 'CHAT' | 'OTHER' |
enabled = true
) {
return useQuery< ResponseType< SUPPORT_TYPE >, typeof Error >( {
queryKey: [ 'support-availability', supportType ],
queryKey: [ 'support-availability', supportType, VERSION ],
queryFn: async () =>
canAccessWpcomApis()
? await wpcomRequest( {
Expand Down
9 changes: 6 additions & 3 deletions packages/help-center/src/data/use-user-sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { useQuery } from '@tanstack/react-query';
import wpcomRequest from 'wpcom-proxy-request';
import type { SiteDetails } from '@automattic/data-stores';

// Bump this version to invalidate the cache.
const VERSION = 2;

export function useUserSites( userId: number | string, enabled = true ) {
return useQuery( {
queryKey: [ 'user-sites', userId ],
queryKey: [ 'user-sites', userId, VERSION ],
queryFn: () =>
wpcomRequest< { sites: SiteDetails[] } >( {
path: '/me/sites/',
apiVersion: '1.1',
path: '/me/sites/?include_domain_only=true',
apiVersion: '1.2',
} ),
refetchOnWindowFocus: false,
staleTime: 5 * 60 * 1000,
Expand Down
2 changes: 2 additions & 0 deletions packages/help-center/src/hooks/use-chat-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default function useChatWidget(
window.zE( 'messenger:set', 'conversationFields', [
{ id: ZENDESK_SOURCE_URL_TICKET_FIELD_ID, value: window.location.href },
] );
} else {
throw new Error( 'Zendesk chat widget not loaded' );
}
} )
.catch( () => {
Expand Down

0 comments on commit fd6505d

Please sign in to comment.