@shopgate/engage
Version:
Shopgate's ENGAGE library.
61 lines (60 loc) • 2.04 kB
JavaScript
import React, { useMemo, useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { FormBuilder } from '@shopgate/engage/components';
import { useRegistration } from "../../hooks";
import Section from "../../../checkout/components/Checkout/CheckoutSection";
import { ELEMENT_ID_SHIPPING_CONTACT } from "../../constants";
import generateFormConfig from "./RegistrationFormShipping.config";
import { form, section, shippingFormSection } from "./RegistrationContent.style";
/**
* The RegistrationFormShipping component.
* @param {Object} props The component props
* @returns {JSX}
*/
import { jsx as _jsx } from "react/jsx-runtime";
const RegistrationFormShipping = ({
isGuest
}) => {
const {
supportedCountries,
countrySortOrder,
userLocation,
defaultShippingFormState,
shippingFormValidationErrors,
updateShippingForm,
isShippingFormVisible,
isShippingAddressSelectionEnabled,
numberOfAddressLines
} = useRegistration(isGuest);
const formConfig = useMemo(() => generateFormConfig({
supportedCountries,
countrySortOrder,
userLocation,
numberOfAddressLines
}), [countrySortOrder, numberOfAddressLines, supportedCountries, userLocation]);
const handleUpdate = useCallback(values => {
updateShippingForm(values);
}, [updateShippingForm]);
if (!isShippingAddressSelectionEnabled || !isShippingFormVisible) {
return null;
}
return /*#__PURE__*/_jsx(Section, {
title: "registration.headlines.shipping_address",
className: classNames(section, shippingFormSection),
hasForm: true,
id: ELEMENT_ID_SHIPPING_CONTACT,
children: /*#__PURE__*/_jsx(FormBuilder, {
className: form,
name: "RegistrationShipping",
config: formConfig,
defaults: defaultShippingFormState,
validationErrors: shippingFormValidationErrors,
handleUpdate: handleUpdate
})
});
};
RegistrationFormShipping.defaultProps = {
isGuest: false
};
export default RegistrationFormShipping;