Conditionally check/uncheck the Order Intent

This commit is contained in:
Narek Zakarian 2025-02-18 16:55:01 +04:00
parent 5059ca24ff
commit 167e12e54e
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
2 changed files with 16 additions and 1 deletions

View file

@ -1,7 +1,13 @@
import { ToggleControl } from '@wordpress/components';
import { Action, Description } from '../Elements';
const ControlToggleButton = ( { label, description, value, onChange } ) => (
const ControlToggleButton = ( {
label,
description,
value,
onChange,
disabled = false,
} ) => (
<Action>
<ToggleControl
className="ppcp--control-toggle"
@ -12,6 +18,7 @@ const ControlToggleButton = ( { label, description, value, onChange } ) => (
help={
description ? <Description>{ description }</Description> : null
}
disabled={ disabled }
/>
</Action>
);

View file

@ -1,4 +1,5 @@
import { __ } from '@wordpress/i18n';
import { useEffect } from 'react';
import { ControlToggleButton } from '../../../../../ReusableComponents/Controls';
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
@ -12,6 +13,12 @@ const OrderIntent = () => {
setCaptureVirtualOnlyOrders,
} = SettingsHooks.useSettings();
useEffect( () => {
if ( ! authorizeOnly && captureVirtualOnlyOrders ) {
setCaptureVirtualOnlyOrders( false );
}
}, [ authorizeOnly ] );
return (
<SettingsBlock
title={ __( 'Order Intent', 'woocommerce-paypal-payments' ) }
@ -34,6 +41,7 @@ const OrderIntent = () => {
) }
onChange={ setCaptureVirtualOnlyOrders }
value={ captureVirtualOnlyOrders }
disabled={ ! authorizeOnly }
/>
</SettingsBlock>
);