woocommerce/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/payment-methods/payment-methods.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { usePaymentMethods } from '@woocommerce/base-context/hooks';
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
import { __ } from '@wordpress/i18n';
import Label from '@woocommerce/base-components/label';
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
import { usePaymentMethodDataContext } from '@woocommerce/base-context';
/**
* Internal dependencies
*/
import NoPaymentMethods from './no-payment-methods';
import PaymentMethodOptions from './payment-method-options';
import SavedPaymentMethodOptions from './saved-payment-method-options';
/**
* PaymentMethods component.
*
* @return {*} The rendered component.
*/
const PaymentMethods = () => {
const { isInitialized, paymentMethods } = usePaymentMethods();
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
const { customerPaymentMethods } = usePaymentMethodDataContext();
if ( isInitialized && Object.keys( paymentMethods ).length === 0 ) {
return <NoPaymentMethods />;
}
return (
<>
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
<SavedPaymentMethodOptions />
{ Object.keys( customerPaymentMethods ).length > 0 && (
<Label
label={ __(
'Use another payment method.',
'woo-gutenberg-products-block'
) }
screenReaderLabel={ __(
'Other available payment methods',
'woo-gutenberg-products-block'
) }
wrapperElement="p"
wrapperProps={ {
className: [
'wc-block-components-checkout-step__description wc-block-components-checkout-step__description-payments-aligned',
],
} }
/>
) }
<PaymentMethodOptions />
</>
);
};
export default PaymentMethods;