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';
|
|
|
|
import RadioControl from '@woocommerce/base-components/radio-control';
|
|
|
|
import InputRow from '@woocommerce/base-components/input-row';
|
2020-01-06 22:28:09 +00:00
|
|
|
import { CheckboxControl } from '@wordpress/components';
|
|
|
|
import CheckoutProvider from '@woocommerce/base-context/checkout-context';
|
|
|
|
import {
|
|
|
|
ExpressCheckoutFormControl,
|
|
|
|
PaymentMethods,
|
|
|
|
} from '@woocommerce/base-components/payment-methods';
|
|
|
|
|
2019-12-03 14:12:46 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-01-10 14:37:27 +00:00
|
|
|
import placeholderShippingMethods from '../placeholder-shipping-methods';
|
2019-12-03 14:12:46 +00:00
|
|
|
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
|
|
|
|
id="email-field"
|
|
|
|
type="email"
|
|
|
|
label={ __(
|
|
|
|
'Email address',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ contactFields.email }
|
|
|
|
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-01-06 22:28:09 +00:00
|
|
|
{ shippingMethods.length === 0 && (
|
2019-12-16 22:13:41 +00:00
|
|
|
<FormStep
|
|
|
|
id="shipping-fields"
|
2020-01-03 14:23:49 +00:00
|
|
|
className="wc-block-checkout__shipping-fields"
|
2019-12-16 22:13:41 +00:00
|
|
|
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 }
|
|
|
|
>
|
2020-01-06 22:28:09 +00:00
|
|
|
{ isEditor && <NoShipping /> }
|
|
|
|
</FormStep>
|
|
|
|
) }
|
|
|
|
{ shippingMethods.length > 0 && (
|
|
|
|
<Fragment>
|
|
|
|
<FormStep
|
|
|
|
id="shipping-fields"
|
|
|
|
className="wc-block-checkout__shipping-fields"
|
|
|
|
title={ __(
|
|
|
|
'Shipping address',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
description={ __(
|
|
|
|
'Enter the physical address where you want us to deliver your order.',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
stepNumber={ 2 }
|
|
|
|
>
|
|
|
|
<InputRow>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'First name',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.firstName }
|
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
firstName: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Surname',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.lastName }
|
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
lastName: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
2019-12-16 22:13:41 +00:00
|
|
|
<TextInput
|
|
|
|
label={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
'Street address',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
value={ shippingFields.streetAddress }
|
2019-12-16 22:13:41 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-01-06 22:28:09 +00:00
|
|
|
streetAddress: newValue,
|
2019-12-16 22:13:41 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
'Apartment, suite, etc.',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
value={ shippingFields.apartment }
|
2019-12-16 22:13:41 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-01-06 22:28:09 +00:00
|
|
|
apartment: newValue,
|
2019-12-16 22:13:41 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
2020-01-06 22:28:09 +00:00
|
|
|
<InputRow>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Country',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.country }
|
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
country: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'City',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-16 11:31:00 +00:00
|
|
|
value={ shippingFields.city }
|
2020-01-06 22:28:09 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-01-16 11:31:00 +00:00
|
|
|
city: newValue,
|
2020-01-06 22:28:09 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
|
|
|
<InputRow>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'County',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.county }
|
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
county: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
label={ __(
|
|
|
|
'Postal code',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ shippingFields.postalCode }
|
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
|
|
|
postalCode: newValue,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</InputRow>
|
2019-12-16 22:13:41 +00:00
|
|
|
<TextInput
|
2020-01-06 22:28:09 +00:00
|
|
|
type="tel"
|
2019-12-16 22:13:41 +00:00
|
|
|
label={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
'Phone',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
value={ shippingFields.phone }
|
2019-12-16 22:13:41 +00:00
|
|
|
onChange={ ( newValue ) =>
|
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-01-06 22:28:09 +00:00
|
|
|
phone: newValue,
|
2019-12-16 22:13:41 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
2020-01-06 22:28:09 +00:00
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-checkout__use-address-for-billing"
|
2019-12-16 22:13:41 +00:00
|
|
|
label={ __(
|
2020-01-06 22:28:09 +00:00
|
|
|
'Use same address for billing',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
checked={ shippingFields.useSameForBilling }
|
|
|
|
onChange={ () =>
|
2019-12-16 22:13:41 +00:00
|
|
|
setShippingFields( {
|
|
|
|
...shippingFields,
|
2020-01-06 22:28:09 +00:00
|
|
|
useSameForBilling: ! shippingFields.useSameForBilling,
|
2019-12-16 22:13:41 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
2020-01-06 22:28:09 +00:00
|
|
|
</FormStep>
|
|
|
|
<FormStep
|
|
|
|
id="shipping-option"
|
|
|
|
className="wc-block-checkout__shipping-option"
|
|
|
|
title={ __(
|
|
|
|
'Shipping options',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
description={ __(
|
|
|
|
'Select your shipping method below.',
|
2019-12-16 22:13:41 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
stepNumber={ 3 }
|
|
|
|
>
|
|
|
|
<RadioControl
|
|
|
|
selected={ shippingMethod.method || 'collect' }
|
|
|
|
id="shipping-method"
|
|
|
|
onChange={ ( option ) =>
|
|
|
|
setShippingMethod( {
|
|
|
|
...shippingMethod,
|
|
|
|
method: option,
|
|
|
|
} )
|
|
|
|
}
|
2020-01-10 14:37:27 +00:00
|
|
|
options={ placeholderShippingMethods.map(
|
|
|
|
( option ) => ( {
|
|
|
|
label: option.label,
|
|
|
|
value: option.value,
|
|
|
|
description: option.dispatcher,
|
|
|
|
secondaryLabel: option.price,
|
|
|
|
secondaryDescription: option.schedule,
|
|
|
|
} )
|
|
|
|
) }
|
2020-01-06 22:28:09 +00:00
|
|
|
/>
|
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-checkout__add-note"
|
|
|
|
label="Add order notes?"
|
|
|
|
checked={ shippingMethod.orderNote }
|
|
|
|
onChange={ () =>
|
|
|
|
setShippingMethod( {
|
|
|
|
...shippingMethod,
|
|
|
|
orderNote: ! shippingMethod.orderNote,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormStep>
|
|
|
|
</Fragment>
|
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;
|