Skip to content

Commit

Permalink
✨ (lp) Add new pricing page
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Sep 27, 2022
1 parent d8b1d8a commit c94a658
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ export const BillingContent = () => {
if (!workspace) return null
return (
<Stack spacing="10" w="full">
<CurrentSubscriptionContent
plan={workspace.plan}
stripeId={workspace.stripeId}
onCancelSuccess={() =>
refreshWorkspace({
plan: Plan.FREE,
additionalChatsIndex: 0,
additionalStorageIndex: 0,
})
}
/>
<UsageContent workspace={workspace} />
{workspace.plan !== Plan.LIFETIME && workspace.plan !== Plan.OFFERED && (
<ChangePlanForm />
)}
<Stack gap="2">
<CurrentSubscriptionContent
plan={workspace.plan}
stripeId={workspace.stripeId}
onCancelSuccess={() =>
refreshWorkspace({
plan: Plan.FREE,
additionalChatsIndex: 0,
additionalStorageIndex: 0,
})
}
/>
{workspace.plan !== Plan.LIFETIME &&
workspace.plan !== Plan.OFFERED && <ChangePlanForm />}
</Stack>

{workspace.stripeId && <InvoicesList workspace={workspace} />}
</Stack>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
Link,
Spinner,
Stack,
Flex,
Button,
Heading,
} from '@chakra-ui/react'
import { PlanTag } from 'components/shared/PlanTag'
import { Plan } from 'db'
Expand Down Expand Up @@ -35,15 +35,29 @@ export const CurrentSubscriptionContent = ({
setIsCancelling(false)
}

const isSubscribed = (plan === Plan.STARTER || plan === Plan.PRO) && stripeId

if (isCancelling) return <Spinner colorScheme="gray" />
return (
<Stack gap="2">
<Heading fontSize="3xl">Subscription</Heading>
<HStack>
<Text>Current workspace subscription: </Text>
<PlanTag plan={plan} />
{isSubscribed && (
<Link
as="button"
color="gray.500"
textDecor="underline"
fontSize="sm"
onClick={cancelSubscription}
>
Cancel my subscription
</Link>
)}
</HStack>

{(plan === Plan.STARTER || plan === Plan.PRO) && stripeId && (
{isSubscribed && (
<>
<Stack gap="1">
<Text fontSize="sm">
Expand All @@ -59,17 +73,6 @@ export const CurrentSubscriptionContent = ({
Billing Portal
</Button>
</Stack>
<Flex>
<Link
as="button"
color="gray.500"
textDecor="underline"
fontSize="sm"
onClick={cancelSubscription}
>
Cancel my subscription
</Link>
</Flex>
</>
)}
</Stack>
Expand Down
11 changes: 1 addition & 10 deletions apps/builder/components/shared/ChangePlanForm/ChangePlanForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,7 @@ export const ChangePlanForm = () => {

return (
<Stack spacing={4}>
<HStack
alignItems="stretch"
spacing="4"
w="full"
pt={
workspace?.plan === Plan.STARTER || workspace?.plan === Plan.PRO
? '10'
: '0'
}
>
<HStack alignItems="stretch" spacing="4" w="full">
<StarterPlanContent
initialChatsLimitIndex={
workspace?.plan === Plan.STARTER ? data?.additionalChatsIndex : 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
getStorageLimit,
storageLimit,
parseNumberWithCommas,
formatPrice,
computePrice,
} from 'utils'
import { MoreInfoTooltip } from '../MoreInfoTooltip'
import { FeaturesList } from './components/FeaturesList'
import { computePrice, formatPrice } from './helpers'

type ProPlanContentProps = {
initialChatsLimitIndex?: number
Expand Down Expand Up @@ -72,8 +73,6 @@ export const ProPlanContent = ({
? getStorageLimit(workspace)
: undefined

console.log('workspaceChatsLimit', workspaceChatsLimit)
console.log('workspaceStorageLimit', workspace)
const isCurrentPlan =
chatsLimit[Plan.PRO].totalIncluded +
chatsLimit[Plan.PRO].increaseStep.amount *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import {
getStorageLimit,
storageLimit,
parseNumberWithCommas,
computePrice,
formatPrice,
} from 'utils'
import { MoreInfoTooltip } from '../MoreInfoTooltip'
import { FeaturesList } from './components/FeaturesList'
import { computePrice, formatPrice } from './helpers'

type StarterPlanContentProps = {
initialChatsLimitIndex?: number
Expand Down
86 changes: 0 additions & 86 deletions apps/builder/components/shared/ChangePlanForm/helpers.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { loadStripe } from '@stripe/stripe-js/pure'
import { Plan, User } from 'db'
import { env, isDefined, isEmpty, sendRequest } from 'utils'
import { guessIfUserIsEuropean } from '../helpers'
import {
env,
guessIfUserIsEuropean,
isDefined,
isEmpty,
sendRequest,
} from 'utils'

type UpgradeProps = {
user: User
Expand Down
4 changes: 0 additions & 4 deletions apps/builder/pages/api/stripe/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ const updateSubscription = async (req: NextApiRequest) => {
}
: undefined,
].filter(isDefined)
console.log(items)
await stripe.subscriptions.update(subscription.id, {
items,
})
Expand All @@ -171,7 +170,6 @@ const updateSubscription = async (req: NextApiRequest) => {

const cancelSubscription =
(req: NextApiRequest, res: NextApiResponse) => async (userId: string) => {
console.log(req.query.stripeId, userId)
const stripeId = req.query.stripeId as string | undefined
if (!stripeId) return badRequest(res)
if (!process.env.STRIPE_SECRET_KEY)
Expand All @@ -189,9 +187,7 @@ const cancelSubscription =
const existingSubscription = await stripe.subscriptions.list({
customer: workspace.stripeId,
})
console.log('yes')
await stripe.subscriptions.del(existingSubscription.data[0].id)
console.log('deleted')
await prisma.workspace.update({
where: { id: workspace.id },
data: {
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/pages/typebots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const DashboardPage = () => {
const { workspace } = useWorkspace()

useEffect(() => {
const subscribePlan = query.subscribePlan as 'pro' | 'starter' | undefined
const subscribePlan = query.subscribePlan as Plan | undefined
if (workspace && subscribePlan && user && workspace.plan === 'FREE') {
setIsLoading(true)
pay({
user,
plan: subscribePlan === 'pro' ? Plan.PRO : Plan.STARTER,
plan: subscribePlan,
workspaceId: workspace.id,
additionalChats: 0,
additionalStorage: 0,
Expand Down
3 changes: 0 additions & 3 deletions apps/builder/pages/typebots/[typebotId]/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const ResultsPage = () => {
})
const { data: usageData } = useUsage(workspace?.id)

console.log(workspace?.id, usageData)

const chatsLimitPercentage = useMemo(() => {
if (!usageData?.totalChatsUsed || !workspace?.plan) return 0
return Math.round(
Expand All @@ -53,7 +51,6 @@ const ResultsPage = () => {
])

const storageLimitPercentage = useMemo(() => {
console.log(usageData?.totalStorageUsed)
if (!usageData?.totalStorageUsed || !workspace?.plan) return 0
return Math.round(
(usageData.totalStorageUsed /
Expand Down
Loading

0 comments on commit c94a658

Please sign in to comment.