Skip to content

Commit b81fcf0

Browse files
authored
⚡ Auto continue bot on whatsApp if starting block is input (#849)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ### Summary by CodeRabbit **New Features:** - Added WhatsApp integration feature to the Pro plan. **Refactor:** - Introduced the ability to exclude specific plans from being displayed in the Change Plan Modal. - Renamed the function `isProPlan` to `hasProPerks`, enhancing code readability and maintainability. - Updated the `EmbedButton` component to handle a new `lockTagPlan` property and use the `modal` function instead of the `Modal` component. **Chore:** - Removed the `whatsAppPhoneNumberId` field from the `Typebot` model across various files, simplifying the data structure of the model. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 459fc4d commit b81fcf0

File tree

30 files changed

+224
-140
lines changed

30 files changed

+224
-140
lines changed

apps/builder/src/components/UnlockPlanAlertInfo.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ import {
88
useDisclosure,
99
} from '@chakra-ui/react'
1010
import React from 'react'
11-
import { ChangePlanModal } from '@/features/billing/components/ChangePlanModal'
11+
import {
12+
ChangePlanModal,
13+
ChangePlanModalProps,
14+
} from '@/features/billing/components/ChangePlanModal'
1215
import { useI18n } from '@/locales'
1316

1417
type Props = {
1518
contentLabel: React.ReactNode
1619
buttonLabel?: string
17-
type?: string
18-
} & AlertProps
20+
} & AlertProps &
21+
Pick<ChangePlanModalProps, 'type' | 'excludedPlans'>
1922

