@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.
Files changed (372) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +134 -0
  3. package/esm/Cart.js +62 -0
  4. package/esm/CartAlert.js +47 -0
  5. package/esm/CartHeader.js +29 -0
  6. package/esm/CartProvider.js +1101 -0
  7. package/esm/CartTotals.js +89 -0
  8. package/esm/assets/merchi-monster-loader.gif +0 -0
  9. package/esm/assets/merchi-swipe-outline.png +0 -0
  10. package/esm/assets/product-not-found.png +0 -0
  11. package/esm/assets/stripe-payment-secure.png +0 -0
  12. package/esm/buttons/Button.js +23 -0
  13. package/esm/buttons/ButtonBack.js +35 -0
  14. package/esm/buttons/ButtonClearCart.js +17 -0
  15. package/esm/buttons/ButtonInvoiceDownload.js +88 -0
  16. package/esm/buttons/ButtonNext.js +39 -0
  17. package/esm/buttons/ButtonNextDynamic.js +19 -0
  18. package/esm/buttons/ButtonOpenCartMerchiCartModal.js +47 -0
  19. package/esm/buttons/ButtonPay.js +26 -0
  20. package/esm/buttons/ButtonShipmentTabNext.js +28 -0
  21. package/esm/buttons/index.js +7 -0
  22. package/esm/components/Alert.js +26 -0
  23. package/esm/components/CartBody.js +14 -0
  24. package/esm/components/CartClient.js +62 -0
  25. package/esm/components/CartFooter.js +12 -0
  26. package/esm/components/CartItemRow.js +230 -0
  27. package/esm/components/CartPaymentSettingsInvalid.js +13 -0
  28. package/esm/components/CartShipment.js +52 -0
  29. package/esm/components/CartTabContent.js +12 -0
  30. package/esm/components/CartTabPanel.js +25 -0
  31. package/esm/components/CartTableContainer.js +12 -0
  32. package/esm/components/CartTitle.js +26 -0
  33. package/esm/components/CartTotalsListGroup.js +71 -0
  34. package/esm/components/Collapse.js +32 -0
  35. package/esm/components/CustomCartProductForm.js +128 -0
  36. package/esm/components/CustomerCheckoutMethodTabs.js +94 -0
  37. package/esm/components/DiscountInputGroup.js +293 -0
  38. package/esm/components/LoadingTemplate.js +23 -0
  39. package/esm/components/NoCartItems.js +20 -0
  40. package/esm/components/ShipmentGroupCard.js +207 -0
  41. package/esm/components/Table.js +13 -0
  42. package/esm/components/containers.js +31 -0
  43. package/esm/components/index.js +18 -0
  44. package/esm/components/product-form-sdk-externals.js +36 -0
  45. package/esm/forms/FormNewCustomer.js +243 -0
  46. package/esm/forms/FormReturningCustomer.js +165 -0
  47. package/esm/forms/FormShipmentAddressAndNotes.js +195 -0
  48. package/esm/forms/FormSquarePayment.js +19 -0
  49. package/esm/forms/FormStripePayment.js +19 -0
  50. package/esm/forms/FormWhatsappCustomer.js +253 -0
  51. package/esm/forms/InputAcceptUserTermsAndConditions.js +35 -0
  52. package/esm/forms/InputError.js +16 -0
  53. package/esm/forms/InputSelect.js +48 -0
  54. package/esm/forms/InputText.js +56 -0
  55. package/esm/forms/InputsAddress.js +476 -0
  56. package/esm/forms/index.js +8 -0
  57. package/esm/index.js +13 -0
  58. package/esm/modals.js +51 -0
  59. package/esm/panels/PanelCartItems.js +49 -0
  60. package/esm/panels/PanelCartShipment.js +66 -0
  61. package/esm/panels/PanelClearCart.js +56 -0
  62. package/esm/panels/PanelClientCheckout.js +81 -0
  63. package/esm/panels/PanelEditCartItem.js +199 -0
  64. package/esm/panels/PanelPaymentSuccess.js +63 -0
  65. package/esm/panels/index.js +7 -0
  66. package/esm/square/SquareCard.js +106 -0
  67. package/esm/stripe/LegacyStripeCardForm.js +157 -0
  68. package/esm/stripe/StripeCardFields.js +126 -0
  69. package/esm/stripe/StripeCardForm.js +33 -0
  70. package/esm/stripe/StripePaymentButtons.js +98 -0
  71. package/esm/stripe/actions.js +192 -0
  72. package/esm/stripe/utils.js +20 -0
  73. package/esm/styles/globals.css +463 -0
  74. package/esm/styles/globals.css.map +1 -0
  75. package/esm/tabs/CartNav.js +28 -0
  76. package/esm/tabs/NavTab.js +31 -0
  77. package/esm/types/assets.d.js +0 -0
  78. package/esm/types/index.js +1 -0
  79. package/esm/types/merchi_product_form/index.d.js +0 -0
  80. package/esm/types/merchi_sdk_ts/index.d.js +0 -0
  81. package/esm/types/react-redux/index.d.js +0 -0
  82. package/esm/utilities/address.js +457 -0
  83. package/esm/utilities/area.js +297 -0
  84. package/esm/utilities/cart.js +95 -0
  85. package/esm/utilities/company.js +6 -0
  86. package/esm/utilities/cookie.js +156 -0
  87. package/esm/utilities/currency.js +219 -0
  88. package/esm/utilities/customForm.js +57 -0
  89. package/esm/utilities/helpers.js +229 -0
  90. package/esm/utilities/index.js +14 -0
  91. package/esm/utilities/invoice.js +112 -0
  92. package/esm/utilities/job.js +9 -0
  93. package/esm/utilities/local_storage.js +85 -0
  94. package/esm/utilities/product.js +13 -0
  95. package/esm/utilities/shipment.js +11 -0
  96. package/esm/utilities/tabs.js +51 -0
  97. package/esm/utilities/user.js +65 -0
  98. package/esm/utilities/variations.js +58 -0
  99. package/lib/Cart.d.ts +9 -0
  100. package/lib/Cart.js +69 -0
  101. package/lib/CartAlert.d.ts +3 -0
  102. package/lib/CartAlert.js +53 -0
  103. package/lib/CartHeader.d.ts +3 -0
  104. package/lib/CartHeader.js +37 -0
  105. package/lib/CartProvider.d.ts +236 -0
  106. package/lib/CartProvider.js +1107 -0
  107. package/lib/CartTotals.d.ts +7 -0
  108. package/lib/CartTotals.js +96 -0
  109. package/lib/assets/merchi-monster-loader.gif +0 -0
  110. package/lib/assets/merchi-swipe-outline.png +0 -0
  111. package/lib/assets/product-not-found.png +0 -0
  112. package/lib/assets/stripe-payment-secure.png +0 -0
  113. package/lib/buttons/Button.d.ts +11 -0
  114. package/lib/buttons/Button.js +31 -0
  115. package/lib/buttons/ButtonBack.d.ts +6 -0
  116. package/lib/buttons/ButtonBack.js +44 -0
  117. package/lib/buttons/ButtonClearCart.d.ts +3 -0
  118. package/lib/buttons/ButtonClearCart.js +24 -0
  119. package/lib/buttons/ButtonInvoiceDownload.d.ts +3 -0
  120. package/lib/buttons/ButtonInvoiceDownload.js +96 -0
  121. package/lib/buttons/ButtonNext.d.ts +3 -0
  122. package/lib/buttons/ButtonNext.js +48 -0
  123. package/lib/buttons/ButtonNextDynamic.d.ts +3 -0
  124. package/lib/buttons/ButtonNextDynamic.js +28 -0
  125. package/lib/buttons/ButtonOpenCartMerchiCartModal.d.ts +9 -0
  126. package/lib/buttons/ButtonOpenCartMerchiCartModal.js +57 -0
  127. package/lib/buttons/ButtonPay.d.ts +7 -0
  128. package/lib/buttons/ButtonPay.js +35 -0
  129. package/lib/buttons/ButtonShipmentTabNext.d.ts +2 -0
  130. package/lib/buttons/ButtonShipmentTabNext.js +37 -0
  131. package/lib/buttons/index.d.ts +7 -0
  132. package/lib/buttons/index.js +48 -0
  133. package/lib/components/Alert.d.ts +7 -0
  134. package/lib/components/Alert.js +34 -0
  135. package/lib/components/CartBody.d.ts +7 -0
  136. package/lib/components/CartBody.js +22 -0
  137. package/lib/components/CartClient.d.ts +4 -0
  138. package/lib/components/CartClient.js +71 -0
  139. package/lib/components/CartFooter.d.ts +6 -0
  140. package/lib/components/CartFooter.js +20 -0
  141. package/lib/components/CartItemRow.d.ts +7 -0
  142. package/lib/components/CartItemRow.js +236 -0
  143. package/lib/components/CartPaymentSettingsInvalid.d.ts +2 -0
  144. package/lib/components/CartPaymentSettingsInvalid.js +21 -0
  145. package/lib/components/CartShipment.d.ts +6 -0
  146. package/lib/components/CartShipment.js +59 -0
  147. package/lib/components/CartTabContent.d.ts +6 -0
  148. package/lib/components/CartTabContent.js +20 -0
  149. package/lib/components/CartTabPanel.d.ts +7 -0
  150. package/lib/components/CartTabPanel.js +31 -0
  151. package/lib/components/CartTableContainer.d.ts +6 -0
  152. package/lib/components/CartTableContainer.js +20 -0
  153. package/lib/components/CartTitle.d.ts +2 -0
  154. package/lib/components/CartTitle.js +34 -0
  155. package/lib/components/CartTotalsListGroup.d.ts +3 -0
  156. package/lib/components/CartTotalsListGroup.js +78 -0
  157. package/lib/components/Collapse.d.ts +3 -0
  158. package/lib/components/Collapse.js +40 -0
  159. package/lib/components/CustomCartProductForm.d.ts +18 -0
  160. package/lib/components/CustomCartProductForm.js +136 -0
  161. package/lib/components/CustomerCheckoutMethodTabs.d.ts +6 -0
  162. package/lib/components/CustomerCheckoutMethodTabs.js +103 -0
  163. package/lib/components/DiscountInputGroup.d.ts +2 -0
  164. package/lib/components/DiscountInputGroup.js +301 -0
  165. package/lib/components/LoadingTemplate.d.ts +7 -0
  166. package/lib/components/LoadingTemplate.js +30 -0
  167. package/lib/components/NoCartItems.d.ts +3 -0
  168. package/lib/components/NoCartItems.js +27 -0
  169. package/lib/components/ShipmentGroupCard.d.ts +7 -0
  170. package/lib/components/ShipmentGroupCard.js +215 -0
  171. package/lib/components/Table.d.ts +7 -0
  172. package/lib/components/Table.js +19 -0
  173. package/lib/components/containers.d.ts +14 -0
  174. package/lib/components/containers.js +40 -0
  175. package/lib/components/index.d.ts +18 -0
  176. package/lib/components/index.js +133 -0
  177. package/lib/components/product-form-sdk-externals.d.ts +46 -0
  178. package/lib/components/product-form-sdk-externals.js +43 -0
  179. package/lib/forms/FormNewCustomer.d.ts +4 -0
  180. package/lib/forms/FormNewCustomer.js +252 -0
  181. package/lib/forms/FormReturningCustomer.d.ts +3 -0
  182. package/lib/forms/FormReturningCustomer.js +173 -0
  183. package/lib/forms/FormShipmentAddressAndNotes.d.ts +15 -0
  184. package/lib/forms/FormShipmentAddressAndNotes.js +203 -0
  185. package/lib/forms/FormSquarePayment.d.ts +3 -0
  186. package/lib/forms/FormSquarePayment.js +27 -0
  187. package/lib/forms/FormStripePayment.d.ts +3 -0
  188. package/lib/forms/FormStripePayment.js +27 -0
  189. package/lib/forms/FormWhatsappCustomer.d.ts +3 -0
  190. package/lib/forms/FormWhatsappCustomer.js +261 -0
  191. package/lib/forms/InputAcceptUserTermsAndConditions.d.ts +7 -0
  192. package/lib/forms/InputAcceptUserTermsAndConditions.js +41 -0
  193. package/lib/forms/InputError.d.ts +8 -0
  194. package/lib/forms/InputError.js +24 -0
  195. package/lib/forms/InputSelect.d.ts +14 -0
  196. package/lib/forms/InputSelect.js +55 -0
  197. package/lib/forms/InputText.d.ts +12 -0
  198. package/lib/forms/InputText.js +63 -0
  199. package/lib/forms/InputsAddress.d.ts +11 -0
  200. package/lib/forms/InputsAddress.js +485 -0
  201. package/lib/forms/index.d.ts +8 -0
  202. package/lib/forms/index.js +63 -0
  203. package/lib/index.d.ts +13 -0
  204. package/lib/index.js +93 -0
  205. package/lib/modals.d.ts +17 -0
  206. package/lib/modals.js +59 -0
  207. package/lib/panels/PanelCartItems.d.ts +3 -0
  208. package/lib/panels/PanelCartItems.js +56 -0
  209. package/lib/panels/PanelCartShipment.d.ts +3 -0
  210. package/lib/panels/PanelCartShipment.js +72 -0
  211. package/lib/panels/PanelClearCart.d.ts +3 -0
  212. package/lib/panels/PanelClearCart.js +62 -0
  213. package/lib/panels/PanelClientCheckout.d.ts +3 -0
  214. package/lib/panels/PanelClientCheckout.js +88 -0
  215. package/lib/panels/PanelEditCartItem.d.ts +6 -0
  216. package/lib/panels/PanelEditCartItem.js +206 -0
  217. package/lib/panels/PanelPaymentSuccess.d.ts +3 -0
  218. package/lib/panels/PanelPaymentSuccess.js +69 -0
  219. package/lib/panels/index.d.ts +7 -0
  220. package/lib/panels/index.js +48 -0
  221. package/lib/square/SquareCard.d.ts +3 -0
  222. package/lib/square/SquareCard.js +114 -0
  223. package/lib/stripe/LegacyStripeCardForm.d.ts +3 -0
  224. package/lib/stripe/LegacyStripeCardForm.js +166 -0
  225. package/lib/stripe/StripeCardFields.d.ts +15 -0
  226. package/lib/stripe/StripeCardFields.js +135 -0
  227. package/lib/stripe/StripeCardForm.d.ts +2 -0
  228. package/lib/stripe/StripeCardForm.js +42 -0
  229. package/lib/stripe/StripePaymentButtons.d.ts +8 -0
  230. package/lib/stripe/StripePaymentButtons.js +106 -0
  231. package/lib/stripe/actions.d.ts +4 -0
  232. package/lib/stripe/actions.js +200 -0
  233. package/lib/stripe/utils.d.ts +18 -0
  234. package/lib/stripe/utils.js +27 -0
  235. package/lib/styles/globals.css +463 -0
  236. package/lib/styles/globals.css.map +1 -0
  237. package/lib/tabs/CartNav.d.ts +3 -0
  238. package/lib/tabs/CartNav.js +36 -0
  239. package/lib/tabs/NavTab.d.ts +9 -0
  240. package/lib/tabs/NavTab.js +39 -0
  241. package/lib/types/index.d.ts +13 -0
  242. package/lib/types/index.js +1 -0
  243. package/lib/utilities/address.d.ts +30 -0
  244. package/lib/utilities/address.js +468 -0
  245. package/lib/utilities/area.d.ts +77 -0
  246. package/lib/utilities/area.js +328 -0
  247. package/lib/utilities/cart.d.ts +9 -0
  248. package/lib/utilities/cart.js +108 -0
  249. package/lib/utilities/company.d.ts +2 -0
  250. package/lib/utilities/company.js +13 -0
  251. package/lib/utilities/cookie.d.ts +4 -0
  252. package/lib/utilities/cookie.js +165 -0
  253. package/lib/utilities/currency.d.ts +5 -0
  254. package/lib/utilities/currency.js +229 -0
  255. package/lib/utilities/customForm.d.ts +17 -0
  256. package/lib/utilities/customForm.js +64 -0
  257. package/lib/utilities/helpers.d.ts +24 -0
  258. package/lib/utilities/helpers.js +240 -0
  259. package/lib/utilities/index.d.ts +14 -0
  260. package/lib/utilities/index.js +159 -0
  261. package/lib/utilities/invoice.d.ts +3 -0
  262. package/lib/utilities/invoice.js +118 -0
  263. package/lib/utilities/job.d.ts +1 -0
  264. package/lib/utilities/job.js +15 -0
  265. package/lib/utilities/local_storage.d.ts +31 -0
  266. package/lib/utilities/local_storage.js +96 -0
  267. package/lib/utilities/product.d.ts +2 -0
  268. package/lib/utilities/product.js +21 -0
  269. package/lib/utilities/shipment.d.ts +2 -0
  270. package/lib/utilities/shipment.js +18 -0
  271. package/lib/utilities/tabs.d.ts +14 -0
  272. package/lib/utilities/tabs.js +60 -0
  273. package/lib/utilities/user.d.ts +5 -0
  274. package/lib/utilities/user.js +75 -0
  275. package/lib/utilities/variations.d.ts +18 -0
  276. package/lib/utilities/variations.js +66 -0
  277. package/package.json +109 -0
  278. package/src/Cart.tsx +96 -0
  279. package/src/CartAlert.tsx +35 -0
  280. package/src/CartHeader.tsx +28 -0
  281. package/src/CartProvider.tsx +992 -0
  282. package/src/CartTotals.tsx +102 -0
  283. package/src/assets/merchi-monster-loader.gif +0 -0
  284. package/src/assets/merchi-swipe-outline.png +0 -0
  285. package/src/assets/product-not-found.png +0 -0
  286. package/src/assets/stripe-payment-secure.png +0 -0
  287. package/src/buttons/Button.tsx +35 -0
  288. package/src/buttons/ButtonBack.tsx +42 -0
  289. package/src/buttons/ButtonClearCart.tsx +17 -0
  290. package/src/buttons/ButtonInvoiceDownload.tsx +60 -0
  291. package/src/buttons/ButtonNext.tsx +35 -0
  292. package/src/buttons/ButtonNextDynamic.tsx +31 -0
  293. package/src/buttons/ButtonOpenCartMerchiCartModal.tsx +61 -0
  294. package/src/buttons/ButtonPay.tsx +32 -0
  295. package/src/buttons/ButtonShipmentTabNext.tsx +24 -0
  296. package/src/buttons/index.ts +15 -0
  297. package/src/components/Alert.tsx +31 -0
  298. package/src/components/CartBody.tsx +16 -0
  299. package/src/components/CartClient.tsx +52 -0
  300. package/src/components/CartFooter.tsx +15 -0
  301. package/src/components/CartItemRow.tsx +212 -0
  302. package/src/components/CartPaymentSettingsInvalid.tsx +12 -0
  303. package/src/components/CartShipment.tsx +56 -0
  304. package/src/components/CartTabContent.tsx +15 -0
  305. package/src/components/CartTabPanel.tsx +25 -0
  306. package/src/components/CartTableContainer.tsx +15 -0
  307. package/src/components/CartTitle.tsx +22 -0
  308. package/src/components/CartTotalsListGroup.tsx +58 -0
  309. package/src/components/Collapse.tsx +23 -0
  310. package/src/components/CustomCartProductForm.tsx +123 -0
  311. package/src/components/CustomerCheckoutMethodTabs.tsx +106 -0
  312. package/src/components/DiscountInputGroup.tsx +160 -0
  313. package/src/components/LoadingTemplate.tsx +22 -0
  314. package/src/components/NoCartItems.tsx +20 -0
  315. package/src/components/ShipmentGroupCard.tsx +170 -0
  316. package/src/components/Table.tsx +15 -0
  317. package/src/components/containers.tsx +40 -0
  318. package/src/components/index.ts +38 -0
  319. package/src/components/product-form-sdk-externals.ts +67 -0
  320. package/src/forms/FormNewCustomer.tsx +170 -0
  321. package/src/forms/FormReturningCustomer.tsx +117 -0
  322. package/src/forms/FormShipmentAddressAndNotes.tsx +165 -0
  323. package/src/forms/FormSquarePayment.tsx +19 -0
  324. package/src/forms/FormStripePayment.tsx +19 -0
  325. package/src/forms/FormWhatsappCustomer.tsx +179 -0
  326. package/src/forms/InputAcceptUserTermsAndConditions.tsx +43 -0
  327. package/src/forms/InputError.tsx +23 -0
  328. package/src/forms/InputSelect.tsx +58 -0
  329. package/src/forms/InputText.tsx +56 -0
  330. package/src/forms/InputsAddress.tsx +438 -0
  331. package/src/forms/index.ts +18 -0
  332. package/src/index.ts +31 -0
  333. package/src/modals.tsx +65 -0
  334. package/src/panels/PanelCartItems.tsx +56 -0
  335. package/src/panels/PanelCartShipment.tsx +86 -0
  336. package/src/panels/PanelClearCart.tsx +50 -0
  337. package/src/panels/PanelClientCheckout.tsx +102 -0
  338. package/src/panels/PanelEditCartItem.tsx +172 -0
  339. package/src/panels/PanelPaymentSuccess.tsx +66 -0
  340. package/src/panels/index.ts +15 -0
  341. package/src/square/SquareCard.tsx +84 -0
  342. package/src/stripe/LegacyStripeCardForm.tsx +91 -0
  343. package/src/stripe/StripeCardFields.tsx +173 -0
  344. package/src/stripe/StripeCardForm.tsx +18 -0
  345. package/src/stripe/StripePaymentButtons.tsx +117 -0
  346. package/src/stripe/actions.ts +94 -0
  347. package/src/stripe/utils.ts +22 -0
  348. package/src/styles/globals.scss +475 -0
  349. package/src/tabs/CartNav.tsx +18 -0
  350. package/src/tabs/NavTab.tsx +36 -0
  351. package/src/types/assets.d.ts +4 -0
  352. package/src/types/index.ts +15 -0
  353. package/src/types/merchi_product_form/index.d.ts +1 -0
  354. package/src/types/merchi_sdk_ts/index.d.ts +1 -0
  355. package/src/types/react-redux/index.d.ts +0 -0
  356. package/src/utilities/address.ts +463 -0
  357. package/src/utilities/area.ts +359 -0
  358. package/src/utilities/cart.ts +80 -0
  359. package/src/utilities/company.ts +8 -0
  360. package/src/utilities/cookie.ts +58 -0
  361. package/src/utilities/currency.ts +216 -0
  362. package/src/utilities/customForm.ts +71 -0
  363. package/src/utilities/helpers.ts +213 -0
  364. package/src/utilities/index.ts +14 -0
  365. package/src/utilities/invoice.ts +60 -0
  366. package/src/utilities/job.ts +13 -0
  367. package/src/utilities/local_storage.ts +130 -0
  368. package/src/utilities/product.ts +14 -0
  369. package/src/utilities/shipment.ts +11 -0
  370. package/src/utilities/tabs.ts +38 -0
  371. package/src/utilities/user.ts +33 -0
  372. package/src/utilities/variations.ts +80 -0
