2023-09-12 13:17:14 +02:00
|
|
|
import {
|
|
|
|
|
Text,
|
|
|
|
|
HStack,
|
|
|
|
|
Stack,
|
|
|
|
|
Heading,
|
|
|
|
|
Alert,
|
|
|
|
|
AlertIcon,
|
|
|
|
|
} from '@chakra-ui/react'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { Plan } from '@typebot.io/prisma'
|
2023-02-17 16:19:39 +01:00
|
|
|
import React from 'react'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { PlanTag } from './PlanTag'
|
2023-02-17 16:19:39 +01:00
|
|
|
import { BillingPortalButton } from './BillingPortalButton'
|
|
|
|
|
import { trpc } from '@/lib/trpc'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { Workspace } from '@typebot.io/schemas'
|
2023-04-06 17:31:23 +02:00
|
|
|
import { useScopedI18n } from '@/locales'
|
2022-09-17 16:37:33 +02:00
|
|
|
|
2023-03-15 11:51:30 +01:00
|
|
|
type Props = {
|
2023-02-17 16:19:39 +01:00
|
|
|
workspace: Pick<Workspace, 'id' | 'plan' | 'stripeId'>
|
2022-09-17 16:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-13 11:39:10 +02:00
|
|
|
export const CurrentSubscriptionSummary = ({ workspace }: Props) => {
|
2023-04-06 17:31:23 +02:00
|
|
|
const scopedT = useScopedI18n('billing.currentSubscription')
|
2022-09-17 16:37:33 +02:00
|
|
|
|
2023-04-13 11:39:10 +02:00
|
|
|
const { data } = trpc.billing.getSubscription.useQuery({
|
|
|
|
|
workspaceId: workspace.id,
|
|
|
|
|
})
|
2022-09-17 16:37:33 +02:00
|
|
|
|
2023-02-17 16:19:39 +01:00
|
|
|
const isSubscribed =
|
|
|
|
|
(workspace.plan === Plan.STARTER || workspace.plan === Plan.PRO) &&
|
|
|
|
|
workspace.stripeId
|
2022-09-18 19:01:37 +02:00
|
|
|
|
2022-09-17 16:37:33 +02:00
|
|
|
return (
|
2022-12-20 16:55:43 +01:00
|
|
|
<Stack spacing="4">
|
2023-04-06 17:31:23 +02:00
|
|
|
<Heading fontSize="3xl">{scopedT('heading')}</Heading>
|
2022-10-01 08:36:49 +02:00
|
|
|
<HStack data-testid="current-subscription">
|
2023-04-06 17:31:23 +02:00
|
|
|
<Text>{scopedT('subheading')} </Text>
|
2023-04-13 11:39:10 +02:00
|
|
|
<PlanTag plan={workspace.plan} />
|
|
|
|
|
{data?.subscription?.cancelDate && (
|
|
|
|
|
<Text fontSize="sm">
|
2023-09-05 18:15:59 +02:00
|
|
|
({scopedT('cancelDate')}{' '}
|
|
|
|
|
{data.subscription.cancelDate.toDateString()})
|
2023-04-13 11:39:10 +02:00
|
|
|
</Text>
|
2022-09-18 19:01:37 +02:00
|
|
|
)}
|
2022-09-17 16:37:33 +02:00
|
|
|
</HStack>
|
2023-09-12 13:17:14 +02:00
|
|
|
{data?.subscription?.status === 'past_due' && (
|
|
|
|
|
<Alert fontSize="sm" status="error">
|
|
|
|
|
<AlertIcon />
|
|
|
|
|
{scopedT('pastDueAlert')}
|
|
|
|
|
</Alert>
|
|
|
|
|
)}
|
2022-09-17 16:37:33 +02:00
|
|
|
|
2023-09-12 13:17:14 +02:00
|
|
|
{isSubscribed && (
|
|
|
|
|
<BillingPortalButton
|
|
|
|
|
workspaceId={workspace.id}
|
|
|
|
|
colorScheme={
|
|
|
|
|
data?.subscription?.status === 'past_due' ? 'blue' : undefined
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-09-17 16:37:33 +02:00
|
|
|
</Stack>
|
|
|
|
|
)
|
|
|
|
|
}
|