@shopify/shop-minis-react 0.3.4 → 0.4.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/dist/components/MinisContainer.js +11 -10
- package/dist/components/MinisContainer.js.map +1 -1
- package/dist/hooks/content/useContent.js +12 -18
- package/dist/hooks/content/useContent.js.map +1 -1
- package/dist/hooks/product/useCuratedProducts.js +9 -11
- package/dist/hooks/product/useCuratedProducts.js.map +1 -1
- package/dist/hooks/product/usePopularProducts.js +9 -11
- package/dist/hooks/product/usePopularProducts.js.map +1 -1
- package/dist/hooks/product/useProduct.js +11 -17
- package/dist/hooks/product/useProduct.js.map +1 -1
- package/dist/hooks/product/useProductList.js +10 -21
- package/dist/hooks/product/useProductList.js.map +1 -1
- package/dist/hooks/product/useProductLists.js +11 -13
- package/dist/hooks/product/useProductLists.js.map +1 -1
- package/dist/hooks/product/useProductMedia.js +12 -18
- package/dist/hooks/product/useProductMedia.js.map +1 -1
- package/dist/hooks/product/useProductSearch.js +34 -27
- package/dist/hooks/product/useProductSearch.js.map +1 -1
- package/dist/hooks/product/useProductVariants.js +11 -14
- package/dist/hooks/product/useProductVariants.js.map +1 -1
- package/dist/hooks/product/useProducts.js +12 -11
- package/dist/hooks/product/useProducts.js.map +1 -1
- package/dist/hooks/product/useRecommendedProducts.js +11 -13
- package/dist/hooks/product/useRecommendedProducts.js.map +1 -1
- package/dist/hooks/shop/useRecommendedShops.js +11 -13
- package/dist/hooks/shop/useRecommendedShops.js.map +1 -1
- package/dist/hooks/shop/useShop.js +12 -11
- package/dist/hooks/shop/useShop.js.map +1 -1
- package/dist/hooks/user/useBuyerAttributes.js +8 -10
- package/dist/hooks/user/useBuyerAttributes.js.map +1 -1
- package/dist/hooks/user/useCurrentUser.js +7 -9
- package/dist/hooks/user/useCurrentUser.js.map +1 -1
- package/dist/hooks/user/useFollowedShops.js +11 -14
- package/dist/hooks/user/useFollowedShops.js.map +1 -1
- package/dist/hooks/user/useOrders.js +7 -9
- package/dist/hooks/user/useOrders.js.map +1 -1
- package/dist/hooks/user/useRecentProducts.js +11 -13
- package/dist/hooks/user/useRecentProducts.js.map +1 -1
- package/dist/hooks/user/useRecentShops.js +10 -13
- package/dist/hooks/user/useRecentShops.js.map +1 -1
- package/dist/hooks/user/useSavedProducts.js +10 -13
- package/dist/hooks/user/useSavedProducts.js.map +1 -1
- package/dist/internal/reactQuery/MinisQueryProvider.js +11 -0
- package/dist/internal/reactQuery/MinisQueryProvider.js.map +1 -0
- package/dist/internal/reactQuery/queryClient.js +33 -0
- package/dist/internal/reactQuery/queryClient.js.map +1 -0
- package/dist/internal/reactQuery/useShopActionInfiniteQuery.js +52 -0
- package/dist/internal/reactQuery/useShopActionInfiniteQuery.js.map +1 -0
- package/dist/internal/reactQuery/useShopActionQuery.js +37 -0
- package/dist/internal/reactQuery/useShopActionQuery.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/focusManager.js +45 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/focusManager.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js +89 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.js +55 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/mutation.js +198 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/mutation.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/mutationCache.js +99 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/mutationCache.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/notifyManager.js +67 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/notifyManager.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/onlineManager.js +39 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/onlineManager.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/query.js +299 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/query.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryCache.js +80 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryCache.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryClient.js +215 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryClient.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryObserver.js +300 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/queryObserver.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/removable.js +25 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/removable.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/retryer.js +76 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/retryer.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/subscribable.js +21 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/subscribable.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/thenable.js +26 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/thenable.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/utils.js +176 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_query-core@5.86.0/node_modules/@tanstack/query-core/build/modern/utils.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js +7 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js +17 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js +19 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js +21 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/suspense.js +18 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/suspense.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js +64 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useInfiniteQuery.js +13 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useInfiniteQuery.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useQuery.js +9 -0
- package/dist/shop-minis-react/node_modules/.pnpm/@tanstack_react-query@5.86.0_react@19.1.0/node_modules/@tanstack/react-query/build/modern/useQuery.js.map +1 -0
- package/package.json +2 -7
- package/src/components/MinisContainer.tsx +6 -3
- package/src/hooks/content/useContent.ts +6 -17
- package/src/hooks/product/useCuratedProducts.ts +4 -6
- package/src/hooks/product/usePopularProducts.ts +4 -6
- package/src/hooks/product/useProduct.ts +6 -17
- package/src/hooks/product/useProductList.ts +4 -19
- package/src/hooks/product/useProductLists.ts +4 -6
- package/src/hooks/product/useProductMedia.ts +6 -17
- package/src/hooks/product/useProductSearch.ts +19 -15
- package/src/hooks/product/useProductVariants.ts +5 -13
- package/src/hooks/product/useProducts.ts +8 -12
- package/src/hooks/product/useRecommendedProducts.ts +4 -6
- package/src/hooks/shop/useRecommendedShops.ts +4 -6
- package/src/hooks/shop/useShop.ts +8 -12
- package/src/hooks/user/useBuyerAttributes.ts +4 -6
- package/src/hooks/user/useCurrentUser.ts +4 -6
- package/src/hooks/user/useFollowedShops.ts +5 -13
- package/src/hooks/user/useOrders.ts +4 -6
- package/src/hooks/user/useRecentProducts.ts +4 -6
- package/src/hooks/user/useRecentShops.ts +5 -13
- package/src/hooks/user/useSavedProducts.ts +5 -13
- package/src/internal/reactQuery/MinisQueryProvider.test.tsx +38 -0
- package/src/internal/reactQuery/MinisQueryProvider.tsx +16 -0
- package/src/internal/reactQuery/index.ts +8 -0
- package/src/internal/reactQuery/queryClient.test.tsx +91 -0
- package/src/internal/reactQuery/queryClient.ts +43 -0
- package/src/internal/reactQuery/useShopActionInfiniteQuery.test.tsx +357 -0
- package/src/internal/reactQuery/useShopActionInfiniteQuery.ts +129 -0
- package/src/internal/reactQuery/useShopActionQuery.test.tsx +184 -0
- package/src/internal/reactQuery/useShopActionQuery.ts +74 -0
- package/dist/internal/useShopActionsDataFetching.js +0 -79
- package/dist/internal/useShopActionsDataFetching.js.map +0 -1
- package/dist/internal/useShopActionsPaginatedDataFetching.js +0 -96
- package/dist/internal/useShopActionsPaginatedDataFetching.js.map +0 -1
- package/src/hooks/product/useProductSearch.test.ts +0 -470
- package/src/internal/useShopActionsDataFetching.test.ts +0 -465
- package/src/internal/useShopActionsDataFetching.ts +0 -150
- package/src/internal/useShopActionsPaginatedDataFetching.ts +0 -188
- package/src/stories/Accordion.stories.tsx +0 -124
- package/src/stories/AddToCart.stories.tsx +0 -251
- package/src/stories/Alert.stories.tsx +0 -38
- package/src/stories/AlertDialog.stories.tsx +0 -48
- package/src/stories/Avatar.stories.tsx +0 -29
- package/src/stories/Badge.stories.tsx +0 -46
- package/src/stories/Button.stories.tsx +0 -81
- package/src/stories/Card.stories.tsx +0 -40
- package/src/stories/Checkbox.stories.tsx +0 -44
- package/src/stories/FavoriteButton.stories.tsx +0 -58
- package/src/stories/IconButton.stories.tsx +0 -68
- package/src/stories/ImageContentWrapper.stories.tsx +0 -65
- package/src/stories/Input.stories.tsx +0 -44
- package/src/stories/Label.stories.tsx +0 -19
- package/src/stories/List.stories.tsx +0 -64
- package/src/stories/MerchantCard.stories.tsx +0 -127
- package/src/stories/ProductCard.stories.tsx +0 -92
- package/src/stories/ProductLink.stories.tsx +0 -46
- package/src/stories/ProductVariantPrice.stories.tsx +0 -70
- package/src/stories/Progress.stories.tsx +0 -30
- package/src/stories/PullToRefreshList.stories.tsx +0 -122
- package/src/stories/QuantitySelector.stories.tsx +0 -78
- package/src/stories/RadioGroup.stories.tsx +0 -51
- package/src/stories/Search.stories.tsx +0 -37
- package/src/stories/Select.stories.tsx +0 -85
- package/src/stories/Skeleton.stories.tsx +0 -19
- package/src/stories/TextInput.stories.tsx +0 -26
- package/src/stories/Toaster.stories.tsx +0 -46
- package/src/stories/Touchable.stories.tsx +0 -40
- package/src/stories/VideoPlayer.stories.tsx +0 -129
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import {useCallback, useEffect, useMemo, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ShopAction, PaginationInfo} from '@shopify/shop-minis-platform/actions'
|
|
4
|
-
|
|
5
|
-
import {DataHookFetchPolicy, PaginatedDataHookReturnsBase} from '../types'
|
|
6
|
-
import {formatError, MiniError} from '../utils/errors'
|
|
7
|
-
|
|
8
|
-
export interface ShopActionsDataFetchingResult<S>
|
|
9
|
-
extends PaginatedDataHookReturnsBase {
|
|
10
|
-
data: S | null
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const useShopActionsPaginatedDataFetching = <
|
|
14
|
-
S = unknown,
|
|
15
|
-
P extends {after?: string; fetchPolicy?: DataHookFetchPolicy} = {
|
|
16
|
-
after?: undefined
|
|
17
|
-
fetchPolicy?: DataHookFetchPolicy
|
|
18
|
-
},
|
|
19
|
-
>(
|
|
20
|
-
action: ShopAction<P, {data: S; pageInfo: PaginationInfo}>,
|
|
21
|
-
params: P,
|
|
22
|
-
options: {
|
|
23
|
-
skip?: boolean
|
|
24
|
-
hook?: string
|
|
25
|
-
validator?: (data: S) => void
|
|
26
|
-
}
|
|
27
|
-
): ShopActionsDataFetchingResult<S> => {
|
|
28
|
-
const [state, setState] = useState<{
|
|
29
|
-
data: S | null
|
|
30
|
-
pageInfo: PaginationInfo
|
|
31
|
-
loading: boolean
|
|
32
|
-
error: Error | null
|
|
33
|
-
}>({
|
|
34
|
-
data: null,
|
|
35
|
-
pageInfo: {hasNextPage: false, endCursor: null},
|
|
36
|
-
loading: false,
|
|
37
|
-
error: null,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const skip = options?.skip === true
|
|
41
|
-
const {validator, hook} = options
|
|
42
|
-
const runValidator = useCallback(
|
|
43
|
-
(dataToValidate: S): Error | null => {
|
|
44
|
-
try {
|
|
45
|
-
validator?.(dataToValidate)
|
|
46
|
-
return null
|
|
47
|
-
} catch (err) {
|
|
48
|
-
if (err instanceof Error) return err
|
|
49
|
-
|
|
50
|
-
return new MiniError({
|
|
51
|
-
hook,
|
|
52
|
-
message: 'Validation failed',
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
[validator, hook]
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
// Params object is recreated on every render, so we need to memoize it.
|
|
60
|
-
// We don't know what's inside the params object, but we can stringify it.
|
|
61
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
-
const stableParams = useMemo(() => params, [JSON.stringify(params)])
|
|
63
|
-
|
|
64
|
-
// There's a lot of complexity here because each type of fetch has different side effects if we are trying to
|
|
65
|
-
// stay close to how Apollo client works. eg:
|
|
66
|
-
// - Initial fetch: set loading, set error, set data, reset on error (don't throw)
|
|
67
|
-
// - change params fetch: set loading, set error, set data, reset on error (don't throw)
|
|
68
|
-
// - refetch fetch: don't set loading, set error, update data, leave data as is was on error (also throw)
|
|
69
|
-
// - fetchMore fetch: don't set loading, don't set error, update data, leave data as is was on error (also throw)
|
|
70
|
-
const fetch = useCallback(
|
|
71
|
-
async (
|
|
72
|
-
extraParams?: Partial<P>,
|
|
73
|
-
{
|
|
74
|
-
setLoading = true,
|
|
75
|
-
setError = true,
|
|
76
|
-
resetOnError = true,
|
|
77
|
-
throwOnError = true,
|
|
78
|
-
appendData = false,
|
|
79
|
-
}: {
|
|
80
|
-
setLoading?: boolean
|
|
81
|
-
setError?: boolean
|
|
82
|
-
resetOnError?: boolean
|
|
83
|
-
throwOnError?: boolean
|
|
84
|
-
appendData?: boolean
|
|
85
|
-
} = {}
|
|
86
|
-
) => {
|
|
87
|
-
let queryError: Error | null = null
|
|
88
|
-
let validationError: Error | null = null
|
|
89
|
-
|
|
90
|
-
setState(curState => ({
|
|
91
|
-
...curState,
|
|
92
|
-
loading: setLoading ? true : curState.loading,
|
|
93
|
-
}))
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const result = await action({...stableParams, ...extraParams})
|
|
97
|
-
|
|
98
|
-
if (result.ok) {
|
|
99
|
-
validationError = runValidator(result.data.data)
|
|
100
|
-
|
|
101
|
-
setState(curState => {
|
|
102
|
-
let newData = result.data.data
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
appendData &&
|
|
106
|
-
curState.data &&
|
|
107
|
-
Array.isArray(curState.data) &&
|
|
108
|
-
Array.isArray(result.data.data)
|
|
109
|
-
) {
|
|
110
|
-
newData = [...curState.data, ...result.data.data] as S
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
...curState,
|
|
115
|
-
data: newData,
|
|
116
|
-
pageInfo: result.data.pageInfo,
|
|
117
|
-
loading: false,
|
|
118
|
-
error: validationError ?? null,
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
} else {
|
|
122
|
-
throw result.error
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
console.log('caught 1', err)
|
|
126
|
-
queryError = formatError({hook}, err)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const error = validationError || queryError
|
|
130
|
-
|
|
131
|
-
if (error && (setError || resetOnError)) {
|
|
132
|
-
setState(curState => ({
|
|
133
|
-
data: resetOnError ? null : curState.data,
|
|
134
|
-
pageInfo: resetOnError
|
|
135
|
-
? {hasNextPage: false, endCursor: null}
|
|
136
|
-
: curState.pageInfo,
|
|
137
|
-
loading: false,
|
|
138
|
-
error,
|
|
139
|
-
}))
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (error && throwOnError) {
|
|
143
|
-
throw error
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
[action, stableParams, hook, runValidator]
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
const refetch = useCallback(async () => {
|
|
150
|
-
await fetch({fetchPolicy: 'network-only'} as Partial<P>, {
|
|
151
|
-
setLoading: false,
|
|
152
|
-
resetOnError: false,
|
|
153
|
-
throwOnError: true,
|
|
154
|
-
})
|
|
155
|
-
}, [fetch])
|
|
156
|
-
|
|
157
|
-
const fetchMore = useCallback(async () => {
|
|
158
|
-
if (!state.pageInfo.hasNextPage || !state.pageInfo.endCursor) return
|
|
159
|
-
|
|
160
|
-
await fetch({after: state.pageInfo.endCursor} as Partial<P>, {
|
|
161
|
-
setLoading: false,
|
|
162
|
-
setError: false,
|
|
163
|
-
resetOnError: false,
|
|
164
|
-
throwOnError: true,
|
|
165
|
-
appendData: true,
|
|
166
|
-
})
|
|
167
|
-
}, [state.pageInfo.hasNextPage, state.pageInfo.endCursor, fetch])
|
|
168
|
-
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
if (skip) return
|
|
171
|
-
|
|
172
|
-
fetch(
|
|
173
|
-
{},
|
|
174
|
-
{
|
|
175
|
-
throwOnError: false,
|
|
176
|
-
}
|
|
177
|
-
)
|
|
178
|
-
}, [fetch, skip])
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
data: state.data,
|
|
182
|
-
loading: state.loading,
|
|
183
|
-
error: state.error,
|
|
184
|
-
hasNextPage: state.pageInfo.hasNextPage,
|
|
185
|
-
refetch,
|
|
186
|
-
fetchMore,
|
|
187
|
-
}
|
|
188
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Accordion,
|
|
3
|
-
AccordionContent,
|
|
4
|
-
AccordionItem,
|
|
5
|
-
AccordionTrigger,
|
|
6
|
-
} from '../components/ui/accordion'
|
|
7
|
-
|
|
8
|
-
import type {Meta, StoryObj} from '@storybook/react-vite'
|
|
9
|
-
|
|
10
|
-
const meta = {
|
|
11
|
-
title: 'UI/Accordion',
|
|
12
|
-
component: Accordion,
|
|
13
|
-
parameters: {},
|
|
14
|
-
args: {
|
|
15
|
-
type: 'single',
|
|
16
|
-
collapsible: false,
|
|
17
|
-
},
|
|
18
|
-
tags: ['autodocs'],
|
|
19
|
-
} satisfies Meta<typeof Accordion>
|
|
20
|
-
|
|
21
|
-
export default meta
|
|
22
|
-
type Story = StoryObj<typeof meta>
|
|
23
|
-
|
|
24
|
-
export const NonCollapsible: Story = {
|
|
25
|
-
args: {
|
|
26
|
-
type: 'single',
|
|
27
|
-
collapsible: false,
|
|
28
|
-
},
|
|
29
|
-
render: args => (
|
|
30
|
-
<Accordion {...args}>
|
|
31
|
-
<AccordionItem value="item-2">
|
|
32
|
-
<AccordionTrigger>Can i collapse this?</AccordionTrigger>
|
|
33
|
-
<AccordionContent>
|
|
34
|
-
No. When you set the collapsible prop to false, the accordion is not
|
|
35
|
-
collapsible.
|
|
36
|
-
</AccordionContent>
|
|
37
|
-
</AccordionItem>
|
|
38
|
-
</Accordion>
|
|
39
|
-
),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const Collapsible: Story = {
|
|
43
|
-
args: {
|
|
44
|
-
type: 'single',
|
|
45
|
-
collapsible: true,
|
|
46
|
-
},
|
|
47
|
-
render: args => (
|
|
48
|
-
<Accordion {...args}>
|
|
49
|
-
<AccordionItem value="item-2">
|
|
50
|
-
<AccordionTrigger>Can i collapse this?</AccordionTrigger>
|
|
51
|
-
<AccordionContent>
|
|
52
|
-
Yes. When you set the collapsible prop to true, you can collapse the
|
|
53
|
-
</AccordionContent>
|
|
54
|
-
</AccordionItem>
|
|
55
|
-
</Accordion>
|
|
56
|
-
),
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const Single: Story = {
|
|
60
|
-
args: {
|
|
61
|
-
type: 'single',
|
|
62
|
-
},
|
|
63
|
-
render: args => (
|
|
64
|
-
<Accordion {...args}>
|
|
65
|
-
<AccordionItem value="item-1">
|
|
66
|
-
<AccordionTrigger>Single item only</AccordionTrigger>
|
|
67
|
-
<AccordionContent>
|
|
68
|
-
With the single type, only one item can be open at a time.
|
|
69
|
-
</AccordionContent>
|
|
70
|
-
</AccordionItem>
|
|
71
|
-
<AccordionItem value="item-2">
|
|
72
|
-
<AccordionTrigger>Another item</AccordionTrigger>
|
|
73
|
-
<AccordionContent>
|
|
74
|
-
Opening this item will close the previous one.
|
|
75
|
-
</AccordionContent>
|
|
76
|
-
</AccordionItem>
|
|
77
|
-
</Accordion>
|
|
78
|
-
),
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const Multiple: Story = {
|
|
82
|
-
args: {
|
|
83
|
-
type: 'multiple',
|
|
84
|
-
},
|
|
85
|
-
render: args => (
|
|
86
|
-
<Accordion {...args}>
|
|
87
|
-
<AccordionItem value="item-1">
|
|
88
|
-
<AccordionTrigger>Can I open multiple items?</AccordionTrigger>
|
|
89
|
-
<AccordionContent>
|
|
90
|
-
Yes, you can open multiple items at the same time with the multiple
|
|
91
|
-
type.
|
|
92
|
-
</AccordionContent>
|
|
93
|
-
</AccordionItem>
|
|
94
|
-
<AccordionItem value="item-2">
|
|
95
|
-
<AccordionTrigger>Is it customizable?</AccordionTrigger>
|
|
96
|
-
<AccordionContent>
|
|
97
|
-
Yes, you can customize the styling and behavior to match your needs.
|
|
98
|
-
</AccordionContent>
|
|
99
|
-
</AccordionItem>
|
|
100
|
-
<AccordionItem value="item-1">
|
|
101
|
-
<AccordionTrigger>Long content example</AccordionTrigger>
|
|
102
|
-
<AccordionContent>
|
|
103
|
-
<div className="space-y-4">
|
|
104
|
-
<p>
|
|
105
|
-
This is a longer content example that demonstrates how the
|
|
106
|
-
accordion handles substantial amounts of text and content.
|
|
107
|
-
</p>
|
|
108
|
-
<p>
|
|
109
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
110
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
111
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
112
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
113
|
-
</p>
|
|
114
|
-
<ul className="list-disc list-inside space-y-1">
|
|
115
|
-
<li>First item in the list</li>
|
|
116
|
-
<li>Second item in the list</li>
|
|
117
|
-
<li>Third item in the list</li>
|
|
118
|
-
</ul>
|
|
119
|
-
</div>
|
|
120
|
-
</AccordionContent>
|
|
121
|
-
</AccordionItem>
|
|
122
|
-
</Accordion>
|
|
123
|
-
),
|
|
124
|
-
}
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import {Product} from '@shopify/shop-minis-platform'
|
|
2
|
-
|
|
3
|
-
import {AddToCartButton} from '../components/commerce/add-to-cart'
|
|
4
|
-
|
|
5
|
-
import type {Meta, StoryObj} from '@storybook/react-vite'
|
|
6
|
-
|
|
7
|
-
// Mock product for stories
|
|
8
|
-
const mockProduct: Product = {
|
|
9
|
-
id: 'gid://shopify/Product/123',
|
|
10
|
-
title: 'Test Product',
|
|
11
|
-
reviewAnalytics: {
|
|
12
|
-
averageRating: 4.5,
|
|
13
|
-
reviewCount: 100,
|
|
14
|
-
},
|
|
15
|
-
shop: {
|
|
16
|
-
id: 'gid://shopify/Shop/1',
|
|
17
|
-
name: 'Test Shop',
|
|
18
|
-
},
|
|
19
|
-
defaultVariantId: 'gid://shopify/ProductVariant/456',
|
|
20
|
-
isFavorited: false,
|
|
21
|
-
price: {
|
|
22
|
-
amount: '29.99',
|
|
23
|
-
currencyCode: 'USD',
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const meta = {
|
|
28
|
-
title: 'Commerce/AddToCartButton',
|
|
29
|
-
component: AddToCartButton,
|
|
30
|
-
parameters: {},
|
|
31
|
-
tags: ['autodocs'],
|
|
32
|
-
argTypes: {
|
|
33
|
-
size: {
|
|
34
|
-
control: 'radio',
|
|
35
|
-
options: ['sm', 'default', 'lg'],
|
|
36
|
-
description: 'Button size',
|
|
37
|
-
},
|
|
38
|
-
disabled: {
|
|
39
|
-
control: 'boolean',
|
|
40
|
-
description: 'Whether the button is disabled',
|
|
41
|
-
},
|
|
42
|
-
className: {
|
|
43
|
-
control: 'text',
|
|
44
|
-
description: 'Additional CSS classes',
|
|
45
|
-
},
|
|
46
|
-
product: {
|
|
47
|
-
control: 'object',
|
|
48
|
-
description: 'The product object containing product details',
|
|
49
|
-
},
|
|
50
|
-
productVariantId: {
|
|
51
|
-
control: 'text',
|
|
52
|
-
description:
|
|
53
|
-
'The GID of the product variant (e.g. gid://shopify/ProductVariant/456)',
|
|
54
|
-
},
|
|
55
|
-
discountCodes: {
|
|
56
|
-
control: 'object',
|
|
57
|
-
description: 'Array of discount codes to apply',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
args: {
|
|
61
|
-
disabled: false,
|
|
62
|
-
size: 'default',
|
|
63
|
-
product: mockProduct,
|
|
64
|
-
productVariantId: 'gid://shopify/ProductVariant/456',
|
|
65
|
-
},
|
|
66
|
-
} satisfies Meta<typeof AddToCartButton>
|
|
67
|
-
|
|
68
|
-
export default meta
|
|
69
|
-
type Story = StoryObj<typeof meta>
|
|
70
|
-
|
|
71
|
-
export const Default: Story = {
|
|
72
|
-
args: {},
|
|
73
|
-
render: args => {
|
|
74
|
-
return <AddToCartButton {...args} />
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const SmallSize: Story = {
|
|
79
|
-
args: {
|
|
80
|
-
size: 'sm',
|
|
81
|
-
},
|
|
82
|
-
render: args => {
|
|
83
|
-
return <AddToCartButton {...args} />
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const LargeSize: Story = {
|
|
88
|
-
args: {
|
|
89
|
-
size: 'lg',
|
|
90
|
-
},
|
|
91
|
-
render: args => {
|
|
92
|
-
return <AddToCartButton {...args} />
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const WithDiscountCodes: Story = {
|
|
97
|
-
args: {
|
|
98
|
-
discountCodes: ['SUMMER20', 'FREESHIP'],
|
|
99
|
-
},
|
|
100
|
-
render: args => {
|
|
101
|
-
return (
|
|
102
|
-
<div className="space-y-2">
|
|
103
|
-
<p className="text-sm text-gray-600">
|
|
104
|
-
This button will apply discount codes:{' '}
|
|
105
|
-
{args.discountCodes?.join(', ')}
|
|
106
|
-
</p>
|
|
107
|
-
<AddToCartButton {...args} />
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export const Disabled: Story = {
|
|
114
|
-
args: {
|
|
115
|
-
disabled: true,
|
|
116
|
-
},
|
|
117
|
-
render: args => {
|
|
118
|
-
return <AddToCartButton {...args} />
|
|
119
|
-
},
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const ReferralProduct: Story = {
|
|
123
|
-
args: {
|
|
124
|
-
product: {...mockProduct, referral: true},
|
|
125
|
-
},
|
|
126
|
-
render: args => {
|
|
127
|
-
return (
|
|
128
|
-
<div className="space-y-2">
|
|
129
|
-
<p className="text-sm text-gray-600">
|
|
130
|
-
This is a referral product - button shows “View product”
|
|
131
|
-
instead
|
|
132
|
-
</p>
|
|
133
|
-
<AddToCartButton {...args} />
|
|
134
|
-
</div>
|
|
135
|
-
)
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const CustomStyling: Story = {
|
|
140
|
-
args: {
|
|
141
|
-
className: 'bg-purple-600 hover:bg-purple-700 text-white rounded-full px-8',
|
|
142
|
-
},
|
|
143
|
-
render: args => {
|
|
144
|
-
return (
|
|
145
|
-
<div className="space-y-2">
|
|
146
|
-
<p className="text-sm text-gray-600">
|
|
147
|
-
Custom styled button with additional classes
|
|
148
|
-
</p>
|
|
149
|
-
<AddToCartButton {...args} />
|
|
150
|
-
</div>
|
|
151
|
-
)
|
|
152
|
-
},
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export const AllSizes: Story = {
|
|
156
|
-
render: () => {
|
|
157
|
-
return (
|
|
158
|
-
<div className="flex flex-col items-center space-y-4">
|
|
159
|
-
<h3 className="text-lg font-semibold">Button Sizes</h3>
|
|
160
|
-
<div className="flex gap-4 items-center">
|
|
161
|
-
<AddToCartButton
|
|
162
|
-
product={mockProduct}
|
|
163
|
-
productVariantId="gid://shopify/ProductVariant/456"
|
|
164
|
-
size="sm"
|
|
165
|
-
/>
|
|
166
|
-
<AddToCartButton
|
|
167
|
-
product={mockProduct}
|
|
168
|
-
productVariantId="gid://shopify/ProductVariant/456"
|
|
169
|
-
size="default"
|
|
170
|
-
/>
|
|
171
|
-
<AddToCartButton
|
|
172
|
-
product={mockProduct}
|
|
173
|
-
productVariantId="gid://shopify/ProductVariant/456"
|
|
174
|
-
size="lg"
|
|
175
|
-
/>
|
|
176
|
-
</div>
|
|
177
|
-
</div>
|
|
178
|
-
)
|
|
179
|
-
},
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export const InteractiveExample: Story = {
|
|
183
|
-
render: () => {
|
|
184
|
-
const productA: Product = {
|
|
185
|
-
...mockProduct,
|
|
186
|
-
id: 'gid://shopify/Product/111',
|
|
187
|
-
title: 'Product A',
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const productB: Product = {
|
|
191
|
-
...mockProduct,
|
|
192
|
-
id: 'gid://shopify/Product/222',
|
|
193
|
-
title: 'Product B',
|
|
194
|
-
price: {
|
|
195
|
-
amount: '49.99',
|
|
196
|
-
currencyCode: 'USD',
|
|
197
|
-
},
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const productC: Product = {
|
|
201
|
-
...mockProduct,
|
|
202
|
-
id: 'gid://shopify/Product/333',
|
|
203
|
-
title: 'Product C',
|
|
204
|
-
price: {
|
|
205
|
-
amount: '19.99',
|
|
206
|
-
currencyCode: 'USD',
|
|
207
|
-
},
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return (
|
|
211
|
-
<div className="flex flex-col items-center space-y-6 p-8">
|
|
212
|
-
<div className="text-center">
|
|
213
|
-
<h3 className="text-lg font-semibold">Interactive Demo</h3>
|
|
214
|
-
<p className="text-sm text-gray-600 mt-2">
|
|
215
|
-
Click the buttons below to see the add to cart animation
|
|
216
|
-
</p>
|
|
217
|
-
</div>
|
|
218
|
-
|
|
219
|
-
<div className="grid gap-4">
|
|
220
|
-
<div className="text-center">
|
|
221
|
-
<p className="text-xs text-gray-500 mb-2">Product A</p>
|
|
222
|
-
<AddToCartButton
|
|
223
|
-
product={productA}
|
|
224
|
-
productVariantId="gid://shopify/ProductVariant/111"
|
|
225
|
-
/>
|
|
226
|
-
</div>
|
|
227
|
-
|
|
228
|
-
<div className="text-center">
|
|
229
|
-
<p className="text-xs text-gray-500 mb-2">
|
|
230
|
-
Product B (with discount)
|
|
231
|
-
</p>
|
|
232
|
-
<AddToCartButton
|
|
233
|
-
product={productB}
|
|
234
|
-
productVariantId="gid://shopify/ProductVariant/222"
|
|
235
|
-
discountCodes={['SAVE10']}
|
|
236
|
-
/>
|
|
237
|
-
</div>
|
|
238
|
-
|
|
239
|
-
<div className="text-center">
|
|
240
|
-
<p className="text-xs text-gray-500 mb-2">Product C (small size)</p>
|
|
241
|
-
<AddToCartButton
|
|
242
|
-
product={productC}
|
|
243
|
-
productVariantId="gid://shopify/ProductVariant/333"
|
|
244
|
-
size="sm"
|
|
245
|
-
/>
|
|
246
|
-
</div>
|
|
247
|
-
</div>
|
|
248
|
-
</div>
|
|
249
|
-
)
|
|
250
|
-
},
|
|
251
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {Alert, AlertTitle, AlertDescription} from '../components/ui/alert'
|
|
2
|
-
|
|
3
|
-
import type {Meta, StoryObj} from '@storybook/react-vite'
|
|
4
|
-
|
|
5
|
-
const meta = {
|
|
6
|
-
title: 'UI/Alert',
|
|
7
|
-
render: ({variant}) => (
|
|
8
|
-
<Alert variant={variant}>
|
|
9
|
-
<AlertTitle>Alert Title</AlertTitle>
|
|
10
|
-
<AlertDescription>
|
|
11
|
-
This is a default alert with a title and description.
|
|
12
|
-
</AlertDescription>
|
|
13
|
-
</Alert>
|
|
14
|
-
),
|
|
15
|
-
|
|
16
|
-
parameters: {},
|
|
17
|
-
tags: ['autodocs'],
|
|
18
|
-
argTypes: {
|
|
19
|
-
variant: {
|
|
20
|
-
control: 'radio',
|
|
21
|
-
options: ['default', 'destructive'],
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
} satisfies Meta<typeof Alert>
|
|
25
|
-
|
|
26
|
-
export default meta
|
|
27
|
-
type Story = StoryObj<typeof meta>
|
|
28
|
-
|
|
29
|
-
export const Default: Story = {
|
|
30
|
-
args: {
|
|
31
|
-
variant: 'default',
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
export const Destructive: Story = {
|
|
35
|
-
args: {
|
|
36
|
-
variant: 'destructive',
|
|
37
|
-
},
|
|
38
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {fn} from 'storybook/test'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
AlertDialog,
|
|
5
|
-
AlertDialogAction,
|
|
6
|
-
AlertDialogCancel,
|
|
7
|
-
AlertDialogContent,
|
|
8
|
-
AlertDialogDescription,
|
|
9
|
-
AlertDialogFooter,
|
|
10
|
-
AlertDialogHeader,
|
|
11
|
-
AlertDialogTitle,
|
|
12
|
-
AlertDialogTrigger,
|
|
13
|
-
Button,
|
|
14
|
-
} from '../components'
|
|
15
|
-
|
|
16
|
-
import type {Meta, StoryObj} from '@storybook/react-vite'
|
|
17
|
-
|
|
18
|
-
const meta = {
|
|
19
|
-
title: 'Ui/AlertDialog',
|
|
20
|
-
render: () => (
|
|
21
|
-
<AlertDialog>
|
|
22
|
-
<AlertDialogTrigger asChild>
|
|
23
|
-
<Button variant="outline">Open Alert Dialog</Button>
|
|
24
|
-
</AlertDialogTrigger>
|
|
25
|
-
<AlertDialogContent>
|
|
26
|
-
<AlertDialogHeader>
|
|
27
|
-
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
|
|
28
|
-
<AlertDialogDescription>
|
|
29
|
-
This action cannot be undone.
|
|
30
|
-
</AlertDialogDescription>
|
|
31
|
-
</AlertDialogHeader>
|
|
32
|
-
<AlertDialogFooter>
|
|
33
|
-
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
34
|
-
<AlertDialogAction onClick={() => fn()}>Continue</AlertDialogAction>
|
|
35
|
-
</AlertDialogFooter>
|
|
36
|
-
</AlertDialogContent>
|
|
37
|
-
</AlertDialog>
|
|
38
|
-
),
|
|
39
|
-
parameters: {},
|
|
40
|
-
tags: ['autodocs'],
|
|
41
|
-
argTypes: {},
|
|
42
|
-
args: {},
|
|
43
|
-
} satisfies Meta<typeof AlertDialog>
|
|
44
|
-
|
|
45
|
-
export default meta
|
|
46
|
-
type Story = StoryObj<typeof meta>
|
|
47
|
-
|
|
48
|
-
export const Default: Story = {}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {Avatar, AvatarFallback, AvatarImage} from '../components/ui/avatar'
|
|
2
|
-
|
|
3
|
-
import type {StoryObj} from '@storybook/react-vite'
|
|
4
|
-
|
|
5
|
-
interface AvatarProps {
|
|
6
|
-
src: 'https://github.com/shadcn.png'
|
|
7
|
-
userInitials: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const meta = {
|
|
11
|
-
title: 'UI/Avatar',
|
|
12
|
-
render: ({userInitials}: AvatarProps) => (
|
|
13
|
-
<Avatar>
|
|
14
|
-
<AvatarImage src="https://github.com/shadcn.png" />
|
|
15
|
-
<AvatarFallback>{userInitials}</AvatarFallback>
|
|
16
|
-
</Avatar>
|
|
17
|
-
),
|
|
18
|
-
args: {
|
|
19
|
-
className: 'size-12',
|
|
20
|
-
src: 'https://github.com/shadcn.png',
|
|
21
|
-
userInitials: 'CN',
|
|
22
|
-
},
|
|
23
|
-
tags: ['autodocs'],
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default meta
|
|
27
|
-
type Story = StoryObj<typeof meta>
|
|
28
|
-
|
|
29
|
-
export const Default: Story = {}
|