Skip to content

Commit 3f22549

Browse files
regression: Stale phone numbers being available for outbound message (#37053)
1 parent bf35a0b commit 3f22549

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.changeset/few-flowers-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes stale phone numbers being available for outbound message

apps/meteor/client/components/Omnichannel/OutboundMessage/components/OutboundMessageWizard/OutboundMessageWizard.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
33
import { useToastBarDispatch } from '@rocket.chat/fuselage-toastbar';
44
import { Wizard, useWizard, WizardContent, WizardTabs } from '@rocket.chat/ui-client';
55
import { usePermission } from '@rocket.chat/ui-contexts';
6+
import { useQueryClient } from '@tanstack/react-query';
67
import { useEffect, useState } from 'react';
78
import { ErrorBoundary } from 'react-error-boundary';
89
import { useTranslation } from 'react-i18next';
@@ -12,6 +13,7 @@ import type { SubmitPayload } from './forms';
1213
import { ReviewStep, MessageStep, RecipientStep, RepliesStep } from './steps';
1314
import { useHasLicenseModule } from '../../../../../hooks/useHasLicenseModule';
1415
import { formatPhoneNumber } from '../../../../../lib/formatPhoneNumber';
16+
import { omnichannelQueryKeys } from '../../../../../lib/queryKeys';
1517
import GenericError from '../../../../GenericError';
1618
import useOutboundProvidersList from '../../hooks/useOutboundProvidersList';
1719
import { useOutboundMessageUpsellModal } from '../../modals';
@@ -27,6 +29,7 @@ type OutboundMessageWizardProps = {
2729

2830
const OutboundMessageWizard = ({ defaultValues = {}, onSuccess, onError }: OutboundMessageWizardProps) => {
2931
const { t } = useTranslation();
32+
const queryClient = useQueryClient();
3033
const dispatchToastMessage = useToastBarDispatch();
3134
const [state, setState] = useState<Partial<SubmitPayload>>(defaultValues);
3235
const { contact, sender, provider, department, agent, template, templateParameters, recipient } = state;
@@ -63,6 +66,14 @@ const OutboundMessageWizard = ({ defaultValues = {}, onSuccess, onError }: Outbo
6366
],
6467
});
6568

69+
useEffect(
70+
() => () => {
71+
// Clear cached providers and metadata on unmount to avoid stale data
72+
void queryClient.removeQueries({ queryKey: omnichannelQueryKeys.outboundProviders() });
73+
},
74+
[queryClient],
75+
);
76+
6677
useEffect(() => {
6778
if (!isLoadingProviders && !isLoadingModule && (!hasOutboundModule || !hasProviders)) {
6879
upsellModal.open();

apps/meteor/client/components/Omnichannel/OutboundMessage/hooks/useOutboundProvidersList.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type UseOutboundProvidersListProps<TData> = Omit<UseQueryOptions<OutboundProvide
1414
};
1515

1616
const useOutboundProvidersList = <TData = OutboundProvidersResponse>(options?: UseOutboundProvidersListProps<TData>) => {
17-
const { type = 'phone', enabled = true, staleTime = 0, gcTime = 0, ...queryOptions } = options || {};
17+
const { type = 'phone', enabled = true, staleTime = 5 * 60 * 1000, ...queryOptions } = options || {};
1818
const getProviders = useEndpoint('GET', '/v1/omnichannel/outbound/providers');
1919
const hasModule = useHasLicenseModule('outbound-messaging');
2020

@@ -24,7 +24,6 @@ const useOutboundProvidersList = <TData = OutboundProvidersResponse>(options?: U
2424
retry: 3,
2525
enabled: hasModule && enabled,
2626
staleTime,
27-
gcTime,
2827
...queryOptions,
2928
});
3029
};

apps/meteor/client/lib/queryKeys.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ export const omnichannelQueryKeys = {
7676
contacts: (query?: { filter: string; limit?: number }) =>
7777
!query ? [...omnichannelQueryKeys.all, 'contacts'] : ([...omnichannelQueryKeys.all, 'contacts', query] as const),
7878
contact: (contactId?: string) => [...omnichannelQueryKeys.contacts(), contactId] as const,
79-
outboundProviders: ({ type }: { type: IOutboundProvider['providerType'] }) =>
80-
[...omnichannelQueryKeys.all, 'outbound', 'providers', { type }] as const,
81-
outboundProviderMetadata: (providerId: string) => [...omnichannelQueryKeys.all, 'outbound', 'provider', 'metadata', providerId] as const,
79+
outboundProviders: (filter?: { type: IOutboundProvider['providerType'] }) =>
80+
!filter
81+
? ([...omnichannelQueryKeys.all, 'outbound-messaging', 'providers'] as const)
82+
: ([...omnichannelQueryKeys.all, 'outbound-messaging', 'providers', filter] as const),
83+
outboundProviderMetadata: (providerId: string) => [...omnichannelQueryKeys.outboundProviders(), providerId] as const,
8284
};
8385

8486
export const deviceManagementQueryKeys = {

0 commit comments

Comments
 (0)