diff --git a/examples/magento-graphcms/components/Layout/Footer.tsx b/examples/magento-graphcms/components/Layout/Footer.tsx index ff92a7e573..cbdf3062e6 100644 --- a/examples/magento-graphcms/components/Layout/Footer.tsx +++ b/examples/magento-graphcms/components/Layout/Footer.tsx @@ -10,7 +10,7 @@ export type FooterProps = FooterQueryFragment export function Footer(props: FooterProps) { const { footer } = props - const enabled = useCheckoutGuestEnabled() + const cartEnabled = useCheckoutGuestEnabled() return ( ))} - {import.meta.graphCommerce.magentoVersion >= 247 && enabled && ( + {import.meta.graphCommerce.magentoVersion >= 247 && cartEnabled && ( Order status diff --git a/examples/magento-graphcms/pages/cart.tsx b/examples/magento-graphcms/pages/cart.tsx index 44d8b80a78..e7eb790417 100644 --- a/examples/magento-graphcms/pages/cart.tsx +++ b/examples/magento-graphcms/pages/cart.tsx @@ -68,7 +68,6 @@ function CartPage() { )} - 0 - if (useCheckoutShouldLoginToContinue()) return - return ( <> diff --git a/examples/magento-graphcms/pages/checkout/payment.tsx b/examples/magento-graphcms/pages/checkout/payment.tsx index 9a9cd038bd..21cb442660 100644 --- a/examples/magento-graphcms/pages/checkout/payment.tsx +++ b/examples/magento-graphcms/pages/checkout/payment.tsx @@ -9,7 +9,6 @@ import { EmptyCart, getCheckoutIsDisabled, useCartQuery, - useCheckoutShouldLoginToContinue, } from '@graphcommerce/magento-cart' import { BillingPageDocument } from '@graphcommerce/magento-cart-checkout' import { CouponAccordion } from '@graphcommerce/magento-cart-coupon' @@ -20,7 +19,6 @@ import { PaymentMethodActionCardListForm, PaymentMethodContextProvider, } from '@graphcommerce/magento-cart-payment-method' -import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { SubscribeToNewsletter } from '@graphcommerce/magento-newsletter' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { @@ -49,8 +47,6 @@ function PaymentPage() { const cartExists = typeof billingPage.data?.cart !== 'undefined' && (billingPage.data.cart?.items?.length ?? 0) > 0 - if (useCheckoutShouldLoginToContinue()) return - return ( diff --git a/packages/magento-cart/hooks/useCartQuery.ts b/packages/magento-cart/hooks/useCartQuery.ts index 9ea8d7cd69..4e7ab5c78b 100644 --- a/packages/magento-cart/hooks/useCartQuery.ts +++ b/packages/magento-cart/hooks/useCartQuery.ts @@ -45,14 +45,12 @@ export function useCartQuery, @@ -57,12 +57,11 @@ export function useFormGqlMutationCart< ) if (shouldLoginToContinue && result.formState.isSubmitted && shouldBlockOperation) { - console.log(document) return { ...result, error: new ApolloError({ graphQLErrors: [ - new GraphQLError('oepsie', { + new GraphQLError('Action can not be performed by the current user', { extensions: { category: 'graphql-authorization' }, }), ], diff --git a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx b/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx deleted file mode 100644 index 2459517bff..0000000000 --- a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { FullPageMessage, FullPageMessageProps, IconSvg, iconPerson } from '@graphcommerce/next-ui' -import { Trans } from '@lingui/react' -import { Button } from '@mui/material' -import React from 'react' -import { useCustomerAccountCanSignUp } from '../../hooks' - -type UnauthenticatedFullPageMessageProps = Omit & { - icon?: React.ReactNode - title?: React.ReactNode -} - -export function UnauthenticatedFullPageMessage(props: UnauthenticatedFullPageMessageProps) { - const canSignUp = useCustomerAccountCanSignUp() - - return ( - } - title={} - button={ - - } - {...props} - /> - ) -} diff --git a/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx b/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx index 6c4cf1abc3..a50efd0bf7 100644 --- a/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx +++ b/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx @@ -1,11 +1,10 @@ import { mergeErrors, WaitForQueries, WaitForQueriesProps } from '@graphcommerce/ecommerce-ui' -import { FullPageMessage, FullPageMessageProps } from '@graphcommerce/next-ui' +import { FullPageMessage, FullPageMessageProps, iconPerson, IconSvg } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' -import { CircularProgress } from '@mui/material' +import { Button, CircularProgress } from '@mui/material' import React from 'react' import { useCustomerSession } from '../../hooks/useCustomerSession' import { ApolloCustomerErrorFullPage } from '../ApolloCustomerError/ApolloCustomerErrorFullPage' -import { UnauthenticatedFullPageMessage } from './UnauthenticatedFullPageMessage' type WaitForCustomerProps = Omit & Pick & { @@ -65,7 +64,22 @@ export function WaitForCustomer(props: WaitForCustomerProps) { } > {!session.loggedIn && - (unauthenticated ?? )} + (unauthenticated ?? ( + } + title={} + button={ + + } + disableMargin={disableMargin} + /> + ))} {session.loggedIn && error && } {session.loggedIn && !error && children} diff --git a/packages/magento-customer/link/customerLink.ts b/packages/magento-customer/link/customerLink.ts index 9a6af1e979..8aefc9d085 100644 --- a/packages/magento-customer/link/customerLink.ts +++ b/packages/magento-customer/link/customerLink.ts @@ -12,7 +12,7 @@ import { NextRouter } from 'next/router' import { signOut } from '../components/SignOutForm/signOut' import { CustomerTokenDocument } from '../hooks' -export type PushRouter = Pick +export type PushRouter = Pick declare module '@apollo/client' { interface DefaultContext { @@ -128,8 +128,5 @@ const customerErrorLink = (router: PushRouter) => }) }) -export const customerLink = (router: PushRouter) => { - const links = [addTokenHeader, customerErrorLink(router)] - - return ApolloLink.from(links) -} +export const customerLink = (router: PushRouter) => + ApolloLink.from([addTokenHeader, customerErrorLink(router)]) diff --git a/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx b/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx index 7a335c4b96..9d112d8fdf 100644 --- a/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx +++ b/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx @@ -17,8 +17,8 @@ export function GraphQLProvider(props: PluginProps) { const push = useEventCallback((...args) => router.push(...args)) const customerLinkMemo = useMemo( - () => customerLink({ push, events: router.events, locale: router.locale }), - [push, router.events, router.locale], + () => customerLink({ push, events: router.events }), + [push, router.events], ) return ( diff --git a/packages/magento-customer/tsconfig.json b/packages/magento-customer/tsconfig.json index 7d9f1656be..7398153dd6 100644 --- a/packages/magento-customer/tsconfig.json +++ b/packages/magento-customer/tsconfig.json @@ -1,5 +1,5 @@ { "exclude": ["**/node_modules", "**/.*/"], - "include": ["**/*.ts", "**/*.tsx", "../magento-cart/link/isProtectedCartOperation.ts"], + "include": ["**/*.ts", "**/*.tsx"], "extends": "@graphcommerce/typescript-config-pwa/nextjs.json" } diff --git a/packages/magento-graphql/graphqlErrorByCategory.ts b/packages/magento-graphql/graphqlErrorByCategory.ts index 482370200d..3e595986ec 100644 --- a/packages/magento-graphql/graphqlErrorByCategory.ts +++ b/packages/magento-graphql/graphqlErrorByCategory.ts @@ -36,6 +36,7 @@ export function graphqlErrorByCategory( props: GraphQLErrorByCategoryProps | GraphQLErrorByCategoryPropsNoExtract, ): [ApolloError | undefined, GraphQLError | undefined] { const { category, error, extract = true, mask } = props + if (!error) return [error, undefined] const newError = new ApolloError({ @@ -47,7 +48,6 @@ export function graphqlErrorByCategory( const graphqlError = error.graphQLErrors.find((err) => err?.extensions?.category === category) if (mask && graphqlError) { - if (graphqlError.extensions?.category) graphqlError.extensions.category = 'masked' graphqlError.message = mask } diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx index e51c3eb54e..26d44e00d5 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx @@ -1,9 +1,7 @@ -import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/magento-cart' +import { useCartEnabled } from '@graphcommerce/magento-cart' import { Fab, FabProps, iconShoppingBag, iconCheckmark } from '@graphcommerce/next-ui' -import { i18n } from '@lingui/core' import { t } from '@lingui/macro' import { SxProps, Theme } from '@mui/material' -import { useRouter } from 'next/router' import { useAddProductsToCartAction, UseAddProductsToCartActionProps, @@ -19,27 +17,11 @@ export function AddProductsToCartFab(props: AddProductsToCartFabProps) { const { icon = iconShoppingBag, product, sku, ...rest } = props const { showSuccess, ...action } = useAddProductsToCartAction(props) - const router = useRouter() const cartEnabled = useCartEnabled() - const shouldLoginToContinue = useCartShouldLoginToContinue() if (!cartEnabled) return null - return shouldLoginToContinue ? ( - { - e.preventDefault() - e.stopPropagation() - await router.push('/account/signin') - }} - onMouseDown={(e) => { - e.preventDefault() - e.stopPropagation() - }} - /> - ) : ( + return (