-
Notifications
You must be signed in to change notification settings - Fork 407
feat(checkout): CHECKOUT-10399 Redesign payment loaders #3324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0627d27
df8bc5e
6e833e7
7a3ad80
428a671
0b79903
59c2975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,13 @@ import { type PaymentMethod } from '@bigcommerce/checkout-sdk'; | |
| import { find, noop } from 'lodash'; | ||
| import React, { type FunctionComponent, memo, useCallback, useMemo } from 'react'; | ||
|
|
||
| import { useCheckout, useLocale } from '@bigcommerce/checkout/contexts'; | ||
| import { Checklist, ChecklistItem, LoadingOverlay } from '@bigcommerce/checkout/ui'; | ||
| import { useCheckout, useLocale, useThemeContext } from '@bigcommerce/checkout/contexts'; | ||
| import { | ||
| Checklist, | ||
| ChecklistItem, | ||
| LoadingOverlay, | ||
| PaymentMethodSkeleton, | ||
| } from '@bigcommerce/checkout/ui'; | ||
|
|
||
| import { connectFormik, type ConnectFormikProps } from '../../common/form'; | ||
|
|
||
|
|
@@ -47,6 +52,7 @@ const PaymentMethodList: FunctionComponent< | |
| }) => { | ||
| const { language } = useLocale(); | ||
| const { selectedState: config } = useCheckout(({ data }) => data.getConfig()); | ||
| const { enhancedThemeV1 } = useThemeContext(); | ||
|
|
||
| const chequeMethod = find(methods, { id: 'cheque' }); | ||
| const chequeDisabledReason = usePoMethodDisabledReason(chequeMethod); | ||
|
|
@@ -81,37 +87,44 @@ const PaymentMethodList: FunctionComponent< | |
| [methods, onSelect], | ||
| ); | ||
|
|
||
| const checklist = ( | ||
| <Checklist | ||
| defaultSelectedItemId={values.paymentProviderRadio} | ||
| name="paymentProviderRadio" | ||
| onSelect={handleSelect} | ||
| > | ||
| {methods.map((method) => { | ||
| const value = getUniquePaymentMethodId(method.id, method.gateway); | ||
|
|
||
| return ( | ||
| <PaymentMethodListItem | ||
| disabledReason={method === chequeMethod ? chequeDisabledReason : undefined} | ||
| isEmbedded={isEmbedded} | ||
| isInitializingPayment={isInitializingPayment} | ||
| isSelected={value === values.paymentProviderRadio} | ||
| isUsingMultiShipping={isUsingMultiShipping} | ||
| key={value} | ||
| method={method} | ||
| onUnhandledError={onUnhandledError} | ||
| value={value} | ||
| /> | ||
| ); | ||
| })} | ||
| </Checklist> | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <div aria-live="assertive" className="is-srOnly" role="status"> | ||
| {titleText} | ||
| </div> | ||
| <LoadingOverlay isLoading={Boolean(isInitializingPayment)}> | ||
| <Checklist | ||
| defaultSelectedItemId={values.paymentProviderRadio} | ||
| name="paymentProviderRadio" | ||
| onSelect={handleSelect} | ||
| > | ||
| {methods.map((method) => { | ||
| const value = getUniquePaymentMethodId(method.id, method.gateway); | ||
|
|
||
| return ( | ||
| <PaymentMethodListItem | ||
| disabledReason={ | ||
| method === chequeMethod ? chequeDisabledReason : undefined | ||
| } | ||
| isEmbedded={isEmbedded} | ||
| isInitializingPayment={isInitializingPayment} | ||
| isUsingMultiShipping={isUsingMultiShipping} | ||
| key={value} | ||
| method={method} | ||
| onUnhandledError={onUnhandledError} | ||
| value={value} | ||
| /> | ||
| ); | ||
| })} | ||
| </Checklist> | ||
| </LoadingOverlay> | ||
| {enhancedThemeV1 ? ( | ||
| checklist | ||
| ) : ( | ||
| <LoadingOverlay isLoading={Boolean(isInitializingPayment)}> | ||
| {checklist} | ||
| </LoadingOverlay> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
@@ -120,6 +133,7 @@ interface PaymentMethodListItemProps { | |
| disabledReason?: PoDisabledReason; | ||
| isEmbedded?: boolean; | ||
| isInitializingPayment?: boolean; | ||
| isSelected: boolean; | ||
| isUsingMultiShipping?: boolean; | ||
| method: PaymentMethod; | ||
| value: string; | ||
|
|
@@ -130,21 +144,47 @@ const PaymentMethodListItem: FunctionComponent<PaymentMethodListItemProps> = ({ | |
| disabledReason, | ||
| isEmbedded, | ||
| isInitializingPayment, | ||
| isSelected, | ||
| isUsingMultiShipping, | ||
| method, | ||
| onUnhandledError, | ||
| value, | ||
| }) => { | ||
| const { enhancedThemeV1 } = useThemeContext(); | ||
| const isCustomChecklistItem = Boolean(method.initializationData?.isCustomChecklistItem); | ||
|
|
||
| const renderPaymentMethod = useMemo(() => { | ||
| return ( | ||
| const paymentMethod = ( | ||
| <PaymentMethodV2 | ||
| isEmbedded={isEmbedded} | ||
| isUsingMultiShipping={isUsingMultiShipping} | ||
| method={method} | ||
| onUnhandledError={onUnhandledError || noop} | ||
| /> | ||
| ); | ||
| }, [isEmbedded, isUsingMultiShipping, method, onUnhandledError]); | ||
|
|
||
| // Custom checklist items manage their own loading UI | ||
| return enhancedThemeV1 && !isCustomChecklistItem ? ( | ||
| <LoadingOverlay | ||
| hideContentWhenLoading | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heads up that No change for Can you try to test Stripe manally? That one plus another hosted-field provider would be good to check. |
||
| isLoading={isSelected && Boolean(isInitializingPayment)} | ||
| loadingSkeleton={<PaymentMethodSkeleton />} | ||
| > | ||
| {paymentMethod} | ||
| </LoadingOverlay> | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| ) : ( | ||
| paymentMethod | ||
| ); | ||
| }, [ | ||
| enhancedThemeV1, | ||
| isCustomChecklistItem, | ||
| isEmbedded, | ||
| isInitializingPayment, | ||
| isSelected, | ||
| isUsingMultiShipping, | ||
| method, | ||
| onUnhandledError, | ||
| ]); | ||
|
|
||
| const renderPaymentMethodTitle = useCallback( | ||
| (isSelected: boolean) => ( | ||
|
|
@@ -158,7 +198,7 @@ const PaymentMethodListItem: FunctionComponent<PaymentMethodListItemProps> = ({ | |
| [disabledReason, method], | ||
| ); | ||
|
|
||
| if (method.initializationData?.isCustomChecklistItem) { | ||
| if (isCustomChecklistItem) { | ||
| return <CustomChecklistItem content={renderPaymentMethod} htmlId={`radio-${value}`} />; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| @keyframes payment-method-skeleton-pulse { | ||
| 0%, 100% { | ||
| background-color: color("greys", "lighter"); | ||
| } | ||
|
|
||
| 50% { | ||
| background-color: mix(color("greys", "light"), color("greys", "medium"), 50%); | ||
| } | ||
| } | ||
|
|
||
| .payment-method-skeleton { | ||
| @include enhancedThemeV1 { | ||
| padding: spacing("half") 0; | ||
|
|
||
| div { | ||
| animation: payment-method-skeleton-pulse 4000ms infinite cubic-bezier(0.13, 0.615, 0.315, 0.915); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💅 |
||
| background: color("greys", "lighter"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React, { type FunctionComponent } from 'react'; | ||
|
|
||
| import ChecklistSkeleton from './ChecklistSkeleton'; | ||
|
|
||
| export const PaymentMethodSkeleton: FunctionComponent = () => ( | ||
| <div aria-busy="true" data-test="payment-method-skeleton" role="status"> | ||
| <ChecklistSkeleton additionalClassName="payment-method-skeleton" rows={2} /> | ||
| </div> | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom checklist items were previously covered by the list-wide overlay and now get nothing. The comment says they manage their own loading UI — is that true for all of them, or just the wallet buttons you checked? If any of them don't, they'll just sit there looking like a dead radio during init.