@rebuy/rebuy-hydrogen 3.0.0-beta.1 → 3.0.0-beta.10

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 (143) hide show
  1. package/README.md +0 -2
  2. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts +3 -0
  3. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -0
  4. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts +3 -0
  5. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -0
  6. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts +3 -0
  7. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -0
  8. package/dist/components/AddToCartBtn/index.d.ts +2 -0
  9. package/dist/components/AddToCartBtn/index.d.ts.map +1 -0
  10. package/{src/components/AddToCartBtn/types.ts → dist/components/AddToCartBtn/types.d.ts} +1 -2
  11. package/dist/components/AddToCartBtn/types.d.ts.map +1 -0
  12. package/dist/components/ProductCard/ProductCard.d.ts +3 -0
  13. package/dist/components/ProductCard/ProductCard.d.ts.map +1 -0
  14. package/dist/components/ProductCard/index.d.ts +2 -0
  15. package/dist/components/ProductCard/index.d.ts.map +1 -0
  16. package/{src/components/ProductCard/types.ts → dist/components/ProductCard/types.d.ts} +2 -2
  17. package/dist/components/ProductCard/types.d.ts.map +1 -0
  18. package/dist/components/ProductPrice/ProductPrice.d.ts +5 -0
  19. package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -0
  20. package/dist/components/ProductPrice/index.d.ts +2 -0
  21. package/dist/components/ProductPrice/index.d.ts.map +1 -0
  22. package/dist/components/Title/Title.d.ts +3 -0
  23. package/dist/components/Title/Title.d.ts.map +1 -0
  24. package/dist/components/Title/index.d.ts +2 -0
  25. package/dist/components/Title/index.d.ts.map +1 -0
  26. package/{src/components/Title/types.ts → dist/components/Title/types.d.ts} +1 -1
  27. package/dist/components/Title/types.d.ts.map +1 -0
  28. package/dist/components/VariantSelect/VariantSelect.d.ts +3 -0
  29. package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -0
  30. package/dist/components/VariantSelect/index.d.ts +2 -0
  31. package/dist/components/VariantSelect/index.d.ts.map +1 -0
  32. package/{src/components/VariantSelect/types.ts → dist/components/VariantSelect/types.d.ts} +1 -1
  33. package/dist/components/VariantSelect/types.d.ts.map +1 -0
  34. package/{src/context/RebuyContext.tsx → dist/context/RebuyContext.d.ts} +2 -5
  35. package/dist/context/RebuyContext.d.ts.map +1 -0
  36. package/dist/hooks/titleLevel.d.ts +3 -0
  37. package/dist/hooks/titleLevel.d.ts.map +1 -0
  38. package/dist/index.css +296 -0
  39. package/dist/index.css.map +7 -0
  40. package/{src/index.ts → dist/index.d.ts} +1 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +1967 -0
  43. package/dist/index.js.map +7 -0
  44. package/dist/index.mjs +1935 -0
  45. package/dist/index.mjs.map +7 -0
  46. package/dist/providers/RebuyHydrogenContextProvider.d.ts +3 -0
  47. package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -0
  48. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts +3 -0
  49. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -0
  50. package/{src/providers/types.ts → dist/providers/types.d.ts} +12 -16
  51. package/dist/providers/types.d.ts.map +1 -0
  52. package/dist/queries/cart.queries.d.ts +5 -0
  53. package/dist/queries/cart.queries.d.ts.map +1 -0
  54. package/dist/types/common.d.ts +9 -0
  55. package/dist/types/common.d.ts.map +1 -0
  56. package/{src/types/rebuyCustom.ts → dist/types/rebuyCustom.d.ts} +12 -35
  57. package/dist/types/rebuyCustom.d.ts.map +1 -0
  58. package/{src/types/rebuySmartCart.ts → dist/types/rebuySmartCart.d.ts} +1 -5
  59. package/dist/types/rebuySmartCart.d.ts.map +1 -0
  60. package/dist/types/shopify.d.ts +85 -0
  61. package/dist/types/shopify.d.ts.map +1 -0
  62. package/{src/types/widgets.ts → dist/types/widgets.d.ts} +2 -9
  63. package/dist/types/widgets.d.ts.map +1 -0
  64. package/dist/utils/convertToRebuyProduct.d.ts +156 -0
  65. package/dist/utils/convertToRebuyProduct.d.ts.map +1 -0
  66. package/dist/utils/createContextParameters.d.ts +3 -0
  67. package/dist/utils/createContextParameters.d.ts.map +1 -0
  68. package/dist/utils/getEncodedAttributes.d.ts +3 -0
  69. package/dist/utils/getEncodedAttributes.d.ts.map +1 -0
  70. package/dist/utils/getRebuyConfig.d.ts +3 -0
  71. package/dist/utils/getRebuyConfig.d.ts.map +1 -0
  72. package/dist/widgetContainer/RebuyWidgetContainer.d.ts +8 -0
  73. package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -0
  74. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts +3 -0
  75. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -0
  76. package/{src/widgets/RebuyCompleteTheLook/index.ts → dist/widgets/RebuyCompleteTheLook/index.d.ts} +1 -0
  77. package/dist/widgets/RebuyCompleteTheLook/index.d.ts.map +1 -0
  78. package/{src/widgets/RebuyCompleteTheLook/types.ts → dist/widgets/RebuyCompleteTheLook/types.d.ts} +1 -1
  79. package/dist/widgets/RebuyCompleteTheLook/types.d.ts.map +1 -0
  80. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts +5 -0
  81. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -0
  82. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts +5 -0
  83. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -0
  84. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +3 -0
  85. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -0
  86. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts +3 -0
  87. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -0
  88. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts +3 -0
  89. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -0
  90. package/{src/widgets/RebuyDynamicBundleProducts/index.ts → dist/widgets/RebuyDynamicBundleProducts/index.d.ts} +1 -0
  91. package/dist/widgets/RebuyDynamicBundleProducts/index.d.ts.map +1 -0
  92. package/{src/widgets/RebuyDynamicBundleProducts/types.ts → dist/widgets/RebuyDynamicBundleProducts/types.d.ts} +1 -5
  93. package/dist/widgets/RebuyDynamicBundleProducts/types.d.ts.map +1 -0
  94. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts +3 -0
  95. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -0
  96. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts +3 -0
  97. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -0
  98. package/{src/widgets/RebuyProductAddOns/index.ts → dist/widgets/RebuyProductAddOns/index.d.ts} +1 -0
  99. package/dist/widgets/RebuyProductAddOns/index.d.ts.map +1 -0
  100. package/{src/widgets/RebuyProductAddOns/types.ts → dist/widgets/RebuyProductAddOns/types.d.ts} +2 -7
  101. package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -0
  102. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts +3 -0
  103. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -0
  104. package/{src/widgets/RebuyProductRecommendations/index.ts → dist/widgets/RebuyProductRecommendations/index.d.ts} +1 -0
  105. package/dist/widgets/RebuyProductRecommendations/index.d.ts.map +1 -0
  106. package/{src/widgets/RebuyProductRecommendations/types.ts → dist/widgets/RebuyProductRecommendations/types.d.ts} +1 -1
  107. package/dist/widgets/RebuyProductRecommendations/types.d.ts.map +1 -0
  108. package/package.json +48 -36
  109. package/src/components/AddToCartBtn/AddToCartBtn.tsx +0 -45
  110. package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +0 -43
  111. package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +0 -35
  112. package/src/components/AddToCartBtn/index.ts +0 -1
  113. package/src/components/ProductCard/ProductCard.tsx +0 -70
  114. package/src/components/ProductCard/index.ts +0 -1
  115. package/src/components/ProductPrice/ProductPrice.tsx +0 -49
  116. package/src/components/ProductPrice/index.ts +0 -1
  117. package/src/components/Title/Title.tsx +0 -20
  118. package/src/components/Title/index.ts +0 -1
  119. package/src/components/VariantSelect/VariantSelect.tsx +0 -45
  120. package/src/components/VariantSelect/index.ts +0 -1
  121. package/src/hooks/titleLevel.tsx +0 -42
  122. package/src/providers/RebuyHydrogenContextProvider.tsx +0 -112
  123. package/src/providers/RebuyHydrogenReactContextProvider.tsx +0 -192
  124. package/src/queries/cart.queries.ts +0 -467
  125. package/src/types/common.ts +0 -8
  126. package/src/types/css.d.ts +0 -11
  127. package/src/types/env.d.ts +0 -12
  128. package/src/types/rebuy.d.ts +0 -31
  129. package/src/types/shopify.ts +0 -142
  130. package/src/utils/convertToRebuyProduct.tsx +0 -319
  131. package/src/utils/createContextParameters.ts +0 -142
  132. package/src/utils/getEncodedAttributes.ts +0 -11
  133. package/src/utils/getRebuyConfig.ts +0 -31
  134. package/src/widgetContainer/RebuyWidgetContainer.tsx +0 -183
  135. package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +0 -50
  136. package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +0 -62
  137. package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +0 -93
  138. package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +0 -65
  139. package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +0 -118
  140. package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +0 -41
  141. package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +0 -66
  142. package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +0 -218
  143. package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +0 -50
