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-02-26 15:50:53 +00:00
import { previewShippingRates } from '@woocommerce/resource-previews' ;
import { SHIPPING _METHODS _EXIST } from '@woocommerce/block-settings' ;
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 ,
} from '@wordpress/components' ;
2020-03-06 11:43:40 +00:00
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary' ;
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 ,
} = 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 = { _ _ (
'Company name' ,
'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 = { _ _ (
'Apartment, suite, unit etc' ,
'woo-gutenberg-products-block'
) }
checked = { showAddress2Field }
onChange = { ( ) =>
setAttributes ( {
showAddress2Field : ! showAddress2Field ,
} )
}
/ >
< ToggleControl
label = { _ _ (
'Phone number' ,
'woo-gutenberg-products-block'
) }
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 >
< / 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 }
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 ) ;