import { Text, HStack, Link, Spinner, Stack, Heading } from '@chakra-ui/react' import { useToast } from '@/hooks/useToast' import { Plan } from '@typebot.io/prisma' import React from 'react' import { PlanTag } from '../PlanTag' import { BillingPortalButton } from './BillingPortalButton' import { trpc } from '@/lib/trpc' import { Workspace } from '@typebot.io/schemas' type CurrentSubscriptionContentProps = { workspace: Pick onCancelSuccess: () => void } export const CurrentSubscriptionContent = ({ workspace, onCancelSuccess, }: CurrentSubscriptionContentProps) => { const { showToast } = useToast() const { mutate: cancelSubscription, isLoading: isCancelling } = trpc.billing.cancelSubscription.useMutation({ onError: (error) => { showToast({ description: error.message, }) }, onSuccess: onCancelSuccess, }) const isSubscribed = (workspace.plan === Plan.STARTER || workspace.plan === Plan.PRO) && workspace.stripeId return ( Subscription Current workspace subscription: {isCancelling ? ( ) : ( <> {isSubscribed && ( cancelSubscription({ workspaceId: workspace.id }) } > Cancel my subscription )} )} {isSubscribed && !isCancelling && ( <> Need to change payment method or billing information? Head over to your billing portal: )} ) }