/**
* External dependencies
*/
import { Fragment, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import FormStep from '@woocommerce/base-components/checkout/form-step';
import CheckoutForm from '@woocommerce/base-components/checkout/form';
import NoShipping from '@woocommerce/base-components/checkout/no-shipping';
import TextInput from '@woocommerce/base-components/text-input';
import { ShippingCountryInput } from '@woocommerce/base-components/country-input';
import { ShippingStateInput } from '@woocommerce/base-components/state-input';
import ShippingRatesControl, {
Packages,
} from '@woocommerce/base-components/shipping-rates-control';
import InputRow from '@woocommerce/base-components/input-row';
import { CheckboxControl } from '@wordpress/components';
import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils';
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
import CheckoutProvider from '@woocommerce/base-context/checkout-context';
import {
ExpressCheckoutFormControl,
PaymentMethods,
} from '@woocommerce/base-components/payment-methods';
import { SHIPPING_ENABLED } from '@woocommerce/block-settings';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import './style.scss';
import '../../../payment-methods-demo';
/**
* Component displaying an attribute filter.
*/
const Block = ( { shippingRates = [], isEditor = false } ) => {
const [ selectedShippingRate, setSelectedShippingRate ] = useState( {} );
const [ contactFields, setContactFields ] = useState( {} );
const [ shouldSavePayment, setShouldSavePayment ] = useState( true );
const [ shippingFields, setShippingFields ] = useState( {} );
const renderShippingRatesControlOption = ( option ) => ( {
label: decodeEntities( option.name ),
value: option.rate_id,
description: decodeEntities( option.description ),
secondaryLabel: (
),
secondaryDescription: decodeEntities( option.delivery_time ),
} );
return (
(
{ __(
'Already have an account? ',
'woo-gutenberg-products-block'
) }
{ __(
'Log in.',
'woo-gutenberg-products-block'
) }
) }
>
setContactFields( {
...contactFields,
email: newValue,
} )
}
/>
setContactFields( {
...contactFields,
keepUpdated: ! contactFields.keepUpdated,
} )
}
/>
{ SHIPPING_ENABLED && (
setShippingFields( {
...shippingFields,
firstName: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
lastName: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
streetAddress: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
apartment: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
country: newValue,
state: '',
} )
}
/>
setShippingFields( {
...shippingFields,
city: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
state: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
postcode: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
phone: newValue,
} )
}
/>
setShippingFields( {
...shippingFields,
useSameForBilling: ! shippingFields.useSameForBilling,
} )
}
/>
) }
{ SHIPPING_ENABLED &&
( shippingRates.length === 0 && isEditor ? (
) : (
{ shippingRates.length > 0 ? (
) : (
setSelectedShippingRate( {
...selectedShippingRate,
methods: newMethods,
} )
}
/>
) }
setSelectedShippingRate( {
...selectedShippingRate,
orderNote: ! selectedShippingRate.orderNote,
} )
}
/>
) ) }
{ /*@todo this should be something the payment method controls*/ }
setShouldSavePayment( ! shouldSavePayment )
}
/>
);
};
export default Block;