merchi_cart 0.0.7-c → 0.0.7-e
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/package.json +4 -3
- package/src/Cart.tsx +100 -0
- package/src/CartAlert.tsx +34 -0
- package/src/CartHeader.tsx +27 -0
- package/src/CartProvider.tsx +386 -0
- package/src/CartTotals.tsx +106 -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/buttons/Button.tsx +35 -0
- package/src/buttons/ButtonBack.tsx +37 -0
- package/src/buttons/ButtonClearCart.tsx +18 -0
- package/src/buttons/ButtonInvoiceDownload.tsx +63 -0
- package/src/buttons/ButtonNext.tsx +38 -0
- package/src/buttons/ButtonNextDynamic.tsx +31 -0
- package/src/buttons/ButtonPay.tsx +32 -0
- package/src/buttons/ButtonShipmentTabNext.tsx +25 -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 +48 -0
- package/src/components/CartFooter.tsx +15 -0
- package/src/components/CartItemRow.tsx +145 -0
- package/src/components/CartPaymentSettingsInvalid.tsx +12 -0
- package/src/components/CartShipment.tsx +55 -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/Collapse.tsx +23 -0
- package/src/components/LoadingTemplate.tsx +22 -0
- package/src/components/NoCartItems.tsx +15 -0
- package/src/components/ShipmentGroupCard.tsx +156 -0
- package/src/components/Table.tsx +14 -0
- package/src/components/Title.tsx +22 -0
- package/src/components/containers.tsx +40 -0
- package/src/components/index.ts +30 -0
- package/src/forms/FormNewCustomer.tsx +119 -0
- package/src/forms/FormReturningCustomer.tsx +70 -0
- package/src/forms/FormShipmentAddressAndNotes.tsx +142 -0
- package/src/forms/FormSquarePayment.tsx +14 -0
- package/src/forms/FormStripePayment.tsx +14 -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 +205 -0
- package/src/index.tsx +13 -0
- package/src/panels/PanelCartItems.tsx +61 -0
- package/src/panels/PanelCartShipment.tsx +89 -0
- package/src/panels/PanelClearCart.tsx +47 -0
- package/src/panels/PanelClientCheckout.tsx +92 -0
- package/src/panels/PanelEditCartItem.tsx +58 -0
- package/src/panels/PanelPaymentSuccess.tsx +69 -0
- package/src/panels/index.ts +15 -0
- package/src/slices/sliceCart.ts +159 -0
- package/src/slices/sliceCartAlert.ts +39 -0
- package/src/slices/sliceCartItem.ts +29 -0
- package/src/slices/sliceCartPayment.ts +45 -0
- package/src/slices/sliceCartShipment.ts +67 -0
- package/src/slices/sliceFormReturningCustomer.ts +25 -0
- package/src/slices/sliceNewCustomerForm.ts +24 -0
- package/src/square/SquareCard.tsx +58 -0
- package/src/square/actions.ts +40 -0
- package/src/square/slices/reducersSquare.ts +9 -0
- package/src/square/slices/sliceSquareAlerts.ts +29 -0
- package/src/square/slices/sliceSquareForm.ts +29 -0
- package/src/store.ts +499 -0
- package/src/stripe/StripeCardFields.tsx +164 -0
- package/src/stripe/StripeCardForm.tsx +86 -0
- package/src/stripe/StripePaymentButtons.tsx +117 -0
- package/src/stripe/actions.ts +94 -0
- package/src/stripe/slices/sliceStripeAlerts.ts +29 -0
- package/src/stripe/slices/sliceStripeCardForm.ts +9 -0
- package/src/stripe/slices/sliceStripeForm.ts +56 -0
- package/src/stripe/utils.ts +21 -0
- package/src/styles/globals.css +191 -0
- package/src/styles/globals.css.map +1 -0
- package/src/styles/globals.scss +197 -0
- package/src/tabs/CartNav.tsx +20 -0
- package/src/tabs/NavTab.tsx +38 -0
- package/src/utilities/address.ts +351 -0
- package/src/utilities/cart.ts +73 -0
- package/src/utilities/company.ts +8 -0
- package/src/utilities/cookie.ts +54 -0
- package/src/utilities/currency.ts +216 -0
- package/src/utilities/helpers.ts +209 -0
- package/src/utilities/invoice.ts +60 -0
- package/src/utilities/product.ts +7 -0
- package/src/utilities/user.ts +38 -0
- package/src/utilities/variations.ts +56 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merchi_cart",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7e",
|
|
4
4
|
"description": "Merchi's cart",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"homepage": "https://github.com/merchisdk/merchi_cart#readme",
|
|
38
38
|
"files": [
|
|
39
39
|
"esm",
|
|
40
|
-
"lib"
|
|
40
|
+
"lib",
|
|
41
|
+
"src"
|
|
41
42
|
],
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"react": "^18.0.0",
|
|
@@ -88,7 +89,7 @@
|
|
|
88
89
|
"js-cookie": "^3.0.5",
|
|
89
90
|
"lodash": "^4.17.21",
|
|
90
91
|
"merchi_product_form": "^1.0.2",
|
|
91
|
-
"merchi_sdk_ts": "^1.0.2-
|
|
92
|
+
"merchi_sdk_ts": "^1.0.2-g",
|
|
92
93
|
"moment": "^2.30.1",
|
|
93
94
|
"moment-timezone": "^0.5.44",
|
|
94
95
|
"react": "18.2.0",
|
package/src/Cart.tsx
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Provider, useSelector } from 'react-redux';
|
|
3
|
+
import { store } from './store';
|
|
4
|
+
import CartAlert from './CartAlert';
|
|
5
|
+
import CartHeader from './CartHeader';
|
|
6
|
+
import CartNav from './tabs/CartNav';
|
|
7
|
+
import CartTotals from './CartTotals';
|
|
8
|
+
import CartProvider, { PropsCart, useCartContext } from './CartProvider';
|
|
9
|
+
import {
|
|
10
|
+
ButtonBack,
|
|
11
|
+
ButtonClearCart,
|
|
12
|
+
ButtonNextDynamic,
|
|
13
|
+
} from './buttons';
|
|
14
|
+
import {
|
|
15
|
+
CartFooter,
|
|
16
|
+
CartPaymentSettingsInvalid,
|
|
17
|
+
LoadingTemplate,
|
|
18
|
+
} from './components';
|
|
19
|
+
import {
|
|
20
|
+
PanelCartItems,
|
|
21
|
+
PanelCartShipment,
|
|
22
|
+
PanelClearCart,
|
|
23
|
+
PanelClientCheckout,
|
|
24
|
+
PanelEditCartItem,
|
|
25
|
+
PanelPaymentSuccess,
|
|
26
|
+
}from './panels';
|
|
27
|
+
import {
|
|
28
|
+
tabIdClearCart,
|
|
29
|
+
tabIdItem,
|
|
30
|
+
tabIdPaymentSuccess,
|
|
31
|
+
} from './slices/sliceCart';
|
|
32
|
+
import {
|
|
33
|
+
actionFetchTheme,
|
|
34
|
+
initMerchiCart,
|
|
35
|
+
} from './store';
|
|
36
|
+
import './styles/globals.css';
|
|
37
|
+
|
|
38
|
+
function CartComponents() {
|
|
39
|
+
const {
|
|
40
|
+
domainId,
|
|
41
|
+
includeTheme,
|
|
42
|
+
initialiseCart
|
|
43
|
+
} = useCartContext();
|
|
44
|
+
const {
|
|
45
|
+
activeTab,
|
|
46
|
+
cartSettingsInvalid,
|
|
47
|
+
fetchingCart,
|
|
48
|
+
} = useSelector((s: any) => s.stateCart);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
if (initialiseCart && domainId) {
|
|
51
|
+
if (includeTheme) {
|
|
52
|
+
actionFetchTheme(domainId);
|
|
53
|
+
}
|
|
54
|
+
initMerchiCart(domainId);
|
|
55
|
+
}
|
|
56
|
+
}, [domainId, includeTheme, initialiseCart]);
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<CartHeader />
|
|
60
|
+
<CartAlert />
|
|
61
|
+
<CartNav />
|
|
62
|
+
{fetchingCart ? (
|
|
63
|
+
<LoadingTemplate />
|
|
64
|
+
) : cartSettingsInvalid ? (
|
|
65
|
+
<CartPaymentSettingsInvalid />
|
|
66
|
+
) : (
|
|
67
|
+
<div className='merchi-tab-pane'>
|
|
68
|
+
<PanelClearCart />
|
|
69
|
+
<PanelEditCartItem />
|
|
70
|
+
<PanelCartItems />
|
|
71
|
+
<PanelCartShipment />
|
|
72
|
+
<PanelClientCheckout />
|
|
73
|
+
<PanelPaymentSuccess />
|
|
74
|
+
{![tabIdItem, tabIdClearCart, tabIdPaymentSuccess].includes(activeTab) &&
|
|
75
|
+
<>
|
|
76
|
+
<CartFooter>
|
|
77
|
+
<CartTotals />
|
|
78
|
+
</CartFooter>
|
|
79
|
+
<CartFooter>
|
|
80
|
+
<ButtonClearCart />
|
|
81
|
+
<ButtonBack />
|
|
82
|
+
<ButtonNextDynamic />
|
|
83
|
+
</CartFooter>
|
|
84
|
+
</>
|
|
85
|
+
}
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default function Cart(props: PropsCart) {
|
|
93
|
+
return (
|
|
94
|
+
<CartProvider {...props}>
|
|
95
|
+
<Provider store={store}>
|
|
96
|
+
<CartComponents />
|
|
97
|
+
</Provider>
|
|
98
|
+
</CartProvider>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useSelector } from 'react-redux';
|
|
2
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
3
|
+
import { faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
4
|
+
import { Alert } from './components';
|
|
5
|
+
import { closeAlert } from './store';
|
|
6
|
+
import { useCartContext } from './CartProvider';
|
|
7
|
+
|
|
8
|
+
function CartAlert() {
|
|
9
|
+
const { classNameBtnClose } = useCartContext();
|
|
10
|
+
const { alert } = useSelector((s: any) => s.stateCartAlert);
|
|
11
|
+
const { icon, message, show, title } = alert;
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
{show && (
|
|
15
|
+
<Alert alertType={alert.type}>
|
|
16
|
+
{icon &&
|
|
17
|
+
<FontAwesomeIcon icon={icon} />
|
|
18
|
+
} <strong>{title}</strong> {message}
|
|
19
|
+
<button
|
|
20
|
+
type="button"
|
|
21
|
+
className={classNameBtnClose}
|
|
22
|
+
data-bs-dismiss="alert"
|
|
23
|
+
aria-label="Close"
|
|
24
|
+
onClick={closeAlert}
|
|
25
|
+
>
|
|
26
|
+
<FontAwesomeIcon icon={faTimes} />
|
|
27
|
+
</button>
|
|
28
|
+
</Alert>
|
|
29
|
+
)}
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default CartAlert;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
3
|
+
import { faShoppingCart, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
4
|
+
import { useCartContext } from './CartProvider';
|
|
5
|
+
|
|
6
|
+
function CartHeader() {
|
|
7
|
+
const {
|
|
8
|
+
classNameCartHeader,
|
|
9
|
+
classNameBtnClose,
|
|
10
|
+
onClickClose,
|
|
11
|
+
} = useCartContext();
|
|
12
|
+
return (
|
|
13
|
+
<div className={classNameCartHeader}>
|
|
14
|
+
<FontAwesomeIcon icon={faShoppingCart} /> Shopping cart
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
className={classNameBtnClose}
|
|
18
|
+
aria-label="Close"
|
|
19
|
+
onClick={onClickClose}
|
|
20
|
+
>
|
|
21
|
+
<FontAwesomeIcon icon={faTimes} />
|
|
22
|
+
</button>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default CartHeader;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createContext, ReactNode, useContext, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface PropsCart {
|
|
5
|
+
classNameAlertError?: string;
|
|
6
|
+
classNameAlertInfo?: string;
|
|
7
|
+
classNameAlertSuccess?: string;
|
|
8
|
+
classNameAlertWarning?: string;
|
|
9
|
+
classNameBtn?: string;
|
|
10
|
+
classNameBtnBack?: string;
|
|
11
|
+
classNameBtnCartClear?: string;
|
|
12
|
+
classNameBtnClose?: string;
|
|
13
|
+
classNameBtnDanger?: string;
|
|
14
|
+
classNameBtnDefault?: string;
|
|
15
|
+
classNameBtnDownloadInvoice?: string;
|
|
16
|
+
classNameBtnPrimary?: string;
|
|
17
|
+
classNameBtnLink?: string;
|
|
18
|
+
classNameBtnNext?: string;
|
|
19
|
+
classNameBtnNextComplete?: string;
|
|
20
|
+
classNameBtnPay?: string;
|
|
21
|
+
classNameCartBody?: string;
|
|
22
|
+
classNameCartFooter?: string;
|
|
23
|
+
|
|
24
|
+
classNameCartFormCheckbox?: string;
|
|
25
|
+
classNameCartFormGroup?: string;
|
|
26
|
+
classNameCartFormGroupCheckbox?: string;
|
|
27
|
+
classNameCartFormInput?: string;
|
|
28
|
+
classNameCartFormLabelCheckbox?: string;
|
|
29
|
+
classNameCartInputError?: string;
|
|
30
|
+
classNameCartNav?: string;
|
|
31
|
+
classNameCartRow?: string;
|
|
32
|
+
classNameCartRowColumn?: string;
|
|
33
|
+
classNameCartTabItem?: string;
|
|
34
|
+
classNameCartTabItemLink?: string;
|
|
35
|
+
classNameCartGoogleSuggestList?: string;
|
|
36
|
+
classNameCartGoogleSuggestListItem?: string;
|
|
37
|
+
|
|
38
|
+
classNameCartHeader?: string;
|
|
39
|
+
classNameCartItemFeatureImage?: string;
|
|
40
|
+
classNameCartItemInfo?: string;
|
|
41
|
+
classNameCartItemInfoCell?: string;
|
|
42
|
+
classNameCartItemInfoCellRight?: string;
|
|
43
|
+
classNameCartItemInfoContainer?: string;
|
|
44
|
+
classNameCartTab?: string;
|
|
45
|
+
classNameCartTabPanel?: string;
|
|
46
|
+
classNameCartTitle?: string;
|
|
47
|
+
classNameCartTotalContainer?: string;
|
|
48
|
+
classNameCartTotalItem?: string;
|
|
49
|
+
classNameCartTotalItemPrice?: string;
|
|
50
|
+
classNameClearCartContainer?: string;
|
|
51
|
+
classNameClearCartText?: string;
|
|
52
|
+
classNameListClientInfo?: string;
|
|
53
|
+
classNameListContainer?: string;
|
|
54
|
+
classNameListItem?: string;
|
|
55
|
+
classNameList?: string;
|
|
56
|
+
classNameListInline?: string;
|
|
57
|
+
classNameListUnstyled?: string;
|
|
58
|
+
classNameLoadingTemplate?: string;
|
|
59
|
+
classNameLoadingTemplateContainer?: string;
|
|
60
|
+
classNameNoItems?: string;
|
|
61
|
+
classNameShipmentOption?: string;
|
|
62
|
+
classNameTable?: string;
|
|
63
|
+
classNameTableContainer?: string;
|
|
64
|
+
classNameVariationsList?: string;
|
|
65
|
+
customSuccessMessage?: string;
|
|
66
|
+
domainId?: number;
|
|
67
|
+
googlePlacesLoaded?: boolean;
|
|
68
|
+
includeTheme?: boolean,
|
|
69
|
+
initialiseCart?: boolean;
|
|
70
|
+
onClickClose?: () => void;
|
|
71
|
+
showUserTermsAndConditions?: boolean;
|
|
72
|
+
productFormClassNames?: any;
|
|
73
|
+
urlApi?: string;
|
|
74
|
+
urlFrontend?: string;
|
|
75
|
+
urlTrackingPage?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const CartContext = createContext<PropsCart>({
|
|
79
|
+
classNameAlertError: undefined,
|
|
80
|
+
classNameAlertInfo: undefined,
|
|
81
|
+
classNameAlertSuccess: undefined,
|
|
82
|
+
classNameAlertWarning: undefined,
|
|
83
|
+
classNameBtn: undefined,
|
|
84
|
+
classNameBtnBack: undefined,
|
|
85
|
+
classNameBtnCartClear: undefined,
|
|
86
|
+
classNameBtnClose: undefined,
|
|
87
|
+
classNameBtnDanger: undefined,
|
|
88
|
+
classNameBtnDefault: undefined,
|
|
89
|
+
classNameBtnDownloadInvoice: undefined,
|
|
90
|
+
classNameBtnPrimary: undefined,
|
|
91
|
+
classNameBtnLink: undefined,
|
|
92
|
+
classNameBtnNext: undefined,
|
|
93
|
+
classNameBtnNextComplete: undefined,
|
|
94
|
+
classNameBtnPay: undefined,
|
|
95
|
+
classNameCartBody: undefined,
|
|
96
|
+
classNameCartFooter: undefined,
|
|
97
|
+
classNameCartFormCheckbox: undefined,
|
|
98
|
+
classNameCartFormGroup: undefined,
|
|
99
|
+
classNameCartFormGroupCheckbox: undefined,
|
|
100
|
+
classNameCartFormInput: undefined,
|
|
101
|
+
classNameCartInputError: undefined,
|
|
102
|
+
classNameCartFormLabelCheckbox: undefined,
|
|
103
|
+
classNameCartRow: undefined,
|
|
104
|
+
classNameCartRowColumn: undefined,
|
|
105
|
+
classNameCartTabItem: undefined,
|
|
106
|
+
classNameCartTabItemLink: undefined,
|
|
107
|
+
classNameCartGoogleSuggestList: undefined,
|
|
108
|
+
classNameCartGoogleSuggestListItem: undefined,
|
|
109
|
+
classNameCartHeader: undefined,
|
|
110
|
+
classNameCartItemFeatureImage: undefined,
|
|
111
|
+
classNameCartItemInfo: undefined,
|
|
112
|
+
classNameCartItemInfoCell: undefined,
|
|
113
|
+
classNameCartItemInfoCellRight: undefined,
|
|
114
|
+
classNameCartItemInfoContainer: undefined,
|
|
115
|
+
classNameCartNav: undefined,
|
|
116
|
+
classNameCartTab: undefined,
|
|
117
|
+
classNameCartTabPanel: undefined,
|
|
118
|
+
classNameCartTitle: undefined,
|
|
119
|
+
classNameCartTotalContainer: undefined,
|
|
120
|
+
classNameCartTotalItem: undefined,
|
|
121
|
+
classNameCartTotalItemPrice: undefined,
|
|
122
|
+
classNameClearCartContainer: undefined,
|
|
123
|
+
classNameClearCartText: undefined,
|
|
124
|
+
classNameListClientInfo: undefined,
|
|
125
|
+
classNameListContainer: undefined,
|
|
126
|
+
classNameListItem: undefined,
|
|
127
|
+
classNameList: undefined,
|
|
128
|
+
classNameListInline: undefined,
|
|
129
|
+
classNameListUnstyled: undefined,
|
|
130
|
+
classNameLoadingTemplate: undefined,
|
|
131
|
+
classNameLoadingTemplateContainer: undefined,
|
|
132
|
+
classNameNoItems: undefined,
|
|
133
|
+
classNameShipmentOption: undefined,
|
|
134
|
+
classNameTable: undefined,
|
|
135
|
+
classNameTableContainer: undefined,
|
|
136
|
+
classNameVariationsList: undefined,
|
|
137
|
+
customSuccessMessage: undefined,
|
|
138
|
+
domainId: undefined,
|
|
139
|
+
googlePlacesLoaded: false,
|
|
140
|
+
includeTheme: false,
|
|
141
|
+
initialiseCart: true,
|
|
142
|
+
onClickClose: undefined,
|
|
143
|
+
productFormClassNames: {},
|
|
144
|
+
showUserTermsAndConditions: undefined,
|
|
145
|
+
urlApi: undefined,
|
|
146
|
+
urlFrontend: undefined,
|
|
147
|
+
urlTrackingPage: undefined,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const useCartContext = () => useContext(CartContext);
|
|
151
|
+
|
|
152
|
+
interface PropsCartProvider {
|
|
153
|
+
children: ReactNode;
|
|
154
|
+
classNameAlertError?: string;
|
|
155
|
+
classNameAlertInfo?: string;
|
|
156
|
+
classNameAlertSuccess?: string;
|
|
157
|
+
classNameAlertWarning?: string;
|
|
158
|
+
classNameBtn?: string;
|
|
159
|
+
classNameBtnBack?: string;
|
|
160
|
+
classNameBtnCartClear?: string;
|
|
161
|
+
classNameBtnClose?: string;
|
|
162
|
+
classNameBtnDanger?: string;
|
|
163
|
+
classNameBtnDefault?: string;
|
|
164
|
+
classNameBtnDownloadInvoice?: string;
|
|
165
|
+
classNameBtnPrimary?: string;
|
|
166
|
+
classNameBtnNext?: string;
|
|
167
|
+
classNameBtnNextComplete?: string;
|
|
168
|
+
classNameBtnLink?: string;
|
|
169
|
+
classNameBtnPay?: string;
|
|
170
|
+
classNameCartBody?: string;
|
|
171
|
+
classNameCartFooter?: string;
|
|
172
|
+
classNameCartFormCheckbox?: string;
|
|
173
|
+
classNameCartFormGroup?: string;
|
|
174
|
+
classNameCartFormGroupCheckbox?: string;
|
|
175
|
+
classNameCartFormInput?: string;
|
|
176
|
+
classNameCartFormLabelCheckbox?: string;
|
|
177
|
+
classNameCartInputError?: string;
|
|
178
|
+
classNameCartRow?: string;
|
|
179
|
+
classNameCartRowColumn?: string;
|
|
180
|
+
classNameCartTabItem?: string;
|
|
181
|
+
classNameCartTabItemLink?: string;
|
|
182
|
+
classNameCartGoogleSuggestList?: string;
|
|
183
|
+
classNameCartGoogleSuggestListItem?: string;
|
|
184
|
+
classNameCartHeader?: string;
|
|
185
|
+
classNameCartItemFeatureImage?: string;
|
|
186
|
+
classNameCartItemInfo?: string;
|
|
187
|
+
classNameCartItemInfoCell?: string;
|
|
188
|
+
classNameCartItemInfoCellRight?: string;
|
|
189
|
+
classNameCartNav?: string;
|
|
190
|
+
classNameCartTab?: string;
|
|
191
|
+
classNameCartTabPanel?: string;
|
|
192
|
+
classNameCartTitle?: string;
|
|
193
|
+
classNameCartTotalContainer?: string;
|
|
194
|
+
classNameCartTotalItem?: string;
|
|
195
|
+
classNameCartTotalItemPrice?: string;
|
|
196
|
+
classNameClearCartContainer?: string;
|
|
197
|
+
classNameClearCartText?: string;
|
|
198
|
+
classNameListClientInfo?: string;
|
|
199
|
+
classNameCartItemInfoContainer?: string;
|
|
200
|
+
classNameList?: string;
|
|
201
|
+
classNameListInline?: string;
|
|
202
|
+
classNameListContainer?: string;
|
|
203
|
+
classNameListItem?: string;
|
|
204
|
+
classNameListUnstyled?: string;
|
|
205
|
+
classNameLoadingTemplate?: string;
|
|
206
|
+
classNameLoadingTemplateContainer?: string;
|
|
207
|
+
classNameNoItems?: string;
|
|
208
|
+
classNameShipmentOption?: string;
|
|
209
|
+
classNameTable?: string;
|
|
210
|
+
classNameTableContainer?: string;
|
|
211
|
+
classNameVariationsList?: string;
|
|
212
|
+
customSuccessMessage?: string;
|
|
213
|
+
domainId?: number;
|
|
214
|
+
googlePlacesLoaded?: boolean;
|
|
215
|
+
includeTheme?: boolean;
|
|
216
|
+
initialiseCart?: boolean;
|
|
217
|
+
onClickClose?: () => void;
|
|
218
|
+
productFormClassNames?: any;
|
|
219
|
+
showUserTermsAndConditions?: boolean;
|
|
220
|
+
urlApi?: string;
|
|
221
|
+
urlFrontend?: string;
|
|
222
|
+
urlTrackingPage?: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const CartProvider = ({
|
|
226
|
+
children,
|
|
227
|
+
classNameAlertError = 'alert alert-danger',
|
|
228
|
+
classNameAlertInfo = 'alert alert-info',
|
|
229
|
+
classNameAlertSuccess = 'alert alert-success',
|
|
230
|
+
classNameAlertWarning = 'alert alert-warning',
|
|
231
|
+
classNameBtn = 'btn',
|
|
232
|
+
classNameBtnBack = 'btn-lg btn-default pull-left',
|
|
233
|
+
classNameBtnCartClear = 'btn-lg btn-danger mr-auto',
|
|
234
|
+
classNameBtnClose = 'btn-close',
|
|
235
|
+
classNameBtnDanger = 'btn btn-md btn-danger',
|
|
236
|
+
classNameBtnDefault = 'btn btn-md btn-default',
|
|
237
|
+
classNameBtnDownloadInvoice = 'btn btn-lg btn-primary',
|
|
238
|
+
classNameBtnPrimary = 'btn btn-md btn-primary',
|
|
239
|
+
classNameBtnLink = 'btn-md btn-link',
|
|
240
|
+
classNameBtnNext = 'btn-lg btn-primary',
|
|
241
|
+
classNameBtnNextComplete = 'btn-lg btn-success',
|
|
242
|
+
classNameBtnPay = 'btn-lg btn-primary width-full',
|
|
243
|
+
classNameCartBody = 'merchi-cart-body',
|
|
244
|
+
classNameCartFooter = 'merchi-cart-footer', // add to sass
|
|
245
|
+
classNameCartFormCheckbox = 'form-check-input',
|
|
246
|
+
classNameCartFormGroup = 'form-group',
|
|
247
|
+
classNameCartFormGroupCheckbox = 'form-check',
|
|
248
|
+
classNameCartFormInput = 'form-control',
|
|
249
|
+
classNameCartFormLabelCheckbox = '',
|
|
250
|
+
classNameCartInputError = 'text-danger',
|
|
251
|
+
classNameCartNav = 'nav merchi-nav-tabs merchi-nav merchi-nav-fill merchi-nav-pills',
|
|
252
|
+
classNameCartRow = 'merchi-row',
|
|
253
|
+
classNameCartRowColumn = 'merchi-column',
|
|
254
|
+
classNameCartTabItem = 'nav-item merchi-nav-item',
|
|
255
|
+
classNameCartTabItemLink = 'merchi-nav-link',
|
|
256
|
+
classNameCartGoogleSuggestList = 'list-group m-b-0',
|
|
257
|
+
classNameCartGoogleSuggestListItem = 'list-group-item cursor-pointer',
|
|
258
|
+
classNameCartHeader = 'merchi-cart-header', // add to sass
|
|
259
|
+
classNameCartItemFeatureImage = 'img-rounded m-10',
|
|
260
|
+
classNameCartItemInfo = 'text-muted font-weight-normal font-italic',
|
|
261
|
+
classNameCartItemInfoCell = 'border-0 align-middle',
|
|
262
|
+
classNameCartItemInfoCellRight = 'border-0 align-middle text-right',
|
|
263
|
+
classNameCartItemInfoContainer = 'ml-3 d-inline-block align-middle',
|
|
264
|
+
classNameCartTab = 'merchi-tab-content',
|
|
265
|
+
classNameCartTabPanel = 'merchi-tab-panel',
|
|
266
|
+
classNameCartTitle = 'merchi-cart-title', // add to sass // paddingBottom: '0.5rem', paddingTop: '0.5rem', textAlign: 'center',
|
|
267
|
+
classNameCartTotalContainer = 'merchi-cart-total-container', // add to sass
|
|
268
|
+
classNameCartTotalItem = 'merchi-cart-total-item', // add to sass; original text-right cart-cell-width-subtotal
|
|
269
|
+
classNameCartTotalItemPrice = 'merchi-cart-total-item-price', // add to sass: original text-right
|
|
270
|
+
classNameClearCartContainer = 'merchi-cart-clear-container',
|
|
271
|
+
classNameClearCartText = 'merchi-cart-clear-text',
|
|
272
|
+
classNameListClientInfo = 'merchi-cart-client-info-list', // add to sass: original className='list-unstyled text-center' fontSize: '15px', listStyle: 'none', paddingBottom: '0px', paddingLeft: '0px'
|
|
273
|
+
classNameList = 'list-group',
|
|
274
|
+
classNameListInline = 'list-inline',
|
|
275
|
+
classNameListUnstyled = 'list-unstyled',
|
|
276
|
+
classNameListContainer = 'pb-2',
|
|
277
|
+
classNameListItem = 'list-group-item',
|
|
278
|
+
classNameLoadingTemplate = 'merchi-loading-template',
|
|
279
|
+
classNameLoadingTemplateContainer = 'merchi-loading-template-container',
|
|
280
|
+
classNameNoItems = 'merchi-no-cart-items',
|
|
281
|
+
classNameShipmentOption = 'merchi-shipment-option',
|
|
282
|
+
classNameTable = 'table table-bordered',
|
|
283
|
+
classNameTableContainer = 'table-responsive',
|
|
284
|
+
classNameVariationsList = 'list-unstyled list-inline',
|
|
285
|
+
customSuccessMessage,
|
|
286
|
+
domainId,
|
|
287
|
+
includeTheme = false,
|
|
288
|
+
initialiseCart = true,
|
|
289
|
+
onClickClose = () => console.log('close merchi cart!'),
|
|
290
|
+
productFormClassNames = {},
|
|
291
|
+
showUserTermsAndConditions = true,
|
|
292
|
+
urlApi = 'https://api.merchi.co/v6/',
|
|
293
|
+
urlFrontend = 'https://merchi.co/',
|
|
294
|
+
urlTrackingPage,
|
|
295
|
+
}: PropsCartProvider) => {
|
|
296
|
+
const [googlePlacesLoaded, setGoogleMapsLoaded] = useState(false);
|
|
297
|
+
// Persistent callback setup
|
|
298
|
+
if (typeof window !== 'undefined') {
|
|
299
|
+
if (!(window as any).googleMapsScriptLoaded) {
|
|
300
|
+
(window as any).googleMapsScriptLoaded = () => {
|
|
301
|
+
setGoogleMapsLoaded(true);
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return (
|
|
306
|
+
<CartContext.Provider
|
|
307
|
+
value={
|
|
308
|
+
{
|
|
309
|
+
classNameAlertError,
|
|
310
|
+
classNameAlertInfo,
|
|
311
|
+
classNameAlertSuccess,
|
|
312
|
+
classNameAlertWarning,
|
|
313
|
+
classNameBtn,
|
|
314
|
+
classNameBtnBack,
|
|
315
|
+
classNameBtnCartClear,
|
|
316
|
+
classNameBtnClose,
|
|
317
|
+
classNameBtnDanger,
|
|
318
|
+
classNameBtnDefault,
|
|
319
|
+
classNameBtnDownloadInvoice,
|
|
320
|
+
classNameBtnPrimary,
|
|
321
|
+
classNameBtnLink,
|
|
322
|
+
classNameBtnNext,
|
|
323
|
+
classNameBtnNextComplete,
|
|
324
|
+
classNameBtnPay,
|
|
325
|
+
classNameCartBody,
|
|
326
|
+
classNameCartFooter,
|
|
327
|
+
classNameCartFormCheckbox,
|
|
328
|
+
classNameCartFormGroup,
|
|
329
|
+
classNameCartFormGroupCheckbox,
|
|
330
|
+
classNameCartFormInput,
|
|
331
|
+
classNameCartFormLabelCheckbox,
|
|
332
|
+
classNameCartInputError,
|
|
333
|
+
classNameCartNav,
|
|
334
|
+
classNameCartRow,
|
|
335
|
+
classNameCartRowColumn,
|
|
336
|
+
classNameCartTabItem,
|
|
337
|
+
classNameCartTabItemLink,
|
|
338
|
+
classNameCartGoogleSuggestList,
|
|
339
|
+
classNameCartGoogleSuggestListItem,
|
|
340
|
+
classNameCartHeader,
|
|
341
|
+
classNameCartItemFeatureImage,
|
|
342
|
+
classNameCartItemInfo,
|
|
343
|
+
classNameCartItemInfoCell,
|
|
344
|
+
classNameCartItemInfoCellRight,
|
|
345
|
+
classNameCartItemInfoContainer,
|
|
346
|
+
classNameCartTab,
|
|
347
|
+
classNameCartTabPanel,
|
|
348
|
+
classNameCartTitle,
|
|
349
|
+
classNameCartTotalContainer,
|
|
350
|
+
classNameCartTotalItem,
|
|
351
|
+
classNameCartTotalItemPrice,
|
|
352
|
+
classNameClearCartContainer,
|
|
353
|
+
classNameClearCartText,
|
|
354
|
+
classNameListClientInfo,
|
|
355
|
+
classNameList,
|
|
356
|
+
classNameListInline,
|
|
357
|
+
classNameListContainer,
|
|
358
|
+
classNameListItem,
|
|
359
|
+
classNameListUnstyled,
|
|
360
|
+
classNameLoadingTemplate,
|
|
361
|
+
classNameLoadingTemplateContainer,
|
|
362
|
+
classNameNoItems,
|
|
363
|
+
classNameShipmentOption,
|
|
364
|
+
classNameTable,
|
|
365
|
+
classNameTableContainer,
|
|
366
|
+
classNameVariationsList,
|
|
367
|
+
customSuccessMessage,
|
|
368
|
+
domainId,
|
|
369
|
+
googlePlacesLoaded,
|
|
370
|
+
includeTheme,
|
|
371
|
+
initialiseCart,
|
|
372
|
+
onClickClose,
|
|
373
|
+
productFormClassNames,
|
|
374
|
+
showUserTermsAndConditions,
|
|
375
|
+
urlApi,
|
|
376
|
+
urlFrontend,
|
|
377
|
+
urlTrackingPage,
|
|
378
|
+
} as PropsCart
|
|
379
|
+
}
|
|
380
|
+
>
|
|
381
|
+
{children}
|
|
382
|
+
</CartContext.Provider>
|
|
383
|
+
);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
export default CartProvider;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useSelector } from 'react-redux';
|
|
2
|
+
import { formatCurrency } from './utilities/currency';
|
|
3
|
+
import { cartRequiresShipment } from './utilities/cart';
|
|
4
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
5
|
+
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons';
|
|
6
|
+
import { Table } from './components';
|
|
7
|
+
import { useCartContext } from './CartProvider';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
attribute: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function CartTotal({ attribute }: Props) {
|
|
14
|
+
const {
|
|
15
|
+
cart,
|
|
16
|
+
fetchingCart,
|
|
17
|
+
loading,
|
|
18
|
+
} = useSelector((s: any) => s.stateCart);
|
|
19
|
+
const {
|
|
20
|
+
fetchingShipmentGroups,
|
|
21
|
+
fetchingShipmentQuote,
|
|
22
|
+
} = useSelector((s: any) => s.stateCartShipment);
|
|
23
|
+
const { domain } = cart;
|
|
24
|
+
const company = domain ? domain.company : null;
|
|
25
|
+
const currency = company ? company.defaultCurrency : 'AUD';
|
|
26
|
+
const isLoading =
|
|
27
|
+
fetchingCart ||
|
|
28
|
+
fetchingShipmentGroups ||
|
|
29
|
+
fetchingShipmentQuote ||
|
|
30
|
+
loading;
|
|
31
|
+
const money = cart[attribute] ? cart[attribute] : 0;
|
|
32
|
+
return (
|
|
33
|
+
<div style={{paddingRight: 8}}>
|
|
34
|
+
{isLoading ?
|
|
35
|
+
<FontAwesomeIcon
|
|
36
|
+
icon={faCircleNotch}
|
|
37
|
+
spin={true}
|
|
38
|
+
/>
|
|
39
|
+
:
|
|
40
|
+
`${currency} ${formatCurrency(money, { currency })}`
|
|
41
|
+
}
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface RowProps {
|
|
47
|
+
attr: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function CostsTableRow({ attr, name }: RowProps) {
|
|
52
|
+
const {
|
|
53
|
+
classNameCartTotalItem,
|
|
54
|
+
classNameCartTotalItemPrice,
|
|
55
|
+
} = useCartContext();
|
|
56
|
+
return (
|
|
57
|
+
<tr>
|
|
58
|
+
<td className={classNameCartTotalItem}>
|
|
59
|
+
{name}
|
|
60
|
+
</td>
|
|
61
|
+
<th className={classNameCartTotalItemPrice}>
|
|
62
|
+
<CartTotal attribute={attr} />
|
|
63
|
+
</th>
|
|
64
|
+
</tr>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function CartTotals() {
|
|
69
|
+
const {
|
|
70
|
+
classNameCartTotalContainer,
|
|
71
|
+
classNameCartTotalItemPrice
|
|
72
|
+
} = useCartContext();
|
|
73
|
+
const { cart } = useSelector((s: any) => s.stateCart);
|
|
74
|
+
const cartItems = cart.cartItems ? cart.cartItems : [];
|
|
75
|
+
return (
|
|
76
|
+
<div className={classNameCartTotalContainer}>
|
|
77
|
+
<Table>
|
|
78
|
+
<tbody>
|
|
79
|
+
<CostsTableRow
|
|
80
|
+
attr='cartItemsTotalCost'
|
|
81
|
+
name='Subtotal'
|
|
82
|
+
/>
|
|
83
|
+
{
|
|
84
|
+
cartRequiresShipment({ ...cart, cartItems }) &&
|
|
85
|
+
<CostsTableRow
|
|
86
|
+
attr='shipmentTotalCost'
|
|
87
|
+
name='Shipping'
|
|
88
|
+
/>
|
|
89
|
+
}
|
|
90
|
+
<CostsTableRow
|
|
91
|
+
attr='totalCost'
|
|
92
|
+
name='Total'
|
|
93
|
+
/>
|
|
94
|
+
<tr>
|
|
95
|
+
<td />
|
|
96
|
+
<td className={classNameCartTotalItemPrice}>
|
|
97
|
+
Total price includes taxes
|
|
98
|
+
</td>
|
|
99
|
+
</tr>
|
|
100
|
+
</tbody>
|
|
101
|
+
</Table>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default CartTotals;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|