-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collects required company name and email and create the customer before redirecting to checkout
- Loading branch information
1 parent
c1a636b
commit 26e5d9c
Showing
5 changed files
with
161 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
apps/builder/src/features/billing/components/PreCheckoutModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { TextInput } from '@/components/inputs' | ||
import { useToast } from '@/hooks/useToast' | ||
import { trpc } from '@/lib/trpc' | ||
import { | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalOverlay, | ||
Stack, | ||
} from '@chakra-ui/react' | ||
import { useRouter } from 'next/router' | ||
import React, { FormEvent, useState } from 'react' | ||
import { isDefined } from 'utils' | ||
|
||
export type PreCheckoutModalProps = { | ||
selectedSubscription: | ||
| { | ||
plan: 'STARTER' | 'PRO' | ||
workspaceId: string | ||
additionalChats: number | ||
additionalStorage: number | ||
currency: 'eur' | 'usd' | ||
} | ||
| undefined | ||
existingCompany?: string | ||
existingEmail?: string | ||
onClose: () => void | ||
} | ||
|
||
export const PreCheckoutModal = ({ | ||
selectedSubscription, | ||
existingCompany, | ||
existingEmail, | ||
onClose, | ||
}: PreCheckoutModalProps) => { | ||
const router = useRouter() | ||
const { showToast } = useToast() | ||
const { mutate: createCheckoutSession, isLoading: isCreatingCheckout } = | ||
trpc.billing.createCheckoutSession.useMutation({ | ||
onError: (error) => { | ||
showToast({ | ||
description: error.message, | ||
}) | ||
}, | ||
onSuccess: ({ checkoutUrl }) => { | ||
router.push(checkoutUrl) | ||
}, | ||
}) | ||
|
||
const [customer, setCustomer] = useState({ | ||
company: existingCompany ?? '', | ||
email: existingEmail ?? '', | ||
}) | ||
|
||
const updateCustomerCompany = (company: string) => { | ||
setCustomer((customer) => ({ ...customer, company })) | ||
} | ||
|
||
const updateCustomerEmail = (email: string) => { | ||
setCustomer((customer) => ({ ...customer, email })) | ||
} | ||
|
||
const createCustomer = (e: FormEvent) => { | ||
e.preventDefault() | ||
if (!selectedSubscription) return | ||
createCheckoutSession({ | ||
...selectedSubscription, | ||
email: customer.email, | ||
company: customer.company, | ||
returnUrl: window.location.href, | ||
}) | ||
} | ||
|
||
return ( | ||
<Modal isOpen={isDefined(selectedSubscription)} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalBody py="8"> | ||
<Stack as="form" onSubmit={createCustomer} spacing="4"> | ||
<TextInput | ||
isRequired | ||
label="Company name" | ||
defaultValue={customer.company} | ||
onChange={updateCustomerCompany} | ||
withVariableButton={false} | ||
debounceTimeout={0} | ||
/> | ||
<TextInput | ||
isRequired | ||
type="email" | ||
label="Email" | ||
defaultValue={customer.email} | ||
onChange={updateCustomerEmail} | ||
withVariableButton={false} | ||
debounceTimeout={0} | ||
/> | ||
<Button | ||
type="submit" | ||
isLoading={isCreatingCheckout} | ||
colorScheme="blue" | ||
isDisabled={customer.company === '' || customer.email === ''} | ||
> | ||
Go to checkout | ||
</Button> | ||
</Stack> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26e5d9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
bot.winglabs.com.br
carsalesenquiry.com
chat.marius.digital
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.reventepro.com
typebot.stillio.com
wordsandimagery.com
88584434.therpm.club
92109660.therpm.club
abbonamento.bwell.it
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.cotemeuplano.com
bot.leadbooster.help
bot.mycompay.reviews
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
forms.bonanza.design
hello.advergreen.com
kuiz.sistemniaga.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
acelera.maxbot.com.br
aidigitalmarketing.kr
bbutton.wpwakanda.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.incusservices.com
bot.meuesocial.com.br
bot.mycompany.reviews
bot.outstandbrand.com
bot.ramonmatos.com.br
newsletter.itshcormeos.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
jcapp.virtuesocialmedia.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
jc-app.virtuesocialmedia.com
piazzatorre.barrettamario.it
type.cookieacademyonline.com
upload.atlasoutfittersk9.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
chrome-os-inquiry-system.itschromeos.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
26e5d9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./apps/docs
docs.typebot.io
docs-typebot-io.vercel.app
docs-git-main-typebot-io.vercel.app
26e5d9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
landing-page-v2 – ./apps/landing-page
typebot.io
landing-page-v2-git-main-typebot-io.vercel.app
www.get-typebot.com
landing-page-v2-typebot-io.vercel.app
www.typebot.io
get-typebot.com
26e5d9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app