@merchi/cart 1.4.4
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/LICENSE +21 -0
- package/README.md +134 -0
- package/esm/Cart.js +62 -0
- package/esm/CartAlert.js +47 -0
- package/esm/CartHeader.js +29 -0
- package/esm/CartProvider.js +1101 -0
- package/esm/CartTotals.js +89 -0
- package/esm/assets/merchi-monster-loader.gif +0 -0
- package/esm/assets/merchi-swipe-outline.png +0 -0
- package/esm/assets/product-not-found.png +0 -0
- package/esm/assets/stripe-payment-secure.png +0 -0
- package/esm/buttons/Button.js +23 -0
- package/esm/buttons/ButtonBack.js +35 -0
- package/esm/buttons/ButtonClearCart.js +17 -0
- package/esm/buttons/ButtonInvoiceDownload.js +88 -0
- package/esm/buttons/ButtonNext.js +39 -0
- package/esm/buttons/ButtonNextDynamic.js +19 -0
- package/esm/buttons/ButtonOpenCartMerchiCartModal.js +47 -0
- package/esm/buttons/ButtonPay.js +26 -0
- package/esm/buttons/ButtonShipmentTabNext.js +28 -0
- package/esm/buttons/index.js +7 -0
- package/esm/components/Alert.js +26 -0
- package/esm/components/CartBody.js +14 -0
- package/esm/components/CartClient.js +62 -0
- package/esm/components/CartFooter.js +12 -0
- package/esm/components/CartItemRow.js +230 -0
- package/esm/components/CartPaymentSettingsInvalid.js +13 -0
- package/esm/components/CartShipment.js +52 -0
- package/esm/components/CartTabContent.js +12 -0
- package/esm/components/CartTabPanel.js +25 -0
- package/esm/components/CartTableContainer.js +12 -0
- package/esm/components/CartTitle.js +26 -0
- package/esm/components/CartTotalsListGroup.js +71 -0
- package/esm/components/Collapse.js +32 -0
- package/esm/components/CustomCartProductForm.js +128 -0
- package/esm/components/CustomerCheckoutMethodTabs.js +94 -0
- package/esm/components/DiscountInputGroup.js +293 -0
- package/esm/components/LoadingTemplate.js +23 -0
- package/esm/components/NoCartItems.js +20 -0
- package/esm/components/ShipmentGroupCard.js +207 -0
- package/esm/components/Table.js +13 -0
- package/esm/components/containers.js +31 -0
- package/esm/components/index.js +18 -0
- package/esm/components/product-form-sdk-externals.js +36 -0
- package/esm/forms/FormNewCustomer.js +243 -0
- package/esm/forms/FormReturningCustomer.js +165 -0
- package/esm/forms/FormShipmentAddressAndNotes.js +195 -0
- package/esm/forms/FormSquarePayment.js +19 -0
- package/esm/forms/FormStripePayment.js +19 -0
- package/esm/forms/FormWhatsappCustomer.js +253 -0
- package/esm/forms/InputAcceptUserTermsAndConditions.js +35 -0
- package/esm/forms/InputError.js +16 -0
- package/esm/forms/InputSelect.js +48 -0
- package/esm/forms/InputText.js +56 -0
- package/esm/forms/InputsAddress.js +476 -0
- package/esm/forms/index.js +8 -0
- package/esm/index.js +13 -0
- package/esm/modals.js +51 -0
- package/esm/panels/PanelCartItems.js +49 -0
- package/esm/panels/PanelCartShipment.js +66 -0
- package/esm/panels/PanelClearCart.js +56 -0
- package/esm/panels/PanelClientCheckout.js +81 -0
- package/esm/panels/PanelEditCartItem.js +199 -0
- package/esm/panels/PanelPaymentSuccess.js +63 -0
- package/esm/panels/index.js +7 -0
- package/esm/square/SquareCard.js +106 -0
- package/esm/stripe/LegacyStripeCardForm.js +157 -0
- package/esm/stripe/StripeCardFields.js +126 -0
- package/esm/stripe/StripeCardForm.js +33 -0
- package/esm/stripe/StripePaymentButtons.js +98 -0
- package/esm/stripe/actions.js +192 -0
- package/esm/stripe/utils.js +20 -0
- package/esm/styles/globals.css +463 -0
- package/esm/styles/globals.css.map +1 -0
- package/esm/tabs/CartNav.js +28 -0
- package/esm/tabs/NavTab.js +31 -0
- package/esm/types/assets.d.js +0 -0
- package/esm/types/index.js +1 -0
- package/esm/types/merchi_product_form/index.d.js +0 -0
- package/esm/types/merchi_sdk_ts/index.d.js +0 -0
- package/esm/types/react-redux/index.d.js +0 -0
- package/esm/utilities/address.js +457 -0
- package/esm/utilities/area.js +297 -0
- package/esm/utilities/cart.js +95 -0
- package/esm/utilities/company.js +6 -0
- package/esm/utilities/cookie.js +156 -0
- package/esm/utilities/currency.js +219 -0
- package/esm/utilities/customForm.js +57 -0
- package/esm/utilities/helpers.js +229 -0
- package/esm/utilities/index.js +14 -0
- package/esm/utilities/invoice.js +112 -0
- package/esm/utilities/job.js +9 -0
- package/esm/utilities/local_storage.js +85 -0
- package/esm/utilities/product.js +13 -0
- package/esm/utilities/shipment.js +11 -0
- package/esm/utilities/tabs.js +51 -0
- package/esm/utilities/user.js +65 -0
- package/esm/utilities/variations.js +58 -0
- package/lib/Cart.d.ts +9 -0
- package/lib/Cart.js +69 -0
- package/lib/CartAlert.d.ts +3 -0
- package/lib/CartAlert.js +53 -0
- package/lib/CartHeader.d.ts +3 -0
- package/lib/CartHeader.js +37 -0
- package/lib/CartProvider.d.ts +236 -0
- package/lib/CartProvider.js +1107 -0
- package/lib/CartTotals.d.ts +7 -0
- package/lib/CartTotals.js +96 -0
- package/lib/assets/merchi-monster-loader.gif +0 -0
- package/lib/assets/merchi-swipe-outline.png +0 -0
- package/lib/assets/product-not-found.png +0 -0
- package/lib/assets/stripe-payment-secure.png +0 -0
- package/lib/buttons/Button.d.ts +11 -0
- package/lib/buttons/Button.js +31 -0
- package/lib/buttons/ButtonBack.d.ts +6 -0
- package/lib/buttons/ButtonBack.js +44 -0
- package/lib/buttons/ButtonClearCart.d.ts +3 -0
- package/lib/buttons/ButtonClearCart.js +24 -0
- package/lib/buttons/ButtonInvoiceDownload.d.ts +3 -0
- package/lib/buttons/ButtonInvoiceDownload.js +96 -0
- package/lib/buttons/ButtonNext.d.ts +3 -0
- package/lib/buttons/ButtonNext.js +48 -0
- package/lib/buttons/ButtonNextDynamic.d.ts +3 -0
- package/lib/buttons/ButtonNextDynamic.js +28 -0
- package/lib/buttons/ButtonOpenCartMerchiCartModal.d.ts +9 -0
- package/lib/buttons/ButtonOpenCartMerchiCartModal.js +57 -0
- package/lib/buttons/ButtonPay.d.ts +7 -0
- package/lib/buttons/ButtonPay.js +35 -0
- package/lib/buttons/ButtonShipmentTabNext.d.ts +2 -0
- package/lib/buttons/ButtonShipmentTabNext.js +37 -0
- package/lib/buttons/index.d.ts +7 -0
- package/lib/buttons/index.js +48 -0
- package/lib/components/Alert.d.ts +7 -0
- package/lib/components/Alert.js +34 -0
- package/lib/components/CartBody.d.ts +7 -0
- package/lib/components/CartBody.js +22 -0
- package/lib/components/CartClient.d.ts +4 -0
- package/lib/components/CartClient.js +71 -0
- package/lib/components/CartFooter.d.ts +6 -0
- package/lib/components/CartFooter.js +20 -0
- package/lib/components/CartItemRow.d.ts +7 -0
- package/lib/components/CartItemRow.js +236 -0
- package/lib/components/CartPaymentSettingsInvalid.d.ts +2 -0
- package/lib/components/CartPaymentSettingsInvalid.js +21 -0
- package/lib/components/CartShipment.d.ts +6 -0
- package/lib/components/CartShipment.js +59 -0
- package/lib/components/CartTabContent.d.ts +6 -0
- package/lib/components/CartTabContent.js +20 -0
- package/lib/components/CartTabPanel.d.ts +7 -0
- package/lib/components/CartTabPanel.js +31 -0
- package/lib/components/CartTableContainer.d.ts +6 -0
- package/lib/components/CartTableContainer.js +20 -0
- package/lib/components/CartTitle.d.ts +2 -0
- package/lib/components/CartTitle.js +34 -0
- package/lib/components/CartTotalsListGroup.d.ts +3 -0
- package/lib/components/CartTotalsListGroup.js +78 -0
- package/lib/components/Collapse.d.ts +3 -0
- package/lib/components/Collapse.js +40 -0
- package/lib/components/CustomCartProductForm.d.ts +18 -0
- package/lib/components/CustomCartProductForm.js +136 -0
- package/lib/components/CustomerCheckoutMethodTabs.d.ts +6 -0
- package/lib/components/CustomerCheckoutMethodTabs.js +103 -0
- package/lib/components/DiscountInputGroup.d.ts +2 -0
- package/lib/components/DiscountInputGroup.js +301 -0
- package/lib/components/LoadingTemplate.d.ts +7 -0
- package/lib/components/LoadingTemplate.js +30 -0
- package/lib/components/NoCartItems.d.ts +3 -0
- package/lib/components/NoCartItems.js +27 -0
- package/lib/components/ShipmentGroupCard.d.ts +7 -0
- package/lib/components/ShipmentGroupCard.js +215 -0
- package/lib/components/Table.d.ts +7 -0
- package/lib/components/Table.js +19 -0
- package/lib/components/containers.d.ts +14 -0
- package/lib/components/containers.js +40 -0
- package/lib/components/index.d.ts +18 -0
- package/lib/components/index.js +133 -0
- package/lib/components/product-form-sdk-externals.d.ts +46 -0
- package/lib/components/product-form-sdk-externals.js +43 -0
- package/lib/forms/FormNewCustomer.d.ts +4 -0
- package/lib/forms/FormNewCustomer.js +252 -0
- package/lib/forms/FormReturningCustomer.d.ts +3 -0
- package/lib/forms/FormReturningCustomer.js +173 -0
- package/lib/forms/FormShipmentAddressAndNotes.d.ts +15 -0
- package/lib/forms/FormShipmentAddressAndNotes.js +203 -0
- package/lib/forms/FormSquarePayment.d.ts +3 -0
- package/lib/forms/FormSquarePayment.js +27 -0
- package/lib/forms/FormStripePayment.d.ts +3 -0
- package/lib/forms/FormStripePayment.js +27 -0
- package/lib/forms/FormWhatsappCustomer.d.ts +3 -0
- package/lib/forms/FormWhatsappCustomer.js +261 -0
- package/lib/forms/InputAcceptUserTermsAndConditions.d.ts +7 -0
- package/lib/forms/InputAcceptUserTermsAndConditions.js +41 -0
- package/lib/forms/InputError.d.ts +8 -0
- package/lib/forms/InputError.js +24 -0
- package/lib/forms/InputSelect.d.ts +14 -0
- package/lib/forms/InputSelect.js +55 -0
- package/lib/forms/InputText.d.ts +12 -0
- package/lib/forms/InputText.js +63 -0
- package/lib/forms/InputsAddress.d.ts +11 -0
- package/lib/forms/InputsAddress.js +485 -0
- package/lib/forms/index.d.ts +8 -0
- package/lib/forms/index.js +63 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +93 -0
- package/lib/modals.d.ts +17 -0
- package/lib/modals.js +59 -0
- package/lib/panels/PanelCartItems.d.ts +3 -0
- package/lib/panels/PanelCartItems.js +56 -0
- package/lib/panels/PanelCartShipment.d.ts +3 -0
- package/lib/panels/PanelCartShipment.js +72 -0
- package/lib/panels/PanelClearCart.d.ts +3 -0
- package/lib/panels/PanelClearCart.js +62 -0
- package/lib/panels/PanelClientCheckout.d.ts +3 -0
- package/lib/panels/PanelClientCheckout.js +88 -0
- package/lib/panels/PanelEditCartItem.d.ts +6 -0
- package/lib/panels/PanelEditCartItem.js +206 -0
- package/lib/panels/PanelPaymentSuccess.d.ts +3 -0
- package/lib/panels/PanelPaymentSuccess.js +69 -0
- package/lib/panels/index.d.ts +7 -0
- package/lib/panels/index.js +48 -0
- package/lib/square/SquareCard.d.ts +3 -0
- package/lib/square/SquareCard.js +114 -0
- package/lib/stripe/LegacyStripeCardForm.d.ts +3 -0
- package/lib/stripe/LegacyStripeCardForm.js +166 -0
- package/lib/stripe/StripeCardFields.d.ts +15 -0
- package/lib/stripe/StripeCardFields.js +135 -0
- package/lib/stripe/StripeCardForm.d.ts +2 -0
- package/lib/stripe/StripeCardForm.js +42 -0
- package/lib/stripe/StripePaymentButtons.d.ts +8 -0
- package/lib/stripe/StripePaymentButtons.js +106 -0
- package/lib/stripe/actions.d.ts +4 -0
- package/lib/stripe/actions.js +200 -0
- package/lib/stripe/utils.d.ts +18 -0
- package/lib/stripe/utils.js +27 -0
- package/lib/styles/globals.css +463 -0
- package/lib/styles/globals.css.map +1 -0
- package/lib/tabs/CartNav.d.ts +3 -0
- package/lib/tabs/CartNav.js +36 -0
- package/lib/tabs/NavTab.d.ts +9 -0
- package/lib/tabs/NavTab.js +39 -0
- package/lib/types/index.d.ts +13 -0
- package/lib/types/index.js +1 -0
- package/lib/utilities/address.d.ts +30 -0
- package/lib/utilities/address.js +468 -0
- package/lib/utilities/area.d.ts +77 -0
- package/lib/utilities/area.js +328 -0
- package/lib/utilities/cart.d.ts +9 -0
- package/lib/utilities/cart.js +108 -0
- package/lib/utilities/company.d.ts +2 -0
- package/lib/utilities/company.js +13 -0
- package/lib/utilities/cookie.d.ts +4 -0
- package/lib/utilities/cookie.js +165 -0
- package/lib/utilities/currency.d.ts +5 -0
- package/lib/utilities/currency.js +229 -0
- package/lib/utilities/customForm.d.ts +17 -0
- package/lib/utilities/customForm.js +64 -0
- package/lib/utilities/helpers.d.ts +24 -0
- package/lib/utilities/helpers.js +240 -0
- package/lib/utilities/index.d.ts +14 -0
- package/lib/utilities/index.js +159 -0
- package/lib/utilities/invoice.d.ts +3 -0
- package/lib/utilities/invoice.js +118 -0
- package/lib/utilities/job.d.ts +1 -0
- package/lib/utilities/job.js +15 -0
- package/lib/utilities/local_storage.d.ts +31 -0
- package/lib/utilities/local_storage.js +96 -0
- package/lib/utilities/product.d.ts +2 -0
- package/lib/utilities/product.js +21 -0
- package/lib/utilities/shipment.d.ts +2 -0
- package/lib/utilities/shipment.js +18 -0
- package/lib/utilities/tabs.d.ts +14 -0
- package/lib/utilities/tabs.js +60 -0
- package/lib/utilities/user.d.ts +5 -0
- package/lib/utilities/user.js +75 -0
- package/lib/utilities/variations.d.ts +18 -0
- package/lib/utilities/variations.js +66 -0
- package/package.json +109 -0
- package/src/Cart.tsx +96 -0
- package/src/CartAlert.tsx +35 -0
- package/src/CartHeader.tsx +28 -0
- package/src/CartProvider.tsx +992 -0
- package/src/CartTotals.tsx +102 -0
- package/src/assets/merchi-monster-loader.gif +0 -0
- package/src/assets/merchi-swipe-outline.png +0 -0
- package/src/assets/product-not-found.png +0 -0
- package/src/assets/stripe-payment-secure.png +0 -0
- package/src/buttons/Button.tsx +35 -0
- package/src/buttons/ButtonBack.tsx +42 -0
- package/src/buttons/ButtonClearCart.tsx +17 -0
- package/src/buttons/ButtonInvoiceDownload.tsx +60 -0
- package/src/buttons/ButtonNext.tsx +35 -0
- package/src/buttons/ButtonNextDynamic.tsx +31 -0
- package/src/buttons/ButtonOpenCartMerchiCartModal.tsx +61 -0
- package/src/buttons/ButtonPay.tsx +32 -0
- package/src/buttons/ButtonShipmentTabNext.tsx +24 -0
- package/src/buttons/index.ts +15 -0
- package/src/components/Alert.tsx +31 -0
- package/src/components/CartBody.tsx +16 -0
- package/src/components/CartClient.tsx +52 -0
- package/src/components/CartFooter.tsx +15 -0
- package/src/components/CartItemRow.tsx +212 -0
- package/src/components/CartPaymentSettingsInvalid.tsx +12 -0
- package/src/components/CartShipment.tsx +56 -0
- package/src/components/CartTabContent.tsx +15 -0
- package/src/components/CartTabPanel.tsx +25 -0
- package/src/components/CartTableContainer.tsx +15 -0
- package/src/components/CartTitle.tsx +22 -0
- package/src/components/CartTotalsListGroup.tsx +58 -0
- package/src/components/Collapse.tsx +23 -0
- package/src/components/CustomCartProductForm.tsx +123 -0
- package/src/components/CustomerCheckoutMethodTabs.tsx +106 -0
- package/src/components/DiscountInputGroup.tsx +160 -0
- package/src/components/LoadingTemplate.tsx +22 -0
- package/src/components/NoCartItems.tsx +20 -0
- package/src/components/ShipmentGroupCard.tsx +170 -0
- package/src/components/Table.tsx +15 -0
- package/src/components/containers.tsx +40 -0
- package/src/components/index.ts +38 -0
- package/src/components/product-form-sdk-externals.ts +67 -0
- package/src/forms/FormNewCustomer.tsx +170 -0
- package/src/forms/FormReturningCustomer.tsx +117 -0
- package/src/forms/FormShipmentAddressAndNotes.tsx +165 -0
- package/src/forms/FormSquarePayment.tsx +19 -0
- package/src/forms/FormStripePayment.tsx +19 -0
- package/src/forms/FormWhatsappCustomer.tsx +179 -0
- package/src/forms/InputAcceptUserTermsAndConditions.tsx +43 -0
- package/src/forms/InputError.tsx +23 -0
- package/src/forms/InputSelect.tsx +58 -0
- package/src/forms/InputText.tsx +56 -0
- package/src/forms/InputsAddress.tsx +438 -0
- package/src/forms/index.ts +18 -0
- package/src/index.ts +31 -0
- package/src/modals.tsx +65 -0
- package/src/panels/PanelCartItems.tsx +56 -0
- package/src/panels/PanelCartShipment.tsx +86 -0
- package/src/panels/PanelClearCart.tsx +50 -0
- package/src/panels/PanelClientCheckout.tsx +102 -0
- package/src/panels/PanelEditCartItem.tsx +172 -0
- package/src/panels/PanelPaymentSuccess.tsx +66 -0
- package/src/panels/index.ts +15 -0
- package/src/square/SquareCard.tsx +84 -0
- package/src/stripe/LegacyStripeCardForm.tsx +91 -0
- package/src/stripe/StripeCardFields.tsx +173 -0
- package/src/stripe/StripeCardForm.tsx +18 -0
- package/src/stripe/StripePaymentButtons.tsx +117 -0
- package/src/stripe/actions.ts +94 -0
- package/src/stripe/utils.ts +22 -0
- package/src/styles/globals.scss +475 -0
- package/src/tabs/CartNav.tsx +18 -0
- package/src/tabs/NavTab.tsx +36 -0
- package/src/types/assets.d.ts +4 -0
- package/src/types/index.ts +15 -0
- package/src/types/merchi_product_form/index.d.ts +1 -0
- package/src/types/merchi_sdk_ts/index.d.ts +1 -0
- package/src/types/react-redux/index.d.ts +0 -0
- package/src/utilities/address.ts +463 -0
- package/src/utilities/area.ts +359 -0
- package/src/utilities/cart.ts +80 -0
- package/src/utilities/company.ts +8 -0
- package/src/utilities/cookie.ts +58 -0
- package/src/utilities/currency.ts +216 -0
- package/src/utilities/customForm.ts +71 -0
- package/src/utilities/helpers.ts +213 -0
- package/src/utilities/index.ts +14 -0
- package/src/utilities/invoice.ts +60 -0
- package/src/utilities/job.ts +13 -0
- package/src/utilities/local_storage.ts +130 -0
- package/src/utilities/product.ts +14 -0
- package/src/utilities/shipment.ts +11 -0
- package/src/utilities/tabs.ts +38 -0
- package/src/utilities/user.ts +33 -0
- package/src/utilities/variations.ts +80 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useForm } from 'react-hook-form';
|
|
3
|
+
import { Merchi } from '@merchi/sdk';
|
|
4
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
5
|
+
import { faCircleNotch, faTags, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
6
|
+
import { useCartContext } from '../CartProvider';
|
|
7
|
+
import Title from './CartTitle';
|
|
8
|
+
import { makeCart, makeDiscountItem } from '../utilities/cart';
|
|
9
|
+
import { cartEmbed } from '../utilities/helpers';
|
|
10
|
+
import { getCartCookieToken } from '../utilities/cookie';
|
|
11
|
+
|
|
12
|
+
export default function DiscountInputGroup() {
|
|
13
|
+
const {
|
|
14
|
+
alertError,
|
|
15
|
+
cart,
|
|
16
|
+
setCart,
|
|
17
|
+
discountButtonText = 'Apply',
|
|
18
|
+
discountClassName = 'merchi-discount-group-container',
|
|
19
|
+
discountClassNameButton = 'btn btn-primary',
|
|
20
|
+
discountClassNameButtonContainer = 'col-auto',
|
|
21
|
+
discountClassNameButtonItemRemove = 'btn btn-lg btn-link',
|
|
22
|
+
discountClassNameErrorMessage = 'text-danger',
|
|
23
|
+
discountClassNameInput = 'form-control input-lg',
|
|
24
|
+
discountClassNameInputContainer,
|
|
25
|
+
discountClassNameListItem = 'list-group-item d-flex align-items-center justify-content-between mt-2',
|
|
26
|
+
discountClassNameListItems = 'list-group',
|
|
27
|
+
discountClassNameMainContainer,
|
|
28
|
+
discountShowAppliedItems,
|
|
29
|
+
domainId,
|
|
30
|
+
} = useCartContext();
|
|
31
|
+
const { discountItems = [] } = cart;
|
|
32
|
+
const defaultCodes = discountItems.map((i: any) => i.code).join(',');
|
|
33
|
+
const merchi = new Merchi();
|
|
34
|
+
const hookForm = useForm({
|
|
35
|
+
defaultValues: { codes: defaultCodes },
|
|
36
|
+
});
|
|
37
|
+
const {
|
|
38
|
+
getValues,
|
|
39
|
+
register,
|
|
40
|
+
setValue,
|
|
41
|
+
trigger,
|
|
42
|
+
formState: { errors },
|
|
43
|
+
} = hookForm;
|
|
44
|
+
const [loading, setLoading] = React.useState(false);
|
|
45
|
+
const [error, setError] = React.useState(({} as any));
|
|
46
|
+
|
|
47
|
+
const onSubmit = async (data: { codes: string }) => {
|
|
48
|
+
const validate = await trigger();
|
|
49
|
+
if (validate) {
|
|
50
|
+
await validateCodes(data.codes);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
async function actionPatchCart(cartEnt: any) {
|
|
55
|
+
try {
|
|
56
|
+
const cart = await cartEnt.save({embed: cartEmbed});
|
|
57
|
+
setCart(cart.toJson());
|
|
58
|
+
} catch (e: any) {
|
|
59
|
+
alertError(e.errorMessage || e.message || 'nknown server error.');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function validateCodes(codes: string) {
|
|
64
|
+
const query: Array<any> = [['codes', codes]];
|
|
65
|
+
setLoading(true);
|
|
66
|
+
setError({});
|
|
67
|
+
const cartToken = await getCartCookieToken((domainId as string | number));
|
|
68
|
+
try {
|
|
69
|
+
let url = `/carts/${cart.id}/check_discount_code/`;
|
|
70
|
+
const r = await merchi.authenticatedFetch(url, { query });
|
|
71
|
+
const updatedItems = r.items || [];
|
|
72
|
+
setItems(updatedItems);
|
|
73
|
+
const cartEnt = makeCart({...cart}, false, cartToken);
|
|
74
|
+
cartEnt.discountItems = updatedItems.map(
|
|
75
|
+
(r: any) => makeDiscountItem({...r}, true)
|
|
76
|
+
);
|
|
77
|
+
actionPatchCart(cartEnt);
|
|
78
|
+
} catch (e: any) {
|
|
79
|
+
setError({message: `Error: ${e.errorMessage || e.message || 'Unexpected error.'}`});
|
|
80
|
+
const cartEnt = makeCart({...cart, discountItems: []}, false, cartToken);
|
|
81
|
+
const discountItems = cartEnt.discountItems;
|
|
82
|
+
cartEnt.discountItems = discountItems;
|
|
83
|
+
actionPatchCart(cartEnt);
|
|
84
|
+
} finally {
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function handleClick() {
|
|
90
|
+
const { codes } = getValues();
|
|
91
|
+
await onSubmit({ codes });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const [items, setItems] = React.useState(discountItems || []);
|
|
95
|
+
|
|
96
|
+
async function removeItem(index: number) {
|
|
97
|
+
const item: any = {...(items[index] as any)};
|
|
98
|
+
const codes = getValues('codes');
|
|
99
|
+
const newValues = codes.replace(item.code, "");
|
|
100
|
+
setValue('codes', newValues);
|
|
101
|
+
await validateCodes(newValues);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div className={discountClassNameMainContainer}>
|
|
106
|
+
<Title icon={faTags} title='Apply discount code' />
|
|
107
|
+
<div className={discountClassName}>
|
|
108
|
+
<div className={discountClassNameInputContainer}>
|
|
109
|
+
<input
|
|
110
|
+
type="text"
|
|
111
|
+
className={discountClassNameInput}
|
|
112
|
+
placeholder='discount20,discount10'
|
|
113
|
+
{...register('codes', {required: 'Codes must be provided.'})}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
<div className={discountClassNameButtonContainer}>
|
|
117
|
+
<button
|
|
118
|
+
className={discountClassNameButton}
|
|
119
|
+
disabled={loading}
|
|
120
|
+
onClick={handleClick}
|
|
121
|
+
>
|
|
122
|
+
{loading ? (
|
|
123
|
+
<FontAwesomeIcon icon={faCircleNotch} />
|
|
124
|
+
) : discountButtonText}
|
|
125
|
+
</button>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
{error.message && (
|
|
129
|
+
<div className={discountClassNameErrorMessage}>
|
|
130
|
+
{error.message}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
{errors.codes && (
|
|
134
|
+
<div className={discountClassNameErrorMessage}>
|
|
135
|
+
{(errors as any)?.codes?.message}
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
{discountShowAppliedItems && (
|
|
139
|
+
<div className={discountClassNameListItems}>
|
|
140
|
+
{items.map((item: any, index: number) =>
|
|
141
|
+
<div
|
|
142
|
+
className={discountClassNameListItem}
|
|
143
|
+
key={index}
|
|
144
|
+
>
|
|
145
|
+
<div>{item.code} {item.description}</div>
|
|
146
|
+
<div>
|
|
147
|
+
<button
|
|
148
|
+
className={discountClassNameButtonItemRemove}
|
|
149
|
+
onClick={() => removeItem(index)}
|
|
150
|
+
>
|
|
151
|
+
<FontAwesomeIcon icon={faTimes} />
|
|
152
|
+
</button>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useCartContext } from "../CartProvider";
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
height?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default function LoadingTemplate({ height }: Props) {
|
|
8
|
+
const {
|
|
9
|
+
classNameLoadingTemplate,
|
|
10
|
+
classNameLoadingTemplateContainer,
|
|
11
|
+
} = useCartContext();
|
|
12
|
+
const style = height ? { height } : {};
|
|
13
|
+
return (
|
|
14
|
+
<div className={classNameLoadingTemplateContainer} style={style}>
|
|
15
|
+
<div className={classNameLoadingTemplate} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function LoadingTemplateSm() {
|
|
21
|
+
return <LoadingTemplate height={300} />;
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useCartContext } from "../CartProvider";
|
|
3
|
+
import pngProductNotFound from "../assets/product-not-found.png";
|
|
4
|
+
|
|
5
|
+
function NoCartItems() {
|
|
6
|
+
const { classNameNoItems } = useCartContext();
|
|
7
|
+
return (
|
|
8
|
+
<div className={classNameNoItems}>
|
|
9
|
+
<img
|
|
10
|
+
src={pngProductNotFound?.src || pngProductNotFound || ''}
|
|
11
|
+
alt="Cart items not found"
|
|
12
|
+
width={276}
|
|
13
|
+
height={215}
|
|
14
|
+
/>
|
|
15
|
+
<p>No cart items.</p>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default NoCartItems;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { addressInOneLine } from "../utilities/address";
|
|
3
|
+
import { currencyTaxAndCost } from "../utilities/currency";
|
|
4
|
+
import { useCartContext } from "../CartProvider";
|
|
5
|
+
import pngProductNotFound from "../assets/product-not-found.png";
|
|
6
|
+
import { makeCart, makeCartShipmentQuote } from "../utilities/cart";
|
|
7
|
+
import { cartEmbed } from "../utilities/helpers";
|
|
8
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
9
|
+
import { faCheckSquare, faSquare } from "@fortawesome/free-solid-svg-icons";
|
|
10
|
+
import { getCartCookieToken } from "../utilities/cookie";
|
|
11
|
+
|
|
12
|
+
function NoCartShipmentOptionsFound() {
|
|
13
|
+
const { classNameNoItems } = useCartContext();
|
|
14
|
+
return (
|
|
15
|
+
<div className={classNameNoItems}>
|
|
16
|
+
<img
|
|
17
|
+
src={
|
|
18
|
+
(pngProductNotFound && "src" in pngProductNotFound
|
|
19
|
+
? pngProductNotFound.src
|
|
20
|
+
: pngProductNotFound) || ""
|
|
21
|
+
}
|
|
22
|
+
width={276}
|
|
23
|
+
height={215}
|
|
24
|
+
/>
|
|
25
|
+
<p>No shipment options found.</p>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface PropsPickupInfo {
|
|
31
|
+
originAddress: any;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function PickupInfo({ originAddress }: PropsPickupInfo) {
|
|
35
|
+
return <small>Pick up from: {addressInOneLine(originAddress)}</small>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function ShipmentPrice({ quote }: any) {
|
|
39
|
+
const { shipmentMethod, taxType, totalCost } = quote;
|
|
40
|
+
const { currency } = shipmentMethod;
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<small>
|
|
44
|
+
<strong>
|
|
45
|
+
{totalCost > 0
|
|
46
|
+
? currencyTaxAndCost(currency, taxType, totalCost)
|
|
47
|
+
: ""}
|
|
48
|
+
</strong>
|
|
49
|
+
</small>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface PropsShipmentOptionInfo {
|
|
55
|
+
quote: any;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ShipmentOptionInfo({ quote }: PropsShipmentOptionInfo) {
|
|
59
|
+
const { classNameShipmentOption } = useCartContext();
|
|
60
|
+
const { name, shipmentMethod } = quote;
|
|
61
|
+
const { originAddress, pickUp, transportCompanyName } = shipmentMethod;
|
|
62
|
+
return (
|
|
63
|
+
<div className={classNameShipmentOption}>
|
|
64
|
+
{!name ? (
|
|
65
|
+
<>
|
|
66
|
+
{transportCompanyName && (
|
|
67
|
+
<p className="mb-0">{shipmentMethod.name}</p>
|
|
68
|
+
)}
|
|
69
|
+
{pickUp ? (
|
|
70
|
+
<PickupInfo originAddress={originAddress} />
|
|
71
|
+
) : (
|
|
72
|
+
<small>{transportCompanyName}</small>
|
|
73
|
+
)}
|
|
74
|
+
</>
|
|
75
|
+
) : (
|
|
76
|
+
<>
|
|
77
|
+
<p className="m-0">{name}</p>
|
|
78
|
+
{pickUp && <PickupInfo originAddress={originAddress} />}
|
|
79
|
+
</>
|
|
80
|
+
)}
|
|
81
|
+
<ShipmentPrice quote={quote} />
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface ShipmentOptionProps {
|
|
87
|
+
isSelected: boolean;
|
|
88
|
+
doClick: () => void;
|
|
89
|
+
quote: any;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function ShipmentQuote({ isSelected, doClick, quote }: ShipmentOptionProps) {
|
|
93
|
+
const { classNameListItem } = useCartContext();
|
|
94
|
+
return (
|
|
95
|
+
<div
|
|
96
|
+
className={classNameListItem}
|
|
97
|
+
onClick={doClick}
|
|
98
|
+
style={{ cursor: "pointer" }}
|
|
99
|
+
>
|
|
100
|
+
<div
|
|
101
|
+
style={{
|
|
102
|
+
alignItems: "center",
|
|
103
|
+
display: "flex",
|
|
104
|
+
justifyContent: "space-between",
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
<ShipmentOptionInfo quote={quote} />
|
|
108
|
+
<div>
|
|
109
|
+
<FontAwesomeIcon icon={isSelected ? faCheckSquare : faSquare} />
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface Props {
|
|
117
|
+
group: any;
|
|
118
|
+
groupIndex: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function ShipmentGroupCard({ group, groupIndex }: Props) {
|
|
122
|
+
const { alertError, cart, classNameList, classNameListInline, domainId, setCart } = useCartContext();
|
|
123
|
+
const { cartItems, quotes = [] } = group;
|
|
124
|
+
const [selectedQuote, setSelectedQuote] = useState(group.selectedQuote || {});
|
|
125
|
+
async function doClick(groupIndex: number, quote: any) {
|
|
126
|
+
setSelectedQuote(quote);
|
|
127
|
+
try {
|
|
128
|
+
const token = await getCartCookieToken((domainId as string | number));
|
|
129
|
+
const cartEnt = makeCart({ ...cart }, false, token);
|
|
130
|
+
const cartShipmentQuote = makeCartShipmentQuote({ ...quote });
|
|
131
|
+
(cartEnt as any).shipmentGroups[groupIndex].selectedQuote = cartShipmentQuote;
|
|
132
|
+
await cartEnt.save({ embed: cartEmbed });
|
|
133
|
+
const cartJson = await cartEnt.toJson();
|
|
134
|
+
setCart({ ...cart, ...cartJson });
|
|
135
|
+
} catch (e: any) {
|
|
136
|
+
alertError(
|
|
137
|
+
e.errorMessage || e.message || "Unable to select shipment option."
|
|
138
|
+
);
|
|
139
|
+
setSelectedQuote({});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return (
|
|
143
|
+
<div>
|
|
144
|
+
<ul className={classNameListInline}>
|
|
145
|
+
<li>
|
|
146
|
+
<strong>Shipment {groupIndex + 1} contents:</strong>
|
|
147
|
+
</li>
|
|
148
|
+
{cartItems.map((item: any, index: number) => (
|
|
149
|
+
<li key={index}>{item.product.name}</li>
|
|
150
|
+
))}
|
|
151
|
+
</ul>
|
|
152
|
+
{quotes.length ? (
|
|
153
|
+
<div className={classNameList}>
|
|
154
|
+
{quotes.map((q: any, i: number) => (
|
|
155
|
+
<ShipmentQuote
|
|
156
|
+
key={`${i}-group-quote`}
|
|
157
|
+
quote={q}
|
|
158
|
+
isSelected={(selectedQuote as any)?.id === q.id}
|
|
159
|
+
doClick={() => doClick(groupIndex, q)}
|
|
160
|
+
/>
|
|
161
|
+
))}
|
|
162
|
+
</div>
|
|
163
|
+
) : (
|
|
164
|
+
<NoCartShipmentOptionsFound />
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default ShipmentGroupCard;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCartContext } from "../CartProvider";
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
children: any;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function Table({ children, className = '' }: Props) {
|
|
9
|
+
const { classNameTable } = useCartContext();
|
|
10
|
+
return (
|
|
11
|
+
<table className={`${classNameTable} ${className}`}>
|
|
12
|
+
{children}
|
|
13
|
+
</table>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface CheckoutContainerProps {
|
|
4
|
+
children: any;
|
|
5
|
+
textAlign?: any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function CheckoutContainer({ children, textAlign = 'center' }: CheckoutContainerProps) {
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
style={{
|
|
12
|
+
display: 'flex',
|
|
13
|
+
justifyContent: 'center',
|
|
14
|
+
textAlign: textAlign,
|
|
15
|
+
}}
|
|
16
|
+
>
|
|
17
|
+
{children}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface InnerProps {
|
|
23
|
+
children: any;
|
|
24
|
+
paddingBottom?: string;
|
|
25
|
+
paddingTop?: string;
|
|
26
|
+
width?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function InnerContainer({ children, paddingBottom, paddingTop, width = 400 }: InnerProps) {
|
|
30
|
+
return (
|
|
31
|
+
<div style={{
|
|
32
|
+
padding: '3rem',
|
|
33
|
+
paddingBottom: paddingBottom,
|
|
34
|
+
paddingTop: paddingTop,
|
|
35
|
+
width: width,
|
|
36
|
+
}}>
|
|
37
|
+
{children}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Alert from './Alert';
|
|
2
|
+
import CartBody from './CartBody';
|
|
3
|
+
import CartClient from './CartClient';
|
|
4
|
+
import CartFooter from './CartFooter';
|
|
5
|
+
import CartPaymentSettingsInvalid from './CartPaymentSettingsInvalid';
|
|
6
|
+
import CartShipment from './CartShipment';
|
|
7
|
+
import CartTabContent from './CartTabContent';
|
|
8
|
+
import CartTableContainer from './CartTableContainer';
|
|
9
|
+
import CartTabPanel from './CartTabPanel';
|
|
10
|
+
import Collapse from './Collapse';
|
|
11
|
+
import CustomerCheckoutMethodTabs from './CustomerCheckoutMethodTabs';
|
|
12
|
+
import DiscountInputGroup from './DiscountInputGroup';
|
|
13
|
+
import LoadingTemplate, { LoadingTemplateSm } from './LoadingTemplate';
|
|
14
|
+
import NoCartItems from './NoCartItems';
|
|
15
|
+
import ShipmentGroupCard from './ShipmentGroupCard';
|
|
16
|
+
import Table from './Table';
|
|
17
|
+
import Title from './CartTitle';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
Alert,
|
|
21
|
+
CartBody,
|
|
22
|
+
CartClient,
|
|
23
|
+
CartFooter,
|
|
24
|
+
CartPaymentSettingsInvalid,
|
|
25
|
+
CartShipment,
|
|
26
|
+
CartTabContent,
|
|
27
|
+
CartTableContainer,
|
|
28
|
+
CartTabPanel,
|
|
29
|
+
Collapse,
|
|
30
|
+
CustomerCheckoutMethodTabs,
|
|
31
|
+
DiscountInputGroup,
|
|
32
|
+
LoadingTemplate,
|
|
33
|
+
LoadingTemplateSm,
|
|
34
|
+
NoCartItems,
|
|
35
|
+
ShipmentGroupCard,
|
|
36
|
+
Table,
|
|
37
|
+
Title,
|
|
38
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full @merchi/product-form-sdk runtime for window.MerchiProductFormSdk.
|
|
3
|
+
* Keep in sync with merchi_api/common/js/product_form_gate.cjs SDK_EXPORTS.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
SDK_VERSION,
|
|
7
|
+
serializeJob,
|
|
8
|
+
nonEmptyGroups,
|
|
9
|
+
formatCurrency,
|
|
10
|
+
urlFor,
|
|
11
|
+
createPricing,
|
|
12
|
+
createProductFormRuntime,
|
|
13
|
+
productHasGroups,
|
|
14
|
+
groupFieldsOf,
|
|
15
|
+
independentFieldsOf,
|
|
16
|
+
isOptionQuantityGridProduct,
|
|
17
|
+
buildProductFormJob,
|
|
18
|
+
jobToFormState,
|
|
19
|
+
selectionsToVariations,
|
|
20
|
+
Section,
|
|
21
|
+
Stack,
|
|
22
|
+
Card,
|
|
23
|
+
Heading,
|
|
24
|
+
Text,
|
|
25
|
+
Divider,
|
|
26
|
+
Field,
|
|
27
|
+
GroupRows,
|
|
28
|
+
OptionQuantityGrid,
|
|
29
|
+
ProductFormProvider,
|
|
30
|
+
ProductFormShell,
|
|
31
|
+
ProductFormActions,
|
|
32
|
+
useProductForm,
|
|
33
|
+
OPTION_FIELD_TYPES,
|
|
34
|
+
theme,
|
|
35
|
+
} from '@merchi/product-form-sdk';
|
|
36
|
+
|
|
37
|
+
export const MerchiProductFormSdkExternals = {
|
|
38
|
+
SDK_VERSION,
|
|
39
|
+
serializeJob,
|
|
40
|
+
nonEmptyGroups,
|
|
41
|
+
formatCurrency,
|
|
42
|
+
urlFor,
|
|
43
|
+
createPricing,
|
|
44
|
+
createProductFormRuntime,
|
|
45
|
+
productHasGroups,
|
|
46
|
+
groupFieldsOf,
|
|
47
|
+
independentFieldsOf,
|
|
48
|
+
isOptionQuantityGridProduct,
|
|
49
|
+
buildProductFormJob,
|
|
50
|
+
jobToFormState,
|
|
51
|
+
selectionsToVariations,
|
|
52
|
+
Section,
|
|
53
|
+
Stack,
|
|
54
|
+
Card,
|
|
55
|
+
Heading,
|
|
56
|
+
Text,
|
|
57
|
+
Divider,
|
|
58
|
+
Field,
|
|
59
|
+
GroupRows,
|
|
60
|
+
OptionQuantityGrid,
|
|
61
|
+
ProductFormProvider,
|
|
62
|
+
ProductFormShell,
|
|
63
|
+
ProductFormActions,
|
|
64
|
+
useProductForm,
|
|
65
|
+
OPTION_FIELD_TYPES,
|
|
66
|
+
theme,
|
|
67
|
+
};
|