mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Switch PaymentMethodsBlock to new action
This commit is contained in:
parent
7613babb7c
commit
e4feb1f8f8
1 changed files with 7 additions and 9 deletions
|
@ -4,19 +4,17 @@ import { PaymentHooks } from '../../../data';
|
||||||
|
|
||||||
// TODO: This is not a reusable component, as it's connected to the Redux store.
|
// TODO: This is not a reusable component, as it's connected to the Redux store.
|
||||||
const PaymentMethodsBlock = ( { paymentMethods = [], onTriggerModal } ) => {
|
const PaymentMethodsBlock = ( { paymentMethods = [], onTriggerModal } ) => {
|
||||||
const { setPersistent } = PaymentHooks.useStore();
|
const { changePaymentSettings } = PaymentHooks.useStore();
|
||||||
|
|
||||||
|
const handleSelect = ( methodId, isSelected ) =>
|
||||||
|
changePaymentSettings( methodId, {
|
||||||
|
enabled: isSelected,
|
||||||
|
} );
|
||||||
|
|
||||||
if ( ! paymentMethods.length ) {
|
if ( ! paymentMethods.length ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSelect = ( paymentMethod, isSelected ) => {
|
|
||||||
setPersistent( paymentMethod.id, {
|
|
||||||
...paymentMethod,
|
|
||||||
enabled: isSelected,
|
|
||||||
} );
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsBlock className="ppcp--grid ppcp-r-settings-block__payment-methods">
|
<SettingsBlock className="ppcp--grid ppcp-r-settings-block__payment-methods">
|
||||||
{ paymentMethods.map( ( paymentMethod ) => (
|
{ paymentMethods.map( ( paymentMethod ) => (
|
||||||
|
@ -25,7 +23,7 @@ const PaymentMethodsBlock = ( { paymentMethods = [], onTriggerModal } ) => {
|
||||||
paymentMethod={ paymentMethod }
|
paymentMethod={ paymentMethod }
|
||||||
isSelected={ paymentMethod.enabled }
|
isSelected={ paymentMethod.enabled }
|
||||||
onSelect={ ( checked ) =>
|
onSelect={ ( checked ) =>
|
||||||
handleSelect( paymentMethod, checked )
|
handleSelect( paymentMethod.id, checked )
|
||||||
}
|
}
|
||||||
onTriggerModal={ () =>
|
onTriggerModal={ () =>
|
||||||
onTriggerModal?.( paymentMethod.id )
|
onTriggerModal?.( paymentMethod.id )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue