2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 16:18:13 +00:00
|
|
|
import classnames from 'classnames';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
2021-11-26 14:47:37 +00:00
|
|
|
import { PanelBody, ExternalLink } from '@wordpress/components';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
|
|
|
|
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
|
2021-09-03 13:25:09 +00:00
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2021-11-26 14:47:37 +00:00
|
|
|
import Noninteractive from '@woocommerce/base-components/noninteractive';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
FormStepBlock,
|
|
|
|
AdditionalFields,
|
|
|
|
AdditionalFieldsContent,
|
|
|
|
} from '../../form-step';
|
|
|
|
import Block from './block';
|
|
|
|
|
|
|
|
type paymentAdminLink = {
|
|
|
|
id: number;
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
};
|
|
|
|
|
2021-10-20 16:18:13 +00:00
|
|
|
export const Edit = ( {
|
|
|
|
attributes,
|
|
|
|
setAttributes,
|
|
|
|
}: {
|
|
|
|
attributes: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
showStepNumber: boolean;
|
|
|
|
className: string;
|
|
|
|
};
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
|
|
|
} ): JSX.Element => {
|
2021-07-22 11:03:00 +00:00
|
|
|
const globalPaymentMethods = getSetting(
|
|
|
|
'globalPaymentMethods'
|
|
|
|
) as paymentAdminLink[];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormStepBlock
|
2021-10-20 16:18:13 +00:00
|
|
|
attributes={ attributes }
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
className={ classnames(
|
|
|
|
'wc-block-checkout__payment-method',
|
|
|
|
attributes?.className
|
|
|
|
) }
|
2021-07-22 11:03:00 +00:00
|
|
|
>
|
|
|
|
<InspectorControls>
|
|
|
|
{ globalPaymentMethods.length > 0 && (
|
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
|
|
|
'Methods',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
|
|
|
'You currently have the following payment integrations active.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
{ globalPaymentMethods.map( ( method ) => {
|
|
|
|
return (
|
|
|
|
<ExternalLinkCard
|
|
|
|
key={ method.id }
|
|
|
|
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout§ion=${ method.id }` }
|
|
|
|
title={ method.title }
|
|
|
|
description={ method.description }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
<ExternalLink
|
|
|
|
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Manage payment methods',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</ExternalLink>
|
|
|
|
</PanelBody>
|
|
|
|
) }
|
|
|
|
</InspectorControls>
|
2021-11-26 14:47:37 +00:00
|
|
|
<Noninteractive>
|
2021-07-22 11:03:00 +00:00
|
|
|
<Block />
|
2021-11-26 14:47:37 +00:00
|
|
|
</Noninteractive>
|
2021-09-07 16:01:14 +00:00
|
|
|
<AdditionalFields block={ innerBlockAreas.PAYMENT_METHODS } />
|
2021-07-22 11:03:00 +00:00
|
|
|
</FormStepBlock>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<AdditionalFieldsContent />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|