2
0

🚸 (billing) Improve upgrade UX for non admin

Closes #1299
This commit is contained in:
Baptiste Arnaud
2024-03-12 18:12:13 +01:00
parent ecec7023b9
commit 1f40a4d758
3 changed files with 26 additions and 11 deletions

View File

@@ -1,6 +1,5 @@
import { Stack } from '@chakra-ui/react' import { Stack } from '@chakra-ui/react'
import { useWorkspace } from '@/features/workspace/WorkspaceProvider' import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
import { Plan } from '@typebot.io/prisma'
import React from 'react' import React from 'react'
import { InvoicesList } from './InvoicesList' import { InvoicesList } from './InvoicesList'
import { ChangePlanForm } from './ChangePlanForm' import { ChangePlanForm } from './ChangePlanForm'
@@ -8,7 +7,7 @@ import { UsageProgressBars } from './UsageProgressBars'
import { CurrentSubscriptionSummary } from './CurrentSubscriptionSummary' import { CurrentSubscriptionSummary } from './CurrentSubscriptionSummary'
export const BillingSettingsLayout = () => { export const BillingSettingsLayout = () => {
const { workspace } = useWorkspace() const { workspace, currentRole } = useWorkspace()
if (!workspace) return null if (!workspace) return null
return ( return (
@@ -16,12 +15,7 @@ export const BillingSettingsLayout = () => {
<UsageProgressBars workspace={workspace} /> <UsageProgressBars workspace={workspace} />
<Stack spacing="4"> <Stack spacing="4">
<CurrentSubscriptionSummary workspace={workspace} /> <CurrentSubscriptionSummary workspace={workspace} />
{workspace.plan !== Plan.CUSTOM && <ChangePlanForm workspace={workspace} currentRole={currentRole} />
workspace.plan !== Plan.LIFETIME &&
workspace.plan !== Plan.UNLIMITED &&
workspace.plan !== Plan.OFFERED && (
<ChangePlanForm workspace={workspace} />
)}
</Stack> </Stack>
{workspace.stripeId && <InvoicesList workspaceId={workspace.id} />} {workspace.stripeId && <InvoicesList workspaceId={workspace.id} />}

View File

@@ -1,5 +1,5 @@
import { Stack, HStack, Text } from '@chakra-ui/react' import { Stack, HStack, Text } from '@chakra-ui/react'
import { Plan } from '@typebot.io/prisma' import { Plan, WorkspaceRole } from '@typebot.io/prisma'
import { TextLink } from '@/components/TextLink' import { TextLink } from '@/components/TextLink'
import { useToast } from '@/hooks/useToast' import { useToast } from '@/hooks/useToast'
import { trpc } from '@/lib/trpc' import { trpc } from '@/lib/trpc'
@@ -16,10 +16,15 @@ import { WorkspaceInApp } from '@/features/workspace/WorkspaceProvider'
type Props = { type Props = {
workspace: WorkspaceInApp workspace: WorkspaceInApp
currentRole?: WorkspaceRole
excludedPlans?: ('STARTER' | 'PRO')[] excludedPlans?: ('STARTER' | 'PRO')[]
} }
export const ChangePlanForm = ({ workspace, excludedPlans }: Props) => { export const ChangePlanForm = ({
workspace,
currentRole,
excludedPlans,
}: Props) => {
const { t } = useTranslate() const { t } = useTranslate()
const { user } = useUser() const { user } = useUser()
@@ -82,6 +87,20 @@ export const ChangePlanForm = ({ workspace, excludedPlans }: Props) => {
) )
return null return null
const isSubscribed =
(workspace.plan === Plan.STARTER || workspace.plan === Plan.PRO) &&
workspace.stripeId
if (workspace.plan !== Plan.FREE && !isSubscribed) return null
if (currentRole !== WorkspaceRole.ADMIN)
return (
<Text>
Only workspace admins can change the subscription plan. Contact your
workspace admin to change the plan.
</Text>
)
return ( return (
<Stack spacing={6}> <Stack spacing={6}>
<HStack maxW="500px"> <HStack maxW="500px">

View File

@@ -27,7 +27,8 @@ export const ChangePlanModal = ({
excludedPlans, excludedPlans,
}: ChangePlanModalProps) => { }: ChangePlanModalProps) => {
const { t } = useTranslate() const { t } = useTranslate()
const { workspace } = useWorkspace() const { workspace, currentRole } = useWorkspace()
return ( return (
<Modal <Modal
isOpen={isOpen} isOpen={isOpen}
@@ -46,6 +47,7 @@ export const ChangePlanModal = ({
<ChangePlanForm <ChangePlanForm
workspace={workspace} workspace={workspace}
excludedPlans={excludedPlans} excludedPlans={excludedPlans}
currentRole={currentRole}
/> />
)} )}
</ModalBody> </ModalBody>