-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathpayment-form.jsx
More file actions
127 lines (120 loc) · 6.25 KB
/
payment-form.jsx
File metadata and controls
127 lines (120 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import {FormattedMessage, FormattedNumber, useIntl} from 'react-intl'
import PropTypes from 'prop-types'
import {Box, Flex, RadioGroup, Stack, Text} from '@chakra-ui/react'
import Tooltip from '../../../components/tooltip'
import {useCurrentBasket} from '../../../hooks/use-current-basket'
import {LockIcon, PaypalIcon} from '../../../components/icons'
import CreditCardFields from '../../../components/forms/credit-card-fields'
import {useCurrency} from '../../../hooks'
const PaymentForm = ({form, onSubmit}) => {
const {formatMessage} = useIntl()
const {data: basket} = useCurrentBasket()
const {currency} = useCurrency()
return (
<form onSubmit={form.handleSubmit(onSubmit)}>
<Stack gap={8}>
<Stack gap={5}>
<Box border="1px solid" borderColor="gray.100" rounded="base" overflow="hidden">
<RadioGroup.Root
value="cc"
aria-label={formatMessage({
defaultMessage: 'Payment',
id: 'payment_selection.radio_group.assistive_msg'
})}
name="payment-selection"
>
<Box
py={3}
px={[4, 4, 6]}
bg="gray.50"
borderBottom="1px solid"
borderColor="gray.100"
>
<RadioGroup.Item
value="cc"
w="full"
display="flex"
alignItems="center"
>
<RadioGroup.ItemHiddenInput />
<RadioGroup.ItemIndicator />
<RadioGroup.ItemText flex="1">
<Flex justify="space-between">
<Stack direction="row" align="center">
<Text fontWeight="bold">
<FormattedMessage
defaultMessage="Credit Card"
id="payment_selection.heading.credit_card"
/>
</Text>
<Tooltip
content={formatMessage({
defaultMessage:
'This is a secure SSL encrypted payment.',
id: 'payment_selection.tooltip.secure_payment'
})}
contentProps={{
css: {'--tooltip-bg': 'colors.blue.800'}
}}
positioning={{
strategy: 'fixed',
flip: false
}}
>
<LockIcon
color="gray.700"
boxSize={5}
cursor="pointer"
/>
</Tooltip>
</Stack>
<Text fontWeight="bold">
<FormattedNumber
value={basket?.orderTotal}
style="currency"
currency={currency}
/>
</Text>
</Flex>
</RadioGroup.ItemText>
</RadioGroup.Item>
</Box>
<Box p={[4, 4, 6]} borderBottom="1px solid" borderColor="gray.100">
<Stack gap={6}>
<Stack gap={6}>
<CreditCardFields form={form} />
</Stack>
</Stack>
</Box>
<Box py={3} px={[4, 4, 6]} bg="gray.50" borderColor="gray.100">
<RadioGroup.Item value="paypal">
<RadioGroup.ItemHiddenInput />
<RadioGroup.ItemIndicator />
<RadioGroup.ItemText>
<Box py="2px">
<PaypalIcon width="auto" height="20px" />
</Box>
</RadioGroup.ItemText>
</RadioGroup.Item>
</Box>
</RadioGroup.Root>
</Box>
</Stack>
</Stack>
</form>
)
}
PaymentForm.propTypes = {
/** The form object returned from `useForm` */
form: PropTypes.object,
/** Callback for form submit */
onSubmit: PropTypes.func
}
export default PaymentForm