@@ -30,18 +30,9 @@ import {
3030} from '@sim/emcn/icons'
3131import { isRecordLike , omit } from '@sim/utils/object'
3232import { useParams } from 'next/navigation'
33- import { getOrganizationSettingsHref } from '@/components/settings/navigation'
34- import { useSettingsNavigationTarget } from '@/components/settings/settings-navigation-provider'
3533import { useSession } from '@/lib/auth/client'
3634import { CHAT_PLAN_REQUIRED_REASON } from '@/lib/billing/chat-plan'
37- import {
38- buildHostedUpgradeUrl ,
39- buildUpgradeHref ,
40- HOSTED_BILLING_SETTINGS_URL ,
41- } from '@/lib/billing/upgrade-reasons'
42- import { canManageWorkspaceBilling } from '@/lib/billing/workspace-permissions'
4335import { isBrowserAgentAvailable , sendBrowserPanelAction } from '@/lib/browser-agent/transport'
44- import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
4536import { isSafeHttpUrl } from '@/lib/core/utils/urls'
4637import { readLatestOAuthChatAttempt } from '@/lib/credentials/oauth-chat-attempt'
4738import { getDesktopBridge } from '@/lib/desktop'
@@ -64,7 +55,6 @@ import { OAUTH_PROVIDERS } from '@/lib/oauth/oauth'
6455import { getServiceConfigByProviderId } from '@/lib/oauth/utils'
6556import { organizationSecretNameSchema } from '@/lib/organization-secrets/validation'
6657import { finishTerminalHandoff , isTerminalAvailable } from '@/lib/terminal/transport'
67- import { useOptionalOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
6858import { useChatSurface } from '@/app/workspace/[workspaceId]/home/components/chat-surface-context'
6959import { ContextMentionIcon } from '@/app/workspace/[workspaceId]/home/components/context-mention-icon'
7060import {
@@ -93,6 +83,7 @@ import {
9383} from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/use-oauth-chip-connection'
9484import { usePersonalCredentialConnection } from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/use-personal-credential-connection'
9585import { ResourceWorkspaceHost } from '@/app/workspace/[workspaceId]/home/components/resource-workspace-host'
86+ import { usePlanUpgradeLink } from '@/app/workspace/[workspaceId]/home/hooks/use-plan-upgrade-link'
9687import type {
9788 ChatMessageContext ,
9889 MothershipResource ,
@@ -121,7 +112,6 @@ import { useTablesList } from '@/hooks/queries/tables'
121112import { useWorkflows } from '@/hooks/queries/workflows'
122113import { useWorkspaceFileAtPath , useWorkspaceFileLookup } from '@/hooks/queries/workspace-files'
123114import { useWorkspaceUsageGate } from '@/hooks/queries/workspace-usage'
124- import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
125115
126116export interface OptionsItemData {
127117 title : string
@@ -3500,45 +3490,14 @@ interface PlanUsageLimitDisplayProps {
35003490 * The payer's plan limit, or a free plan that does not include Chat: the card links to where
35013491 * the plan or the limit can change, and a workspace's plan to its upgrade page.
35023492 */
3503- export function PlanUsageLimitDisplay ( { data } : PlanUsageLimitDisplayProps ) {
3504- const { data : session } = useSession ( )
3493+ function PlanUsageLimitDisplay ( { data } : PlanUsageLimitDisplayProps ) {
35053494 const hostContext = useOptionalWorkspaceHostContext ( )
3506- const organizationContext = useOptionalOrganizationContext ( )
3507- const { getSettingsHref } = useSettingsNavigation ( )
3508- const { hosted } = useDeploymentShape ( )
3509- const navigationTarget = useSettingsNavigationTarget ( )
3510- const opensInNewTab = ! hosted || navigationTarget === '_blank'
3495+ const { href, opensInNewTab, buttonLabel, canManageBilling, unavailableMessage } =
3496+ usePlanUpgradeLink ( data )
35113497 const planRequired = data . reason === CHAT_PLAN_REQUIRED_REASON
3512- const buttonLabel = data . action === 'upgrade_plan' ? 'Upgrade Plan' : 'Increase Limit'
3513-
3514- // Self-hosted plan and limit both live on the hosted account, so local
3515- // workspace billing roles say nothing about who may change them.
3516- const href = hosted
3517- ? organizationContext
3518- ? getOrganizationSettingsHref ( organizationContext . organization . id , 'billing' )
3519- : planRequired && hostContext
3520- ? buildUpgradeHref ( hostContext . workspace . id )
3521- : getSettingsHref ( { section : 'billing' } )
3522- : data . action === 'upgrade_plan'
3523- ? buildHostedUpgradeUrl ( )
3524- : HOSTED_BILLING_SETTINGS_URL
3525- const canManageBilling =
3526- ! hosted ||
3527- ( organizationContext
3528- ? organizationContext . viewer . isAdmin
3529- : Boolean ( hostContext && canManageWorkspaceBilling ( hostContext , session ?. user ?. id ) ) )
35303498 const usageGate = useWorkspaceUsageGate (
35313499 data . action === 'increase_limit' && ! canManageBilling ? hostContext ?. workspace . id : undefined
35323500 )
3533- const action = planRequired
3534- ? 'upgrade this workspace’s plan'
3535- : 'manage this workspace’s usage limits'
3536- const unavailableMessage =
3537- organizationContext && ! planRequired
3538- ? 'Contact an organization admin to manage usage limits.'
3539- : organizationContext || hostContext ?. hostOrganizationId
3540- ? `Contact an organization admin to ${ action } .`
3541- : `Only the workspace owner can ${ action } .`
35423501
35433502 return (
35443503 < InteractionCard
0 commit comments