2025-01-28 12:42:43 +01:00
|
|
|
import { ToggleControl, Icon, Button } from '@wordpress/components';
|
|
|
|
import { cog } from '@wordpress/icons';
|
2025-01-21 18:57:36 +01:00
|
|
|
|
|
|
|
import SettingsBlock from '../SettingsBlock';
|
2024-12-08 09:33:49 +01:00
|
|
|
import PaymentMethodIcon from '../PaymentMethodIcon';
|
2025-02-25 21:59:42 +01:00
|
|
|
import WarningMessages from '../../../Components/Screens/Settings/Components/Payment/WarningMessages';
|
2025-01-21 18:57:36 +01:00
|
|
|
|
2025-01-02 13:55:32 +01:00
|
|
|
const PaymentMethodItemBlock = ( {
|
2025-01-22 12:09:21 +01:00
|
|
|
paymentMethod,
|
2025-01-02 13:55:32 +01:00
|
|
|
onTriggerModal,
|
|
|
|
onSelect,
|
|
|
|
isSelected,
|
2025-02-20 00:59:14 +01:00
|
|
|
isDisabled,
|
|
|
|
disabledMessage,
|
2025-02-25 21:59:42 +01:00
|
|
|
warningMessages,
|
2025-01-02 13:55:32 +01:00
|
|
|
} ) => {
|
2025-02-25 21:59:42 +01:00
|
|
|
const hasWarning =
|
|
|
|
warningMessages && Object.keys( warningMessages ).length > 0;
|
2025-01-30 12:54:05 +01:00
|
|
|
|
2025-02-25 12:01:52 +01:00
|
|
|
// Determine class names based on states
|
|
|
|
const methodItemClasses = [
|
|
|
|
'ppcp--method-item',
|
|
|
|
isDisabled ? 'ppcp--method-item--disabled' : '',
|
|
|
|
hasWarning && ! isDisabled ? 'ppcp--method-item--warning' : '',
|
|
|
|
]
|
|
|
|
.filter( Boolean )
|
|
|
|
.join( ' ' );
|
|
|
|
|
2024-12-08 09:33:49 +01:00
|
|
|
return (
|
2025-01-30 12:54:05 +01:00
|
|
|
<SettingsBlock
|
|
|
|
id={ paymentMethod.id }
|
2025-02-25 12:01:52 +01:00
|
|
|
className={ methodItemClasses }
|
2025-01-30 12:54:05 +01:00
|
|
|
separatorAndGap={ false }
|
2025-04-01 16:10:32 +02:00
|
|
|
aria-disabled={ isDisabled ? 'true' : 'false' }
|
2025-01-30 12:54:05 +01:00
|
|
|
>
|
2025-02-20 00:59:14 +01:00
|
|
|
{ isDisabled && (
|
2025-04-01 16:10:32 +02:00
|
|
|
<div
|
|
|
|
className="ppcp--method-disabled-overlay"
|
|
|
|
role="alert"
|
|
|
|
aria-live="polite"
|
|
|
|
>
|
|
|
|
<p className="ppcp--method-disabled-message" tabIndex="0">
|
2025-02-20 00:59:14 +01:00
|
|
|
{ disabledMessage }
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
) }
|
2025-01-24 17:01:03 +01:00
|
|
|
<div className="ppcp--method-inner">
|
|
|
|
<div className="ppcp--method-title-wrapper">
|
2025-01-28 12:42:43 +01:00
|
|
|
{ paymentMethod?.icon && (
|
|
|
|
<PaymentMethodIcon
|
|
|
|
icons={ [ paymentMethod.icon ] }
|
|
|
|
type={ paymentMethod.icon }
|
|
|
|
/>
|
|
|
|
) }
|
2025-01-24 17:01:03 +01:00
|
|
|
<span className="ppcp--method-title">
|
2025-01-22 12:09:21 +01:00
|
|
|
{ paymentMethod.itemTitle }
|
2025-01-02 13:55:32 +01:00
|
|
|
</span>
|
2024-12-16 16:00:27 +01:00
|
|
|
</div>
|
2025-01-24 17:01:03 +01:00
|
|
|
<p className="ppcp--method-description">
|
2025-01-22 12:09:21 +01:00
|
|
|
{ paymentMethod.itemDescription }
|
2025-01-02 13:55:32 +01:00
|
|
|
</p>
|
2025-01-24 17:01:03 +01:00
|
|
|
<div className="ppcp--method-footer">
|
2025-02-25 12:01:52 +01:00
|
|
|
<div className="ppcp--method-toggle-wrapper">
|
|
|
|
<ToggleControl
|
|
|
|
__nextHasNoMarginBottom
|
|
|
|
checked={ isSelected }
|
|
|
|
onChange={ onSelect }
|
2025-04-01 16:10:32 +02:00
|
|
|
disabled={ isDisabled }
|
|
|
|
aria-label={ `Enable ${ paymentMethod.itemTitle }` }
|
2025-02-25 12:01:52 +01:00
|
|
|
/>
|
|
|
|
{ hasWarning && ! isDisabled && isSelected && (
|
2025-02-25 21:59:42 +01:00
|
|
|
<WarningMessages
|
|
|
|
warningMessages={ warningMessages }
|
|
|
|
/>
|
2025-02-25 12:01:52 +01:00
|
|
|
) }
|
|
|
|
</div>
|
2025-01-22 12:09:21 +01:00
|
|
|
{ paymentMethod?.fields && onTriggerModal && (
|
2025-01-24 17:06:15 +01:00
|
|
|
<Button
|
2025-01-24 17:01:03 +01:00
|
|
|
className="ppcp--method-settings"
|
2025-04-01 16:10:32 +02:00
|
|
|
disabled={ isDisabled }
|
2025-01-02 13:55:32 +01:00
|
|
|
onClick={ onTriggerModal }
|
2025-04-01 16:10:32 +02:00
|
|
|
aria-label={ `Configure ${ paymentMethod.itemTitle } settings` }
|
2025-01-02 13:55:32 +01:00
|
|
|
>
|
2025-01-24 17:03:23 +01:00
|
|
|
<Icon icon={ cog } />
|
2025-01-24 17:06:15 +01:00
|
|
|
</Button>
|
2025-01-02 13:55:32 +01:00
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</SettingsBlock>
|
2024-12-08 09:33:49 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethodItemBlock;
|