2023
export const UnlockPlanAlertInfo = ({
2124
contentLabel,
2225
buttonLabel,
2326
type,
27+
excludedPlans,
2428
...props
2529
}: Props) => {
2630
const t = useI18n()
@@ -45,7 +49,12 @@ export const UnlockPlanAlertInfo = ({
4549
>
4650
{buttonLabel ?? t('billing.upgradeAlert.buttonDefaultLabel')}
4751
</Button>
48-
<ChangePlanModal isOpen={isOpen} onClose={onClose} type={type} />
52+
<ChangePlanModal
53+
isOpen={isOpen}
54+
onClose={onClose}
55+
type={type}
56+
excludedPlans={excludedPlans}
57+
/>
4958
</Alert>
5059
)
5160
}

apps/builder/src/features/analytics/components/AnalyticsGraphContainer.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export const AnalyticsGraphContainer = ({ stats }: { stats?: Stats }) => {
8282
onClose={onClose}
8383
isOpen={isOpen}
8484
type={t('billing.limitMessage.analytics')}
85+
excludedPlans={['STARTER']}
8586
/>
8687
<StatsCards stats={stats} pos="absolute" />
8788
</Flex>

apps/builder/src/features/billing/components/ChangePlanForm.tsx

+26-21
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import { StripeClimateLogo } from './StripeClimateLogo'
1616

1717
type Props = {
1818
workspace: Workspace
19+
excludedPlans?: ('STARTER' | 'PRO')[]
1920
}
2021

21-
export const ChangePlanForm = ({ workspace }: Props) => {
22+
export const ChangePlanForm = ({ workspace, excludedPlans }: Props) => {
2223
const scopedT = useScopedI18n('billing')
2324

2425
const { user } = useUser()
@@ -133,27 +134,31 @@ export const ChangePlanForm = ({ workspace }: Props) => {
133134
</HStack>
134135
</HStack>
135136
<HStack alignItems="stretch" spacing="4" w="full">
136-
<StarterPlanPricingCard
137-
workspace={workspace}
138-
currentSubscription={{ isYearly: data.subscription?.isYearly }}
139-
onPayClick={(props) =>
140-
handlePayClick({ ...props, plan: Plan.STARTER })
141-
}
142-
isYearly={isYearly}
143-
isLoading={isUpdatingSubscription}
144-
currency={data.subscription?.currency}
145-
/>
137+
{excludedPlans?.includes('STARTER') ? null : (
138+
<StarterPlanPricingCard
139+
workspace={workspace}
140+
currentSubscription={{ isYearly: data.subscription?.isYearly }}
141+
onPayClick={(props) =>
142+
handlePayClick({ ...props, plan: Plan.STARTER })
143+
}
144+
isYearly={isYearly}
145+
isLoading={isUpdatingSubscription}
146+
currency={data.subscription?.currency}
147+
/>
148+
)}
146149

147-
<ProPlanPricingCard
148-
workspace={workspace}
149-
currentSubscription={{ isYearly: data.subscription?.isYearly }}
150-
onPayClick={(props) =>
151-
handlePayClick({ ...props, plan: Plan.PRO })
152-
}
153-
isYearly={isYearly}
154-
isLoading={isUpdatingSubscription}
155-
currency={data.subscription?.currency}
156-
/>
150+
{excludedPlans?.includes('PRO') ? null : (
151+
<ProPlanPricingCard
152+
workspace={workspace}
153+
currentSubscription={{ isYearly: data.subscription?.isYearly }}
154+
onPayClick={(props) =>
155+
handlePayClick({ ...props, plan: Plan.PRO })
156+
}
157+
isYearly={isYearly}
158+
isLoading={isUpdatingSubscription}
159+
currency={data.subscription?.currency}
160+
/>
161+
)}
157162
</HStack>
158163
</Stack>
159164
)}

apps/builder/src/features/billing/components/ChangePlanModal.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ import {
1313
} from '@chakra-ui/react'
1414
import { ChangePlanForm } from './ChangePlanForm'
1515

16-
type ChangePlanModalProps = {
16+
export type ChangePlanModalProps = {
1717
type?: string
1818
isOpen: boolean
19+
excludedPlans?: ('STARTER' | 'PRO')[]
1920
onClose: () => void
2021
}
2122

2223
export const ChangePlanModal = ({
2324
onClose,
2425
isOpen,
2526
type,
27+
excludedPlans,
2628
}: ChangePlanModalProps) => {
2729
const t = useI18n()
2830
const { workspace } = useWorkspace()
2931
return (
30-
<Modal isOpen={isOpen} onClose={onClose} size="2xl">
32+
<Modal
33+
isOpen={isOpen}
34+
onClose={onClose}
35+
size={excludedPlans ? 'lg' : '2xl'}
36+
>
3137
<ModalOverlay />
3238
<ModalContent>
3339
<ModalBody as={Stack} spacing="6" pt="10">
@@ -36,7 +42,12 @@ export const ChangePlanModal = ({
3642
{t('billing.upgradeLimitLabel', { type: type })}
3743
</AlertInfo>
3844
)}
39-
{workspace && <ChangePlanForm workspace={workspace} />}
45+
{workspace && (
46+
<ChangePlanForm
47+
workspace={workspace}
48+
excludedPlans={excludedPlans}
49+
/>
50+
)}
4051
</ModalBody>
4152

4253
<ModalFooter>

apps/builder/src/features/billing/components/ProPlanPricingCard.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const ProPlanPricingCard = ({
200200
</Text>
201201
<MoreInfoTooltip>{scopedT('chatsTooltip')}</MoreInfoTooltip>
202202
</HStack>,
203+
scopedT('pro.whatsAppIntegration'),
203204
scopedT('pro.customDomains'),
204205
scopedT('pro.analytics'),
205206
]}

apps/builder/src/features/billing/components/UpgradeButton.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import { isNotDefined } from '@typebot.io/lib'
55
import { ChangePlanModal } from './ChangePlanModal'
66
import { useI18n } from '@/locales'
77

8-
type Props = { limitReachedType?: string } & ButtonProps
8+
type Props = {
9+
limitReachedType?: string
10+
excludedPlans?: ('STARTER' | 'PRO')[]
11+
} & ButtonProps
912

10-
export const UpgradeButton = ({ limitReachedType, ...props }: Props) => {
13+
export const UpgradeButton = ({
14+
limitReachedType,
15+
excludedPlans,
16+
...props
17+
}: Props) => {
1118
const t = useI18n()
1219
const { isOpen, onOpen, onClose } = useDisclosure()
1320
const { workspace } = useWorkspace()
@@ -23,6 +30,7 @@ export const UpgradeButton = ({ limitReachedType, ...props }: Props) => {
2330
isOpen={isOpen}
2431
onClose={onClose}
2532
type={limitReachedType}
33+
excludedPlans={excludedPlans}
2634
/>
2735
</Button>
2836
)

apps/builder/src/features/billing/helpers/isProPlan.ts renamed to apps/builder/src/features/billing/helpers/hasProPerks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isDefined } from '@typebot.io/lib'
22
import { Workspace, Plan } from '@typebot.io/prisma'
33

4-
export const isProPlan = (workspace?: Pick<Workspace, 'plan'>) =>
4+
export const hasProPerks = (workspace?: Pick<Workspace, 'plan'>) =>
55
isDefined(workspace) &&
66
(workspace.plan === Plan.PRO ||
77
workspace.plan === Plan.LIFETIME ||

apps/builder/src/features/graph/components/edges/DropOffEdge.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
1111
import React, { useMemo } from 'react'
1212
import { useEndpoints } from '../../providers/EndpointsProvider'
1313
import { useGroupsCoordinates } from '../../providers/GroupsCoordinateProvider'
14-
import { isProPlan } from '@/features/billing/helpers/isProPlan'
14+
import { hasProPerks } from '@/features/billing/helpers/hasProPerks'
1515
import { computeDropOffPath } from '../../helpers/computeDropOffPath'
1616
import { computeSourceCoordinates } from '../../helpers/computeSourceCoordinates'
1717
import { TotalAnswersInBlock } from '@typebot.io/schemas/features/analytics'
@@ -64,7 +64,7 @@ export const DropOffEdge = ({
6464
[blockId, totalAnswersInBlocks]
6565
)
6666

67-
const isWorkspaceProPlan = isProPlan(workspace)
67+
const isWorkspaceProPlan = hasProPerks(workspace)
6868

6969
const { totalDroppedUser, dropOffRate } = useMemo(() => {
7070
if (!publishedTypebot || currentBlock?.total === undefined)

apps/builder/src/features/publish/components/SharePage.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { integrationsList } from './embeds/EmbedButton'
2020
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
2121
import { LockTag } from '@/features/billing/components/LockTag'
2222
import { UpgradeButton } from '@/features/billing/components/UpgradeButton'
23-
import { isProPlan } from '@/features/billing/helpers/isProPlan'
23+
import { hasProPerks } from '@/features/billing/helpers/hasProPerks'
2424
import { CustomDomainsDropdown } from '@/features/customDomains/components/CustomDomainsDropdown'
2525
import { TypebotHeader } from '@/features/editor/components/TypebotHeader'
2626
import { parseDefaultPublicId } from '../helpers/parseDefaultPublicId'
@@ -130,14 +130,15 @@ export const SharePage = () => {
130130
{isNotDefined(typebot?.customDomain) &&
131131
env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME ? (
132132
<>
133-
{isProPlan(workspace) ? (
133+
{hasProPerks(workspace) ? (
134134
<CustomDomainsDropdown
135135
onCustomDomainSelect={handleCustomDomainChange}
136136
/>
137137
) : (
138138
<UpgradeButton
139139
colorScheme="gray"
140140
limitReachedType={t('billing.limitMessage.customDomain')}
141+
excludedPlans={[Plan.STARTER]}
141142
>
142143
<Text mr="2">Add my domain</Text>{' '}
143144
<LockTag plan={Plan.PRO} />

0 commit comments

Comments
 (0)