package/package.json CHANGED
@@ -1,35 +1,44 @@
1
1
  {
2
2
  "name": "@rebuy/rebuy-hydrogen",
3
+ "version": "3.0.0-beta.10",
3
4
  "description": "This is the default library for Rebuy + Shopify Hydrogen",
4
- "version": "3.0.0-beta.1",
5
+ "homepage": "https://bitbucket.org/rebuyengine/npm-rebuy-hydrogen#readme",
6
+ "bugs": {
7
+ "url": "https://bitbucket.org/rebuyengine/npm-rebuy-hydrogen/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@bitbucket.org/rebuyengine/npm-rebuy-hydrogen.git"
12
+ },
5
13
  "license": "MIT",
6
14
  "author": "Rebuy, Inc.",
15
+ "type": "module",
7
16
  "main": "./dist/index.js",
8
17
  "module": "./dist/index.mjs",
9
18
  "types": "./dist/index.d.ts",
10
- "type": "module",
11
- "publishConfig": {
12
- "access": "public"
13
- },
14
19
  "files": [
15
20
  "dist",
16
- "README.md",
17
- "**/*.d.ts",
18
- "**/*.ts",
19
- "**/*.tsx"
21
+ "README.md"
20
22
  ],
21
23
  "scripts": {
22
- "clean": "rm -rf dist",
23
- "build:types": "tsc --emitDeclarationOnly --outDir dist",
24
- "build:code": "node esbuild.config.mjs",
25
24
  "build": "npm run clean && npm run build:types && npm run build:code",
25
+ "build:code": "node esbuild.config.mjs",
26
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
26
27
  "build:watch": "npm run clean && npm run build:types && node esbuild.config.mjs --watch",
27
- "format": "npm run lint -- --fix",
28
- "lint": "eslint . --ext .js,.jsx,.json",
28
+ "check-types": "tsc --noEmit",
29
+ "clean": "rm -rf dist",
30
+ "deploy": "npm run build && npx semantic-release --debug --no-ci",
31
+ "deploy:dryrun": "npm run deploy -- --dry-run",
32
+ "dev": "npm run clean && concurrently \"npm run types:watch\" \"npm run build:watch\"",
33
+ "format": "npm run lint -- --fix && npm run lint:css -- --fix",
34
+ "lint": "eslint --ext .js,.jsx,.json,.mjs,.ts,.tsx ./src",
35
+ "lint:css": "stylelint './src/**/*.{css,scss}'",
36
+ "lint:css-skip-warn": "npm run lint:css -- --quiet",
37
+ "lint:skip-warn": "npm run lint -- --quiet",
29
38
  "prepare": "husky install",
39
+ "sort-package": "sort-package-json",
30
40
  "test": "echo \"Error: no test specified\" && exit 1",
31
- "types:watch": "tsc --emitDeclarationOnly --outDir dist --watch",
32
- "dev": "npm run clean && concurrently \"npm run types:watch\" \"npm run build:watch\""
41
+ "types:watch": "tsc --emitDeclarationOnly --outDir dist --watch"
33
42
  },
34
43
  "config": {
35
44
  "commitizen": {
@@ -39,25 +48,25 @@
39
48
  "config": ".cz-config.cjs"
40
49
  }
41
50
  },
42
- "repository": {
43
- "type": "git",
44
- "url": "git+ssh://git@bitbucket.org/rebuyengine/npm-rebuy-hydrogen.git"
45
- },
46
- "bugs": {
47
- "url": "https://bitbucket.org/rebuyengine/npm-rebuy-hydrogen/issues"
51
+ "dependencies": {
52
+ "@rebuy/rebuy": "^1.5.1",
53
+ "classnames": "^2.5.1",
54
+ "dompurify": "^3.2.5",
55
+ "lodash-es": "^4.17.21",
56
+ "zustand": "^5.0.4"
48
57
  },
49
- "homepage": "https://bitbucket.org/rebuyengine/npm-rebuy-hydrogen#readme",
50
58
  "devDependencies": {
51
59
  "@commitlint/cli": "^19.8.0",
52
60
  "@commitlint/config-conventional": "^19.8.0",
53
61
  "@semantic-release/changelog": "^6.0.3",
54
62
  "@semantic-release/commit-analyzer": "^13.0.1",
55
63
  "@semantic-release/git": "^10.0.1",
56
- "@semantic-release/npm": "^12.0.1",
57
64
  "@semantic-release/release-notes-generator": "^14.0.3",
58
65
  "@shopify/hydrogen": ">=2025.0.1",
59
66
  "@shopify/hydrogen-react": ">=2025.0.1",
60
- "@types/react": "^18.0.0",
67
+ "@types/dompurify": "^3.0.5",
68
+ "@types/lodash-es": "^4.17.12",
69
+ "@types/react": "^18.3.3",
61
70
  "@types/three": "^0.175.0",
62
71
  "@typescript-eslint/eslint-plugin": "^8.26.1",
63
72
  "@typescript-eslint/parser": "^8.26.1",
@@ -68,33 +77,36 @@
68
77
  "esbuild": "0.25.2",
69
78
  "eslint": "^8.57.0",
70
79
  "eslint-config-prettier": "^10.1.1",
80
+ "eslint-import-resolver-typescript": "^4.3.4",
71
81
  "eslint-plugin-import": "^2.31.0",
82
+ "eslint-plugin-jsdoc": "^50.2.4",
72
83
  "eslint-plugin-json": "^4.0.1",
73
84
  "eslint-plugin-prettier": "^5.2.3",
74
85
  "eslint-plugin-react": "^7.37.4",
75
- "eslint-plugin-react-hooks": "^5.2.0",
86
+ "eslint-plugin-react-hooks": "^4.6.2",
76
87
  "eslint-plugin-sort-destructure-keys": "^2.0.0",
77
88
  "eslint-plugin-sort-keys": "^2.3.5",
78
89
  "eslint-plugin-typescript-sort-keys": "^3.3.0",
90
+ "eslint-plugin-unused-imports": "^4.1.4",
79
91
  "husky": "^9.1.7",
80
92
  "lint-staged": "^15.5.0",
81
93
  "prettier": "^3.5.2",
82
- "react": "^18.0.0",
94
+ "react": "^18.3.1",
83
95
  "semantic-release": "^24.2.3",
96
+ "sort-package-json": "^2.10.0",
97
+ "stylelint": "^16.19.1",
98
+ "stylelint-config-css-modules": "^4.4.0",
99
+ "stylelint-config-standard": "^36.0.1",
84
100
  "typescript": "^5.8.2"
85
101
  },
86
- "dependencies": {
87
- "@rebuy/rebuy": "^1.5.1"
88
- },
89
102
  "peerDependencies": {
90
103
  "@remix-run/react": ">=2.10.0",
91
104
  "@shopify/hydrogen": ">=2025.0.1",
92
- "@shopify/hydrogen-react": ">=2025.0.1"
105
+ "@shopify/hydrogen-react": ">=2025.0.1",
106
+ "react": ">=18.2.0",
107
+ "react-dom": ">=18.2.0"
93
108
  },
94
- "lint-staged": {
95
- "**/*.{js,jsx,json}": [
96
- "npm run format",
97
- "prettier --write"
98
- ]
109
+ "publishConfig": {
110
+ "access": "public"
99
111
  }
100
112
  }
@@ -1,45 +0,0 @@
1
- import { HydrogenAddToCartBtn } from './HydrogenAddToCartBtn';
2
- import { HydrogenReactAddToCartBtn } from './HydrogenReactAddToCartBtn';
3
-
4
- import type { AddToCartBtnProps } from '~/components/AddToCartBtn/types';
5
-
6
- export const AddToCartBtn = ({
7
- addToCartBtnText,
8
- addToCartCallback,
9
- disabled,
10
- isHydrogenReact,
11
- moneyData,
12
- selectedVariants,
13
- }: AddToCartBtnProps) => {
14
- const linesToAdd = selectedVariants.map((variant) => ({
15
- attributes: [
16
- { key: '_source', value: 'Rebuy' },
17
- { key: '_attribution', value: 'Rebuy Product Recommendations' },
18
- ],
19
- merchandiseId: variant.id,
20
- quantity: 1,
21
- selectedVariant: variant,
22
- }));
23
-
24
- if (isHydrogenReact) {
25
- return (
26
- <HydrogenReactAddToCartBtn
27
- addToCartBtnText={addToCartBtnText}
28
- addToCartCallback={addToCartCallback}
29
- disabled={disabled}
30
- linesToAdd={linesToAdd}
31
- moneyData={moneyData}
32
- />
33
- );
34
- }
35
-
36
- return (
37
- <HydrogenAddToCartBtn
38
- addToCartBtnText={addToCartBtnText}
39
- addToCartCallback={addToCartCallback}
40
- disabled={disabled}
41
- linesToAdd={linesToAdd}
42
- moneyData={moneyData}
43
- />
44
- );
45
- };
@@ -1,43 +0,0 @@
1
- import { type FetcherWithComponents } from '@remix-run/react';
2
- import { CartForm, Money } from '@shopify/hydrogen';
3
-
4
- import styles from './AddToCartBtn.module.css';
5
-
6
- import type { btnProps } from '~/components/AddToCartBtn/types';
7
-
8
- export const HydrogenAddToCartBtn = ({
9
- addToCartBtnText,
10
- addToCartCallback,
11
- disabled,
12
- linesToAdd,
13
- moneyData,
14
- }: btnProps) => {
15
- return (
16
- <CartForm
17
- action={CartForm.ACTIONS.LinesAdd}
18
- inputs={{
19
- lines: linesToAdd,
20
- }}
21
- route="/cart"
22
- >
23
- {(fetcher: FetcherWithComponents<unknown>) => (
24
- <>
25
- <button
26
- className={styles.button}
27
- disabled={disabled || fetcher.state !== 'idle'}
28
- onClick={addToCartCallback}
29
- type="submit"
30
- >
31
- {addToCartBtnText}
32
- {moneyData && (
33
- <>
34
- <span> | </span>
35
- <Money data={moneyData} withoutTrailingZeros />
36
- </>
37
- )}
38
- </button>
39
- </>
40
- )}
41
- </CartForm>
42
- );
43
- };
@@ -1,35 +0,0 @@
1
- import { Money, useCart } from '@shopify/hydrogen-react';
2
-
3
- import styles from './AddToCartBtn.module.css';
4
-
5
- import type { btnProps } from '~/components/AddToCartBtn/types';
6
-
7
- export const HydrogenReactAddToCartBtn = ({
8
- addToCartBtnText,
9
- addToCartCallback,
10
- disabled,
11
- linesToAdd,
12
- moneyData,
13
- }: btnProps) => {
14
- const { linesAdd } = useCart();
15
- const handleAddToCart = () => {
16
- linesAdd(linesToAdd);
17
- addToCartCallback?.();
18
- };
19
- return (
20
- <button
21
- className={styles.button}
22
- disabled={disabled}
23
- onClick={handleAddToCart}
24
- type="button"
25
- >
26
- {addToCartBtnText}
27
- {moneyData && (
28
- <>
29
- <span> | </span>
30
- <Money data={moneyData} withoutTrailingZeros />
31
- </>
32
- )}
33
- </button>
34
- );
35
- };
@@ -1 +0,0 @@
1
- export * from './AddToCartBtn';
@@ -1,70 +0,0 @@
1
- import { Link } from '@remix-run/react';
2
- import { Image } from '@shopify/hydrogen';
3
- import { useState } from 'react';
4
-
5
- import styles from './ProductCard.module.css';
6
-
7
- import type { ProductCardProps } from '~/components/ProductCard/types';
8
- import type { RebuyProduct } from '~/types/rebuyCustom';
9
-
10
- import { AddToCartBtn } from '~/components/AddToCartBtn';
11
- import { RebuyProductPrice } from '~/components/ProductPrice/ProductPrice';
12
- import { Title } from '~/components/Title';
13
- import { VariantSelect } from '~/components/VariantSelect';
14
-
15
- export const ProductCard = ({
16
- addToCartBtnText,
17
- addToCartCallback,
18
- isHydrogenReact,
19
- product,
20
- productCardTitleLevel,
21
- }: ProductCardProps) => {
22
- const [selectedVariant, setSelectedVariant] = useState(
23
- product.variants.nodes[0]
24
- );
25
-
26
- const { image } = selectedVariant;
27
- const handleSelectedVariant = (
28
- product: RebuyProduct,
29
- variant_id: string
30
- ) => {
31
- const updatedVariant = product.variants.nodes.find(
32
- (variant) => variant.id === variant_id
33
- );
34
- if (updatedVariant) {
35
- setSelectedVariant(updatedVariant);
36
- }
37
- };
38
- return (
39
- <div className={styles.container}>
40
- <div>
41
- <Link to={`/products/${product.handle}`}>
42
- <Image
43
- alt={image?.altText ?? `Picture of ${product.title}`}
44
- data={image}
45
- sizes="(max-width: 320px) 280px, (max-width: 768px) 720px, 1440px"
46
- />
47
- </Link>
48
- <div className={styles.productInfo}>
49
- <Link to={`/products/${product.handle}`}>
50
- <Title
51
- level={productCardTitleLevel}
52
- text={product.title}
53
- />
54
- </Link>
55
- <RebuyProductPrice selectedVariant={selectedVariant} />
56
- <VariantSelect
57
- handleSelectedVariant={handleSelectedVariant}
58
- product={product}
59
- />
60
- </div>
61
- </div>
62
- <AddToCartBtn
63
- addToCartBtnText={addToCartBtnText}
64
- addToCartCallback={addToCartCallback}
65
- isHydrogenReact={isHydrogenReact}
66
- selectedVariants={[selectedVariant]}
67
- />
68
- </div>
69
- );
70
- };
@@ -1 +0,0 @@
1
- export * from './ProductCard';
@@ -1,49 +0,0 @@
1
- import { Money } from '@shopify/hydrogen';
2
-
3
- import styles from './ProductPrice.module.css';
4
-
5
- import type { MoneyV2 } from '@shopify/hydrogen-react/storefront-api-types';
6
- import type { RebuyProductVariant } from '~/types/rebuyCustom';
7
-
8
- export const RebuyProductPrice = ({
9
- selectedVariant,
10
- }: {
11
- selectedVariant: RebuyProductVariant;
12
- }) => {
13
- if (!selectedVariant) return null;
14
- const { compareAtPriceV2: compareAtPrice, priceV2: price } =
15
- selectedVariant;
16
-
17
- const isDiscounted = (
18
- price: MoneyV2 | null,
19
- compareAtPrice: MoneyV2 | null
20
- ) => Number(compareAtPrice?.amount) > Number(price?.amount);
21
-
22
- const CompareAtPrice = ({
23
- data: compareAtPrice,
24
- }: {
25
- data: MoneyV2 | null;
26
- }) => {
27
- return (
28
- compareAtPrice && (
29
- <Money
30
- as="span"
31
- className={styles.compareAtPrice}
32
- data={compareAtPrice}
33
- withoutTrailingZeros
34
- />
35
- )
36
- );
37
- };
38
-
39
- return (
40
- price && (
41
- <div className={styles.priceContainer}>
42
- <Money data={price} withoutTrailingZeros />
43
- {compareAtPrice && isDiscounted(price, compareAtPrice) && (
44
- <CompareAtPrice data={compareAtPrice} />
45
- )}
46
- </div>
47
- )
48
- );
49
- };
@@ -1 +0,0 @@
1
- export * from './ProductPrice';
@@ -1,20 +0,0 @@
1
- import type { TitleProps } from '~/components/Title/types';
2
-
3
- export const Title = ({ level, style, text }: TitleProps) => {
4
- switch (level) {
5
- case 'h1':
6
- return <h1 style={style}>{text}</h1>;
7
- case 'h2':
8
- return <h2 style={style}>{text}</h2>;
9
- case 'h3':
10
- return <h3 style={style}>{text}</h3>;
11
- case 'h4':
12
- return <h4 style={style}>{text}</h4>;
13
- case 'h5':
14
- return <h5 style={style}>{text}</h5>;
15
- case 'h6':
16
- return <h6 style={style}>{text}</h6>;
17
- default:
18
- return <h2 style={style}>{text}</h2>;
19
- }
20
- };
@@ -1 +0,0 @@
1
- export * from './Title';
@@ -1,45 +0,0 @@
1
- import styles from './VariantSelect.module.css';
2
-
3
- import type { VariantSelectProps } from '~/components/VariantSelect/types';
4
- import type { RebuyProduct } from '~/types/rebuyCustom';
5
-
6
- export const VariantSelect = ({
7
- handleSelectedVariant,
8
- product,
9
- }: VariantSelectProps) => {
10
- const getOptionsLabel = (product: RebuyProduct) => {
11
- const options = product.variants.nodes[0].selectedOptions;
12
- const optionsFromKeys = options ? Object.keys(options[0]) : [];
13
- const optionsFromValues = options
14
- ? options.map((option) => option.name)
15
- : [];
16
- const useValues = optionsFromKeys.every((key) =>
17
- ['name', 'value'].includes(key)
18
- );
19
-
20
- // Return delimited label for available option(s) e.g. Color / Size, Scent, etc
21
- return (useValues ? optionsFromValues : optionsFromKeys).join(' / ');
22
- };
23
-
24
- return (
25
- product?.variants.nodes.length > 1 && (
26
- <div>
27
- <select
28
- aria-label="select variant"
29
- className={styles.select}
30
- onChange={(e) =>
31
- handleSelectedVariant(product, e.target.value)
32
- }
33
- >
34
- <optgroup label={getOptionsLabel(product)}>
35
- {product.variants.nodes.map(({ id, title }) => (
36
- <option key={id + '-variant'} value={id}>
37
- {title}
38
- </option>
39
- ))}
40
- </optgroup>
41
- </select>
42
- </div>
43
- )
44
- );
45
- };
@@ -1 +0,0 @@
1
- export * from './VariantSelect';
@@ -1,42 +0,0 @@
1
- import { ProductCardTitleLevel } from '~/types/common';
2
-
3
- // Convert the string header level to enum
4
- export const getTitleLevel = (
5
- level: string,
6
- decreaseLevel: boolean = false
7
- ): ProductCardTitleLevel => {
8
- switch (level) {
9
- case 'h1':
10
- if (decreaseLevel) {
11
- return ProductCardTitleLevel.H2;
12
- }
13
- return ProductCardTitleLevel.H1;
14
- case 'h2':
15
- if (decreaseLevel) {
16
- return ProductCardTitleLevel.H3;
17
- }
18
- return ProductCardTitleLevel.H2;
19
- case 'h3':
20
- if (decreaseLevel) {
21
- return ProductCardTitleLevel.H4;
22
- }
23
- return ProductCardTitleLevel.H3;
24
- case 'h4':
25
- if (decreaseLevel) {
26
- return ProductCardTitleLevel.H5;
27
- }
28
- return ProductCardTitleLevel.H4;
29
- case 'h5':
30
- if (decreaseLevel) {
31
- return ProductCardTitleLevel.H6;
32
- }
33
- return ProductCardTitleLevel.H5;
34
- case 'h6':
35
- if (decreaseLevel) {
36
- return ProductCardTitleLevel.H6;
37
- }
38
- return ProductCardTitleLevel.H6;
39
- default:
40
- return ProductCardTitleLevel.H2;
41
- }
42
- };
@@ -1,112 +0,0 @@
1
- import * as Utilities from '@rebuy/rebuy/utilities';
2
- import { Await, useLocation } from '@remix-run/react';
3
- import { useEffect, useMemo, useState } from 'react';
4
-
5
- import type { CartReturn } from '@shopify/hydrogen';
6
- import type {
7
- RebuyHydrogenContextProviderProps,
8
- RebuyHydrogenProps,
9
- } from '~/providers/types';
10
-
11
- import { RebuyContext } from '~/context/RebuyContext';
12
- import { RebuyConfig } from '~/types/rebuyCustom';
13
- import { createContextParameters } from '~/utils/createContextParameters';
14
- import { getRebuyConfig } from '~/utils/getRebuyConfig';
15
-
16
- const RebuyHydrogenContext = ({
17
- cartAttributes,
18
- cartCost,
19
- cartId,
20
- cartLines,
21
- cartNote,
22
- cartQuantity,
23
- children,
24
- }: RebuyHydrogenProps) => {
25
- const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
26
- const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
27
- const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
28
-
29
- const [rebuyConfig, setRebuyConfig] = useState<RebuyConfig | null>(null);
30
- const location = useLocation();
31
- const queryObject = Utilities.queryStringToObject(location.search);
32
- const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
33
-
34
- // Initialization
35
- useEffect(() => {
36
- const initConfig = async () => {
37
- const config = await getRebuyConfig(rebuyKey, storeDomain);
38
- setRebuyConfig(config);
39
- };
40
-
41
- if (!rebuyConfig?.shop) {
42
- initConfig();
43
- }
44
- }, [rebuyConfig, rebuyKey, storeDomain]);
45
-
46
- const contextParameters = useMemo(
47
- () =>
48
- createContextParameters({
49
- cacheKey: rebuyConfig?.shop?.cache_key,
50
- cartAttributes,
51
- cartId,
52
- cartLines,
53
- cartLinesLength: cartLines?.length,
54
- cartNote: cartNote as string,
55
- cartSubtotal: cartCost,
56
- cartTotalQuantity: cartQuantity,
57
- isHydrogenReact: false,
58
- queryObject,
59
- windowUrl,
60
- }),
61
- [
62
- rebuyConfig,
63
- windowUrl,
64
- queryObject,
65
- cartAttributes,
66
- cartCost,
67
- cartId,
68
- cartLines,
69
- cartQuantity,
70
- cartNote,
71
- ]
72
- );
73
-
74
- // Static reference (JSON) + memoization
75
- // ^ prevent re-rendering children when context params are unchanged
76
- const contextParametersJSON = JSON.stringify(contextParameters);
77
- const contextValue = useMemo(
78
- () => ({ contextParameters: JSON.parse(contextParametersJSON) }),
79
- [contextParametersJSON]
80
- );
81
-
82
- return (
83
- <RebuyContext.Provider value={contextValue}>
84
- {children}
85
- </RebuyContext.Provider>
86
- );
87
- };
88
-
89
- export const RebuyHydrogenContextProvider = ({
90
- cart,
91
- children,
92
- }: RebuyHydrogenContextProviderProps) => {
93
- return (
94
- <Await resolve={cart}>
95
- {(resolvedCart) => {
96
- const cart = resolvedCart as CartReturn;
97
- return (
98
- <RebuyHydrogenContext
99
- cartAttributes={cart?.attributes}
100
- cartCost={cart?.cost?.subtotalAmount?.amount}
101
- cartId={cart?.id}
102
- cartLines={cart?.lines?.nodes}
103
- cartNote={cart?.note}
104
- cartQuantity={cart?.totalQuantity}
105
- >
106
- {children}
107
- </RebuyHydrogenContext>
108
- );
109
- }}
110
- </Await>
111
- );
112
- };