Skip to content

Commit 726a7b7

Browse files
committed
fix(settings): scope SSO retry state to failed queries
1 parent b7cdaec commit 726a7b7

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

apps/sim/ee/sso/components/sso-settings.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ describe('SSO organization transitions', () => {
258258

259259
it('shows a billing failure instead of an Enterprise upsell', () => {
260260
const refetch = vi.fn()
261+
const refetchProviders = vi.fn()
262+
mockUseSSOProviders.mockReturnValue({
263+
data: { providers: [provider('org-a')] },
264+
error: null,
265+
isFetching: true,
266+
isLoading: false,
267+
refetch: refetchProviders,
268+
})
261269
mockUseOrganizationBilling.mockReturnValue({
262270
data: undefined,
263271
error: new Error('Billing entitlement failed'),
@@ -270,12 +278,22 @@ describe('SSO organization transitions', () => {
270278

271279
expect(container).toHaveTextContent('Billing entitlement failed')
272280
expect(container).not.toHaveTextContent('available on Enterprise plans only')
281+
expect(findButton('Try again')).not.toBeDisabled()
273282
act(() => findButton('Try again')?.click())
274283
expect(refetch).toHaveBeenCalledOnce()
284+
expect(refetchProviders).not.toHaveBeenCalled()
275285
})
276286

277287
it('retries an initial provider failure without leaving the page', () => {
278288
const refetch = vi.fn()
289+
const refetchBilling = vi.fn()
290+
mockUseOrganizationBilling.mockReturnValue({
291+
data: { data: { subscriptionPlan: 'enterprise' } },
292+
error: null,
293+
isFetching: true,
294+
isLoading: false,
295+
refetch: refetchBilling,
296+
})
279297
mockUseSSOProviders.mockReturnValue({
280298
data: undefined,
281299
error: new Error('Provider lookup failed'),
@@ -287,8 +305,10 @@ describe('SSO organization transitions', () => {
287305
renderSso('org-a')
288306

289307
expect(container).toHaveTextContent('Provider lookup failed')
308+
expect(findButton('Try again')).not.toBeDisabled()
290309
act(() => findButton('Try again')?.click())
291310
expect(refetch).toHaveBeenCalledOnce()
311+
expect(refetchBilling).not.toHaveBeenCalled()
292312
})
293313
})
294314

apps/sim/ee/sso/components/sso-settings.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,22 @@ function OrganizationSsoSettings({ organizationId }: SSOProps) {
293293
return null
294294
}
295295

296-
const loadingError =
297-
(providersData === undefined ? providersError : null) ??
298-
(isBillingEnabled && organizationBillingData === undefined ? organizationBillingError : null)
296+
const providersLoadingError = providersData === undefined ? providersError : null
297+
const organizationBillingLoadingError =
298+
isBillingEnabled && organizationBillingData === undefined ? organizationBillingError : null
299+
const loadingError = providersLoadingError ?? organizationBillingLoadingError
299300
if (loadingError) {
300301
return (
301302
<SettingsQueryErrorState
302303
error={loadingError}
303304
fallback='Failed to load Single Sign-On settings'
304-
isRetrying={isFetchingProviders || (isBillingEnabled && isFetchingOrganizationBilling)}
305+
isRetrying={
306+
(Boolean(providersLoadingError) && isFetchingProviders) ||
307+
(Boolean(organizationBillingLoadingError) && isFetchingOrganizationBilling)
308+
}
305309
onRetry={() => {
306-
if (providersData === undefined && providersError) void refetchProviders()
307-
if (
308-
isBillingEnabled &&
309-
organizationBillingData === undefined &&
310-
organizationBillingError
311-
) {
312-
void refetchOrganizationBilling()
313-
}
310+
if (providersLoadingError) void refetchProviders()
311+
if (organizationBillingLoadingError) void refetchOrganizationBilling()
314312
}}
315313
/>
316314
)

0 commit comments

Comments
 (0)