2022-05-24 14:25:15 -07:00
|
|
|
import {
|
|
|
|
|
Stack,
|
|
|
|
|
useDisclosure,
|
|
|
|
|
Text,
|
|
|
|
|
Select,
|
|
|
|
|
HStack,
|
|
|
|
|
Accordion,
|
|
|
|
|
AccordionButton,
|
|
|
|
|
AccordionIcon,
|
|
|
|
|
AccordionItem,
|
|
|
|
|
AccordionPanel,
|
|
|
|
|
} from '@chakra-ui/react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { DropdownList } from '@/components/DropdownList'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { PaymentInputOptions, PaymentProvider } from '@typebot.io/schemas'
|
2023-03-09 08:46:36 +01:00
|
|
|
import React, { ChangeEvent } from 'react'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { currencies } from '../currencies'
|
2022-05-24 14:25:15 -07:00
|
|
|
import { StripeConfigModal } from './StripeConfigModal'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { CredentialsDropdown } from '@/features/credentials/components/CredentialsDropdown'
|
2023-03-03 09:01:11 +01:00
|
|
|
import { TextInput } from '@/components/inputs'
|
2023-03-09 08:46:36 +01:00
|
|
|
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
|
2022-05-24 14:25:15 -07:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
options: PaymentInputOptions
|
|
|
|
|
onOptionsChange: (options: PaymentInputOptions) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
2023-03-09 08:46:36 +01:00
|
|
|
const { workspace } = useWorkspace()
|
2022-05-24 14:25:15 -07:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
|
|
|
|
|
|
|
|
|
const handleProviderChange = (provider: PaymentProvider) => {
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
provider,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleCredentialsSelect = (credentialsId?: string) => {
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
credentialsId,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleAmountChange = (amount?: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
amount,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleCurrencyChange = (e: ChangeEvent<HTMLSelectElement>) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
currency: e.target.value,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleNameChange = (name: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
additionalInformation: { ...options.additionalInformation, name },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleEmailChange = (email: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
additionalInformation: { ...options.additionalInformation, email },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handlePhoneNumberChange = (phoneNumber: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
additionalInformation: { ...options.additionalInformation, phoneNumber },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleButtonLabelChange = (button: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
2022-06-01 08:47:15 +02:00
|
|
|
labels: { ...options.labels, button },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleSuccessLabelChange = (success: string) =>
|
|
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
labels: { ...options.labels, success },
|
2022-05-24 14:25:15 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack spacing={4}>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Text>Provider:</Text>
|
|
|
|
|
<DropdownList
|
|
|
|
|
onItemSelect={handleProviderChange}
|
|
|
|
|
items={Object.values(PaymentProvider)}
|
|
|
|
|
currentItem={options.provider}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Text>Account:</Text>
|
2023-03-09 08:46:36 +01:00
|
|
|
{workspace && (
|
|
|
|
|
<CredentialsDropdown
|
|
|
|
|
type="stripe"
|
|
|
|
|
workspaceId={workspace.id}
|
|
|
|
|
currentCredentialsId={options.credentialsId}
|
|
|
|
|
onCredentialsSelect={handleCredentialsSelect}
|
|
|
|
|
onCreateNewClick={onOpen}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-05-24 14:25:15 -07:00
|
|
|
</Stack>
|
|
|
|
|
<HStack>
|
2023-03-03 09:01:11 +01:00
|
|
|
<TextInput
|
|
|
|
|
label="Price amount:"
|
|
|
|
|
onChange={handleAmountChange}
|
|
|
|
|
defaultValue={options.amount ?? ''}
|
|
|
|
|
placeholder="30.00"
|
|
|
|
|
/>
|
2022-05-24 14:25:15 -07:00
|
|
|
<Stack>
|
|
|
|
|
<Text>Currency:</Text>
|
|
|
|
|
<Select
|
|
|
|
|
placeholder="Select option"
|
2022-05-27 09:55:51 -07:00
|
|
|
value={options.currency}
|
2022-05-24 14:25:15 -07:00
|
|
|
onChange={handleCurrencyChange}
|
|
|
|
|
>
|
|
|
|
|
{currencies.map((currency) => (
|
2022-05-27 09:55:51 -07:00
|
|
|
<option value={currency.code} key={currency.code}>
|
2022-05-24 14:25:15 -07:00
|
|
|
{currency.code}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Stack>
|
|
|
|
|
</HStack>
|
2023-03-03 09:01:11 +01:00
|
|
|
<TextInput
|
|
|
|
|
label="Button label:"
|
|
|
|
|
onChange={handleButtonLabelChange}
|
|
|
|
|
defaultValue={options.labels.button}
|
|
|
|
|
placeholder="Pay"
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
|
|
|
|
label="Success message:"
|
|
|
|
|
onChange={handleSuccessLabelChange}
|
|
|
|
|
defaultValue={options.labels.success ?? 'Success'}
|
|
|
|
|
placeholder="Success"
|
|
|
|
|
/>
|
2022-05-24 14:25:15 -07:00
|
|
|
<Accordion allowToggle>
|
|
|
|
|
<AccordionItem>
|
|
|
|
|
<AccordionButton justifyContent="space-between">
|
|
|
|
|
Additional information
|
|
|
|
|
<AccordionIcon />
|
|
|
|
|
</AccordionButton>
|
|
|
|
|
<AccordionPanel pb={4} as={Stack} spacing="6">
|
2023-03-03 09:01:11 +01:00
|
|
|
<TextInput
|
|
|
|
|
label="Name:"
|
|
|
|
|
defaultValue={options.additionalInformation?.name ?? ''}
|
|
|
|
|
onChange={handleNameChange}
|
|
|
|
|
placeholder="John Smith"
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
|
|
|
|
label="Email:"
|
|
|
|
|
defaultValue={options.additionalInformation?.email ?? ''}
|
|
|
|
|
onChange={handleEmailChange}
|
|
|
|
|
placeholder="john@gmail.com"
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
|
|
|
|
label="Phone number:"
|
|
|
|
|
defaultValue={options.additionalInformation?.phoneNumber ?? ''}
|
|
|
|
|
onChange={handlePhoneNumberChange}
|
|
|
|
|
placeholder="+33XXXXXXXXX"
|
|
|
|
|
/>
|
2022-05-24 14:25:15 -07:00
|
|
|
</AccordionPanel>
|
|
|
|
|
</AccordionItem>
|
|
|
|
|
</Accordion>
|
|
|
|
|
|
|
|
|
|
<StripeConfigModal
|
|
|
|
|
isOpen={isOpen}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
onNewCredentials={handleCredentialsSelect}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
)
|
|
|
|
|
}
|