Skip to content

Commit

Permalink
⚡ (payment) Add address in payment input
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 5, 2023
1 parent b9f94cd commit c469912
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
Stack,
Accordion,
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
} from '@chakra-ui/react'
import React from 'react'
import { TextInput } from '@/components/inputs'
import { PaymentAddress } from '@typebot.io/schemas'

type Props = {
address: PaymentAddress
onAddressChange: (address: PaymentAddress) => void
}

export const PaymentAddressSettings = ({ address, onAddressChange }: Props) => {
const updateCountry = (country: string) =>
onAddressChange({
...address,
country,
})

const updateLine1 = (line1: string) =>
onAddressChange({
...address,
line1,
})

const updateLine2 = (line2: string) =>
onAddressChange({
...address,
line2,
})

const updateCity = (city: string) =>
onAddressChange({
...address,
city,
})

const updateState = (state: string) =>
onAddressChange({
...address,
state,
})

const updatePostalCode = (postalCode: string) =>
onAddressChange({
...address,
postalCode,
})

return (
<Accordion allowToggle>
<AccordionItem>
<AccordionButton justifyContent="space-between">
Address
<AccordionIcon />
</AccordionButton>
<AccordionPanel py={4} as={Stack} spacing="4">
<TextInput
label="Country:"
defaultValue={address?.country ?? ''}
onChange={updateCountry}
/>
<TextInput
label="Line 1:"
defaultValue={address?.line1 ?? ''}
onChange={updateLine1}
/>
<TextInput
label="Line 2:"
defaultValue={address?.line2 ?? ''}
onChange={updateLine2}
/>
<TextInput
label="City:"
defaultValue={address?.city ?? ''}
onChange={updateCity}
/>
<TextInput
label="State:"
defaultValue={address?.state ?? ''}
onChange={updateState}
/>
<TextInput
label="Postal code:"
defaultValue={address?.postalCode ?? ''}
onChange={updatePostalCode}
/>
</AccordionPanel>
</AccordionItem>
</Accordion>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import {
AccordionPanel,
} from '@chakra-ui/react'
import { DropdownList } from '@/components/DropdownList'
import { PaymentInputOptions, PaymentProvider } from '@typebot.io/schemas'
import {
PaymentAddress,
PaymentInputOptions,
PaymentProvider,
} from '@typebot.io/schemas'
import React, { ChangeEvent } from 'react'
import { currencies } from '../currencies'
import { StripeConfigModal } from './StripeConfigModal'
import { CredentialsDropdown } from '@/features/credentials/components/CredentialsDropdown'
import { TextInput } from '@/components/inputs'
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
import { PaymentAddressSettings } from './PaymentAddressSettings'

type Props = {
options: PaymentInputOptions
Expand Down Expand Up @@ -90,6 +95,12 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
additionalInformation: { ...options.additionalInformation, description },
})

const updateAddress = (address: PaymentAddress) =>
onOptionsChange({
...options,
additionalInformation: { ...options.additionalInformation, address },
})

return (
<Stack spacing={4}>
<Stack>
Expand Down Expand Up @@ -152,7 +163,7 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
Additional information
<AccordionIcon />
</AccordionButton>
<AccordionPanel pb={4} as={Stack} spacing="6">
<AccordionPanel py={4} as={Stack} spacing="6">
<TextInput
label="Description:"
defaultValue={options.additionalInformation?.description ?? ''}
Expand All @@ -177,6 +188,10 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
onChange={updatePhoneNumber}
placeholder="+33XXXXXXXXX"
/>
<PaymentAddressSettings
address={options.additionalInformation?.address}
onAddressChange={updateAddress}
/>
</AccordionPanel>
</AccordionItem>
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export const StripePaymentForm = (props: Props) => {
name: props.options.additionalInformation?.name,
email: props.options.additionalInformation?.email,
phone: props.options.additionalInformation?.phoneNumber,
address: {
...props.options.additionalInformation?.address,
postal_code:
props.options.additionalInformation?.address?.postalCode,
},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions packages/schemas/features/blocks/inputs/payment/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ export type CreditCardDetails = {
cvc: string
}

const addressSchema = z.object({
country: z.string().optional(),
line1: z.string().optional(),
line2: z.string().optional(),
state: z.string().optional(),
city: z.string().optional(),
postalCode: z.string().optional(),
})

export const paymentInputOptionsSchema = optionBaseSchema.merge(
z.object({
provider: z.nativeEnum(PaymentProvider),
Expand All @@ -27,6 +36,7 @@ export const paymentInputOptionsSchema = optionBaseSchema.merge(
name: z.string().optional(),
email: z.string().optional(),
phoneNumber: z.string().optional(),
address: addressSchema.optional(),
})
.optional(),
credentialsId: z.string().optional(),
Expand Down Expand Up @@ -76,3 +86,6 @@ export type PaymentInputRuntimeOptions = z.infer<
typeof paymentInputRuntimeOptionsSchema
>
export type StripeCredentials = z.infer<typeof stripeCredentialsSchema>
export type PaymentAddress = NonNullable<
PaymentInputOptions['additionalInformation']
>['address']

4 comments on commit c469912

@vercel
Copy link

@vercel vercel bot commented on c469912 May 5, 2023

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

@vercel
Copy link

@vercel vercel bot commented on c469912 May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on c469912 May 5, 2023

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

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on c469912 May 5, 2023

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

rabbit.cr8.ai
turkey.cr8.ai
chat.webisharp.com
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
noticiasnet.online
pant.maxbot.com.br
pantherview.cr8.ai
positivobra.com.br
rollingball.cr8.ai
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
ai.digitaldaftar.in
bot.boston-voip.com
bot.cabinpromos.com
bot.carnaval.studio
bot.digitalbled.com
bot.dsignagency.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.leadgenpod.site
bot.ltmidias.com.br
bot.viralsangat.com
bot.winglabs.com.br
carsalesenquiry.com
chat.marius.digital
chat.sr7digital.com
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
hrbot.robomotion.io
inearephones.cr8.ai
kbsub.wpwakanda.com
limitenahora.com.br
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
profileadscloud.com
quest.wpwakanda.com
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.getreview.help
test.reventepro.com
typebot.stillio.com
wordsandimagery.com
88584434.therpm.club
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chat.semanalimpanome.com.br
designguide.techyscouts.com
liveconvert2.kandalearn.com
poll.mosaicohairboutique.it
presente.empresarias.com.mx
register.algorithmpress.com
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
open.campus.aalen.university
piazzatorre.barrettamario.it
poll.mosaicohairboutique.com
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
bot.cabin-rentals-of-georgia.net
open.campus.bot.aalen.university
sondaggio.mosaicohairboutique.it
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
sondaggio.mosaicohairboutique.com
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

Please sign in to comment.