Skip to content

Commit

Permalink
馃毟 (billing) Improve upgrade UX for non admin
Browse files Browse the repository at this point in the history
Closes #1299
  • Loading branch information
baptisteArno committed Mar 12, 2024
1 parent ecec702 commit 1f40a4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { Stack } from '@chakra-ui/react'
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
import { Plan } from '@typebot.io/prisma'
import React from 'react'
import { InvoicesList } from './InvoicesList'
import { ChangePlanForm } from './ChangePlanForm'
import { UsageProgressBars } from './UsageProgressBars'
import { CurrentSubscriptionSummary } from './CurrentSubscriptionSummary'

export const BillingSettingsLayout = () => {
const { workspace } = useWorkspace()
const { workspace, currentRole } = useWorkspace()

if (!workspace) return null
return (
<Stack spacing="10" w="full">
<UsageProgressBars workspace={workspace} />
<Stack spacing="4">
<CurrentSubscriptionSummary workspace={workspace} />
{workspace.plan !== Plan.CUSTOM &&
workspace.plan !== Plan.LIFETIME &&
workspace.plan !== Plan.UNLIMITED &&
workspace.plan !== Plan.OFFERED && (
<ChangePlanForm workspace={workspace} />
)}
<ChangePlanForm workspace={workspace} currentRole={currentRole} />
</Stack>

{workspace.stripeId && <InvoicesList workspaceId={workspace.id} />}
Expand Down
23 changes: 21 additions & 2 deletions apps/builder/src/features/billing/components/ChangePlanForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 { useToast } from '@/hooks/useToast'
import { trpc } from '@/lib/trpc'
Expand All @@ -16,10 +16,15 @@ import { WorkspaceInApp } from '@/features/workspace/WorkspaceProvider'

type Props = {
workspace: WorkspaceInApp
currentRole?: WorkspaceRole
excludedPlans?: ('STARTER' | 'PRO')[]
}

export const ChangePlanForm = ({ workspace, excludedPlans }: Props) => {
export const ChangePlanForm = ({
workspace,
currentRole,
excludedPlans,
}: Props) => {
const { t } = useTranslate()

const { user } = useUser()
Expand Down Expand Up @@ -82,6 +87,20 @@ export const ChangePlanForm = ({ workspace, excludedPlans }: Props) => {
)
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 (
<Stack spacing={6}>
<HStack maxW="500px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const ChangePlanModal = ({
excludedPlans,
}: ChangePlanModalProps) => {
const { t } = useTranslate()
const { workspace } = useWorkspace()
const { workspace, currentRole } = useWorkspace()

return (
<Modal
isOpen={isOpen}
Expand All @@ -46,6 +47,7 @@ export const ChangePlanModal = ({
<ChangePlanForm
workspace={workspace}
excludedPlans={excludedPlans}
currentRole={currentRole}
/>
)}
</ModalBody>
Expand Down

0 comments on commit 1f40a4d

Please sign in to comment.