@@ -0,0 +1,212 @@
1
+ import * as React from 'react';
2
+ import { cartItemCurrencyAndCost } from '../utilities/currency';
3
+ import { productFeatureImageUrl } from '../utilities/product';
4
+ import { valueString } from '../utilities/variations';
5
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
6
+ import { faCircleNotch, faEdit, faTrashAlt } from '@fortawesome/free-solid-svg-icons';
7
+ import { Button } from '../buttons';
8
+ import { useCartContext } from '../CartProvider';
9
+ import { makeCart } from '../utilities/cart';
10
+ import { cartEmbed } from '../utilities/helpers';
11
+ import { tabIdItem } from '../utilities/tabs';
12
+ import { cartItemsNeedShipment } from '../utilities/shipment';
13
+ import {
14
+ cartHasShippmentGroupsAndAllHaveSelectedGroups,
15
+ initTabs,
16
+ setDisableTab,
17
+ tabCheckout,
18
+ tabShipment,
19
+ tabsWithShipment,
20
+ } from '../utilities/tabs';
21
+ import { getCartCookieToken } from '../utilities/cookie';
22
+
23
+ interface VariationListItemProps {
24
+ variation: any;
25
+ }
26
+
27
+ function VariationListItem(props: VariationListItemProps) {
28
+ const { variation } = props;
29
+ const { variationField: field } = variation;
30
+ return (
31
+ <li>{`${field.name}: ${valueString(variation)}`}</li>
32
+ );
33
+ }
34
+
35
+ interface VariationListProps {
36
+ variations: any[];
37
+ }
38
+
39
+ function VariationList({ variations }: VariationListProps) {
40
+ const { classNameVariationsList } = useCartContext();
41
+ return (
42
+ <ul className={classNameVariationsList}>
43
+ {variations.map((v: any, index: number) =>
44
+ <VariationListItem
45
+ key={`${index}-variation`}
46
+ variation={v}
47
+ />
48
+ )}
49
+ </ul>
50
+ );
51
+ }
52
+
53
+ interface GroupVariationItemsProps {
54
+ count: number;
55
+ group: any;
56
+ }
57
+
58
+ function GroupVariationItems(props: GroupVariationItemsProps) {
59
+ const { count, group } = props;
60
+ return (
61
+ <li>
62
+ Group {count} Quantity: {group.quantity}
63
+ <VariationList variations={group.variations} />
64
+ </li>
65
+ );
66
+ }
67
+
68
+ interface VariationsGroupsListProps {
69
+ groups: any[];
70
+ }
71
+
72
+ function VariationsGroupsList({ groups }: VariationsGroupsListProps) {
73
+ const { classNameVariationsList } = useCartContext();
74
+ return (
75
+ <ul className={classNameVariationsList}>
76
+ {groups.map((group: any, index: number) =>
77
+ <GroupVariationItems
78
+ key={`${index}-group-variations`}
79
+ group={group}
80
+ count={index + 1}
81
+ />
82
+ )}
83
+ </ul>
84
+ );
85
+ }
86
+
87
+ interface Props {
88
+ cartItem: any;
89
+ index: number;
90
+ }
91
+
92
+ function CartItemRow({ cartItem, index }: Props) {
93
+ const {
94
+ alertError,
95
+ cart,
96
+
97
+ domainId,
98
+ setCart,
99
+
100
+ classNameBtnLink,
101
+ classNameCartItemFeatureImage,
102
+ classNameCartItemInfo,
103
+ classNameCartItemInfoCell,
104
+ classNameCartItemInfoCellRight,
105
+ classNameCartItemInfoContainer,
106
+
107
+ setActiveTabIndex,
108
+ setCartItem,
109
+ tabs,
110
+ setTabs,
111
+
112
+ showCartItemInfo,
113
+ } = useCartContext();
114
+ const {
115
+ product,
116
+ quantity,
117
+ variations,
118
+ variationsGroups,
119
+ } = cartItem;
120
+ const { name } = product;
121
+
122
+ const [loading, setLoading] = React.useState(false);
123
+
124
+ async function actionDeleteCartItem() {
125
+ setLoading(true);
126
+ const cartToken = await getCartCookieToken((domainId as number));
127
+ try {
128
+ const cartEnt = makeCart({...cart}, false, cartToken);
129
+ const cartItems = (cartEnt as any).cartItems;
130
+ cartItems.splice(index, 1);
131
+ (cartEnt as any).cartItems = cartItems;
132
+ const r = await cartEnt.save({embed: cartEmbed});
133
+ const cartJson = r.toJson();
134
+ const needsShipping = cartItemsNeedShipment(cartJson);
135
+ setCart({...cartJson});
136
+ if (cart.cartItems.length === 0) {
137
+ setTabs([...initTabs]);
138
+ } else {
139
+ if (needsShipping) {
140
+ setTabs([...tabsWithShipment]);
141
+ if (cart.cartItems.length) {
142
+ const _tabs = [...tabs];
143
+ _tabs[1] = setDisableTab(tabShipment, false);
144
+ if (cartHasShippmentGroupsAndAllHaveSelectedGroups(cartJson)) {
145
+ _tabs[2] = setDisableTab(tabCheckout, false);
146
+ }
147
+ setTabs([..._tabs]);
148
+ }
149
+ } else {
150
+ setTabs([...initTabs]);
151
+ }
152
+ }
153
+ } catch(e: any) {
154
+ alertError(e.errorMessage || e.message || 'Unable to remove item from cart.');
155
+ } finally {
156
+ setLoading(false);
157
+ }
158
+ }
159
+ return (
160
+ <tr>
161
+ <td scope='row' className={classNameCartItemInfoCell}>
162
+ <img
163
+ src={productFeatureImageUrl(product)}
164
+ alt={name}
165
+ width='70'
166
+ className={classNameCartItemFeatureImage}
167
+ />
168
+ {showCartItemInfo && (
169
+ <div className={classNameCartItemInfoContainer}>
170
+ <div className={classNameCartItemInfo}>
171
+ <h5 style={{display: 'inline'}}>
172
+ {name}
173
+ </h5>
174
+ {variations && <VariationList variations={variations} />}
175
+ </div>
176
+ <div className={classNameCartItemInfo}>
177
+ {variationsGroups && <VariationsGroupsList groups={variationsGroups} />}
178
+ </div>
179
+ </div>
180
+ )}
181
+ </td>
182
+ <td className={classNameCartItemInfoCellRight}>
183
+ <strong>{quantity}</strong>
184
+ </td>
185
+ <td className={classNameCartItemInfoCellRight}>
186
+ <strong>{cartItemCurrencyAndCost(cartItem)}</strong>
187
+ </td>
188
+ <td className={classNameCartItemInfoCellRight}>
189
+ <Button
190
+ className={classNameBtnLink}
191
+ onClick={() => {
192
+ setCartItem({...cartItem});
193
+ setActiveTabIndex(tabIdItem);
194
+ }}
195
+ >
196
+ <FontAwesomeIcon icon={faEdit} />
197
+ </Button>
198
+ <Button
199
+ className={classNameBtnLink}
200
+ onClick={actionDeleteCartItem} //TODO modify delete action
201
+ >
202
+ <FontAwesomeIcon
203
+ icon={loading ? faCircleNotch : faTrashAlt}
204
+ spin={loading}
205
+ />
206
+ </Button>
207
+ </td>
208
+ </tr>
209
+ );
210
+ }
211
+
212
+ export default CartItemRow;
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+
3
+ export default function CartPaymentSettingsInvalid() {
4
+ return (
5
+ <div className='merchi-loading-container'>
6
+ <div className='merchi-payment-gateway-inactive' />
7
+ <p className="merchi-loading-container-text">
8
+ Payment gateway is currently inactive.
9
+ </p>
10
+ </div>
11
+ );
12
+ }
@@ -0,0 +1,56 @@
1
+ import Title from './CartTitle';
2
+ import { tabIdShipment } from '../utilities/tabs';
3
+ import { addressInOneLine } from '../utilities/address';
4
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
+ import { faEdit, faTruck } from '@fortawesome/free-solid-svg-icons';
6
+ import { Button } from '../buttons';
7
+ import { useCartContext } from '../CartProvider';
8
+
9
+ interface Props {
10
+ cart: any;
11
+ }
12
+
13
+ function CartShipment({ cart }: Props) {
14
+ const {
15
+ classNameBtnDefault,
16
+ classNameListContainer,
17
+ classNameListUnstyled,
18
+ setActiveTabIndex,
19
+ } = useCartContext();
20
+ const { receiverAddress, receiverNotes } = cart;
21
+ const address = receiverAddress ? receiverAddress : null;
22
+ function openShipmentTab() {
23
+ setActiveTabIndex(tabIdShipment);
24
+ }
25
+ return (
26
+ <div className={classNameListContainer}>
27
+ <Title
28
+ icon={faTruck}
29
+ title='Ship to'
30
+ />
31
+ <ul
32
+ className={classNameListUnstyled}
33
+ style={{fontSize: '15px', marginBottom: '1rem'}}
34
+ >
35
+ <li>
36
+ <span style={{display: 'inline-block'}}>
37
+ {address ? addressInOneLine(address) : 'Shipping address not set'}
38
+ </span>
39
+ </li>
40
+ {receiverNotes && (
41
+ <li>
42
+ {receiverNotes}
43
+ </li>
44
+ )}
45
+ </ul>
46
+ <Button
47
+ onClick={openShipmentTab}
48
+ className={classNameBtnDefault}
49
+ >
50
+ <FontAwesomeIcon icon={faEdit} /> {address ? ' Change' : ' Set'}
51
+ </Button>
52
+ </div>
53
+ );
54
+ }
55
+
56
+ export default CartShipment;
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { useCartContext } from '../CartProvider';
3
+
4
+ interface Props {
5
+ children?: any;
6
+ }
7
+
8
+ export default function CartTabContent({ children }: Props) {
9
+ const { classNameCartTab } = useCartContext();
10
+ return (
11
+ <div className={classNameCartTab}>
12
+ {children}
13
+ </div>
14
+ );
15
+ }
@@ -0,0 +1,25 @@
1
+ import { useCartContext } from '../CartProvider';
2
+
3
+ interface Props {
4
+ children: any;
5
+ tabId: number;
6
+ }
7
+
8
+ export default function CartTabPanel({ children, tabId }: Props) {
9
+ const { activeTabIndex, classNameCartTabPanel, tabs } = useCartContext();
10
+ const currentTabIndex = tabs.findIndex((t: any) => t.tabId === activeTabIndex);
11
+ const activeTabValues = tabs[currentTabIndex];
12
+ const isActive =
13
+ (tabId === -1 && activeTabIndex === -1) ||
14
+ (tabId === -2 && activeTabIndex === -2) ||
15
+ !!(activeTabValues && tabId === activeTabValues.tabId);
16
+
17
+ // Unmount inactive tabs so heavy children (payments, product form) stay out of the tree.
18
+ if (!isActive) return null;
19
+
20
+ return (
21
+ <div className={classNameCartTabPanel} style={{ display: 'block' }}>
22
+ {children}
23
+ </div>
24
+ );
25
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { useCartContext } from '../CartProvider';
3
+
4
+ interface Props {
5
+ children: any;
6
+ }
7
+
8
+ export default function CartTableContainer({ children }: Props) {
9
+ const { classNameTableContainer } = useCartContext();
10
+ return (
11
+ <div className={classNameTableContainer}>
12
+ {children}
13
+ </div>
14
+ );
15
+ }
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3
+ import { useCartContext } from '../CartProvider';
4
+
5
+ export default function Title({ icon, title }: any) {
6
+ const {
7
+ classNameCartTitle,
8
+ } = useCartContext();
9
+ return (
10
+ <div className={classNameCartTitle}>
11
+ {typeof icon === 'string' ? (
12
+ <i className={`${icon} fa-2x`}></i>
13
+ ) : (
14
+ <FontAwesomeIcon icon={icon} size='2x' />
15
+ )}
16
+ <br />
17
+ <div style={{ marginTop: '1rem' }}>
18
+ <strong>{title}</strong>
19
+ </div>
20
+ </div>
21
+ );
22
+ }
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import { useCartContext } from '../CartProvider';
3
+ import { cartRequiresShipment } from '../utilities/cart';
4
+ import { CartTotal } from '../CartTotals';
5
+
6
+ interface RowProps {
7
+ attr: string;
8
+ name: string;
9
+ }
10
+
11
+ function CostsListItem({ attr, name }: RowProps) {
12
+ const {
13
+ classNameCartTotalItem,
14
+ classNameCartTotalItemPrice,
15
+ classNameListItemCartTotals,
16
+ } = useCartContext();
17
+
18
+ return (
19
+ <li className={classNameListItemCartTotals}>
20
+ <span className={classNameCartTotalItem}>{name}</span>
21
+ <span className={classNameCartTotalItemPrice}>
22
+ <CartTotal attribute={attr} />
23
+ </span>
24
+ </li>
25
+ );
26
+ }
27
+
28
+ function CartTotalsListGroup() {
29
+ const {
30
+ cart,
31
+ classNameCartTotaListContainer,
32
+ classNameCartTotalItemPrice,
33
+ classNameList,
34
+ classNameListItem
35
+ } = useCartContext();
36
+ const cartItems = cart.cartItems ? cart.cartItems : [];
37
+
38
+ return (
39
+ <div className={classNameCartTotaListContainer}>
40
+ <ul className={classNameList}>
41
+ {!!Number(cart.discountedAmount) && (
42
+ <CostsListItem attr="discountedAmount" name="Discount" />
43
+ )}
44
+ <CostsListItem attr="cartItemsSubtotalCost" name="Subtotal" />
45
+ {cartRequiresShipment({ ...cart, cartItems }) && (
46
+ <CostsListItem attr="shipmentTotalCost" name="Shipping" />
47
+ )}
48
+ {!!cart.taxAmount && (<CostsListItem attr="taxAmount" name="Tax" />)}
49
+ <CostsListItem attr="totalCost" name="Total" />
50
+ <li className={classNameListItem}>
51
+ <div className={classNameCartTotalItemPrice}>Total price includes taxes</div>
52
+ </li>
53
+ </ul>
54
+ </div>
55
+ );
56
+ }
57
+
58
+ export default CartTotalsListGroup;
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import { useState, useRef, useEffect } from 'react';
3
+
4
+ function Collapse({ isOpen, children }: any) {
5
+ const [height, setHeight] = useState(isOpen ? 'auto' : '0');
6
+ const ref = useRef(null);
7
+
8
+ useEffect(() => {
9
+ setHeight(isOpen ? `${(ref as any).current.scrollHeight}px` : '0');
10
+ }, [isOpen]);
11
+
12
+ return (
13
+ <div
14
+ className={`merchi-collapse ${isOpen ? 'show' : ''}`}
15
+ ref={ref}
16
+ style={{ transition: 'height 0.35s ease', overflow: 'hidden', height }}
17
+ >
18
+ {children}
19
+ </div>
20
+ );
21
+ }
22
+
23
+ export default Collapse;
@@ -0,0 +1,123 @@
1
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { MerchiProductFormSdkExternals } from './product-form-sdk-externals';
3
+ import { loadFormBundle, publishedFormBundle } from '../utilities/customForm';
4
+ import { LoadingTemplateSm } from './LoadingTemplate';
5
+
6
+ interface Props {
7
+ product: any;
8
+ /** Current cart item used to hydrate quantity / selections. */
9
+ initialJob: any;
10
+ apiUrl?: string;
11
+ onSave: (job: any) => void;
12
+ /** Rendered when there is no published bundle or load/runtime fails. */
13
+ fallback: React.ReactNode;
14
+ /** Notifies the host when the custom form is actively rendering. */
15
+ onActiveChange?: (active: boolean) => void;
16
+ }
17
+
18
+ /**
19
+ * Loads a product's published custom form for cart-item edit. On any failure
20
+ * renders `fallback` (the default @merchi/product-form) so the cart stays usable.
21
+ */
22
+ export function CustomCartProductForm({
23
+ product,
24
+ initialJob,
25
+ apiUrl,
26
+ onSave,
27
+ fallback,
28
+ onActiveChange,
29
+ }: Props) {
30
+ const [Loaded, setLoaded] = useState<React.ComponentType<any> | null>(null);
31
+ const [failed, setFailed] = useState(false);
32
+ const [loading, setLoading] = useState(true);
33
+ const onSaveRef = useRef(onSave);
34
+ onSaveRef.current = onSave;
35
+ const onActiveChangeRef = useRef(onActiveChange);
36
+ onActiveChangeRef.current = onActiveChange;
37
+
38
+ const bundleKey = publishedFormBundle(product)?.url ?? '';
39
+
40
+ useEffect(() => {
41
+ let active = true;
42
+ setLoaded(null);
43
+ setFailed(false);
44
+ setLoading(true);
45
+ const bundle = publishedFormBundle(product);
46
+ if (!bundle) {
47
+ setFailed(true);
48
+ setLoading(false);
49
+ return;
50
+ }
51
+ const w = window as any;
52
+ w.React = React;
53
+ w.MerchiProductFormSdk = MerchiProductFormSdkExternals;
54
+ loadFormBundle(bundle)
55
+ .then((Component) => {
56
+ if (active) {
57
+ setLoaded(() => Component);
58
+ setLoading(false);
59
+ }
60
+ })
61
+ .catch((e) => {
62
+ console.error('[merchi_cart] custom form load failed', e);
63
+ if (active) {
64
+ setFailed(true);
65
+ setLoading(false);
66
+ }
67
+ });
68
+ return () => {
69
+ active = false;
70
+ };
71
+ }, [product, bundleKey]);
72
+
73
+ const props = useMemo(() => {
74
+ try {
75
+ const runtime = MerchiProductFormSdkExternals.createProductFormRuntime({
76
+ apiUrl: apiUrl || '',
77
+ product,
78
+ onAddToCart: (job: any) => onSaveRef.current?.(job),
79
+ });
80
+ return {
81
+ product,
82
+ pricing: runtime.pricing,
83
+ actions: runtime.actions,
84
+ helpers: runtime.helpers,
85
+ };
86
+ } catch (e) {
87
+ console.error('[merchi_cart] custom form props build failed', e);
88
+ return null;
89
+ }
90
+ }, [product, apiUrl]);
91
+
92
+ const isActive = !failed && !loading && !!Loaded && !!props;
93
+ useEffect(() => {
94
+ onActiveChangeRef.current?.(isActive);
95
+ return () => onActiveChangeRef.current?.(false);
96
+ }, [isActive]);
97
+
98
+ if (loading) return <LoadingTemplateSm />;
99
+ if (failed || !Loaded || !props) return <>{fallback}</>;
100
+
101
+ const Shell = MerchiProductFormSdkExternals.ProductFormShell;
102
+
103
+ return (
104
+ <>
105
+ {Shell ? (
106
+ <Shell
107
+ product={props.product}
108
+ pricing={props.pricing}
109
+ actions={props.actions}
110
+ helpers={props.helpers}
111
+ initialJob={initialJob}
112
+ actionLabels={{ addToCart: 'Save' }}
113
+ >
114
+ <Loaded {...props} />
115
+ </Shell>
116
+ ) : (
117
+ <Loaded {...props} />
118
+ )}
119
+ </>
120
+ );
121
+ }
122
+
123
+ export default CustomCartProductForm;
@@ -0,0 +1,106 @@
1
+ import * as React from 'react';
2
+ import { useState } from 'react';
3
+ import { BiCheck, BiUser } from 'react-icons/bi';
4
+ import { FaWhatsapp } from 'react-icons/fa';
5
+ import FormNewCustomer from '../forms/FormNewCustomer';
6
+ import FormReturningCustomer from '../forms/FormReturningCustomer';
7
+ import FormWhatsappCustomer from '../forms/FormWhatsappCustomer';
8
+
9
+ type CheckoutMethod = 'new' | 'returning' | 'whatsapp';
10
+ type SectionIconType = 'user' | 'whatsapp';
11
+
12
+ interface CustomerCheckoutMethodTabsProps {
13
+ whatsappEnabled?: boolean;
14
+ }
15
+
16
+ function renderSectionIcon(iconType: SectionIconType) {
17
+ if (iconType === 'whatsapp') {
18
+ return (
19
+ <FaWhatsapp className="merchi-customer-checkout-option__icon-svg merchi-customer-checkout-option__icon-svg--whatsapp" />
20
+ );
21
+ }
22
+
23
+ return <BiUser className="merchi-customer-checkout-option__icon-svg" />;
24
+ }
25
+
26
+ export default function CustomerCheckoutMethodTabs({
27
+ whatsappEnabled = false,
28
+ }: CustomerCheckoutMethodTabsProps) {
29
+ const [activeMethod, setActiveMethod] = useState<CheckoutMethod | null>(null);
30
+
31
+ const sections: Array<{
32
+ id: CheckoutMethod;
33
+ label: string;
34
+ iconType: SectionIconType;
35
+ form: React.ReactNode;
36
+ }> = [
37
+ {
38
+ id: 'returning',
39
+ label: 'Returning customer',
40
+ iconType: 'user',
41
+ form: <FormReturningCustomer />,
42
+ },
43
+ {
44
+ id: 'new',
45
+ label: 'New customer',
46
+ iconType: 'user',
47
+ form: <FormNewCustomer />,
48
+ },
49
+ ];
50
+
51
+ if (whatsappEnabled) {
52
+ sections.push({
53
+ id: 'whatsapp',
54
+ label: 'WhatsApp checkout',
55
+ iconType: 'whatsapp',
56
+ form: <FormWhatsappCustomer />,
57
+ });
58
+ }
59
+
60
+ return (
61
+ <>
62
+ <p className="merchi-customer-checkout__heading">Choose a checkout option</p>
63
+ <div
64
+ className="merchi-customer-checkout-options"
65
+ role="radiogroup"
66
+ aria-label="Choose a checkout option"
67
+ >
68
+ {sections.map((section) => {
69
+ const isSelected = activeMethod === section.id;
70
+ return (
71
+ <div
72
+ key={section.id}
73
+ className={`merchi-customer-checkout-option${isSelected ? ' is-selected' : ''}`}
74
+ >
75
+ <button
76
+ type="button"
77
+ role="radio"
78
+ aria-checked={isSelected}
79
+ aria-expanded={isSelected}
80
+ className="merchi-customer-checkout-option__header"
81
+ onClick={() => setActiveMethod(section.id)}
82
+ >
83
+ <span className="merchi-customer-checkout-option__title">
84
+ <span className="merchi-customer-checkout-option__icon">
85
+ {renderSectionIcon(section.iconType)}
86
+ </span>
87
+ <span className="merchi-customer-checkout-option__label">
88
+ {section.label}
89
+ </span>
90
+ </span>
91
+ <span className="merchi-customer-checkout-option__checkbox" aria-hidden>
92
+ {isSelected && <BiCheck />}
93
+ </span>
94
+ </button>
95
+ {isSelected && (
96
+ <div className="merchi-customer-checkout-option__body">
97
+ {section.form}
98
+ </div>
99
+ )}
100
+ </div>
101
+ );
102
+ })}
103
+ </div>
104
+ </>
105
+ );
106
+ }