@redotech/redo-hydrogen 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/package.json +1 -1
- package/src/components/redo-checkout-buttons.tsx +8 -7
- package/src/providers/redo-coverage-client.tsx +20 -4
- package/src/types.ts +3 -0
- package/src/utils/cart.ts +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CartReturn
|
|
1
|
+
import { CartReturn } from '@shopify/hydrogen';
|
|
2
2
|
import { ReactNode, DependencyList } from 'react';
|
|
3
3
|
import { ProductVariant } from '@shopify/hydrogen-react/storefront-api-types';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -8,8 +8,11 @@ type CartAttributeKey = string;
|
|
|
8
8
|
interface RedoCoverageClient {
|
|
9
9
|
enable(): Promise<boolean>;
|
|
10
10
|
disable(): Promise<boolean>;
|
|
11
|
+
get loading(): boolean;
|
|
11
12
|
get enabled(): boolean;
|
|
12
13
|
get price(): number;
|
|
14
|
+
get storeId(): string | undefined;
|
|
15
|
+
get cart(): CartReturn | undefined;
|
|
13
16
|
get cartProduct(): CartProductVariantFragment | undefined;
|
|
14
17
|
get cartAttribute(): CartAttributeKey | undefined;
|
|
15
18
|
}
|
|
@@ -36,8 +39,6 @@ declare const useRedoCoverageClient: () => RedoCoverageClient;
|
|
|
36
39
|
|
|
37
40
|
declare const RedoCheckoutButtons: (props: {
|
|
38
41
|
cart: CartReturn;
|
|
39
|
-
storefront: Storefront;
|
|
40
|
-
storeId: string;
|
|
41
42
|
children?: ReactNode;
|
|
42
43
|
onClick?: (enabled: boolean) => void;
|
|
43
44
|
}) => react_jsx_runtime.JSX.Element;
|
package/package.json
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
CartForm,
|
|
4
4
|
CartActionInput,
|
|
5
5
|
CartReturn,
|
|
6
|
-
Storefront,
|
|
7
6
|
} from "@shopify/hydrogen";
|
|
8
7
|
import { useRedoCoverageClient } from "../providers/redo-coverage-client";
|
|
9
8
|
import { CartInfoToEnable, RedoCoverageClient } from "../types";
|
|
@@ -89,14 +88,12 @@ const findAncestor = (
|
|
|
89
88
|
|
|
90
89
|
const RedoCheckoutButtons = (props: {
|
|
91
90
|
cart: CartReturn;
|
|
92
|
-
storefront: Storefront;
|
|
93
|
-
storeId: string;
|
|
94
91
|
children?: ReactNode;
|
|
95
92
|
onClick?: (enabled: boolean) => void;
|
|
96
93
|
}) => {
|
|
97
94
|
const redoCoverageClient = useRedoCoverageClient();
|
|
98
|
-
let cart =
|
|
99
|
-
let checkoutUrl = cart
|
|
95
|
+
let cart = redoCoverageClient.cart;
|
|
96
|
+
let checkoutUrl = redoCoverageClient.cart?.checkoutUrl || '/checkout';
|
|
100
97
|
let [redoProductToAdd, setRedoProductToAdd] =
|
|
101
98
|
useState<CartInfoToEnable | null>(null);
|
|
102
99
|
let [checkoutButtonsUI, setCheckoutButtonsUI] = useState<CheckoutButtonUIResponse | null>(
|
|
@@ -105,12 +102,16 @@ const RedoCheckoutButtons = (props: {
|
|
|
105
102
|
|
|
106
103
|
useEffect(() => {
|
|
107
104
|
(async () => {
|
|
108
|
-
|
|
105
|
+
if(!redoCoverageClient.storeId || !cart) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const buttons = await getButtonsToShow({ redoCoverageClient, cart, storeId: redoCoverageClient.storeId });
|
|
109
110
|
if(buttons) {
|
|
110
111
|
setCheckoutButtonsUI(buttons);
|
|
111
112
|
}
|
|
112
113
|
})();
|
|
113
|
-
}, [cart, redoCoverageClient.price]);
|
|
114
|
+
}, [cart, redoCoverageClient.price, redoCoverageClient.storeId]);
|
|
114
115
|
|
|
115
116
|
const wrapperClickHandler = async (e: MouseEvent) => {
|
|
116
117
|
let clickedElement = e.target as HTMLElement;
|
|
@@ -10,7 +10,7 @@ const DEFAULT_REDO_CONTEXT_VALUE: RedoContextValue = {
|
|
|
10
10
|
loading: true,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const RedoContext = createContext(DEFAULT_REDO_CONTEXT_VALUE);
|
|
13
|
+
const RedoContext = createContext<RedoContextValue>(DEFAULT_REDO_CONTEXT_VALUE);
|
|
14
14
|
|
|
15
15
|
const RedoProvider = ({
|
|
16
16
|
cart,
|
|
@@ -27,6 +27,10 @@ const RedoProvider = ({
|
|
|
27
27
|
const [loading, setLoading] = useState<boolean>(true);
|
|
28
28
|
|
|
29
29
|
useEffect(() => {
|
|
30
|
+
if(!cart) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
30
34
|
fetch(`https://${REDO_PUBLIC_API_HOSTNAME}/v2.2/stores/${storeId}/coverage-products`, {
|
|
31
35
|
method: 'POST',
|
|
32
36
|
headers: {
|
|
@@ -67,9 +71,12 @@ const RedoProvider = ({
|
|
|
67
71
|
let json = await res.json();
|
|
68
72
|
|
|
69
73
|
setLoading(false);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
|
|
75
|
+
if(!json?.coverageProducts?.[0]?.cartInfoToEnable) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setCartInfoToEnable(json.coverageProducts[0].cartInfoToEnable);
|
|
73
80
|
})
|
|
74
81
|
}, [cart]);
|
|
75
82
|
|
|
@@ -136,17 +143,26 @@ const useRedoCoverageClient = (): RedoCoverageClient => {
|
|
|
136
143
|
});
|
|
137
144
|
return true;
|
|
138
145
|
},
|
|
146
|
+
get loading() {
|
|
147
|
+
return redoContext.loading;
|
|
148
|
+
},
|
|
139
149
|
get enabled() {
|
|
140
150
|
return redoContext.enabled;
|
|
141
151
|
},
|
|
142
152
|
get price() {
|
|
143
153
|
return Number(redoContext.cartInfoToEnable?.selectedVariant.price.amount);
|
|
144
154
|
},
|
|
155
|
+
get cart() {
|
|
156
|
+
return redoContext.cart;
|
|
157
|
+
},
|
|
145
158
|
get cartProduct() {
|
|
146
159
|
return redoContext.cartInfoToEnable?.selectedVariant;
|
|
147
160
|
},
|
|
148
161
|
get cartAttribute() {
|
|
149
162
|
return redoContext.cartInfoToEnable?.cartAttribute
|
|
163
|
+
},
|
|
164
|
+
get storeId() {
|
|
165
|
+
return redoContext.storeId;
|
|
150
166
|
}
|
|
151
167
|
}
|
|
152
168
|
};
|
package/src/types.ts
CHANGED
|
@@ -10,8 +10,11 @@ type CartAttributeKey = string;
|
|
|
10
10
|
interface RedoCoverageClient {
|
|
11
11
|
enable(): Promise<boolean>;
|
|
12
12
|
disable(): Promise<boolean>;
|
|
13
|
+
get loading(): boolean;
|
|
13
14
|
get enabled(): boolean;
|
|
14
15
|
get price(): number;
|
|
16
|
+
get storeId(): string | undefined;
|
|
17
|
+
get cart(): CartReturn | undefined;
|
|
15
18
|
get cartProduct(): CartProductVariantFragment | undefined
|
|
16
19
|
get cartAttribute(): CartAttributeKey | undefined
|
|
17
20
|
}
|
package/src/utils/cart.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FetcherWithComponents, useFetcher } from "@remix-run/react";
|
|
2
2
|
import { CartInfoToEnable } from "../types";
|
|
3
3
|
import { CartForm, CartReturn } from "@shopify/hydrogen";
|
|
4
|
-
import { CartLine } from "@shopify/hydrogen-react/storefront-api-types";
|
|
5
4
|
import type { AppData } from '@remix-run/react/dist/data';
|
|
6
5
|
import React from 'react'
|
|
7
6
|
|