mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
44 lines
1 KiB
JavaScript
44 lines
1 KiB
JavaScript
import SettingsBlock from '../SettingsBlock';
|
|
import PaymentMethodItemBlock from './PaymentMethodItemBlock';
|
|
import { usePaymentMethods } from '../../../data/payment/hooks';
|
|
|
|
const PaymentMethodsBlock = ( {
|
|
paymentMethods,
|
|
className = '',
|
|
onTriggerModal,
|
|
} ) => {
|
|
const { setPersistent } = usePaymentMethods();
|
|
|
|
if ( ! paymentMethods?.length ) {
|
|
return null;
|
|
}
|
|
|
|
const handleSelect = ( paymentMethod, isSelected ) => {
|
|
setPersistent( paymentMethod.id, {
|
|
...paymentMethod,
|
|
enabled: isSelected,
|
|
} );
|
|
};
|
|
|
|
return (
|
|
<SettingsBlock
|
|
className={ `ppcp-r-settings-block__payment-methods ${ className }` }
|
|
>
|
|
{ paymentMethods.map( ( paymentMethod ) => (
|
|
<PaymentMethodItemBlock
|
|
key={ paymentMethod.id }
|
|
{ ...paymentMethod }
|
|
isSelected={ paymentMethod.enabled }
|
|
onSelect={ ( checked ) =>
|
|
handleSelect( paymentMethod, checked )
|
|
}
|
|
onTriggerModal={ () =>
|
|
onTriggerModal?.( paymentMethod.id )
|
|
}
|
|
/>
|
|
) ) }
|
|
</SettingsBlock>
|
|
);
|
|
};
|
|
|
|
export default PaymentMethodsBlock;
|