2019-12-03 14:12:46 +00:00
/ * *
* External dependencies
* /
2019-12-16 14:59:16 +00:00
import { _ _ } from '@wordpress/i18n' ;
import { withFeedbackPrompt } from '@woocommerce/block-hocs' ;
2020-03-12 09:41:35 +00:00
import {
previewCart ,
previewShippingRates ,
} from '@woocommerce/resource-previews' ;
2020-03-04 15:13:38 +00:00
import { InspectorControls } from '@wordpress/block-editor' ;
2020-03-05 13:06:47 +00:00
import {
PanelBody ,
ToggleControl ,
CheckboxControl ,
2020-03-06 12:20:17 +00:00
Notice ,
2020-03-05 13:06:47 +00:00
} from '@wordpress/components' ;
2020-03-06 11:43:40 +00:00
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary' ;
2020-03-06 12:20:17 +00:00
import {
PRIVACY _URL ,
TERMS _URL ,
SHIPPING _METHODS _EXIST ,
} from '@woocommerce/block-settings' ;
import { getAdminLink } from '@woocommerce/settings' ;
import { _ _experimentalCreateInterpolateElement } from 'wordpress-element' ;
2019-12-03 14:12:46 +00:00
/ * *
* Internal dependencies
* /
import Block from './block.js' ;
2019-12-06 13:18:55 +00:00
import './editor.scss' ;
2019-12-03 14:12:46 +00:00
2020-03-04 15:13:38 +00:00
const CheckoutEditor = ( { attributes , setAttributes } ) => {
2020-03-05 13:06:47 +00:00
const {
className ,
useShippingAsBilling ,
showCompanyField ,
showAddress2Field ,
showPhoneField ,
requireCompanyField ,
requirePhoneField ,
2020-03-06 12:20:17 +00:00
showPolicyLinks ,
2020-03-05 13:06:47 +00:00
} = attributes ;
2019-12-03 14:12:46 +00:00
return (
< div className = { className } >
2020-03-04 15:13:38 +00:00
< InspectorControls >
2020-03-05 13:06:47 +00:00
< PanelBody
title = { _ _ (
'Form options' ,
'woo-gutenberg-products-block'
) }
>
< p className = "wc-block-checkout__controls-text" >
{ _ _ (
'Choose whether your checkout form requires extra information from customers.' ,
'woo-gutenberg-products-block'
) }
< / p >
< ToggleControl
label = { _ _ (
2020-03-09 14:23:16 +00:00
'Company' ,
2020-03-05 13:06:47 +00:00
'woo-gutenberg-products-block'
) }
checked = { showCompanyField }
onChange = { ( ) =>
setAttributes ( {
showCompanyField : ! showCompanyField ,
} )
}
/ >
{ showCompanyField && (
< CheckboxControl
label = { _ _ (
'Require company name?' ,
'woo-gutenberg-products-block'
) }
checked = { requireCompanyField }
onChange = { ( ) =>
setAttributes ( {
requireCompanyField : ! requireCompanyField ,
} )
}
className = "components-base-control--nested"
/ >
) }
< ToggleControl
label = { _ _ (
2020-03-09 14:23:16 +00:00
'Apartment, suite, etc.' ,
2020-03-05 13:06:47 +00:00
'woo-gutenberg-products-block'
) }
checked = { showAddress2Field }
onChange = { ( ) =>
setAttributes ( {
showAddress2Field : ! showAddress2Field ,
} )
}
/ >
< ToggleControl
2020-03-09 14:23:16 +00:00
label = { _ _ ( 'Phone' , 'woo-gutenberg-products-block' ) }
2020-03-05 13:06:47 +00:00
checked = { showPhoneField }
onChange = { ( ) =>
setAttributes ( {
showPhoneField : ! showPhoneField ,
} )
}
/ >
{ showPhoneField && (
< CheckboxControl
label = { _ _ (
'Require phone number?' ,
'woo-gutenberg-products-block'
) }
checked = { requirePhoneField }
onChange = { ( ) =>
setAttributes ( {
requirePhoneField : ! requirePhoneField ,
} )
}
className = "components-base-control--nested"
/ >
) }
< / P a n e l B o d y >
2020-03-04 15:13:38 +00:00
< PanelBody
title = { _ _ (
'Billing address' ,
'woo-gutenberg-products-block'
) }
>
< p className = "wc-block-checkout__controls-text" >
{ _ _ (
'Reduce the number of fields required to checkout.' ,
'woo-gutenberg-products-block'
) }
< / p >
< ToggleControl
label = { _ _ (
'Use the shipping address as the billing address' ,
'woo-gutenberg-products-block'
) }
checked = { useShippingAsBilling }
onChange = { ( ) =>
setAttributes ( {
useShippingAsBilling : ! useShippingAsBilling ,
} )
}
/ >
< / P a n e l B o d y >
2020-03-06 12:20:17 +00:00
< PanelBody
title = { _ _ ( 'Content' , 'woo-gutenberg-products-block' ) }
>
< p className = "wc-block-checkout__controls-text" >
{ _ _ (
'Choose additional content to display on checkout.' ,
'woo-gutenberg-products-block'
) }
< / p >
< ToggleControl
label = { _ _ (
'Show links to terms and conditions and privacy policy' ,
'woo-gutenberg-products-block'
) }
checked = { showPolicyLinks }
onChange = { ( ) =>
setAttributes ( {
showPolicyLinks : ! showPolicyLinks ,
} )
}
/ >
{ showPolicyLinks && ( ! PRIVACY _URL || ! TERMS _URL ) && (
< Notice
className = "wc-block-base-control-notice"
isDismissible = { false }
>
{ _ _experimentalCreateInterpolateElement (
_ _ (
'Pages must be first setup in store settings: <a1>Privacy policy</a1>, <a2>Terms and conditions</a2>.' ,
'woo-gutenberg-products-block'
) ,
{
a1 : (
// eslint-disable-next-line jsx-a11y/anchor-has-content
< a
href = { getAdminLink (
'admin.php?page=wc-settings&tab=account'
) }
target = "_blank"
rel = "noopener noreferrer"
/ >
) ,
a2 : (
// eslint-disable-next-line jsx-a11y/anchor-has-content
< a
href = { getAdminLink (
'admin.php?page=wc-settings&tab=advanced'
) }
target = "_blank"
rel = "noopener noreferrer"
/ >
) ,
}
) }
< / N o t i c e >
) }
< / P a n e l B o d y >
2020-03-04 15:13:38 +00:00
< / I n s p e c t o r C o n t r o l s >
2020-03-06 11:43:40 +00:00
< BlockErrorBoundary
header = { _ _ (
'Checkout Block Error' ,
'woo-gutenberg-products-block'
) }
text = { _ _ (
'There was an error whilst rendering the checkout block. If this problem continues, try re-creating the block.' ,
'woo-gutenberg-products-block'
) }
showErrorMessage = { true }
errorMessagePrefix = { _ _ (
'Error message:' ,
'woo-gutenberg-products-block'
) }
>
< Block
attributes = { attributes }
2020-03-12 09:41:35 +00:00
cartTotals = { previewCart . totals }
2020-03-06 11:43:40 +00:00
isEditor = { true }
shippingRates = {
SHIPPING _METHODS _EXIST ? previewShippingRates : [ ]
}
/ >
< / B l o c k E r r o r B o u n d a r y >
2019-12-03 14:12:46 +00:00
< / d i v >
) ;
} ;
2019-12-16 14:59:16 +00:00
export default withFeedbackPrompt (
_ _ (
'We are currently working on improving our checkout and providing merchants with tools and options to customize their checkout to their stores needs.' ,
'woo-gutenberg-products-block'
)
) ( CheckoutEditor ) ;