diff --git a/.changeset/late-cats-jump.md b/.changeset/late-cats-jump.md new file mode 100644 index 0000000000..77817f3594 --- /dev/null +++ b/.changeset/late-cats-jump.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/ecommerce-ui': patch +--- + +`` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart diff --git a/.changeset/mighty-humans-listen.md b/.changeset/mighty-humans-listen.md new file mode 100644 index 0000000000..5fce194f9a --- /dev/null +++ b/.changeset/mighty-humans-listen.md @@ -0,0 +1,7 @@ +--- +'@graphcommerce/magento-cart-shipping-address': patch +'@graphcommerce/magento-newsletter': patch +'@graphcommerce/magento-cart': patch +--- + +Deprecate the allowUrl option for useCartQuery, it was already enabled by default and should never be set to false. diff --git a/.changeset/nice-bugs-push.md b/.changeset/nice-bugs-push.md new file mode 100644 index 0000000000..8f7c1aebdd --- /dev/null +++ b/.changeset/nice-bugs-push.md @@ -0,0 +1,6 @@ +--- +"@graphcommerce/magento-cart": patch +"@graphcommerce/magento-customer": patch +--- + +Solve an issue where the user would be presented with the Session expired dialog when the user would be logging in during the checkout process. diff --git a/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx b/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx index 4f52af378b..247778db2d 100644 --- a/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx +++ b/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx @@ -1,3 +1,4 @@ +import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils' import { QueryResult } from '@graphcommerce/graphql' import React, { startTransition, useEffect, useState } from 'react' @@ -10,13 +11,13 @@ export type WaitForQueriesProps = { /** Shows the fallback during: SSR, Hydration and Query Loading. */ export const WaitForQueries = (props: WaitForQueriesProps) => { - const { waitFor, fallback, children, noSsr = false } = props + const { waitFor, fallback, children, noSsr = true } = props // Make sure the first render is always the same as the server. // Make sure we we use startTransition to make sure we don't get into trouble with Suspense. const [mounted, setMounted] = useState(!noSsr) useEffect(() => { - if (noSsr) startTransition(() => setMounted(true)) + if (noSsr) setMounted(true) }, [noSsr]) // We are done when all queries either have data or an error. diff --git a/packages/magento-cart-payment-method/hooks/useCartLock.ts b/packages/magento-cart-payment-method/hooks/useCartLock.ts index d687ce145f..38e666644f 100644 --- a/packages/magento-cart-payment-method/hooks/useCartLock.ts +++ b/packages/magento-cart-payment-method/hooks/useCartLock.ts @@ -1,4 +1,5 @@ -import { useCurrentCartId } from '@graphcommerce/magento-cart' +import { useApolloClient } from '@graphcommerce/graphql' +import { cartLock, useCurrentCartId } from '@graphcommerce/magento-cart' import { useUrlQuery } from '@graphcommerce/next-ui' import { useEffect, useState } from 'react' @@ -19,9 +20,10 @@ let justLocked = false * Todo: Block all operations on the cart while the cart is being blocked. */ export function useCartLock() { - const { currentCartId } = useCurrentCartId() + const { currentCartId, locked } = useCurrentCartId() const [queryState, setRouterQuery] = useUrlQuery() const [, setForceRender] = useState(0) + const client = useApolloClient() useEffect(() => { const pageshow = (e: PageTransitionEvent) => { @@ -38,6 +40,7 @@ export function useCartLock() { const lock = (params: Omit) => { if (!currentCartId) return undefined justLocked = true + cartLock(client.cache, true) return setRouterQuery({ locked: '1', cart_id: currentCartId, @@ -46,13 +49,14 @@ export function useCartLock() { } const unlock = async (params: Omit) => { + cartLock(client.cache, false) await setRouterQuery({ cart_id: null, locked: null, method: null, ...params } as E) return queryState } const resulting: Omit & { locked: boolean; justLocked: boolean } = { ...queryState, - locked: queryState.locked === '1' || Boolean(queryState.PayerID), + locked: locked || queryState.locked === '1' || Boolean(queryState.PayerID), justLocked, } diff --git a/packages/magento-cart/components/CartDebugger/CartDebugger.tsx b/packages/magento-cart/components/CartDebugger/CartDebugger.tsx index 05152c3fb8..21f066e123 100644 --- a/packages/magento-cart/components/CartDebugger/CartDebugger.tsx +++ b/packages/magento-cart/components/CartDebugger/CartDebugger.tsx @@ -1,6 +1,6 @@ import { useApolloClient } from '@graphcommerce/graphql' import { Button } from '@mui/material' -import { CurrentCartIdDocument } from '../../hooks/CurrentCartId.gql' +import { readCartId, writeCartId } from '../../hooks' export function CartDebugger() { const client = useApolloClient() @@ -12,24 +12,14 @@ export function CartDebugger() { variant='text' size='small' onClick={() => { - const currentCardId = client.readQuery({ query: CurrentCartIdDocument }) - if (!currentCardId?.currentCartId) { + const currentCartId = readCartId(client.cache) + if (!currentCartId) { // eslint-disable-next-line no-console console.log('No customerToken available, nothing to break') } else { // eslint-disable-next-line no-console console.log(`Changing current token to a random one`) - - client.writeQuery({ - query: CurrentCartIdDocument, - data: { - currentCartId: { - ...currentCardId.currentCartId, - id: `${Math.random().toString(36).slice(2)}random-cardId`, - }, - }, - broadcast: true, - }) + writeCartId(client.cache, `${Math.random().toString(36).slice(2)}random-cardId`) } }} > diff --git a/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx b/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx index 82971603cb..4aa6e5c1af 100644 --- a/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx +++ b/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx @@ -38,10 +38,7 @@ type OrderSummaryProps = ActionCardLayoutProps & { export function CartItemSummary(props: OrderSummaryProps) { const { sx = [], size, layout = 'list', itemProps, ...cardLayout } = props - const { data } = useCartQuery(CartItemSummaryDocument, { - allowUrl: true, - fetchPolicy: 'cache-only', - }) + const { data } = useCartQuery(CartItemSummaryDocument, { fetchPolicy: 'cache-only' }) if (!data?.cart) return null @@ -85,7 +82,7 @@ export function CartItemSummary(props: OrderSummaryProps) { className={classes.scrollerContainer} {...cardLayout} > - {items?.filter(nonNullable).map((item) => ( + {(items ?? []).filter(nonNullable).map((item) => ( * @see https://github.com/magento/magento2/issues/33848 */ export function CartTotals(props: CartTotalsProps) { - const { data } = useCartQuery(GetCartTotalsDocument, { allowUrl: true }) + const { data } = useCartQuery(GetCartTotalsDocument) const { containerMargin, additionalSubtotals, additionalTotals, sx = [] } = props const classes = withState({ containerMargin }) diff --git a/packages/magento-cart/hooks/CurrentCartId.graphql b/packages/magento-cart/hooks/CurrentCartId.graphql index 0ed32d02f5..a8b4b8a3bf 100644 --- a/packages/magento-cart/hooks/CurrentCartId.graphql +++ b/packages/magento-cart/hooks/CurrentCartId.graphql @@ -2,5 +2,6 @@ query CurrentCartId { currentCartId @client { __typename id + locked } } diff --git a/packages/magento-cart/hooks/CurrentCartId.graphqls b/packages/magento-cart/hooks/CurrentCartId.graphqls index e9cee2a29c..4856711677 100644 --- a/packages/magento-cart/hooks/CurrentCartId.graphqls +++ b/packages/magento-cart/hooks/CurrentCartId.graphqls @@ -4,6 +4,7 @@ extend type Query { type CurrentCartId { id: String + locked: Boolean } input RegisterCartIdInput { diff --git a/packages/magento-cart/hooks/CustomerCart.graphql b/packages/magento-cart/hooks/CustomerCart.graphql index 3ce034a4e3..d055551c10 100644 --- a/packages/magento-cart/hooks/CustomerCart.graphql +++ b/packages/magento-cart/hooks/CustomerCart.graphql @@ -2,6 +2,5 @@ query CustomerCart { customerCart { id __typename - ...CartItemCountChanged } } diff --git a/packages/magento-cart/hooks/UseMergeCustomerCart.graphql b/packages/magento-cart/hooks/MergeCarts.graphql similarity index 50% rename from packages/magento-cart/hooks/UseMergeCustomerCart.graphql rename to packages/magento-cart/hooks/MergeCarts.graphql index 2ffb7fc8ad..9bb7d501e6 100644 --- a/packages/magento-cart/hooks/UseMergeCustomerCart.graphql +++ b/packages/magento-cart/hooks/MergeCarts.graphql @@ -1,7 +1,6 @@ -mutation UseMergeCustomerCart($sourceCartId: String!, $destinationCartId: String!) { +mutation MergeCarts($sourceCartId: String!, $destinationCartId: String!) { mergeCarts(source_cart_id: $sourceCartId, destination_cart_id: $destinationCartId) { __typename id - ...CartItemCountChanged } } diff --git a/packages/magento-cart/hooks/useAssignCurrentCartId.ts b/packages/magento-cart/hooks/useAssignCurrentCartId.ts index de62813bec..dfc3fb1213 100644 --- a/packages/magento-cart/hooks/useAssignCurrentCartId.ts +++ b/packages/magento-cart/hooks/useAssignCurrentCartId.ts @@ -8,11 +8,26 @@ export const CART_ID_COOKIE = 'cart' export function writeCartId(cache: ApolloCache, id: string | null = null) { cache.writeQuery({ query: CurrentCartIdDocument, - data: { currentCartId: { __typename: 'CurrentCartId', id } }, + data: { currentCartId: { __typename: 'CurrentCartId', locked: false, id } }, broadcast: true, }) } +export function readCartId(cache: ApolloCache) { + return cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId +} + +export function cartLock(cache: ApolloCache, locked: boolean) { + const currentCartId = cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId + if (currentCartId?.id && currentCartId.locked !== locked) { + cache.writeQuery({ + query: CurrentCartIdDocument, + data: { currentCartId: { ...currentCartId, locked } }, + broadcast: true, + }) + } +} + export function useAssignCurrentCartId() { const { cache } = useApolloClient() diff --git a/packages/magento-cart/hooks/useCartIdCreate.ts b/packages/magento-cart/hooks/useCartIdCreate.ts index 95d2395699..0cde1b5ed5 100644 --- a/packages/magento-cart/hooks/useCartIdCreate.ts +++ b/packages/magento-cart/hooks/useCartIdCreate.ts @@ -1,16 +1,14 @@ import { useApolloClient } from '@graphcommerce/graphql' import { i18n } from '@lingui/core' import { CreateEmptyCartDocument } from './CreateEmptyCart.gql' -import { CurrentCartIdDocument } from './CurrentCartId.gql' -import { useAssignCurrentCartId } from './useAssignCurrentCartId' +import { readCartId, useAssignCurrentCartId } from './useAssignCurrentCartId' export function useCartIdCreate() { const client = useApolloClient() const assignCurrentCartId = useAssignCurrentCartId() return async (): Promise => { - const currentCartId = client.cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId - ?.id + const currentCartId = readCartId(client.cache)?.id if (currentCartId) return currentCartId diff --git a/packages/magento-cart/hooks/useCartQuery.ts b/packages/magento-cart/hooks/useCartQuery.ts index d93e84d981..b62530fc68 100644 --- a/packages/magento-cart/hooks/useCartQuery.ts +++ b/packages/magento-cart/hooks/useCartQuery.ts @@ -15,18 +15,21 @@ import { useCurrentCartId } from './useCurrentCartId' export function useCartQuery( document: TypedDocumentNode, options: QueryHookOptions> & { + /** + * @deprecated Not used anymore, when the cart_id is in the URL, it will always be used. + */ allowUrl?: boolean } = {}, ) { - const { allowUrl = true, ...queryOptions } = options + const { allowUrl, ...queryOptions } = options const router = useRouter() - const { currentCartId } = useCurrentCartId() + const { currentCartId, locked } = useCurrentCartId() const urlCartId = router.query.cart_id - const usingUrl = allowUrl && typeof urlCartId === 'string' + const usingUrl = typeof urlCartId === 'string' const cartId = usingUrl ? urlCartId : currentCartId - if (usingUrl) queryOptions.fetchPolicy = 'cache-first' + if (usingUrl || locked) queryOptions.fetchPolicy = 'cache-only' if (usingUrl && typeof queryOptions.returnPartialData === 'undefined') queryOptions.returnPartialData = true @@ -34,10 +37,5 @@ export function useCartQuery) - - return { - ...result, - // error: called && !currentCartId ? noCartError : result.error, - } + return useQuery(document, queryOptions as QueryHookOptions) } diff --git a/packages/magento-cart/hooks/useClearCurrentCartId.ts b/packages/magento-cart/hooks/useClearCurrentCartId.ts index 5590918cba..a72adbc210 100644 --- a/packages/magento-cart/hooks/useClearCurrentCartId.ts +++ b/packages/magento-cart/hooks/useClearCurrentCartId.ts @@ -1,20 +1,12 @@ import { useApolloClient } from '@graphcommerce/graphql' import { cookie } from '@graphcommerce/next-ui' -import { CurrentCartIdDocument } from './CurrentCartId.gql' import { CART_ID_COOKIE } from './useAssignCurrentCartId' export function useClearCurrentCartId() { const { cache } = useApolloClient() return () => { - const id = cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId?.id - if (!id) return - - cache.writeQuery({ - query: CurrentCartIdDocument, - data: { currentCartId: { __typename: 'CurrentCartId', id: null } }, - broadcast: true, - }) + cache.evict({ fieldName: 'currentCartId', broadcast: true }) cookie(CART_ID_COOKIE, null) } } diff --git a/packages/magento-cart/hooks/useCurrentCartId.ts b/packages/magento-cart/hooks/useCurrentCartId.ts index 47fae36cda..a6da6b5e85 100644 --- a/packages/magento-cart/hooks/useCurrentCartId.ts +++ b/packages/magento-cart/hooks/useCurrentCartId.ts @@ -10,5 +10,10 @@ export function useCurrentCartId< V extends CurrentCartIdQueryVariables, >(options: QueryHookOptions = {}) { const queryResults = useQuery(CurrentCartIdDocument, options) - return { currentCartId: queryResults.data?.currentCartId?.id || '', ...queryResults } + + return { + currentCartId: queryResults.data?.currentCartId?.id || '', + locked: queryResults.data?.currentCartId?.locked || false, + ...queryResults, + } } diff --git a/packages/magento-cart/hooks/useMergeCustomerCart.ts b/packages/magento-cart/hooks/useMergeCustomerCart.ts index 7d704dd4db..d2d7399ca6 100644 --- a/packages/magento-cart/hooks/useMergeCustomerCart.ts +++ b/packages/magento-cart/hooks/useMergeCustomerCart.ts @@ -1,43 +1,6 @@ -import { useMutation } from '@graphcommerce/graphql' -import { useCustomerQuery } from '@graphcommerce/magento-customer' -import { useEffect } from 'react' -import { CustomerCartDocument } from './CustomerCart.gql' -import { UseMergeCustomerCartDocument } from './UseMergeCustomerCart.gql' -import { useAssignCurrentCartId } from './useAssignCurrentCartId' -import { useCurrentCartId } from './useCurrentCartId' - /** - * - Automatically assign the customer cart as the current cart - * - Merge the guest cart into the customer cart + * @deprecated Is replaced by the useSignInFormMergeCart plugin. */ export function useMergeCustomerCart() { - const { currentCartId } = useCurrentCartId() - const assignCurrentCartId = useAssignCurrentCartId() - const [merge] = useMutation(UseMergeCustomerCartDocument, { errorPolicy: 'all' }) - - const destinationCartId = useCustomerQuery(CustomerCartDocument, { fetchPolicy: 'network-only' }) - ?.data?.customerCart.id - - useEffect(() => { - // If we don't have a customer cart, we're done - // If the vistor cart is the same as the customer cart, we're done - if (!destinationCartId || currentCartId === destinationCartId) return - - // If the visitor has a guest cart, try merging it into the customer cart - if (currentCartId) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - merge({ variables: { sourceCartId: currentCartId, destinationCartId } }) - // We're not handling exceptions here: - // If the merge returns an error, we'll use the customer cart without merging the guest cart. - .catch((e) => { - console.error('Error merging carts', e) - }) - .finally(() => { - // Assign the customer cart as the new cart id - assignCurrentCartId(destinationCartId) - }) - } else { - assignCurrentCartId(destinationCartId) - } - }, [assignCurrentCartId, destinationCartId, merge, currentCartId]) + return null } diff --git a/packages/magento-cart/plugins/useSignInFormMergeCart.ts b/packages/magento-cart/plugins/useSignInFormMergeCart.ts new file mode 100644 index 0000000000..707da27be9 --- /dev/null +++ b/packages/magento-cart/plugins/useSignInFormMergeCart.ts @@ -0,0 +1,50 @@ +import { useApolloClient } from '@graphcommerce/graphql' +import type { useSignInForm } from '@graphcommerce/magento-customer/hooks/useSignInForm' +import type { MethodPlugin } from '@graphcommerce/next-config' +import { cartLock, readCartId, useAssignCurrentCartId } from '../hooks' +import { CustomerCartDocument } from '../hooks/CustomerCart.gql' +import { MergeCartsDocument } from '../hooks/MergeCarts.gql' + +export const func = 'useSignInForm' +export const exported = '@graphcommerce/magento-customer/hooks/useSignInForm' + +const useSignInFormMergeCart: MethodPlugin = (useSignInForm, options) => { + const client = useApolloClient() + const assignCurrentCartId = useAssignCurrentCartId() + + return useSignInForm({ + ...options, + onComplete: async (data, variables) => { + await options.onComplete?.(data, variables) + + cartLock(client.cache, true) + + const destinationCartId = ( + await client.query({ + query: CustomerCartDocument, + fetchPolicy: 'network-only', + }) + ).data.customerCart.id + + try { + const sourceCartId = readCartId(client.cache)?.id + if (sourceCartId && sourceCartId !== destinationCartId) { + await client.mutate({ + mutation: MergeCartsDocument, + variables: { sourceCartId, destinationCartId }, + }) + } + } catch (error) { + console.error( + 'Error merging carts, continuing without merging, this might cause issues.', + error, + ) + } finally { + // Assign the customer cart as the new cart id + assignCurrentCartId(destinationCartId) + } + }, + }) +} + +export const plugin = useSignInFormMergeCart diff --git a/packages/magento-cart/typePolicies.ts b/packages/magento-cart/typePolicies.ts index 5b37f34066..fc5cdacd54 100644 --- a/packages/magento-cart/typePolicies.ts +++ b/packages/magento-cart/typePolicies.ts @@ -2,7 +2,7 @@ import { ApolloCache, NormalizedCacheObject } from '@graphcommerce/graphql' import type { StrictTypedTypePolicies } from '@graphcommerce/graphql' import type { CartPrices, QuerycartArgs, ShippingCartAddress } from '@graphcommerce/graphql-mesh' import { CartFabDocument } from './components/CartFab/CartFab.gql' -import { CurrentCartIdDocument } from './hooks/CurrentCartId.gql' +import { readCartId, writeCartId } from './hooks' export const cartTypePolicies: StrictTypedTypePolicies = { CurrentCartId: { keyFields: [] }, @@ -53,11 +53,10 @@ export const migrateCart = ( oldCache: ApolloCache, newCache: ApolloCache, ) => { - const currentCartId = oldCache.readQuery({ query: CurrentCartIdDocument }) - const cartId = currentCartId?.currentCartId?.id + const cartId = readCartId(oldCache)?.id if (cartId) { - newCache.writeQuery({ query: CurrentCartIdDocument, data: currentCartId, broadcast: true }) + writeCartId(newCache, cartId) // We have special handling for the CartFab because it tries to load data only from the cache. const cartFab = oldCache.readQuery({ query: CartFabDocument }) diff --git a/packages/magento-customer/components/SignInForm/SignInForm.tsx b/packages/magento-customer/components/SignInForm/SignInForm.tsx index 919ae27be7..a02ecc7e85 100644 --- a/packages/magento-customer/components/SignInForm/SignInForm.tsx +++ b/packages/magento-customer/components/SignInForm/SignInForm.tsx @@ -1,37 +1,17 @@ import { PasswordElement } from '@graphcommerce/ecommerce-ui' -import { useApolloClient } from '@graphcommerce/graphql' import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql' import { Button, FormRow, FormActions } from '@graphcommerce/next-ui' -import { useFormGqlMutation } from '@graphcommerce/react-hook-form' import { Trans } from '@lingui/react' import { Box, FormControl, Link, SxProps, Theme } from '@mui/material' -import { CustomerDocument } from '../../hooks' +import { useSignInForm } from '../../hooks/useSignInForm' import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert' -import { SignInDocument } from './SignIn.gql' -import { signOut } from '../SignOutForm/signOut' export type SignInFormProps = { email: string; sx?: SxProps } export function SignInForm(props: SignInFormProps) { const { email, sx } = props - const client = useApolloClient() - const form = useFormGqlMutation( - SignInDocument, - { - defaultValues: { email }, - onBeforeSubmit: async (values) => { - const oldEmail = client.cache.readQuery({ query: CustomerDocument })?.customer?.email - /** - * We are logging in because the session expired, but we're logging in with a different - * email address, we need to reset the store. - */ - if (oldEmail && oldEmail !== email) signOut(client) - return { ...values, email } - }, - }, - { errorPolicy: 'all' }, - ) + const form = useSignInForm({ email }) const { handleSubmit, required, formState, error, control } = form const [remainingError, authError] = graphqlErrorByCategory({ diff --git a/packages/magento-customer/hooks/CustomerToken.graphqls b/packages/magento-customer/hooks/CustomerToken.graphqls index a62a01fba0..60f0b7434e 100644 --- a/packages/magento-customer/hooks/CustomerToken.graphqls +++ b/packages/magento-customer/hooks/CustomerToken.graphqls @@ -3,6 +3,6 @@ extend type Query { } extend type CustomerToken { - createdAt: String + createdAt: String @deprecated(reason: "Value is not used in GraphCommerce, but still filled in.") valid: Boolean } diff --git a/packages/magento-customer/hooks/useSignInForm.ts b/packages/magento-customer/hooks/useSignInForm.ts new file mode 100644 index 0000000000..be0f09f54d --- /dev/null +++ b/packages/magento-customer/hooks/useSignInForm.ts @@ -0,0 +1,44 @@ +import { useApolloClient } from '@graphcommerce/graphql' +import { UseFormGraphQlOptions, useFormGqlMutation } from '@graphcommerce/react-hook-form' +import { + SignInDocument, + SignInMutation, + SignInMutationVariables, +} from '../components/SignInForm/SignIn.gql' +import { signOut } from '../components/SignOutForm/signOut' +import { CustomerDocument } from './Customer.gql' + +type UseSignInFormProps = { + email: string +} & UseFormGraphQlOptions + +/** + * To extend the actions that happen after a successful sign in, you can use the `onComplete` option. + * + * @example @graphcommerce/magento-cart/plugins/useSignInFormMergeCart + */ +export function useSignInForm({ email, ...options }: UseSignInFormProps) { + const client = useApolloClient() + + return useFormGqlMutation( + SignInDocument, + { + ...options, + defaultValues: { email, ...options?.defaultValues }, + onBeforeSubmit: async (values) => { + const oldEmail = client.cache.readQuery({ query: CustomerDocument })?.customer?.email + + /** + * We are logging in because the session expired, but we're logging in with a different + * email address, we need to reset the store. + */ + if (oldEmail && oldEmail !== email) signOut(client) + + return options?.onBeforeSubmit + ? options.onBeforeSubmit({ ...values, email }) + : { ...values, email } + }, + }, + { errorPolicy: 'all' }, + ) +} diff --git a/packages/magento-newsletter/components/GuestNewsletterToggle/GuestNewsletterToggle.tsx b/packages/magento-newsletter/components/GuestNewsletterToggle/GuestNewsletterToggle.tsx index 3c1ed0bdce..3e530dc543 100644 --- a/packages/magento-newsletter/components/GuestNewsletterToggle/GuestNewsletterToggle.tsx +++ b/packages/magento-newsletter/components/GuestNewsletterToggle/GuestNewsletterToggle.tsx @@ -25,8 +25,7 @@ export type GuestNewsletterToggleProps = SwitchProps & { sx?: SxProps } export function GuestNewsletterToggle(props: GuestNewsletterToggleProps) { const { sx = [], ...switchProps } = props - const email = - useCartQuery(GetCartEmailDocument, { allowUrl: true }).data?.cart?.email ?? undefined + const email = useCartQuery(GetCartEmailDocument).data?.cart?.email ?? undefined const form = useFormGqlMutation< GuestNewsletterToggleMutation, GuestNewsletterToggleMutationVariables & { isSubscribed?: boolean } diff --git a/packages/magento-newsletter/components/SignupNewsletter/SignupNewsletter.tsx b/packages/magento-newsletter/components/SignupNewsletter/SignupNewsletter.tsx index ec2582b78b..1fd2ed0738 100644 --- a/packages/magento-newsletter/components/SignupNewsletter/SignupNewsletter.tsx +++ b/packages/magento-newsletter/components/SignupNewsletter/SignupNewsletter.tsx @@ -17,7 +17,7 @@ const { withState } = extendableComponent export function SignupNewsletter(props: SignupNewsletterProps) { const { sx = [] } = props - const { data: cartData } = useCartQuery(GetCartEmailDocument, { allowUrl: true }) + const { data: cartData } = useCartQuery(GetCartEmailDocument) const { loggedIn } = useCustomerSession() const classes = withState({ loggedIn })