2
0

(payment) Add address in payment input

This commit is contained in:
Baptiste Arnaud
2023-05-05 14:54:37 -04:00
parent b9f94cdf19
commit c469912979
4 changed files with 132 additions and 2 deletions

View File

@@ -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>
)
}

View File

@@ -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
@@ -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>
@@ -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 ?? ''}
@@ -177,6 +188,10 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
onChange={updatePhoneNumber}
placeholder="+33XXXXXXXXX"
/>
<PaymentAddressSettings
address={options.additionalInformation?.address}
onAddressChange={updateAddress}
/>
</AccordionPanel>
</AccordionItem>
</Accordion>