@commercelayer/react-components 4.10.2 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/addresses/AddressInputSelect.d.ts +29 -0
- package/lib/cjs/components/addresses/AddressInputSelect.js +2 -0
- package/lib/cjs/components/addresses/BillingAddressForm.js +1 -1
- package/lib/cjs/components/addresses/SaveAddressesButton.d.ts +1 -0
- package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/utils/addressesManager.d.ts +6 -3
- package/lib/cjs/utils/addressesManager.js +1 -1
- package/lib/cjs/utils/validateFormFields.d.ts +1 -1
- package/lib/cjs/utils/validateFormFields.js +1 -1
- package/lib/esm/components/addresses/AddressInputSelect.d.ts +29 -0
- package/lib/esm/components/addresses/AddressInputSelect.js +2 -0
- package/lib/esm/components/addresses/BillingAddressForm.js +1 -1
- package/lib/esm/components/addresses/SaveAddressesButton.d.ts +1 -0
- package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/utils/addressesManager.d.ts +6 -3
- package/lib/esm/utils/addressesManager.js +1 -1
- package/lib/esm/utils/validateFormFields.d.ts +1 -1
- package/lib/esm/utils/validateFormFields.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type BaseSelectComponentProps } from '../../typings/index';
|
|
3
|
+
import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
|
|
4
|
+
type SelectFieldName = `billing_address_${`metadata_${string}`}` | `shipping_address_${`metadata_${string}`}`;
|
|
5
|
+
interface Props extends Omit<BaseSelectComponentProps, 'name'>, Pick<JSX.IntrinsicElements['select'], 'className' | 'id' | 'style'> {
|
|
6
|
+
name: Extract<AddressValuesKeys, SelectFieldName>;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The AddressInputSelect component creates a form `select` related to the `metadata` attribute of the `address` object.
|
|
12
|
+
*
|
|
13
|
+
* It requires a `name` prop to define the field name associated with the select and accepts most of HTML `select` tag standard props.
|
|
14
|
+
*
|
|
15
|
+
* <span title="Name prop" type="info">
|
|
16
|
+
* The `name` prop must respect the convention of mentioning one of the available addresses forms (`billing_address` or `shipping_address`) concatenated to the `metadata` address attribute with a `_` separator. Eg.: `billing_address_metadata_your-key`.
|
|
17
|
+
* </span>
|
|
18
|
+
*
|
|
19
|
+
* <span title="Requirement" type="warning">
|
|
20
|
+
* It must to be used inside either the `<BillingAddressForm>` or the `<ShippingAddressForm>` component.
|
|
21
|
+
* </span>
|
|
22
|
+
*
|
|
23
|
+
* <span title="Fields" type="info">
|
|
24
|
+
* Check the `addresses` resource from our [Core API documentation](https://docs.commercelayer.io/core/v/api-reference/addresses/object)
|
|
25
|
+
* for more details about the available attributes to render.
|
|
26
|
+
* </span>
|
|
27
|
+
*/
|
|
28
|
+
export declare function AddressInputSelect(props: Props): JSX.Element;
|
|
29
|
+
export default AddressInputSelect;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AddressInputSelect=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),BaseSelect_1=tslib_1.__importDefault(require("../utils/BaseSelect")),BillingAddressFormContext_1=tslib_1.__importDefault(require("../../context/BillingAddressFormContext")),ShippingAddressFormContext_1=tslib_1.__importDefault(require("../../context/ShippingAddressFormContext"));function AddressInputSelect(props){const{required=!0,value,name,className,options}=props,p=tslib_1.__rest(props,["required","value","name","className","options"]),billingAddress=(0,react_1.useContext)(BillingAddressFormContext_1.default),shippingAddress=(0,react_1.useContext)(ShippingAddressFormContext_1.default);(0,react_1.useEffect)(()=>{value&&billingAddress?.setValue&&billingAddress.setValue(name,value),value&&shippingAddress?.setValue&&shippingAddress.setValue(name,value)},[value]);const hasError=(0,react_1.useMemo)(()=>{var _a,_b,_c,_d;return!!(!((_b=(_a=billingAddress?.errors)===null||_a===void 0?void 0:_a[name])===null||_b===void 0)&&_b.error||!((_d=(_c=shippingAddress?.errors)===null||_c===void 0?void 0:_c[name])===null||_d===void 0)&&_d.error)},[value,billingAddress?.errors,shippingAddress?.errors]),errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=`${className??""} ${hasError&&errorClassName?errorClassName:""}`;return(0,jsx_runtime_1.jsx)(BaseSelect_1.default,Object.assign({className:classNameComputed,ref:billingAddress?.validation||shippingAddress?.validation,required,options,name,value},p))}exports.AddressInputSelect=AddressInputSelect,exports.default=AddressInputSelect;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BillingAddressForm=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),rapid_form_1=require("rapid-form"),react_1=require("react"),BillingAddressFormContext_1=tslib_1.__importDefault(require("../../context/BillingAddressFormContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),localStorage_1=require("../../utils/localStorage");function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,customFieldMessageError}=props,p=tslib_1.__rest(props,["children","errorClassName","autoComplete","reset","customFieldMessageError"]),{validation,values,errors,reset:resetForm,setValue:setValueForm}=(0,rapid_form_1.useRapidForm)(),{setAddressErrors,setAddress,isBusiness}=(0,react_1.useContext)(AddressContext_1.default),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null);(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e,_f;if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),(0,isEmpty_1.default)(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BillingAddressForm=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),rapid_form_1=require("rapid-form"),react_1=require("react"),BillingAddressFormContext_1=tslib_1.__importDefault(require("../../context/BillingAddressFormContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),localStorage_1=require("../../utils/localStorage");function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,customFieldMessageError}=props,p=tslib_1.__rest(props,["children","errorClassName","autoComplete","reset","customFieldMessageError"]),{validation,values,errors,reset:resetForm,setValue:setValueForm}=(0,rapid_form_1.useRapidForm)(),{setAddressErrors,setAddress,isBusiness}=(0,react_1.useContext)(AddressContext_1.default),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null);(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e,_f;if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),(0,isEmpty_1.default)(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=(_a=errors[fieldName])===null||_a===void 0?void 0:_a.code,message=(_b=errors[fieldName])===null||_b===void 0?void 0:_b.message;if(["billing_address_state_code"].includes(fieldName))values?.state_code?formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):delete errors[fieldName];else{const customMessage=customFieldMessageError!=null?customFieldMessageError({field:fieldName,code,message,value:values[fieldName].value}):null;if(customFieldMessageError!=null&&code==="VALIDATION_ERROR"&&!customMessage)continue;formErrors.push({code,message:(_c=customMessage??message)!==null&&_c!==void 0?_c:"",resource:"billing_address",field:fieldName})}}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_e=(_d=ref.current)===null||_d===void 0?void 0:_d.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_e===void 0?void 0:_e.checked)||(0,localStorage_1.getSaveBillingAddressToAddressBook)();reset&&(!(0,isEmpty_1.default)(values)||!(0,isEmpty_1.default)(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_f=ref.current)===null||_f===void 0||_f.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{setValueForm(name,value);const field={[name.replace("billing_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"billing_address"})},errorClassName,requiresBillingInfo:order?.requires_billing_info||!1,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return(0,jsx_runtime_1.jsx)(BillingAddressFormContext_1.default.Provider,{value:providerValues,children:(0,jsx_runtime_1.jsx)("form",Object.assign({ref,autoComplete},p,{children}))})}exports.BillingAddressForm=BillingAddressForm,exports.default=BillingAddressForm;
|
|
@@ -12,6 +12,7 @@ interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onCl
|
|
|
12
12
|
label?: string | ReactNode;
|
|
13
13
|
onClick?: (params: TOnClick) => void;
|
|
14
14
|
addressId?: string;
|
|
15
|
+
requiredMetadataFields?: string[];
|
|
15
16
|
}
|
|
16
17
|
export declare function SaveAddressesButton(props: Props): JSX.Element;
|
|
17
18
|
export default SaveAddressesButton;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SaveAddressesButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),addressesManager_1=require("../../utils/addressesManager"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),validateFormFields_1=require("../../utils/validateFormFields");function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,onClick}=props,p=tslib_1.__rest(props,["children","label","resource","disabled","addressId","onClick"]),{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=(0,react_1.useContext)(AddressContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{customerEmail:email,addresses,isGuest,createCustomerAddress}=(0,react_1.useContext)(CustomerContext_1.default),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=(0,validateFormFields_1.validateValue)(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>Object.assign(Object.assign({},acc),{[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=(0,addressesManager_1.addressesController)({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors}),countryLockDisable=(0,addressesManager_1.countryLockController)({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=yield saveAddresses(email);else if(createCustomerAddress&&billingAddress){const address=Object.assign({},billingAddress);addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}}),parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()}},p,{children:(0,isFunction_1.default)(label)?label():label}))}exports.SaveAddressesButton=SaveAddressesButton,exports.default=SaveAddressesButton;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SaveAddressesButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),addressesManager_1=require("../../utils/addressesManager"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),validateFormFields_1=require("../../utils/validateFormFields");function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,requiredMetadataFields,onClick}=props,p=tslib_1.__rest(props,["children","label","resource","disabled","addressId","requiredMetadataFields","onClick"]),{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=(0,react_1.useContext)(AddressContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{customerEmail:email,addresses,isGuest,createCustomerAddress}=(0,react_1.useContext)(CustomerContext_1.default),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=(0,validateFormFields_1.validateValue)(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>Object.assign(Object.assign({},acc),{[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=(0,addressesManager_1.addressesController)({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors,requiredMetadataFields}),countryLockDisable=(0,addressesManager_1.countryLockController)({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=yield saveAddresses(email);else if(createCustomerAddress&&billingAddress){const address=Object.assign({},billingAddress);addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}}),parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()}},p,{children:(0,isFunction_1.default)(label)?label():label}))}exports.SaveAddressesButton=SaveAddressesButton,exports.default=SaveAddressesButton;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './components/addresses/Address';
|
|
|
5
5
|
export * from './components/addresses/AddressCountrySelector';
|
|
6
6
|
export * from './components/addresses/AddressField';
|
|
7
7
|
export * from './components/addresses/AddressInput';
|
|
8
|
+
export * from './components/addresses/AddressInputSelect';
|
|
8
9
|
export * from './components/addresses/AddressStateSelector';
|
|
9
10
|
export * from './components/addresses/AddressesContainer';
|
|
10
11
|
export * from './components/addresses/AddressesEmpty';
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib");tslib_1.__exportStar(require("./components/ExternalFunction"),exports),tslib_1.__exportStar(require("./components/MetadataInput"),exports),tslib_1.__exportStar(require("./components/SubmitButton"),exports),tslib_1.__exportStar(require("./components/addresses/Address"),exports),tslib_1.__exportStar(require("./components/addresses/AddressCountrySelector"),exports),tslib_1.__exportStar(require("./components/addresses/AddressField"),exports),tslib_1.__exportStar(require("./components/addresses/AddressInput"),exports),tslib_1.__exportStar(require("./components/addresses/AddressStateSelector"),exports),tslib_1.__exportStar(require("./components/addresses/AddressesContainer"),exports),tslib_1.__exportStar(require("./components/addresses/AddressesEmpty"),exports),tslib_1.__exportStar(require("./components/addresses/BillingAddressContainer"),exports),tslib_1.__exportStar(require("./components/addresses/BillingAddressForm"),exports),tslib_1.__exportStar(require("./components/addresses/SaveAddressesButton"),exports),tslib_1.__exportStar(require("./components/addresses/ShippingAddressContainer"),exports),tslib_1.__exportStar(require("./components/addresses/ShippingAddressForm"),exports),tslib_1.__exportStar(require("./components/auth/CommerceLayer"),exports),tslib_1.__exportStar(require("./components/customers/CustomerAddressForm"),exports),tslib_1.__exportStar(require("./components/customers/CustomerContainer"),exports),tslib_1.__exportStar(require("./components/customers/CustomerField"),exports),tslib_1.__exportStar(require("./components/customers/CustomerInput"),exports),tslib_1.__exportStar(require("./components/customers/SaveCustomerButton"),exports),tslib_1.__exportStar(require("./components/errors/Errors"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCard"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardContainer"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardCurrencySelector"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardInput"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponCode"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponForm"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponInput"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponRemoveButton"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponSubmit"),exports),tslib_1.__exportStar(require("./components/in_stock_subscriptions/InStockSubscriptionButton"),exports),tslib_1.__exportStar(require("./components/in_stock_subscriptions/InStockSubscriptionsContainer"),exports),tslib_1.__exportStar(require("./components/line_items/LineItem"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemAmount"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemCode"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemField"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemImage"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemName"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemOption"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemOptions"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemQuantity"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemRemoveLink"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsContainer"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsCount"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsEmpty"),exports),tslib_1.__exportStar(require("./components/orders/AddToCartButton"),exports),tslib_1.__exportStar(require("./components/orders/AdjustmentAmount"),exports),tslib_1.__exportStar(require("./components/orders/CartLink"),exports),tslib_1.__exportStar(require("./components/orders/CheckoutLink"),exports),tslib_1.__exportStar(require("./components/orders/DiscountAmount"),exports),tslib_1.__exportStar(require("./components/orders/GiftCardAmount"),exports),tslib_1.__exportStar(require("./components/orders/OrderContainer"),exports),tslib_1.__exportStar(require("./components/orders/OrderList"),exports),tslib_1.__exportStar(require("./components/orders/OrderListEmpty"),exports),tslib_1.__exportStar(require("./components/orders/OrderListRow"),exports),tslib_1.__exportStar(require("./components/orders/OrderNumber"),exports),tslib_1.__exportStar(require("./components/orders/OrderStorage"),exports),tslib_1.__exportStar(require("./components/orders/PaymentMethodAmount"),exports),tslib_1.__exportStar(require("./components/orders/PlaceOrderButton"),exports),tslib_1.__exportStar(require("./components/orders/PlaceOrderContainer"),exports),tslib_1.__exportStar(require("./components/orders/PrivacyAndTermsCheckbox"),exports),tslib_1.__exportStar(require("./components/orders/ShippingAmount"),exports),tslib_1.__exportStar(require("./components/orders/SubTotalAmount"),exports),tslib_1.__exportStar(require("./components/orders/TaxesAmount"),exports),tslib_1.__exportStar(require("./components/orders/TotalAmount"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelField"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItem"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItemField"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItemsCount"),exports),tslib_1.__exportStar(require("./components/parcels/Parcels"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelsCount"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethod"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodName"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodPrice"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodRadioButton"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodsContainer"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSource"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceBrandIcon"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceBrandName"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceDetail"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceEditButton"),exports),tslib_1.__exportStar(require("./components/prices/Price"),exports),tslib_1.__exportStar(require("./components/prices/PricesContainer"),exports),tslib_1.__exportStar(require("./components/shipments/Shipment"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentField"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentsContainer"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentsCount"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethod"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodName"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodPrice"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodRadioButton"),exports),tslib_1.__exportStar(require("./components/skus/AvailabilityContainer"),exports),tslib_1.__exportStar(require("./components/skus/AvailabilityTemplate"),exports),tslib_1.__exportStar(require("./components/skus/DeliveryLeadTime"),exports),tslib_1.__exportStar(require("./components/skus/SkuField"),exports),tslib_1.__exportStar(require("./components/skus/SkuList"),exports),tslib_1.__exportStar(require("./components/skus/SkuListsContainer"),exports),tslib_1.__exportStar(require("./components/skus/Skus"),exports),tslib_1.__exportStar(require("./components/skus/SkusContainer"),exports),tslib_1.__exportStar(require("./components/stock_transfers/StockTransfer"),exports),tslib_1.__exportStar(require("./components/stock_transfers/StockTransferField"),exports),tslib_1.__exportStar(require("./hooks/useOrderContainer"),exports),tslib_1.__exportStar(require("./hooks/useCommerceLayer"),exports),tslib_1.__exportStar(require("./hooks/useCustomerContainer"),exports),tslib_1.__exportStar(require("./typings/errors"),exports);
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib");tslib_1.__exportStar(require("./components/ExternalFunction"),exports),tslib_1.__exportStar(require("./components/MetadataInput"),exports),tslib_1.__exportStar(require("./components/SubmitButton"),exports),tslib_1.__exportStar(require("./components/addresses/Address"),exports),tslib_1.__exportStar(require("./components/addresses/AddressCountrySelector"),exports),tslib_1.__exportStar(require("./components/addresses/AddressField"),exports),tslib_1.__exportStar(require("./components/addresses/AddressInput"),exports),tslib_1.__exportStar(require("./components/addresses/AddressInputSelect"),exports),tslib_1.__exportStar(require("./components/addresses/AddressStateSelector"),exports),tslib_1.__exportStar(require("./components/addresses/AddressesContainer"),exports),tslib_1.__exportStar(require("./components/addresses/AddressesEmpty"),exports),tslib_1.__exportStar(require("./components/addresses/BillingAddressContainer"),exports),tslib_1.__exportStar(require("./components/addresses/BillingAddressForm"),exports),tslib_1.__exportStar(require("./components/addresses/SaveAddressesButton"),exports),tslib_1.__exportStar(require("./components/addresses/ShippingAddressContainer"),exports),tslib_1.__exportStar(require("./components/addresses/ShippingAddressForm"),exports),tslib_1.__exportStar(require("./components/auth/CommerceLayer"),exports),tslib_1.__exportStar(require("./components/customers/CustomerAddressForm"),exports),tslib_1.__exportStar(require("./components/customers/CustomerContainer"),exports),tslib_1.__exportStar(require("./components/customers/CustomerField"),exports),tslib_1.__exportStar(require("./components/customers/CustomerInput"),exports),tslib_1.__exportStar(require("./components/customers/SaveCustomerButton"),exports),tslib_1.__exportStar(require("./components/errors/Errors"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCard"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardContainer"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardCurrencySelector"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardInput"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponCode"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponForm"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponInput"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponRemoveButton"),exports),tslib_1.__exportStar(require("./components/gift_cards/GiftCardOrCouponSubmit"),exports),tslib_1.__exportStar(require("./components/in_stock_subscriptions/InStockSubscriptionButton"),exports),tslib_1.__exportStar(require("./components/in_stock_subscriptions/InStockSubscriptionsContainer"),exports),tslib_1.__exportStar(require("./components/line_items/LineItem"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemAmount"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemCode"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemField"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemImage"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemName"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemOption"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemOptions"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemQuantity"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemRemoveLink"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsContainer"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsCount"),exports),tslib_1.__exportStar(require("./components/line_items/LineItemsEmpty"),exports),tslib_1.__exportStar(require("./components/orders/AddToCartButton"),exports),tslib_1.__exportStar(require("./components/orders/AdjustmentAmount"),exports),tslib_1.__exportStar(require("./components/orders/CartLink"),exports),tslib_1.__exportStar(require("./components/orders/CheckoutLink"),exports),tslib_1.__exportStar(require("./components/orders/DiscountAmount"),exports),tslib_1.__exportStar(require("./components/orders/GiftCardAmount"),exports),tslib_1.__exportStar(require("./components/orders/OrderContainer"),exports),tslib_1.__exportStar(require("./components/orders/OrderList"),exports),tslib_1.__exportStar(require("./components/orders/OrderListEmpty"),exports),tslib_1.__exportStar(require("./components/orders/OrderListRow"),exports),tslib_1.__exportStar(require("./components/orders/OrderNumber"),exports),tslib_1.__exportStar(require("./components/orders/OrderStorage"),exports),tslib_1.__exportStar(require("./components/orders/PaymentMethodAmount"),exports),tslib_1.__exportStar(require("./components/orders/PlaceOrderButton"),exports),tslib_1.__exportStar(require("./components/orders/PlaceOrderContainer"),exports),tslib_1.__exportStar(require("./components/orders/PrivacyAndTermsCheckbox"),exports),tslib_1.__exportStar(require("./components/orders/ShippingAmount"),exports),tslib_1.__exportStar(require("./components/orders/SubTotalAmount"),exports),tslib_1.__exportStar(require("./components/orders/TaxesAmount"),exports),tslib_1.__exportStar(require("./components/orders/TotalAmount"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelField"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItem"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItemField"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelLineItemsCount"),exports),tslib_1.__exportStar(require("./components/parcels/Parcels"),exports),tslib_1.__exportStar(require("./components/parcels/ParcelsCount"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethod"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodName"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodPrice"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodRadioButton"),exports),tslib_1.__exportStar(require("./components/payment_methods/PaymentMethodsContainer"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSource"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceBrandIcon"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceBrandName"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceDetail"),exports),tslib_1.__exportStar(require("./components/payment_source/PaymentSourceEditButton"),exports),tslib_1.__exportStar(require("./components/prices/Price"),exports),tslib_1.__exportStar(require("./components/prices/PricesContainer"),exports),tslib_1.__exportStar(require("./components/shipments/Shipment"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentField"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentsContainer"),exports),tslib_1.__exportStar(require("./components/shipments/ShipmentsCount"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethod"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodName"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodPrice"),exports),tslib_1.__exportStar(require("./components/shipping_methods/ShippingMethodRadioButton"),exports),tslib_1.__exportStar(require("./components/skus/AvailabilityContainer"),exports),tslib_1.__exportStar(require("./components/skus/AvailabilityTemplate"),exports),tslib_1.__exportStar(require("./components/skus/DeliveryLeadTime"),exports),tslib_1.__exportStar(require("./components/skus/SkuField"),exports),tslib_1.__exportStar(require("./components/skus/SkuList"),exports),tslib_1.__exportStar(require("./components/skus/SkuListsContainer"),exports),tslib_1.__exportStar(require("./components/skus/Skus"),exports),tslib_1.__exportStar(require("./components/skus/SkusContainer"),exports),tslib_1.__exportStar(require("./components/stock_transfers/StockTransfer"),exports),tslib_1.__exportStar(require("./components/stock_transfers/StockTransferField"),exports),tslib_1.__exportStar(require("./hooks/useOrderContainer"),exports),tslib_1.__exportStar(require("./hooks/useCommerceLayer"),exports),tslib_1.__exportStar(require("./hooks/useCustomerContainer"),exports),tslib_1.__exportStar(require("./typings/errors"),exports);
|
|
@@ -9,8 +9,9 @@ interface BillingAddressControllerProps {
|
|
|
9
9
|
invertAddresses?: boolean;
|
|
10
10
|
shippingDisable?: boolean;
|
|
11
11
|
shipToDifferentAddress?: boolean;
|
|
12
|
+
requiredMetadataFields?: string[];
|
|
12
13
|
}
|
|
13
|
-
export declare function billingAddressController({ billing_address, billingAddressId, errors, requiresBillingInfo, invertAddresses, shipToDifferentAddress, shippingDisable }: BillingAddressControllerProps): boolean;
|
|
14
|
+
export declare function billingAddressController({ billing_address, billingAddressId, errors, requiresBillingInfo, invertAddresses, shipToDifferentAddress, shippingDisable, requiredMetadataFields }: BillingAddressControllerProps): boolean;
|
|
14
15
|
interface ShippingAddressControllerProps {
|
|
15
16
|
billingDisable?: boolean;
|
|
16
17
|
errors?: BaseError[];
|
|
@@ -19,8 +20,9 @@ interface ShippingAddressControllerProps {
|
|
|
19
20
|
shipping_address?: AddressCreate;
|
|
20
21
|
shippingAddressId?: string;
|
|
21
22
|
invertAddresses?: boolean;
|
|
23
|
+
requiredMetadataFields?: string[];
|
|
22
24
|
}
|
|
23
|
-
export declare function shippingAddressController({ billingDisable, errors, shipToDifferentAddress, shipping_address, shippingAddressId, invertAddresses, requiresBillingInfo }: ShippingAddressControllerProps): boolean;
|
|
25
|
+
export declare function shippingAddressController({ billingDisable, errors, shipToDifferentAddress, shipping_address, shippingAddressId, invertAddresses, requiresBillingInfo, requiredMetadataFields }: ShippingAddressControllerProps): boolean;
|
|
24
26
|
interface CountryLockControllerProps {
|
|
25
27
|
addresses?: Address[] | null;
|
|
26
28
|
billing_address?: TCustomerAddress;
|
|
@@ -52,8 +54,9 @@ interface AddressControllerProps {
|
|
|
52
54
|
errors?: BaseError[];
|
|
53
55
|
requiresBillingInfo?: boolean | null;
|
|
54
56
|
invertAddresses?: boolean;
|
|
57
|
+
requiredMetadataFields?: string[];
|
|
55
58
|
}
|
|
56
|
-
export declare function addressesController({ billing_address, billingAddressId, shipToDifferentAddress, shipping_address, shippingAddressId, errors, requiresBillingInfo, invertAddresses }: AddressControllerProps): {
|
|
59
|
+
export declare function addressesController({ billing_address, billingAddressId, shipToDifferentAddress, shipping_address, shippingAddressId, errors, requiresBillingInfo, invertAddresses, requiredMetadataFields }: AddressControllerProps): {
|
|
57
60
|
billingDisable: boolean;
|
|
58
61
|
shippingDisable: boolean;
|
|
59
62
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addressesController=exports.invertedAddressesHandler=exports.countryLockController=exports.shippingAddressController=exports.billingAddressController=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),validateFormFields_1=require("./validateFormFields"),AddressReducer_1=require("../reducers/AddressReducer");function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable}){let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!(0,isEmpty_1.default)(errors)||(0,isEmpty_1.default)(billing_address);if((0,isEmpty_1.default)(errors)&&!(0,isEmpty_1.default)(billing_address))
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addressesController=exports.invertedAddressesHandler=exports.countryLockController=exports.shippingAddressController=exports.billingAddressController=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),validateFormFields_1=require("./validateFormFields"),AddressReducer_1=require("../reducers/AddressReducer");function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable,requiredMetadataFields}){console.log("requiredMetadataFields",requiredMetadataFields);let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!(0,isEmpty_1.default)(errors)||(0,isEmpty_1.default)(billing_address);if((0,isEmpty_1.default)(errors)&&!(0,isEmpty_1.default)(billing_address)){let formFields=[...AddressReducer_1.addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formFields=[...formFields,...requiredMetadataFields]),invertAddresses||(requiresBillingInfo&&(formFields=[...formFields,"billing_info"]),console.log("formFields",formFields)),billingDisable=!!(billing_address&&(0,validateFormFields_1.fieldsExist)(billing_address,formFields))}return billingDisable&&!(0,isEmpty_1.default)(billingAddressId)&&(0,isEmpty_1.default)(billing_address)&&(billingDisable=!1),billingDisable}exports.billingAddressController=billingAddressController;function shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses=!1,requiresBillingInfo=!1,requiredMetadataFields}){let shippingDisable=invertAddresses?!(0,isEmpty_1.default)(errors)||(0,isEmpty_1.default)(shipping_address):!!(!billingDisable&&shipToDifferentAddress);if((0,isEmpty_1.default)(errors)&&!(0,isEmpty_1.default)(shipping_address)){let formField=[...AddressReducer_1.addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formField=[...formField,...requiredMetadataFields]),invertAddresses?(requiresBillingInfo&&(formField=[...formField,"billing_info"]),shippingDisable=!!(shipping_address&&(0,validateFormFields_1.fieldsExist)(shipping_address,formField))):shipToDifferentAddress&&(shipping_address==null||delete shipping_address.billing_info,shippingDisable=!!(shipping_address&&(0,validateFormFields_1.fieldsExist)(shipping_address,formField)))}return shippingDisable&&!(0,isEmpty_1.default)(shippingAddressId)&&(0,isEmpty_1.default)(shipping_address)&&(shippingDisable=!1),shippingDisable}exports.shippingAddressController=shippingAddressController;function countryLockController({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId,lineItems}){var _a;if((_a=lineItems?.filter(lineItem=>{var _a2,_b;return((_a2=lineItem?.item)===null||_a2===void 0?void 0:_a2.type)!=null&&["skus","bundles"].includes((_b=lineItem?.item)===null||_b===void 0?void 0:_b.type)}))===null||_a===void 0?void 0:_a.every(lineItem=>{var _a2;return((_a2=lineItem?.item)===null||_a2===void 0?void 0:_a2.do_not_ship)===!0}))return!1;if(countryCodeLock&&!(0,isEmpty_1.default)(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===billingAddressId||a?.reference===billingAddressId)&&a?.country_code!==countryCodeLock);if(!(0,isEmpty_1.default)(addressLocked))return!0}if(countryCodeLock&&!(0,isEmpty_1.default)(billing_address)&&!shipToDifferentAddress)return billing_address?.country_code!==countryCodeLock;if(countryCodeLock&&!(0,isEmpty_1.default)(shipping_address)&&shipToDifferentAddress)return shipping_address?.country_code!==countryCodeLock;if(countryCodeLock&&!(0,isEmpty_1.default)(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===shippingAddressId||a?.reference===shippingAddressId)&&a?.country_code!==countryCodeLock);if(!(0,isEmpty_1.default)(addressLocked))return!0}return!1}exports.countryLockController=countryLockController;function invertedAddressesHandler({order,billingAddress,billingAddressId,customerEmail,shipToDifferentAddress,shippingAddress,shippingAddressId,sdk}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){const currentShippingAddressRef=(_a=order?.shipping_address)===null||_a===void 0?void 0:_a.reference,orderAttributes={id:order?.id,_billing_address_clone_id:shippingAddressId,_shipping_address_clone_id:shippingAddressId,customer_email:customerEmail};if(currentShippingAddressRef===shippingAddressId&&(orderAttributes._billing_address_clone_id=(_b=order?.billing_address)===null||_b===void 0?void 0:_b.id,orderAttributes._shipping_address_clone_id=(_c=order?.shipping_address)===null||_c===void 0?void 0:_c.id),shippingAddress!=null&&Object.keys(shippingAddress).length>0){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._billing_address_same_as_shipping=!0;const hasMetadata=Object.keys(shippingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");shippingAddress.metadata=Object.assign(Object.assign({},shippingAddress.metadata||{}),{[metadataKey]:shippingAddress[key]}),delete shippingAddress[key]});const address=yield sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._billing_address_same_as_shipping,billingAddressId&&(orderAttributes._billing_address_clone_id=billingAddressId),billingAddress!=null&&Object.keys(billingAddress).length>0)){delete orderAttributes._billing_address_clone_id;const hasMetadata=Object.keys(billingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");billingAddress.metadata=Object.assign(Object.assign({},billingAddress.metadata||{}),{[metadataKey]:billingAddress[key]}),delete billingAddress[key]});const address=yield sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}return orderAttributes})}exports.invertedAddressesHandler=invertedAddressesHandler;function addressesController({billing_address,billingAddressId,shipToDifferentAddress,shipping_address,shippingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields}){if(invertAddresses){const shippingDisable2=shippingAddressController({errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses,requiresBillingInfo,requiredMetadataFields}),billingDisable2=billingAddressController({shippingDisable:shippingDisable2,billing_address,billingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields});return{shippingDisable:shippingDisable2,billingDisable:billingDisable2}}const billingDisable=billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo,requiredMetadataFields}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,requiredMetadataFields});return{billingDisable,shippingDisable}}exports.addressesController=addressesController;
|
|
@@ -11,6 +11,6 @@ export type ValidateFormFields = <R extends string[]>(fields: HTMLFormControlsCo
|
|
|
11
11
|
export type ValidateValue = <V extends string | boolean, N extends string, T extends string, B extends TResourceError>(val: V, name: N, type: T, resource: B) => BaseError | Record<string, any>;
|
|
12
12
|
export declare const validateValue: ValidateValue;
|
|
13
13
|
declare const validateFormFields: ValidateFormFields;
|
|
14
|
-
export declare function fieldsExist(address: AddressCreate, schema?: AddressField
|
|
14
|
+
export declare function fieldsExist(address: AddressCreate, schema?: Array<AddressField | string>): boolean;
|
|
15
15
|
export declare function businessMandatoryField(fieldName: AddressInputName, isBusiness?: boolean): boolean;
|
|
16
16
|
export default validateFormFields;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.businessMandatoryField=exports.fieldsExist=exports.validateValue=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),isString_1=tslib_1.__importDefault(require("lodash/isString")),without_1=tslib_1.__importDefault(require("lodash/without")),keys_1=tslib_1.__importDefault(require("lodash/keys")),map_1=tslib_1.__importDefault(require("lodash/map")),AddressReducer_1=require("../reducers/AddressReducer"),EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,validateValue=(val,name,type,resource)=>val?type==="email"&&(0,isString_1.default)(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};exports.validateValue=validateValue;const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return(0,map_1.default)(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||v.required){const error=(0,exports.validateValue)(val,v.name,v.type,resourceType);(0,isEmpty_1.default)(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}};function fieldsExist(address,schema=AddressReducer_1.addressFields){if(address.business){const required=(0,without_1.default)(schema,"first_name","last_name","line_2"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=(0,without_1.default)(schema,"line_2","company"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}}exports.fieldsExist=fieldsExist;const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","shipping_address_company","company"];function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}exports.businessMandatoryField=businessMandatoryField,exports.default=validateFormFields;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.businessMandatoryField=exports.fieldsExist=exports.validateValue=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),isString_1=tslib_1.__importDefault(require("lodash/isString")),without_1=tslib_1.__importDefault(require("lodash/without")),keys_1=tslib_1.__importDefault(require("lodash/keys")),map_1=tslib_1.__importDefault(require("lodash/map")),AddressReducer_1=require("../reducers/AddressReducer"),EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,validateValue=(val,name,type,resource)=>val?type==="email"&&(0,isString_1.default)(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};exports.validateValue=validateValue;const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return(0,map_1.default)(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||v.required){const error=(0,exports.validateValue)(val,v.name,v.type,resourceType);(0,isEmpty_1.default)(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}};function fieldsExist(address,schema=AddressReducer_1.addressFields){if(console.log("address",address),address.business){const required=(0,without_1.default)(schema,"first_name","last_name","line_2"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=(0,without_1.default)(schema,"line_2","company"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}}exports.fieldsExist=fieldsExist;const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","shipping_address_company","company"];function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}exports.businessMandatoryField=businessMandatoryField,exports.default=validateFormFields;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type BaseSelectComponentProps } from '../../typings/index';
|
|
3
|
+
import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
|
|
4
|
+
type SelectFieldName = `billing_address_${`metadata_${string}`}` | `shipping_address_${`metadata_${string}`}`;
|
|
5
|
+
interface Props extends Omit<BaseSelectComponentProps, 'name'>, Pick<JSX.IntrinsicElements['select'], 'className' | 'id' | 'style'> {
|
|
6
|
+
name: Extract<AddressValuesKeys, SelectFieldName>;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The AddressInputSelect component creates a form `select` related to the `metadata` attribute of the `address` object.
|
|
12
|
+
*
|
|
13
|
+
* It requires a `name` prop to define the field name associated with the select and accepts most of HTML `select` tag standard props.
|
|
14
|
+
*
|
|
15
|
+
* <span title="Name prop" type="info">
|
|
16
|
+
* The `name` prop must respect the convention of mentioning one of the available addresses forms (`billing_address` or `shipping_address`) concatenated to the `metadata` address attribute with a `_` separator. Eg.: `billing_address_metadata_your-key`.
|
|
17
|
+
* </span>
|
|
18
|
+
*
|
|
19
|
+
* <span title="Requirement" type="warning">
|
|
20
|
+
* It must to be used inside either the `<BillingAddressForm>` or the `<ShippingAddressForm>` component.
|
|
21
|
+
* </span>
|
|
22
|
+
*
|
|
23
|
+
* <span title="Fields" type="info">
|
|
24
|
+
* Check the `addresses` resource from our [Core API documentation](https://docs.commercelayer.io/core/v/api-reference/addresses/object)
|
|
25
|
+
* for more details about the available attributes to render.
|
|
26
|
+
* </span>
|
|
27
|
+
*/
|
|
28
|
+
export declare function AddressInputSelect(props: Props): JSX.Element;
|
|
29
|
+
export default AddressInputSelect;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useMemo}from"react";import BaseSelect from"../utils/BaseSelect";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import ShippingAddressFormContext from"../../context/ShippingAddressFormContext";export function AddressInputSelect(props){const{required=!0,value,name,className,options,...p}=props,billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext);useEffect(()=>{value&&billingAddress?.setValue&&billingAddress.setValue(name,value),value&&shippingAddress?.setValue&&shippingAddress.setValue(name,value)},[value]);const hasError=useMemo(()=>!!(billingAddress?.errors?.[name]?.error||shippingAddress?.errors?.[name]?.error),[value,billingAddress?.errors,shippingAddress?.errors]),errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=`${className??""} ${hasError&&errorClassName?errorClassName:""}`;return _jsx(BaseSelect,{className:classNameComputed,ref:billingAddress?.validation||shippingAddress?.validation,required,options,name,value,...p})}export default AddressInputSelect;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../../utils/localStorage";export function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,customFieldMessageError,...p}=props,{validation,values,errors,reset:resetForm,setValue:setValueForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"billing_address"})}}else{const formErrors=[];
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../../utils/localStorage";export function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,customFieldMessageError,...p}=props,{validation,values,errors,reset:resetForm,setValue:setValueForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;if(["billing_address_state_code"].includes(fieldName))values?.state_code?formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):delete errors[fieldName];else{const customMessage=customFieldMessageError!=null?customFieldMessageError({field:fieldName,code,message,value:values[fieldName].value}):null;if(customFieldMessageError!=null&&code==="VALIDATION_ERROR"&&!customMessage)continue;formErrors.push({code,message:customMessage??message??"",resource:"billing_address",field:fieldName})}}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=ref.current?.querySelector('[name="billing_address_save_to_customer_book"]')?.checked||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{setValueForm(name,value);const field={[name.replace("billing_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"billing_address"})},errorClassName,requiresBillingInfo:order?.requires_billing_info||!1,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return _jsx(BillingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})}export default BillingAddressForm;
|
|
@@ -12,6 +12,7 @@ interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onCl
|
|
|
12
12
|
label?: string | ReactNode;
|
|
13
13
|
onClick?: (params: TOnClick) => void;
|
|
14
14
|
addressId?: string;
|
|
15
|
+
requiredMetadataFields?: string[];
|
|
15
16
|
}
|
|
16
17
|
export declare function SaveAddressesButton(props: Props): JSX.Element;
|
|
17
18
|
export default SaveAddressesButton;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"../utils/Parent";import AddressContext from"../../context/AddressContext";import{countryLockController,addressesController}from"../../utils/addressesManager";import OrderContext from"../../context/OrderContext";import CustomerContext from"../../context/CustomerContext";import isFunction from"lodash/isFunction";import{validateValue}from"../../utils/validateFormFields";export function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,onClick,...p}=props,{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=useContext(AddressContext),{order}=useContext(OrderContext),{customerEmail:email,addresses,isGuest,createCustomerAddress}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=validateValue(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>({...acc,[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=addressesController({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors}),countryLockDisable=countryLockController({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=async()=>{if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=await saveAddresses(email);else if(createCustomerAddress&&billingAddress){const address={...billingAddress};addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()},...p,children:isFunction(label)?label():label})}export default SaveAddressesButton;
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"../utils/Parent";import AddressContext from"../../context/AddressContext";import{countryLockController,addressesController}from"../../utils/addressesManager";import OrderContext from"../../context/OrderContext";import CustomerContext from"../../context/CustomerContext";import isFunction from"lodash/isFunction";import{validateValue}from"../../utils/validateFormFields";export function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,requiredMetadataFields,onClick,...p}=props,{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=useContext(AddressContext),{order}=useContext(OrderContext),{customerEmail:email,addresses,isGuest,createCustomerAddress}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=validateValue(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>({...acc,[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=addressesController({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors,requiredMetadataFields}),countryLockDisable=countryLockController({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=async()=>{if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=await saveAddresses(email);else if(createCustomerAddress&&billingAddress){const address={...billingAddress};addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()},...p,children:isFunction(label)?label():label})}export default SaveAddressesButton;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './components/addresses/Address';
|
|
|
5
5
|
export * from './components/addresses/AddressCountrySelector';
|
|
6
6
|
export * from './components/addresses/AddressField';
|
|
7
7
|
export * from './components/addresses/AddressInput';
|
|
8
|
+
export * from './components/addresses/AddressInputSelect';
|
|
8
9
|
export * from './components/addresses/AddressStateSelector';
|
|
9
10
|
export * from './components/addresses/AddressesContainer';
|
|
10
11
|
export * from './components/addresses/AddressesEmpty';
|
package/lib/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export*from"./components/ExternalFunction";export*from"./components/MetadataInput";export*from"./components/SubmitButton";export*from"./components/addresses/Address";export*from"./components/addresses/AddressCountrySelector";export*from"./components/addresses/AddressField";export*from"./components/addresses/AddressInput";export*from"./components/addresses/AddressStateSelector";export*from"./components/addresses/AddressesContainer";export*from"./components/addresses/AddressesEmpty";export*from"./components/addresses/BillingAddressContainer";export*from"./components/addresses/BillingAddressForm";export*from"./components/addresses/SaveAddressesButton";export*from"./components/addresses/ShippingAddressContainer";export*from"./components/addresses/ShippingAddressForm";export*from"./components/auth/CommerceLayer";export*from"./components/customers/CustomerAddressForm";export*from"./components/customers/CustomerContainer";export*from"./components/customers/CustomerField";export*from"./components/customers/CustomerInput";export*from"./components/customers/SaveCustomerButton";export*from"./components/errors/Errors";export*from"./components/gift_cards/GiftCard";export*from"./components/gift_cards/GiftCardContainer";export*from"./components/gift_cards/GiftCardCurrencySelector";export*from"./components/gift_cards/GiftCardInput";export*from"./components/gift_cards/GiftCardOrCouponCode";export*from"./components/gift_cards/GiftCardOrCouponForm";export*from"./components/gift_cards/GiftCardOrCouponInput";export*from"./components/gift_cards/GiftCardOrCouponRemoveButton";export*from"./components/gift_cards/GiftCardOrCouponSubmit";export*from"./components/in_stock_subscriptions/InStockSubscriptionButton";export*from"./components/in_stock_subscriptions/InStockSubscriptionsContainer";export*from"./components/line_items/LineItem";export*from"./components/line_items/LineItemAmount";export*from"./components/line_items/LineItemCode";export*from"./components/line_items/LineItemField";export*from"./components/line_items/LineItemImage";export*from"./components/line_items/LineItemName";export*from"./components/line_items/LineItemOption";export*from"./components/line_items/LineItemOptions";export*from"./components/line_items/LineItemQuantity";export*from"./components/line_items/LineItemRemoveLink";export*from"./components/line_items/LineItemsContainer";export*from"./components/line_items/LineItemsCount";export*from"./components/line_items/LineItemsEmpty";export*from"./components/orders/AddToCartButton";export*from"./components/orders/AdjustmentAmount";export*from"./components/orders/CartLink";export*from"./components/orders/CheckoutLink";export*from"./components/orders/DiscountAmount";export*from"./components/orders/GiftCardAmount";export*from"./components/orders/OrderContainer";export*from"./components/orders/OrderList";export*from"./components/orders/OrderListEmpty";export*from"./components/orders/OrderListRow";export*from"./components/orders/OrderNumber";export*from"./components/orders/OrderStorage";export*from"./components/orders/PaymentMethodAmount";export*from"./components/orders/PlaceOrderButton";export*from"./components/orders/PlaceOrderContainer";export*from"./components/orders/PrivacyAndTermsCheckbox";export*from"./components/orders/ShippingAmount";export*from"./components/orders/SubTotalAmount";export*from"./components/orders/TaxesAmount";export*from"./components/orders/TotalAmount";export*from"./components/parcels/ParcelField";export*from"./components/parcels/ParcelLineItem";export*from"./components/parcels/ParcelLineItemField";export*from"./components/parcels/ParcelLineItemsCount";export*from"./components/parcels/Parcels";export*from"./components/parcels/ParcelsCount";export*from"./components/payment_methods/PaymentMethod";export*from"./components/payment_methods/PaymentMethodName";export*from"./components/payment_methods/PaymentMethodPrice";export*from"./components/payment_methods/PaymentMethodRadioButton";export*from"./components/payment_methods/PaymentMethodsContainer";export*from"./components/payment_source/PaymentSource";export*from"./components/payment_source/PaymentSourceBrandIcon";export*from"./components/payment_source/PaymentSourceBrandName";export*from"./components/payment_source/PaymentSourceDetail";export*from"./components/payment_source/PaymentSourceEditButton";export*from"./components/prices/Price";export*from"./components/prices/PricesContainer";export*from"./components/shipments/Shipment";export*from"./components/shipments/ShipmentField";export*from"./components/shipments/ShipmentsContainer";export*from"./components/shipments/ShipmentsCount";export*from"./components/shipping_methods/ShippingMethod";export*from"./components/shipping_methods/ShippingMethodName";export*from"./components/shipping_methods/ShippingMethodPrice";export*from"./components/shipping_methods/ShippingMethodRadioButton";export*from"./components/skus/AvailabilityContainer";export*from"./components/skus/AvailabilityTemplate";export*from"./components/skus/DeliveryLeadTime";export*from"./components/skus/SkuField";export*from"./components/skus/SkuList";export*from"./components/skus/SkuListsContainer";export*from"./components/skus/Skus";export*from"./components/skus/SkusContainer";export*from"./components/stock_transfers/StockTransfer";export*from"./components/stock_transfers/StockTransferField";export*from"./hooks/useOrderContainer";export*from"./hooks/useCommerceLayer";export*from"./hooks/useCustomerContainer";export*from"./typings/errors";
|
|
2
|
+
export*from"./components/ExternalFunction";export*from"./components/MetadataInput";export*from"./components/SubmitButton";export*from"./components/addresses/Address";export*from"./components/addresses/AddressCountrySelector";export*from"./components/addresses/AddressField";export*from"./components/addresses/AddressInput";export*from"./components/addresses/AddressInputSelect";export*from"./components/addresses/AddressStateSelector";export*from"./components/addresses/AddressesContainer";export*from"./components/addresses/AddressesEmpty";export*from"./components/addresses/BillingAddressContainer";export*from"./components/addresses/BillingAddressForm";export*from"./components/addresses/SaveAddressesButton";export*from"./components/addresses/ShippingAddressContainer";export*from"./components/addresses/ShippingAddressForm";export*from"./components/auth/CommerceLayer";export*from"./components/customers/CustomerAddressForm";export*from"./components/customers/CustomerContainer";export*from"./components/customers/CustomerField";export*from"./components/customers/CustomerInput";export*from"./components/customers/SaveCustomerButton";export*from"./components/errors/Errors";export*from"./components/gift_cards/GiftCard";export*from"./components/gift_cards/GiftCardContainer";export*from"./components/gift_cards/GiftCardCurrencySelector";export*from"./components/gift_cards/GiftCardInput";export*from"./components/gift_cards/GiftCardOrCouponCode";export*from"./components/gift_cards/GiftCardOrCouponForm";export*from"./components/gift_cards/GiftCardOrCouponInput";export*from"./components/gift_cards/GiftCardOrCouponRemoveButton";export*from"./components/gift_cards/GiftCardOrCouponSubmit";export*from"./components/in_stock_subscriptions/InStockSubscriptionButton";export*from"./components/in_stock_subscriptions/InStockSubscriptionsContainer";export*from"./components/line_items/LineItem";export*from"./components/line_items/LineItemAmount";export*from"./components/line_items/LineItemCode";export*from"./components/line_items/LineItemField";export*from"./components/line_items/LineItemImage";export*from"./components/line_items/LineItemName";export*from"./components/line_items/LineItemOption";export*from"./components/line_items/LineItemOptions";export*from"./components/line_items/LineItemQuantity";export*from"./components/line_items/LineItemRemoveLink";export*from"./components/line_items/LineItemsContainer";export*from"./components/line_items/LineItemsCount";export*from"./components/line_items/LineItemsEmpty";export*from"./components/orders/AddToCartButton";export*from"./components/orders/AdjustmentAmount";export*from"./components/orders/CartLink";export*from"./components/orders/CheckoutLink";export*from"./components/orders/DiscountAmount";export*from"./components/orders/GiftCardAmount";export*from"./components/orders/OrderContainer";export*from"./components/orders/OrderList";export*from"./components/orders/OrderListEmpty";export*from"./components/orders/OrderListRow";export*from"./components/orders/OrderNumber";export*from"./components/orders/OrderStorage";export*from"./components/orders/PaymentMethodAmount";export*from"./components/orders/PlaceOrderButton";export*from"./components/orders/PlaceOrderContainer";export*from"./components/orders/PrivacyAndTermsCheckbox";export*from"./components/orders/ShippingAmount";export*from"./components/orders/SubTotalAmount";export*from"./components/orders/TaxesAmount";export*from"./components/orders/TotalAmount";export*from"./components/parcels/ParcelField";export*from"./components/parcels/ParcelLineItem";export*from"./components/parcels/ParcelLineItemField";export*from"./components/parcels/ParcelLineItemsCount";export*from"./components/parcels/Parcels";export*from"./components/parcels/ParcelsCount";export*from"./components/payment_methods/PaymentMethod";export*from"./components/payment_methods/PaymentMethodName";export*from"./components/payment_methods/PaymentMethodPrice";export*from"./components/payment_methods/PaymentMethodRadioButton";export*from"./components/payment_methods/PaymentMethodsContainer";export*from"./components/payment_source/PaymentSource";export*from"./components/payment_source/PaymentSourceBrandIcon";export*from"./components/payment_source/PaymentSourceBrandName";export*from"./components/payment_source/PaymentSourceDetail";export*from"./components/payment_source/PaymentSourceEditButton";export*from"./components/prices/Price";export*from"./components/prices/PricesContainer";export*from"./components/shipments/Shipment";export*from"./components/shipments/ShipmentField";export*from"./components/shipments/ShipmentsContainer";export*from"./components/shipments/ShipmentsCount";export*from"./components/shipping_methods/ShippingMethod";export*from"./components/shipping_methods/ShippingMethodName";export*from"./components/shipping_methods/ShippingMethodPrice";export*from"./components/shipping_methods/ShippingMethodRadioButton";export*from"./components/skus/AvailabilityContainer";export*from"./components/skus/AvailabilityTemplate";export*from"./components/skus/DeliveryLeadTime";export*from"./components/skus/SkuField";export*from"./components/skus/SkuList";export*from"./components/skus/SkuListsContainer";export*from"./components/skus/Skus";export*from"./components/skus/SkusContainer";export*from"./components/stock_transfers/StockTransfer";export*from"./components/stock_transfers/StockTransferField";export*from"./hooks/useOrderContainer";export*from"./hooks/useCommerceLayer";export*from"./hooks/useCustomerContainer";export*from"./typings/errors";
|
|
@@ -9,8 +9,9 @@ interface BillingAddressControllerProps {
|
|
|
9
9
|
invertAddresses?: boolean;
|
|
10
10
|
shippingDisable?: boolean;
|
|
11
11
|
shipToDifferentAddress?: boolean;
|
|
12
|
+
requiredMetadataFields?: string[];
|
|
12
13
|
}
|
|
13
|
-
export declare function billingAddressController({ billing_address, billingAddressId, errors, requiresBillingInfo, invertAddresses, shipToDifferentAddress, shippingDisable }: BillingAddressControllerProps): boolean;
|
|
14
|
+
export declare function billingAddressController({ billing_address, billingAddressId, errors, requiresBillingInfo, invertAddresses, shipToDifferentAddress, shippingDisable, requiredMetadataFields }: BillingAddressControllerProps): boolean;
|
|
14
15
|
interface ShippingAddressControllerProps {
|
|
15
16
|
billingDisable?: boolean;
|
|
16
17
|
errors?: BaseError[];
|
|
@@ -19,8 +20,9 @@ interface ShippingAddressControllerProps {
|
|
|
19
20
|
shipping_address?: AddressCreate;
|
|
20
21
|
shippingAddressId?: string;
|
|
21
22
|
invertAddresses?: boolean;
|
|
23
|
+
requiredMetadataFields?: string[];
|
|
22
24
|
}
|
|
23
|
-
export declare function shippingAddressController({ billingDisable, errors, shipToDifferentAddress, shipping_address, shippingAddressId, invertAddresses, requiresBillingInfo }: ShippingAddressControllerProps): boolean;
|
|
25
|
+
export declare function shippingAddressController({ billingDisable, errors, shipToDifferentAddress, shipping_address, shippingAddressId, invertAddresses, requiresBillingInfo, requiredMetadataFields }: ShippingAddressControllerProps): boolean;
|
|
24
26
|
interface CountryLockControllerProps {
|
|
25
27
|
addresses?: Address[] | null;
|
|
26
28
|
billing_address?: TCustomerAddress;
|
|
@@ -52,8 +54,9 @@ interface AddressControllerProps {
|
|
|
52
54
|
errors?: BaseError[];
|
|
53
55
|
requiresBillingInfo?: boolean | null;
|
|
54
56
|
invertAddresses?: boolean;
|
|
57
|
+
requiredMetadataFields?: string[];
|
|
55
58
|
}
|
|
56
|
-
export declare function addressesController({ billing_address, billingAddressId, shipToDifferentAddress, shipping_address, shippingAddressId, errors, requiresBillingInfo, invertAddresses }: AddressControllerProps): {
|
|
59
|
+
export declare function addressesController({ billing_address, billingAddressId, shipToDifferentAddress, shipping_address, shippingAddressId, errors, requiresBillingInfo, invertAddresses, requiredMetadataFields }: AddressControllerProps): {
|
|
57
60
|
billingDisable: boolean;
|
|
58
61
|
shippingDisable: boolean;
|
|
59
62
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import isEmpty from"lodash/isEmpty";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable}){let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address))
|
|
2
|
+
import isEmpty from"lodash/isEmpty";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable,requiredMetadataFields}){console.log("requiredMetadataFields",requiredMetadataFields);let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let formFields=[...addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formFields=[...formFields,...requiredMetadataFields]),invertAddresses?billingDisable=!!(billing_address&&fieldsExist(billing_address,formFields)):(requiresBillingInfo&&(formFields=[...formFields,"billing_info"]),console.log("formFields",formFields),billingDisable=!!(billing_address&&fieldsExist(billing_address,formFields)))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable}export function shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses=!1,requiresBillingInfo=!1,requiredMetadataFields}){let shippingDisable=invertAddresses?!isEmpty(errors)||isEmpty(shipping_address):!!(!billingDisable&&shipToDifferentAddress);if(isEmpty(errors)&&!isEmpty(shipping_address)){let formField=[...addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formField=[...formField,...requiredMetadataFields]),invertAddresses?(requiresBillingInfo&&(formField=[...formField,"billing_info"]),shippingDisable=!!(shipping_address&&fieldsExist(shipping_address,formField))):shipToDifferentAddress&&(delete shipping_address?.billing_info,shippingDisable=!!(shipping_address&&fieldsExist(shipping_address,formField)))}return shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable}export function countryLockController({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId,lineItems}){if(lineItems?.filter(lineItem=>lineItem?.item?.type!=null&&["skus","bundles"].includes(lineItem?.item?.type))?.every(lineItem=>lineItem?.item?.do_not_ship===!0))return!1;if(countryCodeLock&&!isEmpty(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===billingAddressId||a?.reference===billingAddressId)&&a?.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}if(countryCodeLock&&!isEmpty(billing_address)&&!shipToDifferentAddress)return billing_address?.country_code!==countryCodeLock;if(countryCodeLock&&!isEmpty(shipping_address)&&shipToDifferentAddress)return shipping_address?.country_code!==countryCodeLock;if(countryCodeLock&&!isEmpty(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===shippingAddressId||a?.reference===shippingAddressId)&&a?.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}return!1}export async function invertedAddressesHandler({order,billingAddress,billingAddressId,customerEmail,shipToDifferentAddress,shippingAddress,shippingAddressId,sdk}){const currentShippingAddressRef=order?.shipping_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:shippingAddressId,_shipping_address_clone_id:shippingAddressId,customer_email:customerEmail};if(currentShippingAddressRef===shippingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),shippingAddress!=null&&Object.keys(shippingAddress).length>0){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._billing_address_same_as_shipping=!0;const hasMetadata=Object.keys(shippingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");shippingAddress.metadata={...shippingAddress.metadata||{},[metadataKey]:shippingAddress[key]},delete shippingAddress[key]});const address=await sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._billing_address_same_as_shipping,billingAddressId&&(orderAttributes._billing_address_clone_id=billingAddressId),billingAddress!=null&&Object.keys(billingAddress).length>0)){delete orderAttributes._billing_address_clone_id;const hasMetadata=Object.keys(billingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");billingAddress.metadata={...billingAddress.metadata||{},[metadataKey]:billingAddress[key]},delete billingAddress[key]});const address=await sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}return orderAttributes}export function addressesController({billing_address,billingAddressId,shipToDifferentAddress,shipping_address,shippingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields}){if(invertAddresses){const shippingDisable2=shippingAddressController({errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses,requiresBillingInfo,requiredMetadataFields}),billingDisable2=billingAddressController({shippingDisable:shippingDisable2,billing_address,billingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields});return{shippingDisable:shippingDisable2,billingDisable:billingDisable2}}const billingDisable=billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo,requiredMetadataFields}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,requiredMetadataFields});return{billingDisable,shippingDisable}}
|
|
@@ -11,6 +11,6 @@ export type ValidateFormFields = <R extends string[]>(fields: HTMLFormControlsCo
|
|
|
11
11
|
export type ValidateValue = <V extends string | boolean, N extends string, T extends string, B extends TResourceError>(val: V, name: N, type: T, resource: B) => BaseError | Record<string, any>;
|
|
12
12
|
export declare const validateValue: ValidateValue;
|
|
13
13
|
declare const validateFormFields: ValidateFormFields;
|
|
14
|
-
export declare function fieldsExist(address: AddressCreate, schema?: AddressField
|
|
14
|
+
export declare function fieldsExist(address: AddressCreate, schema?: Array<AddressField | string>): boolean;
|
|
15
15
|
export declare function businessMandatoryField(fieldName: AddressInputName, isBusiness?: boolean): boolean;
|
|
16
16
|
export default validateFormFields;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;export const validateValue=(val,name,type,resource)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values={...values,[`${v.name}`]:val}}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?{...values,metadata:{...values.metadata,[`${v.name}`]:val}}:{...values,[`${v.name}`]:val})}),{errors,values}};export function fieldsExist(address,schema=addressFields){if(address.business){const required=without(schema,"first_name","last_name","line_2"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=without(schema,"line_2","company"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}}const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","shipping_address_company","company"];export function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}export default validateFormFields;
|
|
2
|
+
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;export const validateValue=(val,name,type,resource)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values={...values,[`${v.name}`]:val}}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?{...values,metadata:{...values.metadata,[`${v.name}`]:val}}:{...values,[`${v.name}`]:val})}),{errors,values}};export function fieldsExist(address,schema=addressFields){if(console.log("address",address),address.business){const required=without(schema,"first_name","last_name","line_2"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=without(schema,"line_2","company"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}}const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","shipping_address_company","company"];export function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}export default validateFormFields;
|