@graphcommerce/magento-cart 8.1.0-canary.8 → 9.0.0-canary.100
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/Api/CartItemCountChanged.graphql +1 -1
- package/CHANGELOG.md +247 -54
- package/Config.graphqls +17 -0
- package/components/ApolloCartError/ApolloCartErrorAlert.tsx +1 -46
- package/components/CartAddress/CartAddress.graphql +1 -0
- package/components/CartAgreementsForm/CartAgreementsForm.tsx +60 -33
- package/components/CartFab/CartFab.tsx +7 -1
- package/components/CartStartCheckout/CartStartCheckout.graphql +1 -1
- package/components/CartStartCheckout/CartStartCheckout.tsx +23 -7
- package/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +4 -2
- package/components/CartTotals/CartTotals.graphql +8 -4
- package/components/CartTotals/CartTotals.tsx +9 -6
- package/components/EmptyCart/EmptyCart.tsx +8 -4
- package/components/InlineAccount/InlineAccount.tsx +6 -6
- package/components/OrderSucces/OrderSuccesPage.graphql +1 -1
- package/hooks/index.ts +5 -3
- package/hooks/useCartPermissions.ts +21 -0
- package/hooks/useCartQuery.ts +24 -3
- package/hooks/useCheckoutPermissions.ts +21 -0
- package/hooks/useFormGqlMutationCart.ts +40 -3
- package/index.ts +4 -3
- package/link/{createCartErrorLink.ts → cartLink.ts} +60 -4
- package/link/isProtectedCartOperation.ts +5 -0
- package/package.json +16 -15
- package/plugins/MagentoCartGraphqlProvider.tsx +15 -3
- package/plugins/useSignInFormMergeCart.ts +8 -7
- package/typePolicies.ts +1 -0
- package/utils/cartPermissions.ts +23 -0
- package/utils/checkoutPermissions.ts +13 -0
- package/utils/index.ts +2 -0
- package/hooks/CurrentCartId.graphqls +0 -12
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
|
-
import type { useSignInForm } from '@graphcommerce/magento-customer'
|
|
3
|
-
import type {
|
|
2
|
+
import type { useSignInForm as useSignInFormType } from '@graphcommerce/magento-customer'
|
|
3
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
4
4
|
import { cartLock, readCartId, useAssignCurrentCartId } from '../hooks'
|
|
5
5
|
import { CustomerCartDocument } from '../hooks/CustomerCart.gql'
|
|
6
6
|
import { MergeCartsDocument } from '../hooks/MergeCarts.gql'
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
|
|
8
|
+
export const config: PluginConfig = {
|
|
9
|
+
type: 'function',
|
|
10
|
+
module: '@graphcommerce/magento-customer',
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
const
|
|
13
|
+
export const useSignInForm: FunctionPlugin<typeof useSignInFormType> = (useSignInForm, options) => {
|
|
12
14
|
const client = useApolloClient()
|
|
13
15
|
const assignCurrentCartId = useAssignCurrentCartId()
|
|
14
16
|
|
|
@@ -16,6 +18,7 @@ const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInFor
|
|
|
16
18
|
...options,
|
|
17
19
|
onComplete: async (data, variables) => {
|
|
18
20
|
await options.onComplete?.(data, variables)
|
|
21
|
+
if (data.errors) return
|
|
19
22
|
|
|
20
23
|
cartLock(client.cache, true)
|
|
21
24
|
|
|
@@ -46,5 +49,3 @@ const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInFor
|
|
|
46
49
|
},
|
|
47
50
|
})
|
|
48
51
|
}
|
|
49
|
-
|
|
50
|
-
export const plugin = useSignInFormMergeCart
|
package/typePolicies.ts
CHANGED
|
@@ -24,6 +24,7 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
|
|
|
24
24
|
return merged ? [merged] : []
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
|
+
items: { merge: (_, incoming) => incoming },
|
|
27
28
|
prices: {
|
|
28
29
|
merge: (existing: CartPrices[] | undefined, incoming: CartPrices[], options) =>
|
|
29
30
|
options.mergeObjects(existing ?? {}, incoming),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { storefrontConfig } from '@graphcommerce/next-ui'
|
|
2
|
+
|
|
3
|
+
function getCartPermissions(locale: string | undefined) {
|
|
4
|
+
return (
|
|
5
|
+
storefrontConfig(locale)?.permissions?.cart ??
|
|
6
|
+
import.meta.graphCommerce.permissions?.cart ??
|
|
7
|
+
'ENABLED'
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getCartDisabled(locale: string | undefined) {
|
|
12
|
+
return getCartPermissions(locale) === 'DISABLED'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getCartGuestEnabled(locale: string | undefined) {
|
|
16
|
+
return getCartPermissions(locale) === 'ENABLED'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getCartEnabledForUser(locale: string | undefined, loggedIn: () => boolean) {
|
|
20
|
+
if (getCartGuestEnabled(locale)) return true
|
|
21
|
+
if (getCartDisabled(locale)) return false
|
|
22
|
+
return !!loggedIn()
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { storefrontConfig } from '@graphcommerce/next-ui'
|
|
2
|
+
|
|
3
|
+
function getCheckoutPermission(locale: string | undefined) {
|
|
4
|
+
return (
|
|
5
|
+
storefrontConfig(locale)?.permissions?.checkout ??
|
|
6
|
+
import.meta.graphCommerce.permissions?.checkout ??
|
|
7
|
+
'ENABLED'
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getCheckoutIsDisabled(locale: string | undefined) {
|
|
12
|
+
return getCheckoutPermission(locale) === 'DISABLED'
|
|
13
|
+
}
|
package/utils/index.ts
ADDED