@@ -9,13 +9,13 @@ import type {
99import { useMemo , useState } from 'react' ;
1010
1111import { __experimental_PaymentSourcesContext , useCheckoutContext } from '../../contexts' ;
12- import { Box , Button , Col , descriptors , Flex , Form , Icon , localizationKeys , Text } from '../../customizables' ;
12+ import { Box , Button , Col , descriptors , Form , localizationKeys } from '../../customizables' ;
1313import { Alert , Disclosure , Divider , Drawer , LineItems , Select , SelectButton , SelectOptionList } from '../../elements' ;
1414import { useFetch } from '../../hooks' ;
15- import { ArrowUpDown , CreditCard } from '../../icons' ;
15+ import { ArrowUpDown } from '../../icons' ;
1616import { animations } from '../../styledSystem' ;
1717import { handleError } from '../../utils' ;
18- import { AddPaymentSource } from '../PaymentSources' ;
18+ import { AddPaymentSource , PaymentSourceRow } from '../PaymentSources' ;
1919
2020const capitalize = ( name : string ) => name [ 0 ] . toUpperCase ( ) + name . slice ( 1 ) ;
2121
@@ -170,6 +170,7 @@ const CheckoutFormElements = ({
170170 < Disclosure . Content >
171171 < Col gap = { 3 } >
172172 < PaymentSourceMethods
173+ checkout = { checkout }
173174 paymentSources = { paymentSources }
174175 totalDueNow = { checkout . totals . totalDueNow || checkout . totals . grandTotal }
175176 onPaymentSourceSubmit = { onPaymentSourceSubmit }
@@ -208,19 +209,21 @@ const CheckoutFormElements = ({
208209} ;
209210
210211const PaymentSourceMethods = ( {
212+ checkout,
211213 totalDueNow,
212214 paymentSources,
213215 onPaymentSourceSubmit,
214216 isSubmitting,
215217} : {
218+ checkout : __experimental_CommerceCheckoutResource ;
216219 totalDueNow : __experimental_CommerceMoney ;
217220 paymentSources : __experimental_CommercePaymentSourceResource [ ] ;
218221 onPaymentSourceSubmit : React . FormEventHandler < HTMLFormElement > ;
219222 isSubmitting : boolean ;
220223} ) => {
221224 const [ selectedPaymentSource , setSelectedPaymentSource ] = useState <
222225 __experimental_CommercePaymentSourceResource | undefined
223- > ( paymentSources . length > 0 ? paymentSources [ 0 ] : undefined ) ;
226+ > ( checkout . paymentSource || paymentSources . find ( p => p . isDefault ) ) ;
224227
225228 const options = useMemo ( ( ) => {
226229 return paymentSources . map ( source => {
@@ -241,7 +244,7 @@ const PaymentSourceMethods = ({
241244 } ) }
242245 >
243246 < Select
244- elementId = 'role '
247+ elementId = 'paymentSource '
245248 options = { options }
246249 value = { selectedPaymentSource ?. id || null }
247250 onChange = { option => {
@@ -263,20 +266,7 @@ const PaymentSourceMethods = ({
263266 backgroundColor : t . colors . $colorBackground ,
264267 } ) }
265268 >
266- { selectedPaymentSource && (
267- < Flex
268- gap = { 3 }
269- align = 'center'
270- >
271- < Icon icon = { CreditCard } />
272- < Text
273- as = 'span'
274- colorScheme = 'body'
275- >
276- { capitalize ( selectedPaymentSource . cardType ) } ⋯ { selectedPaymentSource . last4 }
277- </ Text >
278- </ Flex >
279- ) }
269+ { selectedPaymentSource && < PaymentSourceRow paymentSource = { selectedPaymentSource } /> }
280270 </ SelectButton >
281271 < SelectOptionList
282272 sx = { t => ( {
0 commit comments