Skip to content

Commit c2a1b30

Browse files
improvement(tables): route row-limit Upgrade action to the explore-plans page
1 parent c8f4149 commit c2a1b30

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

apps/sim/hooks/queries/tables.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useQuery,
1515
useQueryClient,
1616
} from '@tanstack/react-query'
17+
import { useRouter } from 'next/navigation'
1718
import { toast } from '@/components/emcn'
1819
import { isValidationError } from '@/lib/api/client/errors'
1920
import { requestJson } from '@/lib/api/client/request'
@@ -92,7 +93,6 @@ import {
9293
optimisticallyScheduleNewlyEligibleGroups,
9394
} from '@/lib/table/deps'
9495
import { runUploadStrategy } from '@/lib/uploads/client/direct-upload'
95-
import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
9696

9797
const logger = createLogger('TableQueries')
9898

@@ -574,17 +574,15 @@ export function useDeleteTable(workspaceId: string) {
574574
*/
575575
/**
576576
* Toasts a failed row write. A plan row-limit failure (the best-effort cap in
577-
* `assertRowCapacity`) gets an "Upgrade" action routing to billing; other errors are
578-
* a plain auto-dismissing toast. Validation errors are surfaced inline, not here.
577+
* `assertRowCapacity`) gets an "Upgrade" action routing to the explore-plans page;
578+
* other errors are a plain auto-dismissing toast. Validation errors are surfaced
579+
* inline, not here.
579580
*/
580-
function notifyRowWriteError(
581-
error: Error,
582-
navigateToSettings: ReturnType<typeof useSettingsNavigation>['navigateToSettings']
583-
): void {
581+
function notifyRowWriteError(error: Error, onUpgrade: () => void): void {
584582
if (isValidationError(error)) return
585583
if (error.message.toLowerCase().includes('row limit')) {
586584
toast.error(error.message, {
587-
action: { label: 'Upgrade', onClick: () => navigateToSettings({ section: 'billing' }) },
585+
action: { label: 'Upgrade', onClick: onUpgrade },
588586
})
589587
return
590588
}
@@ -593,7 +591,7 @@ function notifyRowWriteError(
593591

594592
export function useCreateTableRow({ workspaceId, tableId }: RowMutationContext) {
595593
const queryClient = useQueryClient()
596-
const { navigateToSettings } = useSettingsNavigation()
594+
const router = useRouter()
597595

598596
return useMutation({
599597
mutationFn: async (
@@ -638,7 +636,8 @@ export function useCreateTableRow({ workspaceId, tableId }: RowMutationContext)
638636
predicate: (query) => !isDefaultOrderRowsQuery(query.queryKey),
639637
})
640638
},
641-
onError: (error) => notifyRowWriteError(error, navigateToSettings),
639+
onError: (error) =>
640+
notifyRowWriteError(error, () => router.push(`/workspace/${workspaceId}/upgrade`)),
642641
onSettled: () => {
643642
// `reconcileCreatedRow` (onSuccess) is the source of truth for the rows
644643
// cache + its `totalCount`; only refresh the count surfaces here so a late
@@ -801,7 +800,7 @@ type BatchCreateTableRowsResponse = ContractJsonResponse<typeof batchCreateTable
801800
*/
802801
export function useBatchCreateTableRows({ workspaceId, tableId }: RowMutationContext) {
803802
const queryClient = useQueryClient()
804-
const { navigateToSettings } = useSettingsNavigation()
803+
const router = useRouter()
805804

806805
return useMutation({
807806
mutationFn: async (
@@ -817,7 +816,8 @@ export function useBatchCreateTableRows({ workspaceId, tableId }: RowMutationCon
817816
},
818817
})
819818
},
820-
onError: (error) => notifyRowWriteError(error, navigateToSettings),
819+
onError: (error) =>
820+
notifyRowWriteError(error, () => router.push(`/workspace/${workspaceId}/upgrade`)),
821821
onSettled: () => {
822822
invalidateRowCount(queryClient, tableId)
823823
},

0 commit comments

Comments
 (0)