⚡ (payment) Add description option on Stripe input
This commit is contained in:
@@ -28,68 +28,74 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
const { workspace } = useWorkspace()
|
const { workspace } = useWorkspace()
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure()
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||||
|
|
||||||
const handleProviderChange = (provider: PaymentProvider) => {
|
const updateProvider = (provider: PaymentProvider) => {
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
provider,
|
provider,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCredentialsSelect = (credentialsId?: string) => {
|
const updateCredentials = (credentialsId?: string) => {
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
credentialsId,
|
credentialsId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAmountChange = (amount?: string) =>
|
const updateAmount = (amount?: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
amount,
|
amount,
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleCurrencyChange = (e: ChangeEvent<HTMLSelectElement>) =>
|
const updateCurrency = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
currency: e.target.value,
|
currency: e.target.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleNameChange = (name: string) =>
|
const updateName = (name: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
additionalInformation: { ...options.additionalInformation, name },
|
additionalInformation: { ...options.additionalInformation, name },
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleEmailChange = (email: string) =>
|
const updateEmail = (email: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
additionalInformation: { ...options.additionalInformation, email },
|
additionalInformation: { ...options.additionalInformation, email },
|
||||||
})
|
})
|
||||||
|
|
||||||
const handlePhoneNumberChange = (phoneNumber: string) =>
|
const updatePhoneNumber = (phoneNumber: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
additionalInformation: { ...options.additionalInformation, phoneNumber },
|
additionalInformation: { ...options.additionalInformation, phoneNumber },
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleButtonLabelChange = (button: string) =>
|
const updateButtonLabel = (button: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
labels: { ...options.labels, button },
|
labels: { ...options.labels, button },
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleSuccessLabelChange = (success: string) =>
|
const updateSuccessLabel = (success: string) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
labels: { ...options.labels, success },
|
labels: { ...options.labels, success },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const updateDescription = (description: string) =>
|
||||||
|
onOptionsChange({
|
||||||
|
...options,
|
||||||
|
additionalInformation: { ...options.additionalInformation, description },
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={4}>
|
<Stack spacing={4}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text>Provider:</Text>
|
<Text>Provider:</Text>
|
||||||
<DropdownList
|
<DropdownList
|
||||||
onItemSelect={handleProviderChange}
|
onItemSelect={updateProvider}
|
||||||
items={Object.values(PaymentProvider)}
|
items={Object.values(PaymentProvider)}
|
||||||
currentItem={options.provider}
|
currentItem={options.provider}
|
||||||
/>
|
/>
|
||||||
@@ -101,7 +107,7 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
type="stripe"
|
type="stripe"
|
||||||
workspaceId={workspace.id}
|
workspaceId={workspace.id}
|
||||||
currentCredentialsId={options.credentialsId}
|
currentCredentialsId={options.credentialsId}
|
||||||
onCredentialsSelect={handleCredentialsSelect}
|
onCredentialsSelect={updateCredentials}
|
||||||
onCreateNewClick={onOpen}
|
onCreateNewClick={onOpen}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -109,7 +115,7 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
<HStack>
|
<HStack>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Price amount:"
|
label="Price amount:"
|
||||||
onChange={handleAmountChange}
|
onChange={updateAmount}
|
||||||
defaultValue={options.amount ?? ''}
|
defaultValue={options.amount ?? ''}
|
||||||
placeholder="30.00"
|
placeholder="30.00"
|
||||||
/>
|
/>
|
||||||
@@ -118,7 +124,7 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
<Select
|
<Select
|
||||||
placeholder="Select option"
|
placeholder="Select option"
|
||||||
value={options.currency}
|
value={options.currency}
|
||||||
onChange={handleCurrencyChange}
|
onChange={updateCurrency}
|
||||||
>
|
>
|
||||||
{currencies.map((currency) => (
|
{currencies.map((currency) => (
|
||||||
<option value={currency.code} key={currency.code}>
|
<option value={currency.code} key={currency.code}>
|
||||||
@@ -130,13 +136,13 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
</HStack>
|
</HStack>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Button label:"
|
label="Button label:"
|
||||||
onChange={handleButtonLabelChange}
|
onChange={updateButtonLabel}
|
||||||
defaultValue={options.labels.button}
|
defaultValue={options.labels.button}
|
||||||
placeholder="Pay"
|
placeholder="Pay"
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Success message:"
|
label="Success message:"
|
||||||
onChange={handleSuccessLabelChange}
|
onChange={updateSuccessLabel}
|
||||||
defaultValue={options.labels.success ?? 'Success'}
|
defaultValue={options.labels.success ?? 'Success'}
|
||||||
placeholder="Success"
|
placeholder="Success"
|
||||||
/>
|
/>
|
||||||
@@ -147,22 +153,28 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
</AccordionButton>
|
</AccordionButton>
|
||||||
<AccordionPanel pb={4} as={Stack} spacing="6">
|
<AccordionPanel pb={4} as={Stack} spacing="6">
|
||||||
|
<TextInput
|
||||||
|
label="Description:"
|
||||||
|
defaultValue={options.additionalInformation?.description ?? ''}
|
||||||
|
onChange={updateDescription}
|
||||||
|
placeholder="A digital product"
|
||||||
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Name:"
|
label="Name:"
|
||||||
defaultValue={options.additionalInformation?.name ?? ''}
|
defaultValue={options.additionalInformation?.name ?? ''}
|
||||||
onChange={handleNameChange}
|
onChange={updateName}
|
||||||
placeholder="John Smith"
|
placeholder="John Smith"
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Email:"
|
label="Email:"
|
||||||
defaultValue={options.additionalInformation?.email ?? ''}
|
defaultValue={options.additionalInformation?.email ?? ''}
|
||||||
onChange={handleEmailChange}
|
onChange={updateEmail}
|
||||||
placeholder="john@gmail.com"
|
placeholder="john@gmail.com"
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Phone number:"
|
label="Phone number:"
|
||||||
defaultValue={options.additionalInformation?.phoneNumber ?? ''}
|
defaultValue={options.additionalInformation?.phoneNumber ?? ''}
|
||||||
onChange={handlePhoneNumberChange}
|
onChange={updatePhoneNumber}
|
||||||
placeholder="+33XXXXXXXXX"
|
placeholder="+33XXXXXXXXX"
|
||||||
/>
|
/>
|
||||||
</AccordionPanel>
|
</AccordionPanel>
|
||||||
@@ -172,7 +184,7 @@ export const PaymentSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
<StripeConfigModal
|
<StripeConfigModal
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onNewCredentials={handleCredentialsSelect}
|
onNewCredentials={updateCredentials}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ const createStripePaymentIntent =
|
|||||||
amount,
|
amount,
|
||||||
currency: options.currency,
|
currency: options.currency,
|
||||||
receipt_email: receiptEmail === '' ? undefined : receiptEmail,
|
receipt_email: receiptEmail === '' ? undefined : receiptEmail,
|
||||||
|
description: options.additionalInformation?.description,
|
||||||
automatic_payment_methods: {
|
automatic_payment_methods: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export const paymentInputOptionsSchema = optionBaseSchema.merge(
|
|||||||
}),
|
}),
|
||||||
additionalInformation: z
|
additionalInformation: z
|
||||||
.object({
|
.object({
|
||||||
|
description: z.string().optional(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
email: z.string().optional(),
|
email: z.string().optional(),
|
||||||
phoneNumber: z.string().optional(),
|
phoneNumber: z.string().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user