2019-12-03 14:12:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-12-16 22:13:41 +00:00
|
|
|
import { Fragment, useState } from '@wordpress/element';
|
2019-12-06 13:18:55 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import FormStep from '@woocommerce/base-components/checkout/form-step';
|
|
|
|
import CheckoutForm from '@woocommerce/base-components/checkout/form';
|
2019-12-16 22:13:41 +00:00
|
|
|
import NoShipping from '@woocommerce/base-components/checkout/no-shipping';
|
|
|
|
import TextInput from '@woocommerce/base-components/text-input';
|
2020-01-17 16:58:08 +00:00
|
|
|
import { ShippingCountryInput } from '@woocommerce/base-components/country-input';
|
2020-02-17 11:12:15 +00:00
|
|
|
import { ShippingStateInput } from '@woocommerce/base-components/state-input';
|
2020-02-14 03:43:13 +00:00
|
|
|
import ShippingRatesControl from '@woocommerce/base-components/shipping-rates-control';
|
2019-12-16 22:13:41 +00:00
|
|
|
import InputRow from '@woocommerce/base-components/input-row';
|
2020-01-06 22:28:09 +00:00
|
|
|
import { CheckboxControl } from '@wordpress/components';
|
2020-02-14 03:43:13 +00:00
|
|
|
import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils';
|
|
|
|
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
|
2020-01-06 22:28:09 +00:00
|
|
|
import CheckoutProvider from '@woocommerce/base-context/checkout-context';
|
|
|
|
import {
|
|
|
|
ExpressCheckoutFormControl,
|
|
|
|
PaymentMethods,
|
|
|
|
} from '@woocommerce/base-components/payment-methods';
|
2020-02-18 10:50:08 +00:00
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
2019-12-03 14:12:46 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-01-06 22:28:09 +00:00
|
|
|
import '../../../payment-methods-demo';
|
2019-12-03 14:12:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component displaying an attribute filter.
|
|
|
|
*/
|
2019-12-16 22:13:41 +00:00
|
|
|
const Block = ( { shippingMethods = [], isEditor = false } ) => {
|
|
|
|
const [ shippingMethod, setShippingMethod ] = useState( {} );
|
|
|
|
const [ contactFields, setContactFields ] = useState( {} );
|
|
|
|
const [ shouldSavePayment, setShouldSavePayment ] = useState( true );
|
|
|
|
const [ shippingFields, setShippingFields ] = useState( {} );
|
2019-12-03 14:12:46 +00:00
|
|
|
return (
|
2020-01-06 22:28:09 +00:00
|
|
|
<CheckoutProvider>
|
|
|
|
<ExpressCheckoutFormControl />
|
|
|
|
<CheckoutForm>
|
2019-12-16 22:13:41 +00:00
|
|
|
<FormStep
|
2020-01-06 22:28:09 +00:00
|
|
|
id="billing-fields"
|
|
|
|
className="wc-block-checkout__billing-fields"
|
2019-12-16 22:13:41 +00:00
|
|
|
title={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
'Contact information',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
description={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
"We'll use this email to send you details and updates about your order.",
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
stepNumber={ 1 }
|
|
|
|
stepHeadingContent={ () => (
|
|
|
|
<Fragment>
|
|
|
|
{ __(
|
|
|
|
'Already have an account? ',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
<a href="/wp-login.php">
|
|
|
|
{ __(
|
|
|
|
'Log in.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</a>
|
|
|
|
</Fragment>
|
|
|
|
) }
|
2019-12-16 22:13:41 +00:00
|
|
|
>
|
2020-01-06 22:28:09 +00:00
|
|
|
<TextInput
|
|
|
|
type="email"
|
|
|
|
label={ __(
|
|
|
|
'Email address',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ contactFields.email }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="email"
|
2020-01-06 22:28:09 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setContactFields( {
|
|
|
|
...contactFields,
|
|
|
|
email: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-checkout__keep-updated"
|
|
|
|
label={ __(
|
|
|
|
'Keep me up to date on news and exclusive offers',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ contactFields.keepUpdated }
|
|
|
|
onChange={ () =>
|
|
|
|
setContactFields( {
|
|
|
|
...contactFields,
|
|
|
|
keepUpdated: ! contactFields.keepUpdated,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
2019-12-16 22:13:41 +00:00
|
|
|
</FormStep>
|
2020-02-14 03:43:13 +00:00
|
|
|
<FormStep
|
|
|
|
id="shipping-fields"
|
|
|
|
className="wc-block-checkout__shipping-fields"
|
|
|
|
title={ __(
|
|
|
|
'Shipping address',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
description={ __(
|
|
|
|
'Enter the physical address where you want us to deliver your order.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
stepNumber={ 2 }
|
|
|
|
>
|
|
|
|
<InputRow>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'First name',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.firstName }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="given-name"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
firstName: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Surname',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.lastName }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="family-name"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
lastName: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Street address',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-14 03:43:13 +00:00
|
|
|
value={ shippingFields.streetAddress }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="address-line1"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
streetAddress: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Apartment, suite, etc.',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-14 03:43:13 +00:00
|
|
|
value={ shippingFields.apartment }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="address-line2"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
apartment: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<InputRow>
|
|
|
|
<ShippingCountryInput
|
|
|
|
label={ __(
|
|
|
|
'Country / Region',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-14 03:43:13 +00:00
|
|
|
value={ shippingFields.country }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="country"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
country: newValue,
|
2020-02-17 11:12:15 +00:00
|
|
|
state: '',
|
2020-02-14 03:43:13 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'City',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-14 03:43:13 +00:00
|
|
|
value={ shippingFields.city }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="address-level2"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
city: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
|
|
|
<InputRow>
|
2020-02-17 11:12:15 +00:00
|
|
|
<ShippingStateInput
|
2020-02-14 12:30:33 +00:00
|
|
|
country={ shippingFields.country }
|
2020-02-14 03:43:13 +00:00
|
|
|
label={ __(
|
2020-02-17 11:12:15 +00:00
|
|
|
'State / County',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-17 11:12:15 +00:00
|
|
|
value={ shippingFields.state }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="address-level1"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-02-17 11:12:15 +00:00
|
|
|
state: newValue,
|
2020-02-14 03:43:13 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Postal code',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-02-17 11:12:15 +00:00
|
|
|
value={ shippingFields.postcode }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="postal-code"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-02-17 11:12:15 +00:00
|
|
|
postcode: newValue,
|
2020-02-14 03:43:13 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
|
|
|
<TextInput
|
|
|
|
type="tel"
|
|
|
|
label={ __( 'Phone', 'woo-gutenberg-products-block' ) }
|
|
|
|
value={ shippingFields.phone }
|
2020-02-19 15:10:26 +00:00
|
|
|
autoComplete="tel"
|
2020-02-14 03:43:13 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
phone: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-checkout__use-address-for-billing"
|
|
|
|
label={ __(
|
|
|
|
'Use same address for billing',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ shippingFields.useSameForBilling }
|
|
|
|
onChange={ () =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
useSameForBilling: ! shippingFields.useSameForBilling,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormStep>
|
|
|
|
{ shippingMethods.length === 0 && isEditor ? (
|
|
|
|
<NoShipping />
|
|
|
|
) : (
|
|
|
|
<FormStep
|
|
|
|
id="shipping-option"
|
|
|
|
className="wc-block-checkout__shipping-option"
|
|
|
|
title={ __(
|
|
|
|
'Shipping options',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
description={ __(
|
|
|
|
'Select your shipping method below.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
stepNumber={ 3 }
|
|
|
|
>
|
|
|
|
<ShippingRatesControl
|
|
|
|
address={
|
|
|
|
shippingFields.country
|
|
|
|
? {
|
|
|
|
address_1:
|
|
|
|
shippingFields.streetAddress,
|
|
|
|
address_2: shippingFields.apartment,
|
|
|
|
city: shippingFields.city,
|
2020-02-17 11:12:15 +00:00
|
|
|
state: shippingFields.state,
|
|
|
|
postcode: shippingFields.postcode,
|
2020-02-14 03:43:13 +00:00
|
|
|
country: shippingFields.country,
|
|
|
|
}
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
noResultsMessage={ __(
|
|
|
|
'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
onChange={ ( newMethods ) =>
|
|
|
|
setShippingMethod( {
|
|
|
|
...shippingMethod,
|
|
|
|
methods: newMethods,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
renderOption={ ( option ) => ( {
|
2020-02-18 10:50:08 +00:00
|
|
|
label: decodeEntities( option.name ),
|
2020-02-14 03:43:13 +00:00
|
|
|
value: option.rate_id,
|
2020-02-18 10:50:08 +00:00
|
|
|
description: decodeEntities(
|
|
|
|
option.description
|
|
|
|
),
|
2020-02-14 03:43:13 +00:00
|
|
|
secondaryLabel: (
|
|
|
|
<FormattedMonetaryAmount
|
|
|
|
currency={ getCurrencyFromPriceResponse(
|
|
|
|
option
|
|
|
|
) }
|
|
|
|
value={ option.price }
|
|
|
|
/>
|
|
|
|
),
|
2020-02-18 10:50:08 +00:00
|
|
|
secondaryDescription: decodeEntities(
|
|
|
|
option.delivery_time
|
|
|
|
),
|
2020-02-14 03:43:13 +00:00
|
|
|
} ) }
|
|
|
|
selected={ shippingMethod.methods }
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-checkout__add-note"
|
|
|
|
label="Add order notes?"
|
|
|
|
checked={ shippingMethod.orderNote }
|
|
|
|
onChange={ () =>
|
|
|
|
setShippingMethod( {
|
|
|
|
...shippingMethod,
|
|
|
|
orderNote: ! shippingMethod.orderNote,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormStep>
|
2019-12-06 13:18:55 +00:00
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
<FormStep
|
|
|
|
id="payment-method"
|
|
|
|
className="wc-block-checkout__payment-method"
|
|
|
|
title={ __(
|
|
|
|
'Payment method',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
description={ __(
|
|
|
|
'Select a payment method below.',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
stepNumber={ 4 }
|
|
|
|
>
|
|
|
|
<PaymentMethods />
|
|
|
|
{ /*@todo this should be something the payment method controls*/ }
|
|
|
|
<CheckboxControl
|
2020-01-10 09:42:53 +00:00
|
|
|
className="wc-block-checkout__save-card-info"
|
2020-01-06 22:28:09 +00:00
|
|
|
label={ __(
|
|
|
|
'Save payment information to my account for future purchases.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ shouldSavePayment }
|
|
|
|
onChange={ () =>
|
|
|
|
setShouldSavePayment( ! shouldSavePayment )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormStep>
|
|
|
|
</CheckoutForm>
|
|
|
|
</CheckoutProvider>
|
2019-12-03 14:12:46 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Block;
|