From c4520684c20f549ce0e561cdf616528ebb3564a6 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 12:15:56 +0100 Subject: [PATCH 01/48] rewrite account urls when guestOnlyMode is active --- packagesDev/next-config/src/withGraphCommerce.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packagesDev/next-config/src/withGraphCommerce.ts b/packagesDev/next-config/src/withGraphCommerce.ts index 167a8208c0..4ba49c6bcd 100644 --- a/packagesDev/next-config/src/withGraphCommerce.ts +++ b/packagesDev/next-config/src/withGraphCommerce.ts @@ -100,6 +100,15 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf rewrites = { beforeFiles: rewrites, afterFiles: [], fallback: [] } } + if (graphcommerceConfig.guestOnlyMode) { + rewrites.beforeFiles.push( + ...[ + { source: '/account', destination: '/404' }, + { source: '/checkout/customer/:path*', destination: '/404' }, + ], + ) + } + if (graphcommerceConfig.productRoute && graphcommerceConfig.productRoute !== '/p/') { rewrites.beforeFiles.push({ source: `${graphcommerceConfig.productRoute ?? '/p/'}:path*`, From abe58fb1b2111f2638f77e2284866652bbe1ecaa Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 12:16:18 +0100 Subject: [PATCH 02/48] Added guestOnlyMode config --- docs/framework/config.md | 2 ++ packages/magento-customer/graphql/Config.graphqls | 3 +++ packagesDev/next-config/dist/generated/config.js | 1 + packagesDev/next-config/src/generated/config.ts | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 packages/magento-customer/graphql/Config.graphqls diff --git a/docs/framework/config.md b/docs/framework/config.md index d3568fffc1..d02c57c256 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -205,6 +205,8 @@ The Google Tagmanager ID to be used on the site. This value is required even if you are configuring different values for each locale. +#### guestOnlyMode: boolean + #### hygraphManagementApi: string Hygraph Management API. **Only used for migrations.** diff --git a/packages/magento-customer/graphql/Config.graphqls b/packages/magento-customer/graphql/Config.graphqls new file mode 100644 index 0000000000..225f5a04dc --- /dev/null +++ b/packages/magento-customer/graphql/Config.graphqls @@ -0,0 +1,3 @@ +extend input GraphCommerceConfig { + guestOnlyMode: Boolean +} diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index d125aaeb5c..f83d6e7914 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -75,6 +75,7 @@ function GraphCommerceConfigSchema() { googleAnalyticsId: _zod.z.string().nullish(), googleRecaptchaKey: _zod.z.string().nullish(), googleTagmanagerId: _zod.z.string().nullish(), + guestOnlyMode: _zod.z.boolean().nullish(), hygraphEndpoint: _zod.z.string().min(1), hygraphManagementApi: _zod.z.string().nullish(), hygraphProjectId: _zod.z.string().nullish(), diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 7930163645..3cfa2119f1 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -203,6 +203,7 @@ export type GraphCommerceConfig = { * This value is required even if you are configuring different values for each locale. */ googleTagmanagerId?: InputMaybe; + guestOnlyMode?: InputMaybe; /** * The HyGraph endpoint. * @@ -449,6 +450,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject Date: Fri, 23 Feb 2024 12:16:55 +0100 Subject: [PATCH 03/48] Hide account buttons when guestOnlyMode is active --- examples/magento-graphcms/pages/404.tsx | 10 +- .../EmailForm/EmailForm.tsx | 3 +- .../InlineAccount/InlineAccount.tsx | 140 +++++++++--------- .../components/CustomerFab/CustomerFab.tsx | 8 +- .../CustomerMenuFabItem.tsx | 8 +- 5 files changed, 90 insertions(+), 79 deletions(-) diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index 5356c8c590..c65f6f05dc 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -16,11 +16,15 @@ function RouteNotFoundPage() { , - - - , ] + !import.meta.graphCommerce.guestOnlyMode && + links.push( + + + , + ) + return ( <> diff --git a/packages/magento-cart-email/EmailForm/EmailForm.tsx b/packages/magento-cart-email/EmailForm/EmailForm.tsx index d74ac6e4dd..6ea4855f13 100644 --- a/packages/magento-cart-email/EmailForm/EmailForm.tsx +++ b/packages/magento-cart-email/EmailForm/EmailForm.tsx @@ -73,7 +73,8 @@ const EmailFormBase = React.memo((props) => { endAdornment: ( {(isEmailAvailable.data?.isEmailAvailable || - !import.meta.graphCommerce.enableGuestCheckoutLogin) && ( + (!import.meta.graphCommerce.enableGuestCheckoutLogin && + !import.meta.graphCommerce.guestOnlyMode)) && ( - )} - - - {cart?.email && toggled && ( - ({ marginTop: theme.spacings.sm })}> - - - - setToggled(false)} - /> + ({ + display: 'flex', + justifyContent: 'space-between', + flexDirection: 'column', + alignItems: 'flex-start', + gap: theme.spacings.md, + [theme.breakpoints.up('sm')]: { + alignItems: 'flex-end', + flexDirection: 'unset', + gap: 0, + }, + })} + > +
+ + {title ?? } + + {description ?? } +
+
+ {!toggled && ( + + )} +
- )} -
- + {cart?.email && toggled && ( + ({ marginTop: theme.spacings.sm })}> + + + + setToggled(false)} + /> + + )} + + + ) ) } diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index e63b4e3ad8..8b5b6696ee 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -54,8 +54,10 @@ export function CustomerFab(props: CustomerFabProps) { const session = useCustomerSession() return ( - }> - - + !import.meta.graphCommerce.guestOnlyMode && ( + }> + + + ) ) } diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 6d2db8b2b7..5658a2eb20 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -41,8 +41,10 @@ export function CustomerMenuFabItem(props: CustomerMenuFabItemProps) { const session = useCustomerSession() return ( - }> - - + !import.meta.graphCommerce.guestOnlyMode && ( + }> + + + ) ) } From 5a53ec872961048740a14ad2cb5a8c4e744210cd Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 13:55:37 +0100 Subject: [PATCH 04/48] fixed eslint error --- examples/magento-graphcms/pages/404.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index c65f6f05dc..c2c670010b 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -18,7 +18,7 @@ function RouteNotFoundPage() { , ] - !import.meta.graphCommerce.guestOnlyMode && + if (!import.meta.graphCommerce.guestOnlyMode) links.push( From a958a9fcec86340e71971cdb39b25a5f02d836d3 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:14:17 +0100 Subject: [PATCH 05/48] updated rewrites --- packagesDev/next-config/src/withGraphCommerce.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packagesDev/next-config/src/withGraphCommerce.ts b/packagesDev/next-config/src/withGraphCommerce.ts index 4ba49c6bcd..985a779b5c 100644 --- a/packagesDev/next-config/src/withGraphCommerce.ts +++ b/packagesDev/next-config/src/withGraphCommerce.ts @@ -103,7 +103,7 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf if (graphcommerceConfig.guestOnlyMode) { rewrites.beforeFiles.push( ...[ - { source: '/account', destination: '/404' }, + { source: '/account/:path*', destination: '/404' }, { source: '/checkout/customer/:path*', destination: '/404' }, ], ) From e7c4198d87339627084865879d62138ad8507644 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:17:10 +0100 Subject: [PATCH 06/48] updated withGraphcommerce config --- .../next-config/dist/generated/config.js | 189 +++++++----------- .../next-config/dist/withGraphCommerce.js | 6 + 2 files changed, 79 insertions(+), 116 deletions(-) diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index f83d6e7914..b53802827c 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -1,138 +1,95 @@ -/* eslint-disable */ "use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -function _export(target, all) { - for(var name in all)Object.defineProperty(target, name, { - enumerable: true, - get: all[name] - }); -} -_export(exports, { - CompareVariantSchema: function() { - return CompareVariantSchema; - }, - GraphCommerceConfigSchema: function() { - return GraphCommerceConfigSchema; - }, - GraphCommerceDebugConfigSchema: function() { - return GraphCommerceDebugConfigSchema; - }, - GraphCommerceStorefrontConfigSchema: function() { - return GraphCommerceStorefrontConfigSchema; - }, - MagentoConfigurableVariantValuesSchema: function() { - return MagentoConfigurableVariantValuesSchema; - }, - ProductFiltersLayoutSchema: function() { - return ProductFiltersLayoutSchema; - }, - RecentlyViewedProductsConfigSchema: function() { - return RecentlyViewedProductsConfigSchema; - }, - SidebarGalleryConfigSchema: function() { - return SidebarGalleryConfigSchema; - }, - SidebarGalleryPaginationVariantSchema: function() { - return SidebarGalleryPaginationVariantSchema; - }, - definedNonNullAnySchema: function() { - return definedNonNullAnySchema; - }, - isDefinedNonNullAny: function() { - return isDefinedNonNullAny; - } -}); -const _zod = require("zod"); -const isDefinedNonNullAny = (v)=>v !== undefined && v !== null; -const definedNonNullAnySchema = _zod.z.any().refine((v)=>isDefinedNonNullAny(v)); -const CompareVariantSchema = _zod.z.enum([ - "CHECKBOX", - "ICON" -]); -const ProductFiltersLayoutSchema = _zod.z.enum([ - "DEFAULT", - "SIDEBAR" -]); -const SidebarGalleryPaginationVariantSchema = _zod.z.enum([ - "DOTS", - "THUMBNAILS_BOTTOM" -]); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0; +/* eslint-disable */ +const zod_1 = require("zod"); +const isDefinedNonNullAny = (v) => v !== undefined && v !== null; +exports.isDefinedNonNullAny = isDefinedNonNullAny; +exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v)); +exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']); +exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']); +exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); function GraphCommerceConfigSchema() { - return _zod.z.object({ - canonicalBaseUrl: _zod.z.string().min(1), - cartDisplayPricesInclTax: _zod.z.boolean().nullish(), - compare: _zod.z.boolean().nullish(), - compareVariant: CompareVariantSchema.nullish(), - configurableVariantForSimple: _zod.z.boolean().nullish(), + return zod_1.z.object({ + canonicalBaseUrl: zod_1.z.string().min(1), + cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), + compare: zod_1.z.boolean().nullish(), + compareVariant: exports.CompareVariantSchema.nullish(), + configurableVariantForSimple: zod_1.z.boolean().nullish(), configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(), - crossSellsHideCartItems: _zod.z.boolean().nullish(), - crossSellsRedirectItems: _zod.z.boolean().nullish(), - customerRequireEmailConfirmation: _zod.z.boolean().nullish(), + crossSellsHideCartItems: zod_1.z.boolean().nullish(), + crossSellsRedirectItems: zod_1.z.boolean().nullish(), + customerRequireEmailConfirmation: zod_1.z.boolean().nullish(), debug: GraphCommerceDebugConfigSchema().nullish(), - demoMode: _zod.z.boolean().nullish(), - enableGuestCheckoutLogin: _zod.z.boolean().nullish(), - googleAnalyticsId: _zod.z.string().nullish(), - googleRecaptchaKey: _zod.z.string().nullish(), - googleTagmanagerId: _zod.z.string().nullish(), - guestOnlyMode: _zod.z.boolean().nullish(), - hygraphEndpoint: _zod.z.string().min(1), - hygraphManagementApi: _zod.z.string().nullish(), - hygraphProjectId: _zod.z.string().nullish(), - hygraphWriteAccessEndpoint: _zod.z.string().nullish(), - hygraphWriteAccessToken: _zod.z.string().nullish(), - limitSsg: _zod.z.boolean().nullish(), - magentoEndpoint: _zod.z.string().min(1), - previewSecret: _zod.z.string().nullish(), - productFiltersLayout: ProductFiltersLayoutSchema.nullish(), - productFiltersPro: _zod.z.boolean().nullish(), - productRoute: _zod.z.string().nullish(), + demoMode: zod_1.z.boolean().nullish(), + enableGuestCheckoutLogin: zod_1.z.boolean().nullish(), + googleAnalyticsId: zod_1.z.string().nullish(), + googleRecaptchaKey: zod_1.z.string().nullish(), + googleTagmanagerId: zod_1.z.string().nullish(), + guestOnlyMode: zod_1.z.boolean().nullish(), + hygraphEndpoint: zod_1.z.string().min(1), + hygraphManagementApi: zod_1.z.string().nullish(), + hygraphProjectId: zod_1.z.string().nullish(), + hygraphWriteAccessEndpoint: zod_1.z.string().nullish(), + hygraphWriteAccessToken: zod_1.z.string().nullish(), + limitSsg: zod_1.z.boolean().nullish(), + magentoEndpoint: zod_1.z.string().min(1), + previewSecret: zod_1.z.string().nullish(), + productFiltersLayout: exports.ProductFiltersLayoutSchema.nullish(), + productFiltersPro: zod_1.z.boolean().nullish(), + productRoute: zod_1.z.string().nullish(), recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(), - robotsAllow: _zod.z.boolean().nullish(), + robotsAllow: zod_1.z.boolean().nullish(), sidebarGallery: SidebarGalleryConfigSchema().nullish(), - storefront: _zod.z.array(GraphCommerceStorefrontConfigSchema()), - wishlistHideForGuests: _zod.z.boolean().nullish(), - wishlistShowFeedbackMessage: _zod.z.boolean().nullish() + storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()), + wishlistHideForGuests: zod_1.z.boolean().nullish(), + wishlistShowFeedbackMessage: zod_1.z.boolean().nullish() }); } +exports.GraphCommerceConfigSchema = GraphCommerceConfigSchema; function GraphCommerceDebugConfigSchema() { - return _zod.z.object({ - pluginStatus: _zod.z.boolean().nullish(), - sessions: _zod.z.boolean().nullish(), - webpackCircularDependencyPlugin: _zod.z.boolean().nullish(), - webpackDuplicatesPlugin: _zod.z.boolean().nullish() + return zod_1.z.object({ + pluginStatus: zod_1.z.boolean().nullish(), + sessions: zod_1.z.boolean().nullish(), + webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(), + webpackDuplicatesPlugin: zod_1.z.boolean().nullish() }); } +exports.GraphCommerceDebugConfigSchema = GraphCommerceDebugConfigSchema; function GraphCommerceStorefrontConfigSchema() { - return _zod.z.object({ - canonicalBaseUrl: _zod.z.string().nullish(), - cartDisplayPricesInclTax: _zod.z.boolean().nullish(), - defaultLocale: _zod.z.boolean().nullish(), - domain: _zod.z.string().nullish(), - googleAnalyticsId: _zod.z.string().nullish(), - googleRecaptchaKey: _zod.z.string().nullish(), - googleTagmanagerId: _zod.z.string().nullish(), - hygraphLocales: _zod.z.array(_zod.z.string().min(1)).nullish(), - linguiLocale: _zod.z.string().nullish(), - locale: _zod.z.string().min(1), - magentoStoreCode: _zod.z.string().min(1) + return zod_1.z.object({ + canonicalBaseUrl: zod_1.z.string().nullish(), + cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), + defaultLocale: zod_1.z.boolean().nullish(), + domain: zod_1.z.string().nullish(), + googleAnalyticsId: zod_1.z.string().nullish(), + googleRecaptchaKey: zod_1.z.string().nullish(), + googleTagmanagerId: zod_1.z.string().nullish(), + hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(), + linguiLocale: zod_1.z.string().nullish(), + locale: zod_1.z.string().min(1), + magentoStoreCode: zod_1.z.string().min(1) }); } +exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema; function MagentoConfigurableVariantValuesSchema() { - return _zod.z.object({ - content: _zod.z.boolean().nullish(), - gallery: _zod.z.boolean().nullish(), - url: _zod.z.boolean().nullish() + return zod_1.z.object({ + content: zod_1.z.boolean().nullish(), + gallery: zod_1.z.boolean().nullish(), + url: zod_1.z.boolean().nullish() }); } +exports.MagentoConfigurableVariantValuesSchema = MagentoConfigurableVariantValuesSchema; function RecentlyViewedProductsConfigSchema() { - return _zod.z.object({ - enabled: _zod.z.boolean().nullish(), - maxCount: _zod.z.number().nullish() + return zod_1.z.object({ + enabled: zod_1.z.boolean().nullish(), + maxCount: zod_1.z.number().nullish() }); } +exports.RecentlyViewedProductsConfigSchema = RecentlyViewedProductsConfigSchema; function SidebarGalleryConfigSchema() { - return _zod.z.object({ - paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() + return zod_1.z.object({ + paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish() }); } +exports.SidebarGalleryConfigSchema = SidebarGalleryConfigSchema; diff --git a/packagesDev/next-config/dist/withGraphCommerce.js b/packagesDev/next-config/dist/withGraphCommerce.js index 3f14595b7f..7538abe612 100644 --- a/packagesDev/next-config/dist/withGraphCommerce.js +++ b/packagesDev/next-config/dist/withGraphCommerce.js @@ -83,6 +83,12 @@ function withGraphCommerce(nextConfig, cwd) { if (Array.isArray(rewrites)) { rewrites = { beforeFiles: rewrites, afterFiles: [], fallback: [] }; } + if (graphcommerceConfig.guestOnlyMode) { + rewrites.beforeFiles.push(...[ + { source: '/account/:path*', destination: '/404' }, + { source: '/checkout/customer/:path*', destination: '/404' }, + ]); + } if (graphcommerceConfig.productRoute && graphcommerceConfig.productRoute !== '/p/') { rewrites.beforeFiles.push({ source: `${graphcommerceConfig.productRoute ?? '/p/'}:path*`, From cd1440ab7985d590117eb63bc94c2026c0e9c9e6 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:35:12 +0100 Subject: [PATCH 07/48] return null if guestOnlyMode instead of wrapping --- .../InlineAccount/InlineAccount.tsx | 141 +++++++++--------- .../components/CustomerFab/CustomerFab.tsx | 10 +- .../CustomerMenuFabItem.tsx | 10 +- 3 files changed, 80 insertions(+), 81 deletions(-) diff --git a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx index 38d4f86ec7..c6506e2214 100644 --- a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx +++ b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx @@ -45,81 +45,80 @@ export function InlineAccount(props: InlineAccountProps) { const canSignUp = isEmailAvailableData?.isEmailAvailable?.is_email_available === true if (loggedIn || !canSignUp) return null + if (import.meta.graphCommerce.guestOnlyMode) return null return ( - !import.meta.graphCommerce.guestOnlyMode && ( -
+
+ ({ + borderRadius: '4px', + border: `1px solid ${theme.palette.divider}`, + padding: theme.spacings.md, + marginTop: theme.spacings.sm, + }), + ...(Array.isArray(sx) ? sx : [sx]), + ]} + > ({ - borderRadius: '4px', - border: `1px solid ${theme.palette.divider}`, - padding: theme.spacings.md, - marginTop: theme.spacings.sm, - }), - ...(Array.isArray(sx) ? sx : [sx]), - ]} + className={classes.innerContainer} + sx={(theme) => ({ + display: 'flex', + justifyContent: 'space-between', + flexDirection: 'column', + alignItems: 'flex-start', + gap: theme.spacings.md, + [theme.breakpoints.up('sm')]: { + alignItems: 'flex-end', + flexDirection: 'unset', + gap: 0, + }, + })} > - ({ - display: 'flex', - justifyContent: 'space-between', - flexDirection: 'column', - alignItems: 'flex-start', - gap: theme.spacings.md, - [theme.breakpoints.up('sm')]: { - alignItems: 'flex-end', - flexDirection: 'unset', - gap: 0, - }, - })} - > -
- - {title ?? } - - {description ?? } -
-
- {!toggled && ( - - )} -
-
- {cart?.email && toggled && ( - ({ marginTop: theme.spacings.sm })}> - - - - setToggled(false)} - /> - - )} +
+ + {title ?? } + + {description ?? } +
+
+ {!toggled && ( + + )} +
-
- ) + {cart?.email && toggled && ( + ({ marginTop: theme.spacings.sm })}> + + + + setToggled(false)} + /> + + )} + +
) } diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index 8b5b6696ee..63fb59008d 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -53,11 +53,11 @@ export type CustomerFabProps = Omit export function CustomerFab(props: CustomerFabProps) { const session = useCustomerSession() + if (import.meta.graphCommerce.guestOnlyMode) return null + return ( - !import.meta.graphCommerce.guestOnlyMode && ( - }> - - - ) + }> + + ) } diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 5658a2eb20..0a3a7abe63 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -40,11 +40,11 @@ function CustomerMenuFabItemContent(props: CustomerMenuFabItemProps) { export function CustomerMenuFabItem(props: CustomerMenuFabItemProps) { const session = useCustomerSession() + if (import.meta.graphCommerce.guestOnlyMode) return null + return ( - !import.meta.graphCommerce.guestOnlyMode && ( - }> - - - ) + }> + + ) } From c3add677877e5cdcc44edf34650288cacb7c9b24 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 12:15:56 +0100 Subject: [PATCH 08/48] rewrite account urls when guestOnlyMode is active --- packagesDev/next-config/src/withGraphCommerce.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packagesDev/next-config/src/withGraphCommerce.ts b/packagesDev/next-config/src/withGraphCommerce.ts index 167a8208c0..4ba49c6bcd 100644 --- a/packagesDev/next-config/src/withGraphCommerce.ts +++ b/packagesDev/next-config/src/withGraphCommerce.ts @@ -100,6 +100,15 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf rewrites = { beforeFiles: rewrites, afterFiles: [], fallback: [] } } + if (graphcommerceConfig.guestOnlyMode) { + rewrites.beforeFiles.push( + ...[ + { source: '/account', destination: '/404' }, + { source: '/checkout/customer/:path*', destination: '/404' }, + ], + ) + } + if (graphcommerceConfig.productRoute && graphcommerceConfig.productRoute !== '/p/') { rewrites.beforeFiles.push({ source: `${graphcommerceConfig.productRoute ?? '/p/'}:path*`, From e09f42b95b3ecf296c169d808f75f04ba7bd6152 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 12:16:18 +0100 Subject: [PATCH 09/48] Added guestOnlyMode config --- docs/framework/config.md | 2 ++ packages/magento-customer/graphql/Config.graphqls | 3 +++ packagesDev/next-config/dist/generated/config.js | 1 + packagesDev/next-config/src/generated/config.ts | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 packages/magento-customer/graphql/Config.graphqls diff --git a/docs/framework/config.md b/docs/framework/config.md index d3568fffc1..d02c57c256 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -205,6 +205,8 @@ The Google Tagmanager ID to be used on the site. This value is required even if you are configuring different values for each locale. +#### guestOnlyMode: boolean + #### hygraphManagementApi: string Hygraph Management API. **Only used for migrations.** diff --git a/packages/magento-customer/graphql/Config.graphqls b/packages/magento-customer/graphql/Config.graphqls new file mode 100644 index 0000000000..225f5a04dc --- /dev/null +++ b/packages/magento-customer/graphql/Config.graphqls @@ -0,0 +1,3 @@ +extend input GraphCommerceConfig { + guestOnlyMode: Boolean +} diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index d125aaeb5c..f83d6e7914 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -75,6 +75,7 @@ function GraphCommerceConfigSchema() { googleAnalyticsId: _zod.z.string().nullish(), googleRecaptchaKey: _zod.z.string().nullish(), googleTagmanagerId: _zod.z.string().nullish(), + guestOnlyMode: _zod.z.boolean().nullish(), hygraphEndpoint: _zod.z.string().min(1), hygraphManagementApi: _zod.z.string().nullish(), hygraphProjectId: _zod.z.string().nullish(), diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 7930163645..3cfa2119f1 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -203,6 +203,7 @@ export type GraphCommerceConfig = { * This value is required even if you are configuring different values for each locale. */ googleTagmanagerId?: InputMaybe; + guestOnlyMode?: InputMaybe; /** * The HyGraph endpoint. * @@ -449,6 +450,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject Date: Fri, 23 Feb 2024 12:16:55 +0100 Subject: [PATCH 10/48] Hide account buttons when guestOnlyMode is active --- examples/magento-graphcms/pages/404.tsx | 10 +- .../EmailForm/EmailForm.tsx | 3 +- .../InlineAccount/InlineAccount.tsx | 140 +++++++++--------- .../components/CustomerFab/CustomerFab.tsx | 8 +- .../CustomerMenuFabItem.tsx | 8 +- 5 files changed, 90 insertions(+), 79 deletions(-) diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index 5356c8c590..c65f6f05dc 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -16,11 +16,15 @@ function RouteNotFoundPage() { , - - - , ] + !import.meta.graphCommerce.guestOnlyMode && + links.push( + + + , + ) + return ( <> diff --git a/packages/magento-cart-email/EmailForm/EmailForm.tsx b/packages/magento-cart-email/EmailForm/EmailForm.tsx index 98e4b191b8..f970e45097 100644 --- a/packages/magento-cart-email/EmailForm/EmailForm.tsx +++ b/packages/magento-cart-email/EmailForm/EmailForm.tsx @@ -73,7 +73,8 @@ const EmailFormBase = React.memo((props) => { endAdornment: ( {(isEmailAvailable.data?.isEmailAvailable || - !import.meta.graphCommerce.enableGuestCheckoutLogin) && ( + (!import.meta.graphCommerce.enableGuestCheckoutLogin && + !import.meta.graphCommerce.guestOnlyMode)) && ( - )} - - - {cart?.email && toggled && ( - ({ marginTop: theme.spacings.sm })}> - - - - setToggled(false)} - /> + ({ + display: 'flex', + justifyContent: 'space-between', + flexDirection: 'column', + alignItems: 'flex-start', + gap: theme.spacings.md, + [theme.breakpoints.up('sm')]: { + alignItems: 'flex-end', + flexDirection: 'unset', + gap: 0, + }, + })} + > +
+ + {title ?? } + + {description ?? } +
+
+ {!toggled && ( + + )} +
- )} -
- + {cart?.email && toggled && ( + ({ marginTop: theme.spacings.sm })}> + + + + setToggled(false)} + /> + + )} + + + ) ) } diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index e63b4e3ad8..8b5b6696ee 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -54,8 +54,10 @@ export function CustomerFab(props: CustomerFabProps) { const session = useCustomerSession() return ( - }> - - + !import.meta.graphCommerce.guestOnlyMode && ( + }> + + + ) ) } diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 6d2db8b2b7..5658a2eb20 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -41,8 +41,10 @@ export function CustomerMenuFabItem(props: CustomerMenuFabItemProps) { const session = useCustomerSession() return ( - }> - - + !import.meta.graphCommerce.guestOnlyMode && ( + }> + + + ) ) } From 818b03b35f53d31e74e8f0c425bf641f646b82d1 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 13:55:37 +0100 Subject: [PATCH 11/48] fixed eslint error --- examples/magento-graphcms/pages/404.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index c65f6f05dc..c2c670010b 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -18,7 +18,7 @@ function RouteNotFoundPage() { , ] - !import.meta.graphCommerce.guestOnlyMode && + if (!import.meta.graphCommerce.guestOnlyMode) links.push( From abd37f7faec1835df4d27316b1b4e5fea892037d Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:14:17 +0100 Subject: [PATCH 12/48] updated rewrites --- packagesDev/next-config/src/withGraphCommerce.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packagesDev/next-config/src/withGraphCommerce.ts b/packagesDev/next-config/src/withGraphCommerce.ts index 4ba49c6bcd..985a779b5c 100644 --- a/packagesDev/next-config/src/withGraphCommerce.ts +++ b/packagesDev/next-config/src/withGraphCommerce.ts @@ -103,7 +103,7 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf if (graphcommerceConfig.guestOnlyMode) { rewrites.beforeFiles.push( ...[ - { source: '/account', destination: '/404' }, + { source: '/account/:path*', destination: '/404' }, { source: '/checkout/customer/:path*', destination: '/404' }, ], ) From 12c622412339b051acc4f9fd6ef37e4de6b39be5 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:17:10 +0100 Subject: [PATCH 13/48] updated withGraphcommerce config --- .../next-config/dist/generated/config.js | 189 +++++++----------- .../next-config/dist/withGraphCommerce.js | 6 + 2 files changed, 79 insertions(+), 116 deletions(-) diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index f83d6e7914..b53802827c 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -1,138 +1,95 @@ -/* eslint-disable */ "use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -function _export(target, all) { - for(var name in all)Object.defineProperty(target, name, { - enumerable: true, - get: all[name] - }); -} -_export(exports, { - CompareVariantSchema: function() { - return CompareVariantSchema; - }, - GraphCommerceConfigSchema: function() { - return GraphCommerceConfigSchema; - }, - GraphCommerceDebugConfigSchema: function() { - return GraphCommerceDebugConfigSchema; - }, - GraphCommerceStorefrontConfigSchema: function() { - return GraphCommerceStorefrontConfigSchema; - }, - MagentoConfigurableVariantValuesSchema: function() { - return MagentoConfigurableVariantValuesSchema; - }, - ProductFiltersLayoutSchema: function() { - return ProductFiltersLayoutSchema; - }, - RecentlyViewedProductsConfigSchema: function() { - return RecentlyViewedProductsConfigSchema; - }, - SidebarGalleryConfigSchema: function() { - return SidebarGalleryConfigSchema; - }, - SidebarGalleryPaginationVariantSchema: function() { - return SidebarGalleryPaginationVariantSchema; - }, - definedNonNullAnySchema: function() { - return definedNonNullAnySchema; - }, - isDefinedNonNullAny: function() { - return isDefinedNonNullAny; - } -}); -const _zod = require("zod"); -const isDefinedNonNullAny = (v)=>v !== undefined && v !== null; -const definedNonNullAnySchema = _zod.z.any().refine((v)=>isDefinedNonNullAny(v)); -const CompareVariantSchema = _zod.z.enum([ - "CHECKBOX", - "ICON" -]); -const ProductFiltersLayoutSchema = _zod.z.enum([ - "DEFAULT", - "SIDEBAR" -]); -const SidebarGalleryPaginationVariantSchema = _zod.z.enum([ - "DOTS", - "THUMBNAILS_BOTTOM" -]); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0; +/* eslint-disable */ +const zod_1 = require("zod"); +const isDefinedNonNullAny = (v) => v !== undefined && v !== null; +exports.isDefinedNonNullAny = isDefinedNonNullAny; +exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v)); +exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']); +exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']); +exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); function GraphCommerceConfigSchema() { - return _zod.z.object({ - canonicalBaseUrl: _zod.z.string().min(1), - cartDisplayPricesInclTax: _zod.z.boolean().nullish(), - compare: _zod.z.boolean().nullish(), - compareVariant: CompareVariantSchema.nullish(), - configurableVariantForSimple: _zod.z.boolean().nullish(), + return zod_1.z.object({ + canonicalBaseUrl: zod_1.z.string().min(1), + cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), + compare: zod_1.z.boolean().nullish(), + compareVariant: exports.CompareVariantSchema.nullish(), + configurableVariantForSimple: zod_1.z.boolean().nullish(), configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(), - crossSellsHideCartItems: _zod.z.boolean().nullish(), - crossSellsRedirectItems: _zod.z.boolean().nullish(), - customerRequireEmailConfirmation: _zod.z.boolean().nullish(), + crossSellsHideCartItems: zod_1.z.boolean().nullish(), + crossSellsRedirectItems: zod_1.z.boolean().nullish(), + customerRequireEmailConfirmation: zod_1.z.boolean().nullish(), debug: GraphCommerceDebugConfigSchema().nullish(), - demoMode: _zod.z.boolean().nullish(), - enableGuestCheckoutLogin: _zod.z.boolean().nullish(), - googleAnalyticsId: _zod.z.string().nullish(), - googleRecaptchaKey: _zod.z.string().nullish(), - googleTagmanagerId: _zod.z.string().nullish(), - guestOnlyMode: _zod.z.boolean().nullish(), - hygraphEndpoint: _zod.z.string().min(1), - hygraphManagementApi: _zod.z.string().nullish(), - hygraphProjectId: _zod.z.string().nullish(), - hygraphWriteAccessEndpoint: _zod.z.string().nullish(), - hygraphWriteAccessToken: _zod.z.string().nullish(), - limitSsg: _zod.z.boolean().nullish(), - magentoEndpoint: _zod.z.string().min(1), - previewSecret: _zod.z.string().nullish(), - productFiltersLayout: ProductFiltersLayoutSchema.nullish(), - productFiltersPro: _zod.z.boolean().nullish(), - productRoute: _zod.z.string().nullish(), + demoMode: zod_1.z.boolean().nullish(), + enableGuestCheckoutLogin: zod_1.z.boolean().nullish(), + googleAnalyticsId: zod_1.z.string().nullish(), + googleRecaptchaKey: zod_1.z.string().nullish(), + googleTagmanagerId: zod_1.z.string().nullish(), + guestOnlyMode: zod_1.z.boolean().nullish(), + hygraphEndpoint: zod_1.z.string().min(1), + hygraphManagementApi: zod_1.z.string().nullish(), + hygraphProjectId: zod_1.z.string().nullish(), + hygraphWriteAccessEndpoint: zod_1.z.string().nullish(), + hygraphWriteAccessToken: zod_1.z.string().nullish(), + limitSsg: zod_1.z.boolean().nullish(), + magentoEndpoint: zod_1.z.string().min(1), + previewSecret: zod_1.z.string().nullish(), + productFiltersLayout: exports.ProductFiltersLayoutSchema.nullish(), + productFiltersPro: zod_1.z.boolean().nullish(), + productRoute: zod_1.z.string().nullish(), recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(), - robotsAllow: _zod.z.boolean().nullish(), + robotsAllow: zod_1.z.boolean().nullish(), sidebarGallery: SidebarGalleryConfigSchema().nullish(), - storefront: _zod.z.array(GraphCommerceStorefrontConfigSchema()), - wishlistHideForGuests: _zod.z.boolean().nullish(), - wishlistShowFeedbackMessage: _zod.z.boolean().nullish() + storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()), + wishlistHideForGuests: zod_1.z.boolean().nullish(), + wishlistShowFeedbackMessage: zod_1.z.boolean().nullish() }); } +exports.GraphCommerceConfigSchema = GraphCommerceConfigSchema; function GraphCommerceDebugConfigSchema() { - return _zod.z.object({ - pluginStatus: _zod.z.boolean().nullish(), - sessions: _zod.z.boolean().nullish(), - webpackCircularDependencyPlugin: _zod.z.boolean().nullish(), - webpackDuplicatesPlugin: _zod.z.boolean().nullish() + return zod_1.z.object({ + pluginStatus: zod_1.z.boolean().nullish(), + sessions: zod_1.z.boolean().nullish(), + webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(), + webpackDuplicatesPlugin: zod_1.z.boolean().nullish() }); } +exports.GraphCommerceDebugConfigSchema = GraphCommerceDebugConfigSchema; function GraphCommerceStorefrontConfigSchema() { - return _zod.z.object({ - canonicalBaseUrl: _zod.z.string().nullish(), - cartDisplayPricesInclTax: _zod.z.boolean().nullish(), - defaultLocale: _zod.z.boolean().nullish(), - domain: _zod.z.string().nullish(), - googleAnalyticsId: _zod.z.string().nullish(), - googleRecaptchaKey: _zod.z.string().nullish(), - googleTagmanagerId: _zod.z.string().nullish(), - hygraphLocales: _zod.z.array(_zod.z.string().min(1)).nullish(), - linguiLocale: _zod.z.string().nullish(), - locale: _zod.z.string().min(1), - magentoStoreCode: _zod.z.string().min(1) + return zod_1.z.object({ + canonicalBaseUrl: zod_1.z.string().nullish(), + cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), + defaultLocale: zod_1.z.boolean().nullish(), + domain: zod_1.z.string().nullish(), + googleAnalyticsId: zod_1.z.string().nullish(), + googleRecaptchaKey: zod_1.z.string().nullish(), + googleTagmanagerId: zod_1.z.string().nullish(), + hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(), + linguiLocale: zod_1.z.string().nullish(), + locale: zod_1.z.string().min(1), + magentoStoreCode: zod_1.z.string().min(1) }); } +exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema; function MagentoConfigurableVariantValuesSchema() { - return _zod.z.object({ - content: _zod.z.boolean().nullish(), - gallery: _zod.z.boolean().nullish(), - url: _zod.z.boolean().nullish() + return zod_1.z.object({ + content: zod_1.z.boolean().nullish(), + gallery: zod_1.z.boolean().nullish(), + url: zod_1.z.boolean().nullish() }); } +exports.MagentoConfigurableVariantValuesSchema = MagentoConfigurableVariantValuesSchema; function RecentlyViewedProductsConfigSchema() { - return _zod.z.object({ - enabled: _zod.z.boolean().nullish(), - maxCount: _zod.z.number().nullish() + return zod_1.z.object({ + enabled: zod_1.z.boolean().nullish(), + maxCount: zod_1.z.number().nullish() }); } +exports.RecentlyViewedProductsConfigSchema = RecentlyViewedProductsConfigSchema; function SidebarGalleryConfigSchema() { - return _zod.z.object({ - paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() + return zod_1.z.object({ + paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish() }); } +exports.SidebarGalleryConfigSchema = SidebarGalleryConfigSchema; diff --git a/packagesDev/next-config/dist/withGraphCommerce.js b/packagesDev/next-config/dist/withGraphCommerce.js index 3f14595b7f..7538abe612 100644 --- a/packagesDev/next-config/dist/withGraphCommerce.js +++ b/packagesDev/next-config/dist/withGraphCommerce.js @@ -83,6 +83,12 @@ function withGraphCommerce(nextConfig, cwd) { if (Array.isArray(rewrites)) { rewrites = { beforeFiles: rewrites, afterFiles: [], fallback: [] }; } + if (graphcommerceConfig.guestOnlyMode) { + rewrites.beforeFiles.push(...[ + { source: '/account/:path*', destination: '/404' }, + { source: '/checkout/customer/:path*', destination: '/404' }, + ]); + } if (graphcommerceConfig.productRoute && graphcommerceConfig.productRoute !== '/p/') { rewrites.beforeFiles.push({ source: `${graphcommerceConfig.productRoute ?? '/p/'}:path*`, From b5f9f6917ffb730670e38a2146cb7a574ccf4d9f Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 23 Feb 2024 14:35:12 +0100 Subject: [PATCH 14/48] return null if guestOnlyMode instead of wrapping --- .../InlineAccount/InlineAccount.tsx | 141 +++++++++--------- .../components/CustomerFab/CustomerFab.tsx | 10 +- .../CustomerMenuFabItem.tsx | 10 +- 3 files changed, 80 insertions(+), 81 deletions(-) diff --git a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx index 38d4f86ec7..c6506e2214 100644 --- a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx +++ b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx @@ -45,81 +45,80 @@ export function InlineAccount(props: InlineAccountProps) { const canSignUp = isEmailAvailableData?.isEmailAvailable?.is_email_available === true if (loggedIn || !canSignUp) return null + if (import.meta.graphCommerce.guestOnlyMode) return null return ( - !import.meta.graphCommerce.guestOnlyMode && ( -
+
+ ({ + borderRadius: '4px', + border: `1px solid ${theme.palette.divider}`, + padding: theme.spacings.md, + marginTop: theme.spacings.sm, + }), + ...(Array.isArray(sx) ? sx : [sx]), + ]} + > ({ - borderRadius: '4px', - border: `1px solid ${theme.palette.divider}`, - padding: theme.spacings.md, - marginTop: theme.spacings.sm, - }), - ...(Array.isArray(sx) ? sx : [sx]), - ]} + className={classes.innerContainer} + sx={(theme) => ({ + display: 'flex', + justifyContent: 'space-between', + flexDirection: 'column', + alignItems: 'flex-start', + gap: theme.spacings.md, + [theme.breakpoints.up('sm')]: { + alignItems: 'flex-end', + flexDirection: 'unset', + gap: 0, + }, + })} > - ({ - display: 'flex', - justifyContent: 'space-between', - flexDirection: 'column', - alignItems: 'flex-start', - gap: theme.spacings.md, - [theme.breakpoints.up('sm')]: { - alignItems: 'flex-end', - flexDirection: 'unset', - gap: 0, - }, - })} - > -
- - {title ?? } - - {description ?? } -
-
- {!toggled && ( - - )} -
-
- {cart?.email && toggled && ( - ({ marginTop: theme.spacings.sm })}> - - - - setToggled(false)} - /> - - )} +
+ + {title ?? } + + {description ?? } +
+
+ {!toggled && ( + + )} +
-
- ) + {cart?.email && toggled && ( + ({ marginTop: theme.spacings.sm })}> + + + + setToggled(false)} + /> + + )} + +
) } diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index 8b5b6696ee..63fb59008d 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -53,11 +53,11 @@ export type CustomerFabProps = Omit export function CustomerFab(props: CustomerFabProps) { const session = useCustomerSession() + if (import.meta.graphCommerce.guestOnlyMode) return null + return ( - !import.meta.graphCommerce.guestOnlyMode && ( - }> - - - ) + }> + + ) } diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 5658a2eb20..0a3a7abe63 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -40,11 +40,11 @@ function CustomerMenuFabItemContent(props: CustomerMenuFabItemProps) { export function CustomerMenuFabItem(props: CustomerMenuFabItemProps) { const session = useCustomerSession() + if (import.meta.graphCommerce.guestOnlyMode) return null + return ( - !import.meta.graphCommerce.guestOnlyMode && ( - }> - - - ) + }> + + ) } From 2bc6517a2039ecc74d76bc8d6ec796bd0a7a1944 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Tue, 12 Mar 2024 10:33:29 +0100 Subject: [PATCH 15/48] Added description to config --- docs/framework/config.md | 2 + .../magento-customer/graphql/Config.graphqls | 3 + .../next-config/dist/generated/config.js | 189 +++++++++++------- .../next-config/src/generated/config.ts | 1 + 4 files changed, 122 insertions(+), 73 deletions(-) diff --git a/docs/framework/config.md b/docs/framework/config.md index d02c57c256..926132f67a 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -207,6 +207,8 @@ This value is required even if you are configuring different values for each loc #### guestOnlyMode: boolean +Disables all login functionalities + #### hygraphManagementApi: string Hygraph Management API. **Only used for migrations.** diff --git a/packages/magento-customer/graphql/Config.graphqls b/packages/magento-customer/graphql/Config.graphqls index 225f5a04dc..f2060eaa7b 100644 --- a/packages/magento-customer/graphql/Config.graphqls +++ b/packages/magento-customer/graphql/Config.graphqls @@ -1,3 +1,6 @@ extend input GraphCommerceConfig { + """ + Disables all login functionalities + """ guestOnlyMode: Boolean } diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index b53802827c..f83d6e7914 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -1,95 +1,138 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0; -/* eslint-disable */ -const zod_1 = require("zod"); -const isDefinedNonNullAny = (v) => v !== undefined && v !== null; -exports.isDefinedNonNullAny = isDefinedNonNullAny; -exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v)); -exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']); -exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']); -exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); +/* eslint-disable */ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + CompareVariantSchema: function() { + return CompareVariantSchema; + }, + GraphCommerceConfigSchema: function() { + return GraphCommerceConfigSchema; + }, + GraphCommerceDebugConfigSchema: function() { + return GraphCommerceDebugConfigSchema; + }, + GraphCommerceStorefrontConfigSchema: function() { + return GraphCommerceStorefrontConfigSchema; + }, + MagentoConfigurableVariantValuesSchema: function() { + return MagentoConfigurableVariantValuesSchema; + }, + ProductFiltersLayoutSchema: function() { + return ProductFiltersLayoutSchema; + }, + RecentlyViewedProductsConfigSchema: function() { + return RecentlyViewedProductsConfigSchema; + }, + SidebarGalleryConfigSchema: function() { + return SidebarGalleryConfigSchema; + }, + SidebarGalleryPaginationVariantSchema: function() { + return SidebarGalleryPaginationVariantSchema; + }, + definedNonNullAnySchema: function() { + return definedNonNullAnySchema; + }, + isDefinedNonNullAny: function() { + return isDefinedNonNullAny; + } +}); +const _zod = require("zod"); +const isDefinedNonNullAny = (v)=>v !== undefined && v !== null; +const definedNonNullAnySchema = _zod.z.any().refine((v)=>isDefinedNonNullAny(v)); +const CompareVariantSchema = _zod.z.enum([ + "CHECKBOX", + "ICON" +]); +const ProductFiltersLayoutSchema = _zod.z.enum([ + "DEFAULT", + "SIDEBAR" +]); +const SidebarGalleryPaginationVariantSchema = _zod.z.enum([ + "DOTS", + "THUMBNAILS_BOTTOM" +]); function GraphCommerceConfigSchema() { - return zod_1.z.object({ - canonicalBaseUrl: zod_1.z.string().min(1), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - compare: zod_1.z.boolean().nullish(), - compareVariant: exports.CompareVariantSchema.nullish(), - configurableVariantForSimple: zod_1.z.boolean().nullish(), + return _zod.z.object({ + canonicalBaseUrl: _zod.z.string().min(1), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + compare: _zod.z.boolean().nullish(), + compareVariant: CompareVariantSchema.nullish(), + configurableVariantForSimple: _zod.z.boolean().nullish(), configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(), - crossSellsHideCartItems: zod_1.z.boolean().nullish(), - crossSellsRedirectItems: zod_1.z.boolean().nullish(), - customerRequireEmailConfirmation: zod_1.z.boolean().nullish(), + crossSellsHideCartItems: _zod.z.boolean().nullish(), + crossSellsRedirectItems: _zod.z.boolean().nullish(), + customerRequireEmailConfirmation: _zod.z.boolean().nullish(), debug: GraphCommerceDebugConfigSchema().nullish(), - demoMode: zod_1.z.boolean().nullish(), - enableGuestCheckoutLogin: zod_1.z.boolean().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - guestOnlyMode: zod_1.z.boolean().nullish(), - hygraphEndpoint: zod_1.z.string().min(1), - hygraphManagementApi: zod_1.z.string().nullish(), - hygraphProjectId: zod_1.z.string().nullish(), - hygraphWriteAccessEndpoint: zod_1.z.string().nullish(), - hygraphWriteAccessToken: zod_1.z.string().nullish(), - limitSsg: zod_1.z.boolean().nullish(), - magentoEndpoint: zod_1.z.string().min(1), - previewSecret: zod_1.z.string().nullish(), - productFiltersLayout: exports.ProductFiltersLayoutSchema.nullish(), - productFiltersPro: zod_1.z.boolean().nullish(), - productRoute: zod_1.z.string().nullish(), + demoMode: _zod.z.boolean().nullish(), + enableGuestCheckoutLogin: _zod.z.boolean().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + guestOnlyMode: _zod.z.boolean().nullish(), + hygraphEndpoint: _zod.z.string().min(1), + hygraphManagementApi: _zod.z.string().nullish(), + hygraphProjectId: _zod.z.string().nullish(), + hygraphWriteAccessEndpoint: _zod.z.string().nullish(), + hygraphWriteAccessToken: _zod.z.string().nullish(), + limitSsg: _zod.z.boolean().nullish(), + magentoEndpoint: _zod.z.string().min(1), + previewSecret: _zod.z.string().nullish(), + productFiltersLayout: ProductFiltersLayoutSchema.nullish(), + productFiltersPro: _zod.z.boolean().nullish(), + productRoute: _zod.z.string().nullish(), recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(), - robotsAllow: zod_1.z.boolean().nullish(), + robotsAllow: _zod.z.boolean().nullish(), sidebarGallery: SidebarGalleryConfigSchema().nullish(), - storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()), - wishlistHideForGuests: zod_1.z.boolean().nullish(), - wishlistShowFeedbackMessage: zod_1.z.boolean().nullish() + storefront: _zod.z.array(GraphCommerceStorefrontConfigSchema()), + wishlistHideForGuests: _zod.z.boolean().nullish(), + wishlistShowFeedbackMessage: _zod.z.boolean().nullish() }); } -exports.GraphCommerceConfigSchema = GraphCommerceConfigSchema; function GraphCommerceDebugConfigSchema() { - return zod_1.z.object({ - pluginStatus: zod_1.z.boolean().nullish(), - sessions: zod_1.z.boolean().nullish(), - webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(), - webpackDuplicatesPlugin: zod_1.z.boolean().nullish() + return _zod.z.object({ + pluginStatus: _zod.z.boolean().nullish(), + sessions: _zod.z.boolean().nullish(), + webpackCircularDependencyPlugin: _zod.z.boolean().nullish(), + webpackDuplicatesPlugin: _zod.z.boolean().nullish() }); } -exports.GraphCommerceDebugConfigSchema = GraphCommerceDebugConfigSchema; function GraphCommerceStorefrontConfigSchema() { - return zod_1.z.object({ - canonicalBaseUrl: zod_1.z.string().nullish(), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - defaultLocale: zod_1.z.boolean().nullish(), - domain: zod_1.z.string().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(), - linguiLocale: zod_1.z.string().nullish(), - locale: zod_1.z.string().min(1), - magentoStoreCode: zod_1.z.string().min(1) + return _zod.z.object({ + canonicalBaseUrl: _zod.z.string().nullish(), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + defaultLocale: _zod.z.boolean().nullish(), + domain: _zod.z.string().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + hygraphLocales: _zod.z.array(_zod.z.string().min(1)).nullish(), + linguiLocale: _zod.z.string().nullish(), + locale: _zod.z.string().min(1), + magentoStoreCode: _zod.z.string().min(1) }); } -exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema; function MagentoConfigurableVariantValuesSchema() { - return zod_1.z.object({ - content: zod_1.z.boolean().nullish(), - gallery: zod_1.z.boolean().nullish(), - url: zod_1.z.boolean().nullish() + return _zod.z.object({ + content: _zod.z.boolean().nullish(), + gallery: _zod.z.boolean().nullish(), + url: _zod.z.boolean().nullish() }); } -exports.MagentoConfigurableVariantValuesSchema = MagentoConfigurableVariantValuesSchema; function RecentlyViewedProductsConfigSchema() { - return zod_1.z.object({ - enabled: zod_1.z.boolean().nullish(), - maxCount: zod_1.z.number().nullish() + return _zod.z.object({ + enabled: _zod.z.boolean().nullish(), + maxCount: _zod.z.number().nullish() }); } -exports.RecentlyViewedProductsConfigSchema = RecentlyViewedProductsConfigSchema; function SidebarGalleryConfigSchema() { - return zod_1.z.object({ - paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish() + return _zod.z.object({ + paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() }); } -exports.SidebarGalleryConfigSchema = SidebarGalleryConfigSchema; diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 3cfa2119f1..f3b4d8189a 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -203,6 +203,7 @@ export type GraphCommerceConfig = { * This value is required even if you are configuring different values for each locale. */ googleTagmanagerId?: InputMaybe; + /** Disables all login functionalities */ guestOnlyMode?: InputMaybe; /** * The HyGraph endpoint. From 3612c994b80bb3b1bc02de10668f69a332402dc4 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Tue, 12 Mar 2024 10:42:09 +0100 Subject: [PATCH 16/48] Added changeset --- .changeset/popular-rules-complain.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/popular-rules-complain.md diff --git a/.changeset/popular-rules-complain.md b/.changeset/popular-rules-complain.md new file mode 100644 index 0000000000..715c4093f3 --- /dev/null +++ b/.changeset/popular-rules-complain.md @@ -0,0 +1,7 @@ +--- +"@graphcommerce/magento-cart-email": patch +"@graphcommerce/magento-customer": patch +"@graphcommerce/magento-cart": patch +--- + +Created guestOnly-mode From 78ed1aa179c8bd3ec4a5d4f1c6bbb553b247da81 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Tue, 12 Mar 2024 10:47:09 +0100 Subject: [PATCH 17/48] Fix guestOnlyOnly for EmailForm --- packages/magento-cart-email/EmailForm/EmailForm.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/magento-cart-email/EmailForm/EmailForm.tsx b/packages/magento-cart-email/EmailForm/EmailForm.tsx index f970e45097..4079aefd79 100644 --- a/packages/magento-cart-email/EmailForm/EmailForm.tsx +++ b/packages/magento-cart-email/EmailForm/EmailForm.tsx @@ -70,11 +70,10 @@ const EmailFormBase = React.memo((props) => { }} InputProps={{ autoComplete: 'email', - endAdornment: ( + endAdornment: !import.meta.graphCommerce.guestOnlyMode && ( {(isEmailAvailable.data?.isEmailAvailable || - (!import.meta.graphCommerce.enableGuestCheckoutLogin && - !import.meta.graphCommerce.guestOnlyMode)) && ( + !import.meta.graphCommerce.enableGuestCheckoutLogin) && ( + } + /> + ) +} diff --git a/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx b/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx index 8db8da8d93..e7bdfccd2c 100644 --- a/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx +++ b/packages/magento-customer/components/WaitForCustomer/WaitForCustomer.tsx @@ -1,10 +1,11 @@ import { mergeErrors, WaitForQueries, WaitForQueriesProps } from '@graphcommerce/ecommerce-ui' -import { FullPageMessage, IconSvg, iconPerson } from '@graphcommerce/next-ui' +import { FullPageMessage } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' -import { Button, CircularProgress } from '@mui/material' +import { 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 & { waitFor?: WaitForQueriesProps['waitFor'] @@ -58,22 +59,7 @@ export function WaitForCustomer(props: WaitForCustomerProps) { ) } > - {!session.loggedIn && - (unauthenticated ?? ( - } - title={} - button={ - - } - /> - ))} + {!session.loggedIn && (unauthenticated ?? )} {session.loggedIn && error && } {session.loggedIn && !error && children} From 0ccd9cb9f784f98c8919006a491a7f3efe32f873 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Wed, 17 Apr 2024 16:34:26 +0200 Subject: [PATCH 23/48] Added translations --- examples/magento-graphcms/locales/de.po | 7 ++----- examples/magento-graphcms/locales/en.po | 7 ++----- examples/magento-graphcms/locales/es.po | 7 ++----- examples/magento-graphcms/locales/fr.po | 7 ++----- examples/magento-graphcms/locales/it.po | 7 ++----- examples/magento-graphcms/locales/nl.po | 7 ++----- 6 files changed, 12 insertions(+), 30 deletions(-) diff --git a/examples/magento-graphcms/locales/de.po b/examples/magento-graphcms/locales/de.po index 3c158f38a2..2b732be01c 100644 --- a/examples/magento-graphcms/locales/de.po +++ b/examples/magento-graphcms/locales/de.po @@ -280,8 +280,8 @@ msgstr "Kostenlos" msgid "Grand total" msgstr "Gesamtsumme" -msgid "Have an account?" -msgstr "Haben Sie ein Kundenkonto?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "Der Gast-Checkout ist für diesen Shop deaktiviert. Bitte melden Sie sich an, um fortzufahren." msgid "Hi {firstname}! You’re now logged in!" msgstr "Hallo {firstname}! Sie sind jetzt angemeldet!" @@ -793,9 +793,6 @@ msgstr "Bewertungen geschrieben: {0}" msgid "You are reviewing {0}" msgstr "Sie bewerten {0}" -msgid "You can find your order history in your account!" -msgstr "Sie können Ihren Bestellverlauf in Ihrem Kundenkonto einsehen!" - msgid "You can now <0>sign in again." msgstr "Sie können sich jetzt <0>erneut anmelden." diff --git a/examples/magento-graphcms/locales/en.po b/examples/magento-graphcms/locales/en.po index 9029cbc350..543c051ac7 100644 --- a/examples/magento-graphcms/locales/en.po +++ b/examples/magento-graphcms/locales/en.po @@ -280,8 +280,8 @@ msgstr "Free" msgid "Grand total" msgstr "Grand total" -msgid "Have an account?" -msgstr "Have an account?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "Guest checkout is disabled for this store please login to continue." msgid "Hi {firstname}! You’re now logged in!" msgstr "Hi {firstname}! You’re now logged in!" @@ -793,9 +793,6 @@ msgstr "Written {0} reviews" msgid "You are reviewing {0}" msgstr "You are reviewing {0}" -msgid "You can find your order history in your account!" -msgstr "You can find your order history in your account!" - msgid "You can now <0>sign in again." msgstr "You can now <0>sign in again." diff --git a/examples/magento-graphcms/locales/es.po b/examples/magento-graphcms/locales/es.po index 0e9e6356bd..a95f9e4b6f 100644 --- a/examples/magento-graphcms/locales/es.po +++ b/examples/magento-graphcms/locales/es.po @@ -280,8 +280,8 @@ msgstr "Gratis" msgid "Grand total" msgstr "Total" -msgid "Have an account?" -msgstr "¿Tiene una cuenta?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "El pago como invitado está deshabilitado para esta tienda. Inicie sesión para continuar." msgid "Hi {firstname}! You’re now logged in!" msgstr "¡Hola {firstname}! Ya estás conectado!" @@ -793,9 +793,6 @@ msgstr "Escribir {0} comentarios" msgid "You are reviewing {0}" msgstr "Está revisando {0}" -msgid "You can find your order history in your account!" -msgstr "¡Puede encontrar el historial de sus pedidos en su cuenta!" - msgid "You can now <0>sign in again." msgstr "Ahora puede<0>iniciar sesión de nuevo." diff --git a/examples/magento-graphcms/locales/fr.po b/examples/magento-graphcms/locales/fr.po index 8cbc02dc47..61c15d048d 100644 --- a/examples/magento-graphcms/locales/fr.po +++ b/examples/magento-graphcms/locales/fr.po @@ -280,8 +280,8 @@ msgstr "Gratuit" msgid "Grand total" msgstr "Total" -msgid "Have an account?" -msgstr "Vous avez déjà un compte?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "Le paiement des invités est désactivé pour ce magasin, veuillez vous connecter pour continuer." msgid "Hi {firstname}! You’re now logged in!" msgstr "Bonjour {firstname}! Vous êtes maintenant connecté!" @@ -793,9 +793,6 @@ msgstr "Évaluations écrites {0}" msgid "You are reviewing {0}" msgstr "Vous évaluez {0}" -msgid "You can find your order history in your account!" -msgstr "Vous pouvez trouver l'historique de vos commandes dans votre compte!" - msgid "You can now <0>sign in again." msgstr "Vous pouvez maintenant<0>vous connecter à nouveau." diff --git a/examples/magento-graphcms/locales/it.po b/examples/magento-graphcms/locales/it.po index 8f61f34613..2718c1d30c 100644 --- a/examples/magento-graphcms/locales/it.po +++ b/examples/magento-graphcms/locales/it.po @@ -280,8 +280,8 @@ msgstr "Gratis" msgid "Grand total" msgstr "Totale" -msgid "Have an account?" -msgstr "Hai già un account?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "Il pagamento come ospite è disabilitato per questo negozio, effettua l'accesso per continuare." msgid "Hi {firstname}! You’re now logged in!" msgstr "Ciao {firstname}! Ora sei loggato!" @@ -793,9 +793,6 @@ msgstr "Scritto {0} recensioni" msgid "You are reviewing {0}" msgstr "Stai recensendo {0}" -msgid "You can find your order history in your account!" -msgstr "Puoi trovare la cronologia dei tuoi ordini nel tuo account!" - msgid "You can now <0>sign in again." msgstr "Ora puoi <0>accedere nuovamente." diff --git a/examples/magento-graphcms/locales/nl.po b/examples/magento-graphcms/locales/nl.po index 62ae68d32a..6892aa2b5a 100644 --- a/examples/magento-graphcms/locales/nl.po +++ b/examples/magento-graphcms/locales/nl.po @@ -280,8 +280,8 @@ msgstr "Gratis" msgid "Grand total" msgstr "Totaal" -msgid "Have an account?" -msgstr "Heeft u al een account?" +msgid "Guest checkout is disabled for this store please login to continue." +msgstr "Afrekenen als gast is uitgeschakeld voor deze winkel. Log in om door te gaan." msgid "Hi {firstname}! You’re now logged in!" msgstr "Hallo {firstname}! U bent nu ingelogd!" @@ -793,9 +793,6 @@ msgstr "{0} reviews geschreven" msgid "You are reviewing {0}" msgstr "U reviewt {0}" -msgid "You can find your order history in your account!" -msgstr "U kunt uw bestelgeschiedenis in uw account vinden!" - msgid "You can now <0>sign in again." msgstr "U kunt nu <0>opnieuw inloggen" From 48d1c4ea6ac90a9519b53f6bc655e6ca2c8f923a Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Wed, 17 Apr 2024 16:35:03 +0200 Subject: [PATCH 24/48] Disabled checkout if user is not loggedIn and DISABLE_GUEST_CHECKOUT is used as config --- .../magento-graphcms/pages/checkout/index.tsx | 16 +++++++++++++-- .../pages/checkout/payment.tsx | 11 +++++++++- .../CartStartCheckout/CartStartCheckout.tsx | 20 +++++++++++++++++-- .../CartStartCheckoutLinkOrButton.tsx | 15 ++++++++++++-- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/examples/magento-graphcms/pages/checkout/index.tsx b/examples/magento-graphcms/pages/checkout/index.tsx index 7aeae371ae..6c0191028a 100644 --- a/examples/magento-graphcms/pages/checkout/index.tsx +++ b/examples/magento-graphcms/pages/checkout/index.tsx @@ -19,7 +19,11 @@ import { CustomerAddressForm, } from '@graphcommerce/magento-cart-shipping-address' import { ShippingMethodForm } from '@graphcommerce/magento-cart-shipping-method' -import { CustomerDocument, useCustomerQuery } from '@graphcommerce/magento-customer' +import { + CustomerDocument, + useCustomerQuery, + useCustomerSession, +} from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { FormActions, @@ -30,6 +34,7 @@ import { LayoutTitle, FullPageMessage, iconAddresses, + useStorefrontConfig, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' @@ -37,6 +42,7 @@ import { CircularProgress, Container, Typography } from '@mui/material' import { useRouter } from 'next/router' import { LayoutDocument, LayoutMinimal, LayoutMinimalProps } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' +import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' type Props = Record type GetPageStaticProps = GetStaticProps @@ -46,11 +52,17 @@ function ShippingPage() { const shippingPage = useCartQuery(ShippingPageDocument, { fetchPolicy: 'cache-and-network' }) const customerAddresses = useCustomerQuery(CustomerDocument, { fetchPolicy: 'cache-and-network' }) + const { signInMode } = useStorefrontConfig() + const { loggedIn } = useCustomerSession() + const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const cartExists = typeof shippingPage.data?.cart !== 'undefined' && (shippingPage.data.cart?.items?.length ?? 0) > 0 - return ( + return disableGuestCheckout ? ( + + ) : ( <> 0 - return ( + const { signInMode } = useStorefrontConfig() + const { loggedIn } = useCustomerSession() + const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + + return disableGuestCheckout ? ( + + ) : ( diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index 8e5ab71dc0..19b139ce2d 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -1,9 +1,15 @@ import { Money } from '@graphcommerce/magento-store' -import { iconChevronRight, IconSvg, extendableComponent } from '@graphcommerce/next-ui' +import { + iconChevronRight, + IconSvg, + extendableComponent, + useStorefrontConfig, +} from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { Box, Button, ButtonProps, SxProps, Theme } from '@mui/material' import React from 'react' import { CartStartCheckoutFragment } from './CartStartCheckout.gql' +import { useCustomerSession } from '@graphcommerce/magento-customer' export type CartStartCheckoutProps = CartStartCheckoutFragment & { children?: React.ReactNode @@ -32,6 +38,10 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { ...cart } = props + const { signInMode } = useStorefrontConfig() + const { loggedIn } = useCustomerSession() + const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const hasTotals = (cart.prices?.grand_total?.value ?? 0) > 0 const hasErrors = cart.items?.some((item) => (item?.errors?.length ?? 0) > 0) @@ -56,7 +66,7 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { onStart?.(e, cart) return onClick?.(e) }} - disabled={disabled || !hasTotals || hasErrors} + disabled={disabled || !hasTotals || hasErrors || disableGuestCheckout} {...buttonProps} > )} + + {disableGuestCheckout && ( + ({ color: 'error.main', mt: theme.spacings.xs })}> + + + )} ) } diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx index 80092ec1c7..48943e62e9 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx @@ -1,8 +1,15 @@ -import { iconChevronRight, IconSvg, LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui' +import { + iconChevronRight, + IconSvg, + LinkOrButton, + LinkOrButtonProps, + useStorefrontConfig, +} from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { SxProps, Theme } from '@mui/material' import React from 'react' import { CartStartCheckoutFragment } from './CartStartCheckout.gql' +import { useCustomerSession } from '@graphcommerce/magento-customer' export type CartStartCheckoutLinkOrButtonProps = CartStartCheckoutFragment & { children?: React.ReactNode @@ -24,6 +31,10 @@ export function CartStartCheckoutLinkOrButton(props: CartStartCheckoutLinkOrButt ...cart } = props + const { signInMode } = useStorefrontConfig() + const { loggedIn } = useCustomerSession() + const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const hasTotals = (cart.prices?.grand_total?.value ?? 0) > 0 const hasErrors = cart.items?.some((item) => (item?.errors?.length ?? 0) > 0) @@ -37,7 +48,7 @@ export function CartStartCheckoutLinkOrButton(props: CartStartCheckoutLinkOrButt onStart?.(e, cart) }} button={{ variant: 'pill', ...button }} - disabled={disabled || !hasTotals || hasErrors} + disabled={disabled || !hasTotals || hasErrors || disableGuestCheckout} color='secondary' endIcon={} {...linkOrButtonProps} From bd146007ea25af8ca5df0eea29f28a203934ce68 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 19 Apr 2024 10:24:10 +0200 Subject: [PATCH 25/48] StartcheckoutButton links to accoun/signin if guest checkout is disabled and user is not logged in --- .../components/CartStartCheckout/CartStartCheckout.tsx | 10 ++-------- .../CartStartCheckoutLinkOrButton.tsx | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index 19b139ce2d..542d64f14a 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -54,7 +54,7 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { ]} > } + {...props} /> ) } From aa3505ac22b92f1ca14a0fcc7911786aa49b899c Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 10 May 2024 14:46:35 +0200 Subject: [PATCH 29/48] Added sign in button to AddProductsToCartButton --- .../AddProductsToCartButton.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx index 0af4411ea8..8010b43693 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx @@ -1,5 +1,7 @@ -import { Button, ButtonProps } from '@graphcommerce/next-ui' +import { useCustomerSession } from '@graphcommerce/magento-customer' +import { Button, ButtonProps, useStorefrontConfig } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' +import { useRouter } from 'next/router' import { useAddProductsToCartAction, UseAddProductsToCartActionProps, @@ -22,8 +24,23 @@ export type AddProductsToCartButtonProps = UseAddProductsToCartActionProps & export function AddProductsToCartButton(props: AddProductsToCartButtonProps) { const { children, product, ...rest } = props const { showSuccess, ...action } = useAddProductsToCartAction(props) + const router = useRouter() + const { loggedIn } = useCustomerSession() + const { signInMode } = useStorefrontConfig() + const loginRequiredForCart = signInMode === 'DISABLE_GUEST_ADD_TO_CART' && !loggedIn - return ( + return loginRequiredForCart ? ( + + ) : ( From a6c58029a5327753273ed1155f5b97b4a83e74aa Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 10 May 2024 14:51:19 +0200 Subject: [PATCH 30/48] Added different fab which navigates to signin --- .../AddProductsToCartFab.tsx | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx index f2615f47c0..e1d9dab076 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx @@ -1,6 +1,14 @@ -import { Fab, FabProps, iconShoppingBag, iconCheckmark } from '@graphcommerce/next-ui' +import { useCustomerSession } from '@graphcommerce/magento-customer' +import { + Fab, + FabProps, + iconShoppingBag, + iconCheckmark, + useStorefrontConfig, +} from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { SxProps, Theme } from '@mui/material' +import { useRouter } from 'next/router' import { useAddProductsToCartAction, UseAddProductsToCartActionProps, @@ -16,7 +24,26 @@ export function AddProductsToCartFab(props: AddProductsToCartFabProps) { const { icon = iconShoppingBag, product, sku, ...rest } = props const { showSuccess, ...action } = useAddProductsToCartAction(props) - return ( + const router = useRouter() + const { loggedIn } = useCustomerSession() + const { signInMode } = useStorefrontConfig() + const loginRequiredForCart = signInMode === 'DISABLE_GUEST_ADD_TO_CART' && !loggedIn + + return loginRequiredForCart ? ( + { + e.preventDefault() + e.stopPropagation() + await router.push('/account/signin') + }} + onMouseDown={(e) => { + e.preventDefault() + e.stopPropagation() + }} + /> + ) : ( Date: Fri, 10 May 2024 14:52:03 +0200 Subject: [PATCH 31/48] Updated pages which need to show a button to the signinPage when guests are not allowed --- examples/magento-graphcms/pages/cart.tsx | 68 +++++++++++-------- .../magento-graphcms/pages/checkout/index.tsx | 6 +- .../pages/checkout/payment.tsx | 4 +- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/examples/magento-graphcms/pages/cart.tsx b/examples/magento-graphcms/pages/cart.tsx index d468422ee8..573c15418e 100644 --- a/examples/magento-graphcms/pages/cart.tsx +++ b/examples/magento-graphcms/pages/cart.tsx @@ -11,6 +11,7 @@ import { import { CartPageDocument } from '@graphcommerce/magento-cart-checkout' import { CouponAccordion } from '@graphcommerce/magento-cart-coupon' import { CartItemsActionCards, CartCrosssellsScroller } from '@graphcommerce/magento-cart-items' +import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { Money, PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, @@ -20,12 +21,14 @@ import { LayoutOverlayHeader, FullPageMessage, OverlayStickyBottom, + useStorefrontConfig, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' import { CircularProgress, Container } from '@mui/material' import { LayoutOverlay, LayoutOverlayProps, productListRenderer } from '../components' import { graphqlSharedClient } from '../lib/graphql/graphqlSsrClient' +import { useCustomerSession } from '@graphcommerce/magento-customer' type Props = Record type GetPageStaticProps = GetStaticProps @@ -40,7 +43,10 @@ function CartPage() { const hasItems = (data?.cart?.total_quantity ?? 0) > 0 && typeof data?.cart?.prices?.grand_total?.value !== 'undefined' + const { loggedIn } = useCustomerSession() + const { signInMode } = useStorefrontConfig() + const loginRequiredForCart = signInMode === 'DISABLE_GUEST_ADD_TO_CART' && !loggedIn return ( <> - {hasItems ? ( + {hasItems && !loginRequiredForCart ? ( }} @@ -67,34 +73,38 @@ function CartPage() { )} - } title={}> - - - } - > - {hasItems ? ( - <> - - - ({ mt: theme.spacings.md })} /> - - - - ({ mt: theme.spacings.md })} - /> - - - - - ) : ( - {error && } - )} - + {loginRequiredForCart ? ( + + ) : ( + } title={}> + + + } + > + {hasItems ? ( + <> + + + ({ mt: theme.spacings.md })} /> + + + + ({ mt: theme.spacings.md })} + /> + + + + + ) : ( + {error && } + )} + + )} ) } diff --git a/examples/magento-graphcms/pages/checkout/index.tsx b/examples/magento-graphcms/pages/checkout/index.tsx index 6c0191028a..e3c62e135f 100644 --- a/examples/magento-graphcms/pages/checkout/index.tsx +++ b/examples/magento-graphcms/pages/checkout/index.tsx @@ -24,6 +24,7 @@ import { useCustomerQuery, useCustomerSession, } from '@graphcommerce/magento-customer' +import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { FormActions, @@ -42,7 +43,6 @@ import { CircularProgress, Container, Typography } from '@mui/material' import { useRouter } from 'next/router' import { LayoutDocument, LayoutMinimal, LayoutMinimalProps } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' -import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' type Props = Record type GetPageStaticProps = GetStaticProps @@ -54,7 +54,9 @@ function ShippingPage() { const { signInMode } = useStorefrontConfig() const { loggedIn } = useCustomerSession() - const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const disableGuestCheckout = + (signInMode === 'DISABLE_GUEST_CHECKOUT' || signInMode === 'DISABLE_GUEST_ADD_TO_CART') && + !loggedIn const cartExists = typeof shippingPage.data?.cart !== 'undefined' && diff --git a/examples/magento-graphcms/pages/checkout/payment.tsx b/examples/magento-graphcms/pages/checkout/payment.tsx index 64244c5e9b..de7705df98 100644 --- a/examples/magento-graphcms/pages/checkout/payment.tsx +++ b/examples/magento-graphcms/pages/checkout/payment.tsx @@ -50,7 +50,9 @@ function PaymentPage() { const { signInMode } = useStorefrontConfig() const { loggedIn } = useCustomerSession() - const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const disableGuestCheckout = + (signInMode === 'DISABLE_GUEST_CHECKOUT' || signInMode === 'DISABLE_GUEST_ADD_TO_CART') && + !loggedIn return disableGuestCheckout ? ( From 8f5a3b928c77db9f98f822a383e6f22071176b14 Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 10 May 2024 15:29:03 +0200 Subject: [PATCH 32/48] Fixed build errors --- .../next-config/dist/generated/config.js | 2 +- .../next-config/src/generated/config.ts | 229 +++++++++--------- 2 files changed, 121 insertions(+), 110 deletions(-) diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index 850c63a0e9..b0a6c820b9 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -134,7 +134,7 @@ function GraphCommerceStorefrontConfigSchema() { linguiLocale: _zod.z.string().nullish(), locale: _zod.z.string().min(1), magentoStoreCode: _zod.z.string().min(1), - signInMode: SignInModesSchema.nullish() + signInMode: SignInModesSchema.nullish(), robotsAllow: _zod.z.boolean().nullish() }); } diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 452591e7ad..6765199f82 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -1,30 +1,32 @@ /* eslint-disable */ import { z } from 'zod' -export type Maybe = T | null; -export type InputMaybe = Maybe; -export type Exact = { [K in keyof T]: T[K] }; -export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type Maybe = T | null +export type InputMaybe = Maybe +export type Exact = { [K in keyof T]: T[K] } +export type MakeOptional = Omit & { [SubKey in K]?: Maybe } +export type MakeMaybe = Omit & { [SubKey in K]: Maybe } +export type MakeEmpty = { + [_ in K]?: never +} +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never } /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { - ID: { input: string; output: string; } - String: { input: string; output: string; } - Boolean: { input: boolean; output: boolean; } - Int: { input: number; output: number; } - Float: { input: number; output: number; } -}; + ID: { input: string; output: string } + String: { input: string; output: string } + Boolean: { input: boolean; output: boolean } + Int: { input: number; output: number } + Float: { input: number; output: number } +} -export type CompareVariant = - | 'CHECKBOX' - | 'ICON'; +export type CompareVariant = 'CHECKBOX' | 'ICON' /** GoogleDatalayerConfig to allow enabling certain aspects of the datalayer */ export type DatalayerConfig = { /** Enable core web vitals tracking for GraphCommerce */ - coreWebVitals?: InputMaybe; -}; + coreWebVitals?: InputMaybe +} /** * # GraphCommerce configuration system @@ -112,20 +114,20 @@ export type GraphCommerceConfig = { * - https://example.com/en * - https://example.com/en-US */ - canonicalBaseUrl: Scalars['String']['input']; + canonicalBaseUrl: Scalars['String']['input'] /** * Due to a limitation of the GraphQL API it is not possible to determine if a cart should be displayed including or excluding tax. * * When Magento's StoreConfig adds this value, this can be replaced. */ - cartDisplayPricesInclTax?: InputMaybe; + cartDisplayPricesInclTax?: InputMaybe /** Use compare functionality */ - compare?: InputMaybe; + compare?: InputMaybe /** * By default the compare feature is denoted with a 'compare ICON' (2 arrows facing one another). * This may be fine for experienced users, but for more clarity it's also possible to present the compare feature as a CHECKBOX accompanied by the 'Compare' label */ - compareVariant?: InputMaybe; + compareVariant?: InputMaybe /** * If a simple product is part of a Configurable product page, should the simple product be * rendered as a configured option of the configurable product page? @@ -138,25 +140,25 @@ export type GraphCommerceConfig = { * If that is the case we render the configurable product page instead of the simple product page but * the options to select the simple product are pre-selected. */ - configurableVariantForSimple?: InputMaybe; + configurableVariantForSimple?: InputMaybe /** * When a user selects a variant, it will switch the values on the configurable page with the values of the configured variant. * * Enabling options here will allow switching of those variants. */ - configurableVariantValues?: InputMaybe; + configurableVariantValues?: InputMaybe /** * Determines if cross sell items should be shown when the user already has the product in their cart. This will result in a product will popping off the screen when you add it to the cart. * * Default: 'false' */ - crossSellsHideCartItems?: InputMaybe; + crossSellsHideCartItems?: InputMaybe /** * Determines if, after adding a cross-sell item to the cart, the user should be redirected to the cross-sell items of the product they just added. * * Default: 'false' */ - crossSellsRedirectItems?: InputMaybe; + crossSellsRedirectItems?: InputMaybe /** * Due to a limitation in the GraphQL API of Magento 2, we need to know if the * customer requires email confirmation. @@ -164,10 +166,10 @@ export type GraphCommerceConfig = { * This value should match Magento 2's configuration value for * `customer/create_account/confirm` and should be removed once we can query */ - customerRequireEmailConfirmation?: InputMaybe; - dataLayer?: InputMaybe; + customerRequireEmailConfirmation?: InputMaybe + dataLayer?: InputMaybe /** Debug configuration for GraphCommerce */ - debug?: InputMaybe; + debug?: InputMaybe /** * Enables some demo specific code that is probably not useful for a project: * @@ -175,7 +177,7 @@ export type GraphCommerceConfig = { * - Adds "dominant_color" attribute swatches to the product list items. * - Creates a big list items in the product list. */ - demoMode?: InputMaybe; + demoMode?: InputMaybe /** * Enable Guest Checkout Login: * During customer login, GraphCommerce queries Magento to determine whether @@ -185,7 +187,7 @@ export type GraphCommerceConfig = { * * `Stores -> Configuration -> Sales -> Checkout -> Checkout Options -> Enable Guest Checkout Login` */ - enableGuestCheckoutLogin?: InputMaybe; + enableGuestCheckoutLogin?: InputMaybe /** * See https://support.google.com/analytics/answer/9539598?hl=en * @@ -193,7 +195,7 @@ export type GraphCommerceConfig = { * * To override the value for a specific locale, configure in i18n config. */ - googleAnalyticsId?: InputMaybe; + googleAnalyticsId?: InputMaybe /** * Google reCAPTCHA site key. * When using reCAPTCHA, this value is required, even if you are configuring different values for each locale. @@ -203,13 +205,13 @@ export type GraphCommerceConfig = { * The secret key should be added in the Magento admin panel (Stores > Configuration > Security > Google ReCAPTCHA Storefront > reCAPTCHA v3 Invisible) * ReCAPTCHA can then be enabled/disabled for the different forms, separately (Stores > Configuration > Security > Google ReCAPTCHA Storefront > Storefront) */ - googleRecaptchaKey?: InputMaybe; + googleRecaptchaKey?: InputMaybe /** * The Google Tagmanager ID to be used on the site. * * This value is required even if you are configuring different values for each locale. */ - googleTagmanagerId?: InputMaybe; + googleTagmanagerId?: InputMaybe /** * The HyGraph endpoint. * @@ -217,11 +219,11 @@ export type GraphCommerceConfig = { * * Project settings -> API Access -> High Performance Read-only Content API */ - hygraphEndpoint: Scalars['String']['input']; + hygraphEndpoint: Scalars['String']['input'] /** Hygraph Management API. **Only used for migrations.** */ - hygraphManagementApi?: InputMaybe; + hygraphManagementApi?: InputMaybe /** Hygraph Project ID. **Only used for migrations.** */ - hygraphProjectId?: InputMaybe; + hygraphProjectId?: InputMaybe /** * Content API. **Only used for migrations.** * @@ -229,7 +231,7 @@ export type GraphCommerceConfig = { * * Project settings -> API Access -> Content API */ - hygraphWriteAccessEndpoint?: InputMaybe; + hygraphWriteAccessEndpoint?: InputMaybe /** * Hygraph Management SDK Authorization Token. **Only used for migrations.** * @@ -261,67 +263,67 @@ export type GraphCommerceConfig = { * yarn graphcommerce hygraph-migrate * ``` */ - hygraphWriteAccessToken?: InputMaybe; + hygraphWriteAccessToken?: InputMaybe /** * Limit the static generation of SSG when building. * * By default GraphCommerce will statically generate all product and category pages during build. This can take quite a long time, to skip this step set this value to true. */ - limitSsg?: InputMaybe; + limitSsg?: InputMaybe /** * GraphQL Magento endpoint. * * Examples: * - https://magento2.test/graphql */ - magentoEndpoint: Scalars['String']['input']; + magentoEndpoint: Scalars['String']['input'] /** To enable next.js' preview mode, configure the secret you'd like to use. */ - previewSecret?: InputMaybe; + previewSecret?: InputMaybe /** * Layout how the filters are rendered. * DEFAULT: Will be rendered as horzontal chips on desktop and mobile * SIDEBAR: Will be rendered as a sidebar on desktop and horizontal chips on mobile */ - productFiltersLayout?: InputMaybe; + productFiltersLayout?: InputMaybe /** Product filters with better UI for mobile and desktop. */ - productFiltersPro?: InputMaybe; + productFiltersPro?: InputMaybe /** * By default we route products to /p/[url] but you can change this to /product/[url] if you wish. * * Default: '/p/' * Example: '/product/' */ - productRoute?: InputMaybe; + productRoute?: InputMaybe /** Settings for recently viewed products */ - recentlyViewedProducts?: InputMaybe; + recentlyViewedProducts?: InputMaybe /** * Allow the site to be indexed by search engines. * If false, the robots.txt file will be set to disallow all. */ - robotsAllow?: InputMaybe; + robotsAllow?: InputMaybe /** Configuration for the SidebarGallery component */ - sidebarGallery?: InputMaybe; + sidebarGallery?: InputMaybe /** All storefront configuration for the project */ - storefront: Array; + storefront: Array /** Hide the wishlist functionality for guests. */ - wishlistHideForGuests?: InputMaybe; + wishlistHideForGuests?: InputMaybe /** Show a message when the product is added to the wishlist. */ - wishlistShowFeedbackMessage?: InputMaybe; -}; + wishlistShowFeedbackMessage?: InputMaybe +} /** Debug configuration for GraphCommerce */ export type GraphCommerceDebugConfig = { /** Reports which plugins are enabled or disabled. */ - pluginStatus?: InputMaybe; + pluginStatus?: InputMaybe /** Enable debugging interface to debug sessions */ - sessions?: InputMaybe; + sessions?: InputMaybe /** * Cyclic dependencies can cause memory issues and other strange bugs. * This plugin will warn you when it detects a cyclic dependency. * * When running into memory issues, it can be useful to enable this plugin. */ - webpackCircularDependencyPlugin?: InputMaybe; + webpackCircularDependencyPlugin?: InputMaybe /** * When updating packages it can happen that the same package is included with different versions in the same project. * @@ -329,8 +331,8 @@ export type GraphCommerceDebugConfig = { * - The same package is included multiple times in the bundle, increasing the bundle size. * - The Typescript types of the package are not compatible with each other, causing Typescript errors. */ - webpackDuplicatesPlugin?: InputMaybe; -}; + webpackDuplicatesPlugin?: InputMaybe +} /** All storefront configuration for the project */ export type GraphCommerceStorefrontConfig = { @@ -342,37 +344,37 @@ export type GraphCommerceStorefrontConfig = { * - https://example.com/en * - https://example.com/en-US */ - canonicalBaseUrl?: InputMaybe; + canonicalBaseUrl?: InputMaybe /** Due to a limitation of the GraphQL API it is not possible to determine if a cart should be displayed including or excluding tax. */ - cartDisplayPricesInclTax?: InputMaybe; + cartDisplayPricesInclTax?: InputMaybe /** * There can only be one entry with defaultLocale set to true. * - If there are more, the first one is used. * - If there is none, the first entry is used. */ - defaultLocale?: InputMaybe; + defaultLocale?: InputMaybe /** Domain configuration, must be a domain https://tools.ietf.org/html/rfc3986 */ - domain?: InputMaybe; + domain?: InputMaybe /** * Configure different Google Analytics IDs for different locales. * * To disable for a specific locale, set the value to null. */ - googleAnalyticsId?: InputMaybe; + googleAnalyticsId?: InputMaybe /** Locale specific google reCAPTCHA key. */ - googleRecaptchaKey?: InputMaybe; + googleRecaptchaKey?: InputMaybe /** The Google Tagmanager ID to be used per locale. */ - googleTagmanagerId?: InputMaybe; + googleTagmanagerId?: InputMaybe /** Add a gcms-locales header to make sure queries return in a certain language, can be an array to define fallbacks. */ - hygraphLocales?: InputMaybe>; + hygraphLocales?: InputMaybe> /** Custom locale used to load the .po files. Must be a valid locale, also used for Intl functions. */ - linguiLocale?: InputMaybe; + linguiLocale?: InputMaybe /** * Must be a [locale string](https://www.unicode.org/reports/tr35/tr35-59/tr35.html#Identifiers) for automatic redirects to work. * * This value can be used as a sub-path identifier only, make sure linguiLocale is configured for each URL. */ - locale: Scalars['String']['input']; + locale: Scalars['String']['input'] /** * Magento store code. * @@ -383,87 +385,88 @@ export type GraphCommerceStorefrontConfig = { * - en-us * - b2b-us */ - magentoStoreCode: Scalars['String']['input']; + magentoStoreCode: Scalars['String']['input'] /** * GUEST_ONLY disables all login functionalities * DISABLE_GUEST_CHECKOUT disables guest checkout. Products can still be added to the cart if not logged in. * DISABLE_GUEST_ADD_TO_CART disables disables guest checkout. Products CAN NOT be added to the cart if not logged in. * DEFAULT allows all functionalities */ - signInMode?: InputMaybe; + signInMode?: InputMaybe + /* * Allow the site to be indexed by search engines. * If false, the robots.txt file will be set to disallow all. */ - robotsAllow?: InputMaybe; -}; + robotsAllow?: InputMaybe +} /** Options to configure which values will be replaced when a variant is selected on the product page. */ export type MagentoConfigurableVariantValues = { /** Use the name, description, short description and meta data from the configured variant */ - content?: InputMaybe; + content?: InputMaybe /** * This option enables the automatic update of product gallery images on the product page when a variant is selected, * provided that the gallery images for the selected variant differ from the currently displayed images. */ - gallery?: InputMaybe; + gallery?: InputMaybe /** * When a variant is selected the URL of the product will be changed in the address bar. * * This only happens when the actual variant is can be accessed by the URL. */ - url?: InputMaybe; -}; + url?: InputMaybe +} -export type ProductFiltersLayout = - | 'DEFAULT' - | 'SIDEBAR'; +export type ProductFiltersLayout = 'DEFAULT' | 'SIDEBAR' /** Settings for recently viewed products */ export type RecentlyViewedProductsConfig = { /** Enable/disable recently viewed products */ - enabled?: InputMaybe; + enabled?: InputMaybe /** Number of recently viewed products to be stored in localStorage */ - maxCount?: InputMaybe; -}; + maxCount?: InputMaybe +} /** SidebarGalleryConfig will contain all configuration values for the Sidebar Gallery component. */ export type SidebarGalleryConfig = { /** Variant used for the pagination */ - paginationVariant?: InputMaybe; -}; + paginationVariant?: InputMaybe +} /** Enumeration of all possible positions for the sidebar gallery thumbnails. */ -export type SidebarGalleryPaginationVariant = - | 'DOTS' - | 'THUMBNAILS_BOTTOM'; +export type SidebarGalleryPaginationVariant = 'DOTS' | 'THUMBNAILS_BOTTOM' export type SignInModes = | 'DEFAULT' | 'DISABLE_GUEST_ADD_TO_CART' | 'DISABLE_GUEST_CHECKOUT' - | 'GUEST_ONLY'; - + | 'GUEST_ONLY' type Properties = Required<{ - [K in keyof T]: z.ZodType; -}>; + [K in keyof T]: z.ZodType +}> -type definedNonNullAny = {}; +type definedNonNullAny = {} -export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null; +export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null -export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v)); +export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v)) -export const CompareVariantSchema = z.enum(['CHECKBOX', 'ICON']); +export const CompareVariantSchema = z.enum(['CHECKBOX', 'ICON']) -export const ProductFiltersLayoutSchema = z.enum(['DEFAULT', 'SIDEBAR']); +export const ProductFiltersLayoutSchema = z.enum(['DEFAULT', 'SIDEBAR']) -export const SidebarGalleryPaginationVariantSchema = z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); +export const SidebarGalleryPaginationVariantSchema = z.enum(['DOTS', 'THUMBNAILS_BOTTOM']) -export const SignInModesSchema = z.enum(['DEFAULT', 'DISABLE_GUEST_ADD_TO_CART', 'DISABLE_GUEST_CHECKOUT', 'GUEST_ONLY']); +export const SignInModesSchema = z.enum([ + 'DEFAULT', + 'DISABLE_GUEST_ADD_TO_CART', + 'DISABLE_GUEST_CHECKOUT', + 'GUEST_ONLY', +]) export function DatalayerConfigSchema(): z.ZodObject> { return z.object({ - coreWebVitals: z.boolean().nullish() + coreWebVitals: z.boolean().nullish(), }) } @@ -501,20 +504,24 @@ export function GraphCommerceConfigSchema(): z.ZodObject> { +export function GraphCommerceDebugConfigSchema(): z.ZodObject< + Properties +> { return z.object({ pluginStatus: z.boolean().nullish(), sessions: z.boolean().nullish(), webpackCircularDependencyPlugin: z.boolean().nullish(), - webpackDuplicatesPlugin: z.boolean().nullish() + webpackDuplicatesPlugin: z.boolean().nullish(), }) } -export function GraphCommerceStorefrontConfigSchema(): z.ZodObject> { +export function GraphCommerceStorefrontConfigSchema(): z.ZodObject< + Properties +> { return z.object({ canonicalBaseUrl: z.string().nullish(), cartDisplayPricesInclTax: z.boolean().nullish(), @@ -527,28 +534,32 @@ export function GraphCommerceStorefrontConfigSchema(): z.ZodObject> { +export function MagentoConfigurableVariantValuesSchema(): z.ZodObject< + Properties +> { return z.object({ content: z.boolean().nullish(), gallery: z.boolean().nullish(), - url: z.boolean().nullish() + url: z.boolean().nullish(), }) } -export function RecentlyViewedProductsConfigSchema(): z.ZodObject> { +export function RecentlyViewedProductsConfigSchema(): z.ZodObject< + Properties +> { return z.object({ enabled: z.boolean().nullish(), - maxCount: z.number().nullish() + maxCount: z.number().nullish(), }) } export function SidebarGalleryConfigSchema(): z.ZodObject> { return z.object({ - paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() + paginationVariant: SidebarGalleryPaginationVariantSchema.nullish(), }) } From 5b36d28205745ffe027a8fcac2199d33eac85caf Mon Sep 17 00:00:00 2001 From: Jesse van der Poel Date: Fri, 10 May 2024 15:49:17 +0200 Subject: [PATCH 33/48] fixed more rrors --- .../CartStartCheckout/CartStartCheckout.tsx | 5 +- .../CartStartCheckoutLinkOrButton.tsx | 5 +- .../next-config/dist/generated/config.js | 5 +- .../next-config/src/generated/config.ts | 235 +++++++++--------- 4 files changed, 119 insertions(+), 131 deletions(-) diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index 4778615d3d..436699bfad 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -46,9 +46,8 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { const { loggedIn } = useCustomerSession() const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn - const hasTotals = (cart.prices?.grand_total?.value ?? 0) > 0 - const hasErrors = cart.items?.some((item) => (item?.errors?.length ?? 0) > 0) - + const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0 + const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0) return ( 0 - const hasErrors = cart.items?.some((item) => (item?.errors?.length ?? 0) > 0) - + const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0 + const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0) return ( = T | null -export type InputMaybe = Maybe -export type Exact = { [K in keyof T]: T[K] } -export type MakeOptional = Omit & { [SubKey in K]?: Maybe } -export type MakeMaybe = Omit & { [SubKey in K]: Maybe } -export type MakeEmpty = { - [_ in K]?: never -} -export type Incremental = - | T - | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never } +export type Maybe = T | null; +export type InputMaybe = Maybe; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +export type MakeEmpty = { [_ in K]?: never }; +export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { - ID: { input: string; output: string } - String: { input: string; output: string } - Boolean: { input: boolean; output: boolean } - Int: { input: number; output: number } - Float: { input: number; output: number } -} + ID: { input: string; output: string; } + String: { input: string; output: string; } + Boolean: { input: boolean; output: boolean; } + Int: { input: number; output: number; } + Float: { input: number; output: number; } +}; -export type CompareVariant = 'CHECKBOX' | 'ICON' +export type CompareVariant = + | 'CHECKBOX' + | 'ICON'; /** GoogleDatalayerConfig to allow enabling certain aspects of the datalayer */ export type DatalayerConfig = { /** Enable core web vitals tracking for GraphCommerce */ - coreWebVitals?: InputMaybe -} + coreWebVitals?: InputMaybe; +}; /** * # GraphCommerce configuration system @@ -114,20 +112,20 @@ export type GraphCommerceConfig = { * - https://example.com/en * - https://example.com/en-US */ - canonicalBaseUrl: Scalars['String']['input'] + canonicalBaseUrl: Scalars['String']['input']; /** * Due to a limitation of the GraphQL API it is not possible to determine if a cart should be displayed including or excluding tax. * * When Magento's StoreConfig adds this value, this can be replaced. */ - cartDisplayPricesInclTax?: InputMaybe + cartDisplayPricesInclTax?: InputMaybe; /** Use compare functionality */ - compare?: InputMaybe + compare?: InputMaybe; /** * By default the compare feature is denoted with a 'compare ICON' (2 arrows facing one another). * This may be fine for experienced users, but for more clarity it's also possible to present the compare feature as a CHECKBOX accompanied by the 'Compare' label */ - compareVariant?: InputMaybe + compareVariant?: InputMaybe; /** * If a simple product is part of a Configurable product page, should the simple product be * rendered as a configured option of the configurable product page? @@ -140,25 +138,25 @@ export type GraphCommerceConfig = { * If that is the case we render the configurable product page instead of the simple product page but * the options to select the simple product are pre-selected. */ - configurableVariantForSimple?: InputMaybe + configurableVariantForSimple?: InputMaybe; /** * When a user selects a variant, it will switch the values on the configurable page with the values of the configured variant. * * Enabling options here will allow switching of those variants. */ - configurableVariantValues?: InputMaybe + configurableVariantValues?: InputMaybe; /** * Determines if cross sell items should be shown when the user already has the product in their cart. This will result in a product will popping off the screen when you add it to the cart. * * Default: 'false' */ - crossSellsHideCartItems?: InputMaybe + crossSellsHideCartItems?: InputMaybe; /** * Determines if, after adding a cross-sell item to the cart, the user should be redirected to the cross-sell items of the product they just added. * * Default: 'false' */ - crossSellsRedirectItems?: InputMaybe + crossSellsRedirectItems?: InputMaybe; /** * Due to a limitation in the GraphQL API of Magento 2, we need to know if the * customer requires email confirmation. @@ -166,10 +164,10 @@ export type GraphCommerceConfig = { * This value should match Magento 2's configuration value for * `customer/create_account/confirm` and should be removed once we can query */ - customerRequireEmailConfirmation?: InputMaybe - dataLayer?: InputMaybe + customerRequireEmailConfirmation?: InputMaybe; + dataLayer?: InputMaybe; /** Debug configuration for GraphCommerce */ - debug?: InputMaybe + debug?: InputMaybe; /** * Enables some demo specific code that is probably not useful for a project: * @@ -177,7 +175,7 @@ export type GraphCommerceConfig = { * - Adds "dominant_color" attribute swatches to the product list items. * - Creates a big list items in the product list. */ - demoMode?: InputMaybe + demoMode?: InputMaybe; /** * Enable Guest Checkout Login: * During customer login, GraphCommerce queries Magento to determine whether @@ -187,7 +185,7 @@ export type GraphCommerceConfig = { * * `Stores -> Configuration -> Sales -> Checkout -> Checkout Options -> Enable Guest Checkout Login` */ - enableGuestCheckoutLogin?: InputMaybe + enableGuestCheckoutLogin?: InputMaybe; /** * See https://support.google.com/analytics/answer/9539598?hl=en * @@ -195,7 +193,7 @@ export type GraphCommerceConfig = { * * To override the value for a specific locale, configure in i18n config. */ - googleAnalyticsId?: InputMaybe + googleAnalyticsId?: InputMaybe; /** * Google reCAPTCHA site key. * When using reCAPTCHA, this value is required, even if you are configuring different values for each locale. @@ -205,13 +203,13 @@ export type GraphCommerceConfig = { * The secret key should be added in the Magento admin panel (Stores > Configuration > Security > Google ReCAPTCHA Storefront > reCAPTCHA v3 Invisible) * ReCAPTCHA can then be enabled/disabled for the different forms, separately (Stores > Configuration > Security > Google ReCAPTCHA Storefront > Storefront) */ - googleRecaptchaKey?: InputMaybe + googleRecaptchaKey?: InputMaybe; /** * The Google Tagmanager ID to be used on the site. * * This value is required even if you are configuring different values for each locale. */ - googleTagmanagerId?: InputMaybe + googleTagmanagerId?: InputMaybe; /** * The HyGraph endpoint. * @@ -219,11 +217,11 @@ export type GraphCommerceConfig = { * * Project settings -> API Access -> High Performance Read-only Content API */ - hygraphEndpoint: Scalars['String']['input'] + hygraphEndpoint: Scalars['String']['input']; /** Hygraph Management API. **Only used for migrations.** */ - hygraphManagementApi?: InputMaybe + hygraphManagementApi?: InputMaybe; /** Hygraph Project ID. **Only used for migrations.** */ - hygraphProjectId?: InputMaybe + hygraphProjectId?: InputMaybe; /** * Content API. **Only used for migrations.** * @@ -231,7 +229,7 @@ export type GraphCommerceConfig = { * * Project settings -> API Access -> Content API */ - hygraphWriteAccessEndpoint?: InputMaybe + hygraphWriteAccessEndpoint?: InputMaybe; /** * Hygraph Management SDK Authorization Token. **Only used for migrations.** * @@ -263,67 +261,67 @@ export type GraphCommerceConfig = { * yarn graphcommerce hygraph-migrate * ``` */ - hygraphWriteAccessToken?: InputMaybe + hygraphWriteAccessToken?: InputMaybe; /** * Limit the static generation of SSG when building. * * By default GraphCommerce will statically generate all product and category pages during build. This can take quite a long time, to skip this step set this value to true. */ - limitSsg?: InputMaybe + limitSsg?: InputMaybe; /** * GraphQL Magento endpoint. * * Examples: * - https://magento2.test/graphql */ - magentoEndpoint: Scalars['String']['input'] + magentoEndpoint: Scalars['String']['input']; /** To enable next.js' preview mode, configure the secret you'd like to use. */ - previewSecret?: InputMaybe + previewSecret?: InputMaybe; /** * Layout how the filters are rendered. * DEFAULT: Will be rendered as horzontal chips on desktop and mobile * SIDEBAR: Will be rendered as a sidebar on desktop and horizontal chips on mobile */ - productFiltersLayout?: InputMaybe + productFiltersLayout?: InputMaybe; /** Product filters with better UI for mobile and desktop. */ - productFiltersPro?: InputMaybe + productFiltersPro?: InputMaybe; /** * By default we route products to /p/[url] but you can change this to /product/[url] if you wish. * * Default: '/p/' * Example: '/product/' */ - productRoute?: InputMaybe + productRoute?: InputMaybe; /** Settings for recently viewed products */ - recentlyViewedProducts?: InputMaybe + recentlyViewedProducts?: InputMaybe; /** * Allow the site to be indexed by search engines. * If false, the robots.txt file will be set to disallow all. */ - robotsAllow?: InputMaybe + robotsAllow?: InputMaybe; /** Configuration for the SidebarGallery component */ - sidebarGallery?: InputMaybe + sidebarGallery?: InputMaybe; /** All storefront configuration for the project */ - storefront: Array + storefront: Array; /** Hide the wishlist functionality for guests. */ - wishlistHideForGuests?: InputMaybe + wishlistHideForGuests?: InputMaybe; /** Show a message when the product is added to the wishlist. */ - wishlistShowFeedbackMessage?: InputMaybe -} + wishlistShowFeedbackMessage?: InputMaybe; +}; /** Debug configuration for GraphCommerce */ export type GraphCommerceDebugConfig = { /** Reports which plugins are enabled or disabled. */ - pluginStatus?: InputMaybe + pluginStatus?: InputMaybe; /** Enable debugging interface to debug sessions */ - sessions?: InputMaybe + sessions?: InputMaybe; /** * Cyclic dependencies can cause memory issues and other strange bugs. * This plugin will warn you when it detects a cyclic dependency. * * When running into memory issues, it can be useful to enable this plugin. */ - webpackCircularDependencyPlugin?: InputMaybe + webpackCircularDependencyPlugin?: InputMaybe; /** * When updating packages it can happen that the same package is included with different versions in the same project. * @@ -331,8 +329,8 @@ export type GraphCommerceDebugConfig = { * - The same package is included multiple times in the bundle, increasing the bundle size. * - The Typescript types of the package are not compatible with each other, causing Typescript errors. */ - webpackDuplicatesPlugin?: InputMaybe -} + webpackDuplicatesPlugin?: InputMaybe; +}; /** All storefront configuration for the project */ export type GraphCommerceStorefrontConfig = { @@ -344,37 +342,37 @@ export type GraphCommerceStorefrontConfig = { * - https://example.com/en * - https://example.com/en-US */ - canonicalBaseUrl?: InputMaybe + canonicalBaseUrl?: InputMaybe; /** Due to a limitation of the GraphQL API it is not possible to determine if a cart should be displayed including or excluding tax. */ - cartDisplayPricesInclTax?: InputMaybe + cartDisplayPricesInclTax?: InputMaybe; /** * There can only be one entry with defaultLocale set to true. * - If there are more, the first one is used. * - If there is none, the first entry is used. */ - defaultLocale?: InputMaybe + defaultLocale?: InputMaybe; /** Domain configuration, must be a domain https://tools.ietf.org/html/rfc3986 */ - domain?: InputMaybe + domain?: InputMaybe; /** * Configure different Google Analytics IDs for different locales. * * To disable for a specific locale, set the value to null. */ - googleAnalyticsId?: InputMaybe + googleAnalyticsId?: InputMaybe; /** Locale specific google reCAPTCHA key. */ - googleRecaptchaKey?: InputMaybe + googleRecaptchaKey?: InputMaybe; /** The Google Tagmanager ID to be used per locale. */ - googleTagmanagerId?: InputMaybe + googleTagmanagerId?: InputMaybe; /** Add a gcms-locales header to make sure queries return in a certain language, can be an array to define fallbacks. */ - hygraphLocales?: InputMaybe> + hygraphLocales?: InputMaybe>; /** Custom locale used to load the .po files. Must be a valid locale, also used for Intl functions. */ - linguiLocale?: InputMaybe + linguiLocale?: InputMaybe; /** * Must be a [locale string](https://www.unicode.org/reports/tr35/tr35-59/tr35.html#Identifiers) for automatic redirects to work. * * This value can be used as a sub-path identifier only, make sure linguiLocale is configured for each URL. */ - locale: Scalars['String']['input'] + locale: Scalars['String']['input']; /** * Magento store code. * @@ -385,88 +383,89 @@ export type GraphCommerceStorefrontConfig = { * - en-us * - b2b-us */ - magentoStoreCode: Scalars['String']['input'] + magentoStoreCode: Scalars['String']['input']; + /** + * Allow the site to be indexed by search engines. + * If false, the robots.txt file will be set to disallow all. + */ + robotsAllow?: InputMaybe; /** * GUEST_ONLY disables all login functionalities * DISABLE_GUEST_CHECKOUT disables guest checkout. Products can still be added to the cart if not logged in. * DISABLE_GUEST_ADD_TO_CART disables disables guest checkout. Products CAN NOT be added to the cart if not logged in. * DEFAULT allows all functionalities */ - signInMode?: InputMaybe - /* - * Allow the site to be indexed by search engines. - * If false, the robots.txt file will be set to disallow all. - */ - robotsAllow?: InputMaybe -} + signInMode?: InputMaybe; +}; /** Options to configure which values will be replaced when a variant is selected on the product page. */ export type MagentoConfigurableVariantValues = { /** Use the name, description, short description and meta data from the configured variant */ - content?: InputMaybe + content?: InputMaybe; /** * This option enables the automatic update of product gallery images on the product page when a variant is selected, * provided that the gallery images for the selected variant differ from the currently displayed images. */ - gallery?: InputMaybe + gallery?: InputMaybe; /** * When a variant is selected the URL of the product will be changed in the address bar. * * This only happens when the actual variant is can be accessed by the URL. */ - url?: InputMaybe -} + url?: InputMaybe; +}; -export type ProductFiltersLayout = 'DEFAULT' | 'SIDEBAR' +export type ProductFiltersLayout = + | 'DEFAULT' + | 'SIDEBAR'; /** Settings for recently viewed products */ export type RecentlyViewedProductsConfig = { /** Enable/disable recently viewed products */ - enabled?: InputMaybe + enabled?: InputMaybe; /** Number of recently viewed products to be stored in localStorage */ - maxCount?: InputMaybe -} + maxCount?: InputMaybe; +}; /** SidebarGalleryConfig will contain all configuration values for the Sidebar Gallery component. */ export type SidebarGalleryConfig = { /** Variant used for the pagination */ - paginationVariant?: InputMaybe -} + paginationVariant?: InputMaybe; +}; /** Enumeration of all possible positions for the sidebar gallery thumbnails. */ -export type SidebarGalleryPaginationVariant = 'DOTS' | 'THUMBNAILS_BOTTOM' +export type SidebarGalleryPaginationVariant = + | 'DOTS' + | 'THUMBNAILS_BOTTOM'; export type SignInModes = | 'DEFAULT' | 'DISABLE_GUEST_ADD_TO_CART' | 'DISABLE_GUEST_CHECKOUT' - | 'GUEST_ONLY' + | 'GUEST_ONLY'; + type Properties = Required<{ - [K in keyof T]: z.ZodType -}> + [K in keyof T]: z.ZodType; +}>; + +type definedNonNullAny = {}; -type definedNonNullAny = {} +export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null; -export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null +export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v)); -export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v)) +export const CompareVariantSchema = z.enum(['CHECKBOX', 'ICON']); -export const CompareVariantSchema = z.enum(['CHECKBOX', 'ICON']) +export const ProductFiltersLayoutSchema = z.enum(['DEFAULT', 'SIDEBAR']); -export const ProductFiltersLayoutSchema = z.enum(['DEFAULT', 'SIDEBAR']) +export const SidebarGalleryPaginationVariantSchema = z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); -export const SidebarGalleryPaginationVariantSchema = z.enum(['DOTS', 'THUMBNAILS_BOTTOM']) +export const SignInModesSchema = z.enum(['DEFAULT', 'DISABLE_GUEST_ADD_TO_CART', 'DISABLE_GUEST_CHECKOUT', 'GUEST_ONLY']); -export const SignInModesSchema = z.enum([ - 'DEFAULT', - 'DISABLE_GUEST_ADD_TO_CART', - 'DISABLE_GUEST_CHECKOUT', - 'GUEST_ONLY', -]) export function DatalayerConfigSchema(): z.ZodObject> { return z.object({ - coreWebVitals: z.boolean().nullish(), + coreWebVitals: z.boolean().nullish() }) } @@ -504,24 +503,20 @@ export function GraphCommerceConfigSchema(): z.ZodObject -> { +export function GraphCommerceDebugConfigSchema(): z.ZodObject> { return z.object({ pluginStatus: z.boolean().nullish(), sessions: z.boolean().nullish(), webpackCircularDependencyPlugin: z.boolean().nullish(), - webpackDuplicatesPlugin: z.boolean().nullish(), + webpackDuplicatesPlugin: z.boolean().nullish() }) } -export function GraphCommerceStorefrontConfigSchema(): z.ZodObject< - Properties -> { +export function GraphCommerceStorefrontConfigSchema(): z.ZodObject> { return z.object({ canonicalBaseUrl: z.string().nullish(), cartDisplayPricesInclTax: z.boolean().nullish(), @@ -534,32 +529,28 @@ export function GraphCommerceStorefrontConfigSchema(): z.ZodObject< linguiLocale: z.string().nullish(), locale: z.string().min(1), magentoStoreCode: z.string().min(1), - signInMode: SignInModesSchema.nullish(), robotsAllow: z.boolean().nullish(), + signInMode: SignInModesSchema.nullish() }) } -export function MagentoConfigurableVariantValuesSchema(): z.ZodObject< - Properties -> { +export function MagentoConfigurableVariantValuesSchema(): z.ZodObject> { return z.object({ content: z.boolean().nullish(), gallery: z.boolean().nullish(), - url: z.boolean().nullish(), + url: z.boolean().nullish() }) } -export function RecentlyViewedProductsConfigSchema(): z.ZodObject< - Properties -> { +export function RecentlyViewedProductsConfigSchema(): z.ZodObject> { return z.object({ enabled: z.boolean().nullish(), - maxCount: z.number().nullish(), + maxCount: z.number().nullish() }) } export function SidebarGalleryConfigSchema(): z.ZodObject> { return z.object({ - paginationVariant: SidebarGalleryPaginationVariantSchema.nullish(), + paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() }) } From 7a9b28c3e86a264e48336ce367d10133ca52a86c Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Wed, 31 Jul 2024 16:05:16 +0200 Subject: [PATCH 34/48] feat(GCOM-1446): replace signInMode with permissions --- .changeset/popular-rules-complain.md | 10 +- docs/framework/config.md | 28 +- .../components/Layout/Footer.tsx | 4 +- .../components/Layout/LayoutNavigation.tsx | 5 +- .../ProductView/AddProductsToCartView.tsx | 34 ++- examples/magento-graphcms/pages/404.tsx | 15 +- .../pages/account/addresses/add.tsx | 3 + .../pages/account/addresses/edit.tsx | 3 + .../pages/account/addresses/index.tsx | 3 + .../pages/account/authentication/index.tsx | 3 + .../pages/account/contact/index.tsx | 3 + .../pages/account/delete/index.tsx | 9 +- .../pages/account/forgot-password.tsx | 3 + .../magento-graphcms/pages/account/index.tsx | 3 + .../pages/account/name/index.tsx | 3 + .../pages/account/orders/index.tsx | 3 + .../pages/account/orders/view.tsx | 5 +- .../pages/account/reviews/add.tsx | 3 + .../pages/account/reviews/index.tsx | 3 + .../magento-graphcms/pages/account/signin.tsx | 3 + examples/magento-graphcms/pages/cart.tsx | 21 +- .../magento-graphcms/pages/checkout/added.tsx | 3 + .../checkout/customer/addresses/edit.tsx | 3 + .../pages/checkout/edit/billing-address.tsx | 5 +- .../magento-graphcms/pages/checkout/index.tsx | 25 +- .../pages/checkout/item/[url].tsx | 3 +- .../pages/checkout/payment.tsx | 21 +- .../pages/checkout/success.tsx | 5 +- .../pages/checkout/terms/[url].tsx | 3 + .../pages/customer/account/confirm.tsx | 3 + .../customer/account/createPassword/index.tsx | 3 + packages/ecommerce-ui/Config.graphqls | 17 ++ packages/ecommerce-ui/hooks/usePermissions.ts | 56 ++++ packages/ecommerce-ui/index.ts | 2 + .../ecommerce-ui/utils/permissionUtils.ts | 22 ++ .../EmailForm/EmailForm.tsx | 20 +- packages/magento-cart/Config.graphqls | 17 ++ .../components/CartFab/CartFab.tsx | 5 +- .../CartStartCheckout/CartStartCheckout.tsx | 42 +-- .../CartStartCheckoutLinkOrButton.tsx | 19 +- .../InlineAccount/InlineAccount.tsx | 10 +- .../AccountSignInUpForm.tsx | 33 ++- .../components/CustomerFab/CustomerFab.tsx | 6 +- .../CustomerMenuFabItem.tsx | 12 +- .../magento-customer/graphql/Config.graphqls | 18 +- .../hooks/useAccountSignInUpForm.tsx | 10 +- .../AddProductsToCartButton.tsx | 13 +- .../AddProductsToCartFab.tsx | 20 +- .../components/LayoutDefault.tsx | 28 +- .../next-config/dist/generated/config.js | 243 +++++++----------- .../next-config/dist/withGraphCommerce.js | 16 -- .../next-config/src/generated/config.ts | 59 +++-- .../next-config/src/withGraphCommerce.ts | 20 +- 53 files changed, 547 insertions(+), 382 deletions(-) create mode 100644 packages/ecommerce-ui/Config.graphqls create mode 100644 packages/ecommerce-ui/hooks/usePermissions.ts create mode 100644 packages/ecommerce-ui/utils/permissionUtils.ts diff --git a/.changeset/popular-rules-complain.md b/.changeset/popular-rules-complain.md index 715c4093f3..d2c4af0366 100644 --- a/.changeset/popular-rules-complain.md +++ b/.changeset/popular-rules-complain.md @@ -1,7 +1,9 @@ --- -"@graphcommerce/magento-cart-email": patch -"@graphcommerce/magento-customer": patch -"@graphcommerce/magento-cart": patch +'@graphcommerce/ecommerce-ui': minor +'@graphcommerce/magento-cart-email': minor +'@graphcommerce/magento-customer': minor +'@graphcommerce/magento-cart': minor +'@graphcommerce/magento-graphcms': minor --- -Created guestOnly-mode +Add `permissions` config so the website or store can be configurated to run in different modes. diff --git a/docs/framework/config.md b/docs/framework/config.md index 808b5d4702..7d0dda4e50 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -293,6 +293,8 @@ Limit the static generation of SSG when building. By default GraphCommerce will statically generate all product and category pages during build. This can take quite a long time, to skip this step set this value to true. +#### permissions: [GraphCommercePermissions](#GraphCommercePermissions) + #### previewSecret: string To enable next.js' preview mode, configure the secret you'd like to use. @@ -369,6 +371,23 @@ Issues that this can cause are: - The same package is included multiple times in the bundle, increasing the bundle size. - The Typescript types of the package are not compatible with each other, causing Typescript errors. +### GraphCommercePermissions + +#### cart: CUSTOMER_ONLY | DISABLED | ENABLED + +Changes the availability of the add to cart buttons and the cart page to either customer only or completely disables it. +Note: Any value here will automatically be passed to `checkout`. For example: setting `cart` to `DISABLED` and `checkout` to `ENABLED` will result in the checkout being disabled. + +#### checkout: CUSTOMER_ONLY | DISABLED | ENABLED + +Changes the availability of the checkout to either customer only or completely disables it. + +#### customerAccount: DISABLED | DISABLE_REGISTRATION | ENABLED = `ENABLED` + +Enables / disabled the account section of the website. DISABLE_REGISTRATION will only disable the registration page. + +#### website: ENABLED + ### GraphCommerceStorefrontConfig All storefront configuration for the project @@ -441,18 +460,13 @@ Add a gcms-locales header to make sure queries return in a certain language, can Custom locale used to load the .po files. Must be a valid locale, also used for Intl functions. +#### permissions: [GraphCommercePermissions](#GraphCommercePermissions) + #### robotsAllow: boolean Allow the site to be indexed by search engines. If false, the robots.txt file will be set to disallow all. -#### signInMode: DEFAULT | DISABLE_GUEST_ADD_TO_CART | DISABLE_GUEST_CHECKOUT | GUEST_ONLY = `DEFAULT` - -GUEST_ONLY disables all login functionalities -DISABLE_GUEST_CHECKOUT disables guest checkout. Products can still be added to the cart if not logged in. -DISABLE_GUEST_ADD_TO_CART disables disables guest checkout. Products CAN NOT be added to the cart if not logged in. -DEFAULT allows all functionalities - ### MagentoConfigurableVariantValues Options to configure which values will be replaced when a variant is selected on the product page. diff --git a/examples/magento-graphcms/components/Layout/Footer.tsx b/examples/magento-graphcms/components/Layout/Footer.tsx index c0e22738f3..8d2c086659 100644 --- a/examples/magento-graphcms/components/Layout/Footer.tsx +++ b/examples/magento-graphcms/components/Layout/Footer.tsx @@ -1,3 +1,4 @@ +import { useCheckoutIsEnabled } from '@graphcommerce/ecommerce-ui' import { Image } from '@graphcommerce/image' import { StoreSwitcherButton } from '@graphcommerce/magento-store' import { Footer as FooterBase } from '@graphcommerce/next-ui' @@ -9,6 +10,7 @@ export type FooterProps = FooterQueryFragment export function Footer(props: FooterProps) { const { footer } = props + const checkoutEnabled = useCheckoutIsEnabled() return ( ))} - {import.meta.graphCommerce.magentoVersion >= 247 && ( + {import.meta.graphCommerce.magentoVersion >= 247 && checkoutEnabled && ( Order status diff --git a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx index ffb3e64e58..b887b98de3 100644 --- a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx +++ b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx @@ -1,3 +1,4 @@ +import { useCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { CartFab } from '@graphcommerce/magento-cart' import { magentoMenuToNavigation } from '@graphcommerce/magento-category' import { CustomerFab, CustomerMenuFabItem } from '@graphcommerce/magento-customer' @@ -39,6 +40,8 @@ export function LayoutNavigation(props: LayoutNavigationProps) { const selection = useNavigationSelection() const router = useRouter() + const cartDisabled = useCartIsDisabled() + return ( <> } /> {/* The placeholder exists because the CartFab is sticky but we want to reserve the space for the */} - + {!cartDisabled && } } diff --git a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx index 2474534cf5..59ada17844 100644 --- a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx +++ b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx @@ -1,3 +1,4 @@ +import { useCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { AddProductsToCartError, AddProductsToCartQuantity, @@ -22,6 +23,8 @@ export type AddProductsToCartViewProps = { export function AddProductsToCartView(props: AddProductsToCartViewProps) { const { product } = props + const cartDisabled = useCartIsDisabled() + return ( <> {isTypename(product, ['ConfigurableProduct']) && ( @@ -38,21 +41,30 @@ export function AddProductsToCartView(props: AddProductsToCartViewProps) { {!isTypename(product, ['GroupedProduct']) && ( <> - - - + {!cartDisabled ? ( + <> + + + + - - - - - - + + + + + + - + - + + + ) : ( + + + + )} )} diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index 77d92e5d48..4b1477ce06 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -1,26 +1,21 @@ +import { useCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { cacheFirst } from '@graphcommerce/graphql' import { SearchLink } from '@graphcommerce/magento-search' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' -import { - GetStaticProps, - Separator, - icon404, - IconSvg, - useStorefrontConfig, -} from '@graphcommerce/next-ui' +import { GetStaticProps, Separator, icon404, IconSvg } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' import { Box, Container, Typography, Link } from '@mui/material' import React from 'react' import { LayoutDocument, LayoutNavigation, LayoutNavigationProps } from '../components' import { graphqlSsrClient, graphqlSharedClient } from '../lib/graphql/graphqlSsrClient' -import { cacheFirst } from '@graphcommerce/graphql' type Props = Record type GetPageStaticProps = GetStaticProps function RouteNotFoundPage() { - const { signInMode } = useStorefrontConfig() + const customerAccountDisabled = useCustomerAccountIsDisabled() const links = [ @@ -28,7 +23,7 @@ function RouteNotFoundPage() { , ] - if (signInMode !== 'GUEST_ONLY') + if (!customerAccountDisabled) links.push( diff --git a/examples/magento-graphcms/pages/account/addresses/add.tsx b/examples/magento-graphcms/pages/account/addresses/add.tsx index e0ee145134..ef1ddf5061 100644 --- a/examples/magento-graphcms/pages/account/addresses/add.tsx +++ b/examples/magento-graphcms/pages/account/addresses/add.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { CreateCustomerAddressForm, @@ -60,6 +61,8 @@ AddNewAddressPage.pageOptions = pageOptions export default AddNewAddressPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/addresses/edit.tsx b/examples/magento-graphcms/pages/account/addresses/edit.tsx index 7761a008bb..abf04d2ddd 100644 --- a/examples/magento-graphcms/pages/account/addresses/edit.tsx +++ b/examples/magento-graphcms/pages/account/addresses/edit.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { EditAddressForm, @@ -75,6 +76,8 @@ EditAddressPage.pageOptions = pageOptions export default EditAddressPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/addresses/index.tsx b/examples/magento-graphcms/pages/account/addresses/index.tsx index e42e3fecd0..69a0388bd1 100644 --- a/examples/magento-graphcms/pages/account/addresses/index.tsx +++ b/examples/magento-graphcms/pages/account/addresses/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { AccountAddresses, @@ -60,6 +61,8 @@ AccountAddressesPage.pageOptions = pageOptions export default AccountAddressesPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const staticClient = graphqlSsrClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/authentication/index.tsx b/examples/magento-graphcms/pages/account/authentication/index.tsx index 5a1692d51a..5cd18cc32a 100644 --- a/examples/magento-graphcms/pages/account/authentication/index.tsx +++ b/examples/magento-graphcms/pages/account/authentication/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ChangePasswordForm, WaitForCustomer } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -48,6 +49,8 @@ AccountAuthenticationPage.pageOptions = pageOptions export default AccountAuthenticationPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/contact/index.tsx b/examples/magento-graphcms/pages/account/contact/index.tsx index 1bfe1f7180..3b8ac9283f 100644 --- a/examples/magento-graphcms/pages/account/contact/index.tsx +++ b/examples/magento-graphcms/pages/account/contact/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { CustomerDocument, @@ -60,6 +61,8 @@ AccountContactPage.pageOptions = pageOptions export default AccountContactPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/delete/index.tsx b/examples/magento-graphcms/pages/account/delete/index.tsx index 41a21d6c35..ce1cc33598 100644 --- a/examples/magento-graphcms/pages/account/delete/index.tsx +++ b/examples/magento-graphcms/pages/account/delete/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { AccountDeleteForm } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -39,14 +40,16 @@ AccountDeletePage.pageOptions = pageOptions export default AccountDeletePage export const getStaticProps: GetPageStaticProps = async (context) => { - const client = graphqlSharedClient(context) - const conf = client.query({ query: StoreConfigDocument }) if ( import.meta.graphCommerce.magentoVersion < 246 || - !import.meta.graphCommerce.customerDeleteEnabled + !import.meta.graphCommerce.customerDeleteEnabled || + getCustomerAccountIsDisabled(context.locale) ) return { notFound: true } + const client = graphqlSharedClient(context) + const conf = client.query({ query: StoreConfigDocument }) + return { props: { apolloState: await conf.then(() => client.cache.extract()), diff --git a/examples/magento-graphcms/pages/account/forgot-password.tsx b/examples/magento-graphcms/pages/account/forgot-password.tsx index f111ca33bc..180a73898f 100644 --- a/examples/magento-graphcms/pages/account/forgot-password.tsx +++ b/examples/magento-graphcms/pages/account/forgot-password.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ForgotPasswordForm } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -42,6 +43,8 @@ AccountForgotPasswordPage.pageOptions = pageOptions export default AccountForgotPasswordPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/index.tsx b/examples/magento-graphcms/pages/account/index.tsx index 75adf56833..f6f1fa79a1 100644 --- a/examples/magento-graphcms/pages/account/index.tsx +++ b/examples/magento-graphcms/pages/account/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst, useQuery } from '@graphcommerce/graphql' import { @@ -173,6 +174,8 @@ AccountIndexPage.pageOptions = pageOptions export default AccountIndexPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const staticClient = graphqlSsrClient(context) const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/name/index.tsx b/examples/magento-graphcms/pages/account/name/index.tsx index 4a52ad082b..a2f3e69d85 100644 --- a/examples/magento-graphcms/pages/account/name/index.tsx +++ b/examples/magento-graphcms/pages/account/name/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ChangeNameForm, @@ -67,6 +68,8 @@ AccountNamePage.pageOptions = pageOptions export default AccountNamePage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/orders/index.tsx b/examples/magento-graphcms/pages/account/orders/index.tsx index ab880a859a..5873aeada9 100644 --- a/examples/magento-graphcms/pages/account/orders/index.tsx +++ b/examples/magento-graphcms/pages/account/orders/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useCustomerQuery, @@ -77,6 +78,8 @@ AccountOrdersPage.pageOptions = pageOptions export default AccountOrdersPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/orders/view.tsx b/examples/magento-graphcms/pages/account/orders/view.tsx index b788e350d8..5a80ba11d4 100644 --- a/examples/magento-graphcms/pages/account/orders/view.tsx +++ b/examples/magento-graphcms/pages/account/orders/view.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useCustomerQuery, @@ -21,7 +22,7 @@ import { } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/macro' -import { Box, Container, Typography } from '@mui/material' +import { Container, Typography } from '@mui/material' import { useRouter } from 'next/router' import { LayoutOverlay, LayoutOverlayProps } from '../../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../../lib/graphql/graphqlSsrClient' @@ -93,6 +94,8 @@ OrderDetailPage.pageOptions = pageOptions export default OrderDetailPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const staticClient = graphqlSsrClient(context) const config = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/reviews/add.tsx b/examples/magento-graphcms/pages/account/reviews/add.tsx index a9b271d854..74e05dbbe2 100644 --- a/examples/magento-graphcms/pages/account/reviews/add.tsx +++ b/examples/magento-graphcms/pages/account/reviews/add.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useQuery } from '@graphcommerce/graphql' import { ApolloCustomerErrorFullPage, CustomerDocument } from '@graphcommerce/magento-customer' @@ -104,6 +105,8 @@ AccountReviewsAddPage.pageOptions = pageOptions export default AccountReviewsAddPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/reviews/index.tsx b/examples/magento-graphcms/pages/account/reviews/index.tsx index 9f9dac5263..7309524d2e 100644 --- a/examples/magento-graphcms/pages/account/reviews/index.tsx +++ b/examples/magento-graphcms/pages/account/reviews/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useCustomerQuery, WaitForCustomer } from '@graphcommerce/magento-customer' import { AccountDashboardReviewsDocument, AccountReviews } from '@graphcommerce/magento-review' @@ -71,6 +72,8 @@ AccountReviewsPage.pageOptions = pageOptions export default AccountReviewsPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/account/signin.tsx b/examples/magento-graphcms/pages/account/signin.tsx index 859d7582c2..f8a1ebd62c 100644 --- a/examples/magento-graphcms/pages/account/signin.tsx +++ b/examples/magento-graphcms/pages/account/signin.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useMergeCustomerCart } from '@graphcommerce/magento-cart' import { AccountSignInUpForm } from '@graphcommerce/magento-customer' @@ -41,6 +42,8 @@ AccountSignInPage.pageOptions = pageOptions export default AccountSignInPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/cart.tsx b/examples/magento-graphcms/pages/cart.tsx index cebf21dd9e..85e630ea11 100644 --- a/examples/magento-graphcms/pages/cart.tsx +++ b/examples/magento-graphcms/pages/cart.tsx @@ -1,4 +1,8 @@ -import { WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { + WaitForQueries, + getCartIsDisabled, + useCartIsAvailableForUser, +} from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ApolloCartErrorAlert, @@ -21,14 +25,12 @@ import { LayoutOverlayHeader, FullPageMessage, OverlayStickyBottom, - useStorefrontConfig, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' import { CircularProgress, Container } from '@mui/material' import { LayoutOverlay, LayoutOverlayProps, productListRenderer } from '../components' import { graphqlSharedClient } from '../lib/graphql/graphqlSsrClient' -import { useCustomerSession } from '@graphcommerce/magento-customer' type Props = Record type GetPageStaticProps = GetStaticProps @@ -43,10 +45,9 @@ function CartPage() { const hasItems = (data?.cart?.total_quantity ?? 0) > 0 && typeof data?.cart?.prices?.grand_total?.value !== 'undefined' - const { loggedIn } = useCustomerSession() - const { signInMode } = useStorefrontConfig() - const loginRequiredForCart = signInMode === 'DISABLE_GUEST_ADD_TO_CART' && !loggedIn + const cartAvaialable = useCartIsAvailableForUser() + return ( <> - {hasItems && !loginRequiredForCart ? ( + {hasItems && cartAvaialable ? ( }} @@ -73,7 +74,7 @@ function CartPage() { )} - {loginRequiredForCart ? ( + {!cartAvaialable ? ( ) : ( ({ mt: theme.spacings.md })} /> - + ) : ( @@ -126,6 +127,8 @@ CartPage.pageOptions = pageOptions export default CartPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCartIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/added.tsx b/examples/magento-graphcms/pages/checkout/added.tsx index 1e1373fe7c..a9daa8dd0f 100644 --- a/examples/magento-graphcms/pages/checkout/added.tsx +++ b/examples/magento-graphcms/pages/checkout/added.tsx @@ -1,3 +1,4 @@ +import { getCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { Image } from '@graphcommerce/image' import { useCrosssellItems } from '@graphcommerce/magento-cart' @@ -162,6 +163,8 @@ CheckoutAdded.pageOptions = pageOptions export default CheckoutAdded export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCartIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx b/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx index a9f2ceed37..da6cacc04f 100644 --- a/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx +++ b/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled, getCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ApolloCustomerErrorFullPage, @@ -90,6 +91,8 @@ CheckoutCustomerAddressesEdit.pageOptions = pageOptions export default CheckoutCustomerAddressesEdit export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCartIsDisabled(context.locale) || getCustomerAccountIsDisabled(context.locale)) + return { notFound: true } const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx b/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx index 0a55ef7262..a50e6e0a76 100644 --- a/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx +++ b/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx @@ -1,4 +1,6 @@ +import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { cacheFirst } from '@graphcommerce/graphql' import { EditBillingAddressForm } from '@graphcommerce/magento-cart-billing-address' import { StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, PageMeta, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' @@ -7,7 +9,6 @@ import { Trans } from '@lingui/react' import { Container } from '@mui/material' import { LayoutDocument, LayoutOverlay, LayoutOverlayProps } from '../../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../../lib/graphql/graphqlSsrClient' -import { cacheFirst } from '@graphcommerce/graphql' type Props = Record type GetPageStaticProps = GetStaticProps @@ -47,6 +48,8 @@ EditBillingAddress.pageOptions = pageOptions export default EditBillingAddress export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCheckoutIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) const staticClient = graphqlSsrClient(context) diff --git a/examples/magento-graphcms/pages/checkout/index.tsx b/examples/magento-graphcms/pages/checkout/index.tsx index 0ff52029d7..c15c1eb917 100644 --- a/examples/magento-graphcms/pages/checkout/index.tsx +++ b/examples/magento-graphcms/pages/checkout/index.tsx @@ -4,8 +4,11 @@ import { ComposedForm, ComposedSubmit, WaitForQueries, + getCheckoutIsDisabled, + useCheckoutIsAvailableForUser, } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { cacheFirst } from '@graphcommerce/graphql' import { ApolloCartErrorAlert, ApolloCartErrorFullPage, @@ -19,11 +22,7 @@ import { CustomerAddressForm, } from '@graphcommerce/magento-cart-shipping-address' import { ShippingMethodForm } from '@graphcommerce/magento-cart-shipping-method' -import { - CustomerDocument, - useCustomerQuery, - useCustomerSession, -} from '@graphcommerce/magento-customer' +import { CustomerDocument, useCustomerQuery } from '@graphcommerce/magento-customer' import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { @@ -35,7 +34,6 @@ import { LayoutTitle, FullPageMessage, iconAddresses, - useStorefrontConfig, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' @@ -43,7 +41,6 @@ import { CircularProgress, Container, Typography } from '@mui/material' import { useRouter } from 'next/router' import { LayoutDocument, LayoutMinimal, LayoutMinimalProps } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' -import { cacheFirst } from '@graphcommerce/graphql' type Props = Record type GetPageStaticProps = GetStaticProps @@ -53,19 +50,15 @@ function ShippingPage() { const shippingPage = useCartQuery(ShippingPageDocument, { fetchPolicy: 'cache-and-network' }) const customerAddresses = useCustomerQuery(CustomerDocument, { fetchPolicy: 'cache-and-network' }) - const { signInMode } = useStorefrontConfig() - const { loggedIn } = useCustomerSession() - const disableGuestCheckout = - (signInMode === 'DISABLE_GUEST_CHECKOUT' || signInMode === 'DISABLE_GUEST_ADD_TO_CART') && - !loggedIn + const checkoutAvailable = useCheckoutIsAvailableForUser() const cartExists = typeof shippingPage.data?.cart !== 'undefined' && (shippingPage.data.cart?.items?.length ?? 0) > 0 - return disableGuestCheckout ? ( - - ) : ( + if (!checkoutAvailable) return + + return ( <> { + if (getCheckoutIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) const staticClient = graphqlSsrClient(context) diff --git a/examples/magento-graphcms/pages/checkout/item/[url].tsx b/examples/magento-graphcms/pages/checkout/item/[url].tsx index 873fa76e42..272299d5f5 100644 --- a/examples/magento-graphcms/pages/checkout/item/[url].tsx +++ b/examples/magento-graphcms/pages/checkout/item/[url].tsx @@ -1,4 +1,4 @@ -import { WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { WaitForQueries, getCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { flushMeasurePerf } from '@graphcommerce/graphql' import { ApolloCartErrorAlert, EmptyCart, useCartQuery } from '@graphcommerce/magento-cart' @@ -115,6 +115,7 @@ CartItemEdit.pageOptions = { export default CartItemEdit export const getServerSideProps: GetSSP = async (context) => { + if (getCartIsDisabled(context.locale)) return { notFound: true } const result = await getStaticProps(context) delete result.revalidate diff --git a/examples/magento-graphcms/pages/checkout/payment.tsx b/examples/magento-graphcms/pages/checkout/payment.tsx index d30cba1db2..1e6474fc6d 100644 --- a/examples/magento-graphcms/pages/checkout/payment.tsx +++ b/examples/magento-graphcms/pages/checkout/payment.tsx @@ -1,5 +1,11 @@ -import { ComposedForm, WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { + ComposedForm, + WaitForQueries, + getCheckoutIsDisabled, + useCheckoutIsAvailableForUser, +} from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { cacheFirst } from '@graphcommerce/graphql' import { ApolloCartErrorFullPage, CartAgreementsForm, @@ -17,7 +23,6 @@ import { PaymentMethodActionCardListForm, PaymentMethodContextProvider, } from '@graphcommerce/magento-cart-payment-method' -import { useCustomerSession } from '@graphcommerce/magento-customer' import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { SubscribeToNewsletter } from '@graphcommerce/magento-newsletter' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -31,14 +36,12 @@ import { Stepper, IconSvg, LayoutTitle, - useStorefrontConfig, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { Trans } from '@lingui/react' import { CircularProgress, Container, Dialog, Typography } from '@mui/material' import { LayoutDocument, LayoutMinimal, LayoutMinimalProps } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' -import { cacheFirst } from '@graphcommerce/graphql' type GetPageStaticProps = GetStaticProps @@ -49,13 +52,9 @@ function PaymentPage() { const cartExists = typeof billingPage.data?.cart !== 'undefined' && (billingPage.data.cart?.items?.length ?? 0) > 0 - const { signInMode } = useStorefrontConfig() - const { loggedIn } = useCustomerSession() - const disableGuestCheckout = - (signInMode === 'DISABLE_GUEST_CHECKOUT' || signInMode === 'DISABLE_GUEST_ADD_TO_CART') && - !loggedIn + const checkoutAvailable = useCheckoutIsAvailableForUser() - return disableGuestCheckout ? ( + return !checkoutAvailable ? ( ) : ( @@ -166,6 +165,8 @@ PaymentPage.pageOptions = pageOptions export default PaymentPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCheckoutIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const staticClient = graphqlSsrClient(context) diff --git a/examples/magento-graphcms/pages/checkout/success.tsx b/examples/magento-graphcms/pages/checkout/success.tsx index 53e645c967..f8340309c4 100644 --- a/examples/magento-graphcms/pages/checkout/success.tsx +++ b/examples/magento-graphcms/pages/checkout/success.tsx @@ -1,4 +1,6 @@ +import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { cacheFirst } from '@graphcommerce/graphql' import { CartItemSummary, CartSummary, InlineAccount } from '@graphcommerce/magento-cart' import { SignupNewsletter } from '@graphcommerce/magento-newsletter' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -22,7 +24,6 @@ import { LayoutMinimalProps, } from '../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../lib/graphql/graphqlSsrClient' -import { cacheFirst } from '@graphcommerce/graphql' type Props = Record type GetPageStaticProps = GetStaticProps @@ -91,6 +92,8 @@ OrderSuccessPage.pageOptions = pageOptions export default OrderSuccessPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCheckoutIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const staticClient = graphqlSsrClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/terms/[url].tsx b/examples/magento-graphcms/pages/checkout/terms/[url].tsx index 50c176d008..c7c343bd9c 100644 --- a/examples/magento-graphcms/pages/checkout/terms/[url].tsx +++ b/examples/magento-graphcms/pages/checkout/terms/[url].tsx @@ -1,3 +1,4 @@ +import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { CartAgreementsDocument, CartAgreementsQuery } from '@graphcommerce/magento-cart' import { StoreConfigDocument } from '@graphcommerce/magento-store' @@ -68,6 +69,8 @@ export const getStaticPaths: GetPageStaticPaths = async ({ locales = [] }) => { } export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCheckoutIsDisabled(context.locale)) return { notFound: true } + const { params } = context const client = graphqlSharedClient(context) const staticClient = graphqlSsrClient(context) diff --git a/examples/magento-graphcms/pages/customer/account/confirm.tsx b/examples/magento-graphcms/pages/customer/account/confirm.tsx index 12c10a2d01..b55dff3419 100644 --- a/examples/magento-graphcms/pages/customer/account/confirm.tsx +++ b/examples/magento-graphcms/pages/customer/account/confirm.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ConfirmCustomerForm } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -40,6 +41,8 @@ AccountConfirmPage.pageOptions = pageOptions export default AccountConfirmPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx b/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx index 306d2fb80e..dcbe544cf6 100644 --- a/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx +++ b/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx @@ -1,3 +1,4 @@ +import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ResetPasswordForm } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' @@ -81,6 +82,8 @@ CustomerAccountCreatePasswordPage.pageOptions = pageOptions export default CustomerAccountCreatePasswordPage export const getStaticProps: GetPageStaticProps = async (context) => { + if (getCustomerAccountIsDisabled(context.locale)) return { notFound: true } + const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/packages/ecommerce-ui/Config.graphqls b/packages/ecommerce-ui/Config.graphqls new file mode 100644 index 0000000000..e132de2d9d --- /dev/null +++ b/packages/ecommerce-ui/Config.graphqls @@ -0,0 +1,17 @@ +enum WebsitePermissions { + ENABLED + # CUSTOMER_ONLY will be implemented later + # DISABLED will be implemented later +} + +input GraphCommercePermissions { + website: WebsitePermissions +} + +extend input GraphCommerceConfig { + permissions: GraphCommercePermissions +} + +extend input GraphCommerceStorefrontConfig { + permissions: GraphCommercePermissions +} diff --git a/packages/ecommerce-ui/hooks/usePermissions.ts b/packages/ecommerce-ui/hooks/usePermissions.ts new file mode 100644 index 0000000000..d692ba1868 --- /dev/null +++ b/packages/ecommerce-ui/hooks/usePermissions.ts @@ -0,0 +1,56 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { useCustomerSession } from '@graphcommerce/magento-customer/hooks/useCustomerSession' +import { useStorefrontConfig } from '@graphcommerce/next-ui' + +export function useCartIsEnabled() { + const cart = + useStorefrontConfig().permissions?.cart ?? import.meta.graphCommerce.permissions?.cart + return !cart || cart === 'ENABLED' +} +export function useCartIsAvailableForUser() { + const { loggedIn } = useCustomerSession() + const cart = + useStorefrontConfig().permissions?.cart ?? import.meta.graphCommerce.permissions?.cart + return cart !== 'CUSTOMER_ONLY' || loggedIn +} +export function useCartIsDisabled() { + const cart = + useStorefrontConfig().permissions?.cart ?? import.meta.graphCommerce.permissions?.cart + return cart === 'DISABLED' +} + +export function useCheckoutIsEnabled() { + const checkout = + useStorefrontConfig().permissions?.checkout ?? import.meta.graphCommerce.permissions?.checkout + return !checkout || checkout === 'ENABLED' +} +export function useCheckoutIsAvailableForUser() { + const { loggedIn } = useCustomerSession() + const checkout = + useStorefrontConfig().permissions?.checkout ?? import.meta.graphCommerce.permissions?.checkout + return checkout !== 'CUSTOMER_ONLY' || loggedIn +} +export function useCheckoutIsDisabled() { + const checkout = + useStorefrontConfig().permissions?.checkout ?? import.meta.graphCommerce.permissions?.checkout + return checkout === 'DISABLED' +} + +export function useCustomerAccountIsEnabled() { + const customerAccount = + useStorefrontConfig().permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount + return !customerAccount || customerAccount === 'ENABLED' +} +export function useCustomerAccountRegistrationDisabled() { + const customerAccount = + useStorefrontConfig().permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount + return !customerAccount || customerAccount === 'DISABLE_REGISTRATION' +} +export function useCustomerAccountIsDisabled() { + const customerAccount = + useStorefrontConfig().permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount + return customerAccount === 'DISABLED' +} diff --git a/packages/ecommerce-ui/index.ts b/packages/ecommerce-ui/index.ts index be947b5087..df18ab5aa0 100644 --- a/packages/ecommerce-ui/index.ts +++ b/packages/ecommerce-ui/index.ts @@ -1,2 +1,4 @@ export * from './components' export * from '@graphcommerce/react-hook-form' +export * from './utils/permissionUtils' +export * from './hooks/usePermissions' diff --git a/packages/ecommerce-ui/utils/permissionUtils.ts b/packages/ecommerce-ui/utils/permissionUtils.ts new file mode 100644 index 0000000000..2d804124ae --- /dev/null +++ b/packages/ecommerce-ui/utils/permissionUtils.ts @@ -0,0 +1,22 @@ +import { storefrontConfig } from '@graphcommerce/next-ui' + +export function getCustomerAccountIsDisabled(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount === 'DISABLED' + ) +} + +export function getCartIsDisabled(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.cart ?? + import.meta.graphCommerce.permissions?.cart === 'DISABLED' + ) +} + +export function getCheckoutIsDisabled(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.checkout ?? + import.meta.graphCommerce.permissions?.checkout === 'DISABLED' + ) +} diff --git a/packages/magento-cart-email/EmailForm/EmailForm.tsx b/packages/magento-cart-email/EmailForm/EmailForm.tsx index de0c6e5c58..1baef0cc47 100644 --- a/packages/magento-cart-email/EmailForm/EmailForm.tsx +++ b/packages/magento-cart-email/EmailForm/EmailForm.tsx @@ -1,4 +1,8 @@ -import { EmailElement, TextFieldElement, WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { + EmailElement, + WaitForQueries, + useCustomerAccountIsEnabled, +} from '@graphcommerce/ecommerce-ui' import { useQuery } from '@graphcommerce/graphql' import { ApolloCartErrorAlert, @@ -6,9 +10,8 @@ import { useFormGqlMutationCart, } from '@graphcommerce/magento-cart' import { IsEmailAvailableDocument, useCustomerSession } from '@graphcommerce/magento-customer' -import { extendableComponent, FormRow, useStorefrontConfig } from '@graphcommerce/next-ui' +import { extendableComponent, FormRow } from '@graphcommerce/next-ui' import { - emailPattern, FormAutoSubmit, useFormCompose, UseFormComposeOptions, @@ -25,14 +28,14 @@ export type EmailFormProps = Pick & { sx?: SxProps } -const name = 'EmailForm' as const +const name = 'EmailForm' const parts = ['root', 'formRow'] as const const { classes } = extendableComponent(name, parts) const EmailFormBase = React.memo((props) => { const { step, sx } = props - const { signInMode } = useStorefrontConfig() + const customerAccountEnabled = useCustomerAccountIsEnabled() const cartEmail = useCartQuery(CartEmailDocument) @@ -44,10 +47,11 @@ const EmailFormBase = React.memo((props) => { const isEmailAvailable = useQuery(IsEmailAvailableDocument, { variables: { email }, - skip: !import.meta.graphCommerce.enableGuestCheckoutLogin || !email, + skip: + (!import.meta.graphCommerce.enableGuestCheckoutLogin && !customerAccountEnabled) || !email, }) - const { formState, required, error, handleSubmit } = form + const { required, error, handleSubmit } = form const submit = handleSubmit(() => {}) useFormCompose({ form, step, submit, key: 'EmailForm' }) @@ -64,7 +68,7 @@ const EmailFormBase = React.memo((props) => { disabled={cartEmail.loading} InputProps={{ autoComplete: 'email', - endAdornment: signInMode !== 'GUEST_ONLY' && ( + endAdornment: customerAccountEnabled && ( {(isEmailAvailable.data?.isEmailAvailable || !import.meta.graphCommerce.enableGuestCheckoutLogin) && ( diff --git a/packages/magento-cart/Config.graphqls b/packages/magento-cart/Config.graphqls index 957498c255..605198c18d 100644 --- a/packages/magento-cart/Config.graphqls +++ b/packages/magento-cart/Config.graphqls @@ -1,3 +1,20 @@ +enum CartPermissions { + ENABLED + CUSTOMER_ONLY + DISABLED +} + +extend input GraphCommercePermissions { + """ + Changes the availability of the add to cart buttons and the cart page to either customer only or completely disables it. + """ + cart: CartPermissions + """ + Changes the availability of the checkout to either customer only or completely disables it. + """ + checkout: CartPermissions +} + extend input GraphCommerceStorefrontConfig { """ Due to a limitation of the GraphQL API it is not possible to determine if a cart should be displayed including or excluding tax. diff --git a/packages/magento-cart/components/CartFab/CartFab.tsx b/packages/magento-cart/components/CartFab/CartFab.tsx index 8cb5ded72f..fc8b4f7ee2 100644 --- a/packages/magento-cart/components/CartFab/CartFab.tsx +++ b/packages/magento-cart/components/CartFab/CartFab.tsx @@ -1,4 +1,4 @@ -import { WaitForQueries } from '@graphcommerce/ecommerce-ui' +import { WaitForQueries, useCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { extendableComponent, iconShoppingBag, @@ -101,6 +101,9 @@ function CartFabContent(props: CartFabContentProps) { export function CartFab(props: CartFabProps) { const cartQuery = useCartQuery(CartFabDocument) + const cartDisabled = useCartIsDisabled() + + if (cartDisabled) return null return ( }> diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index 436699bfad..e34db1278b 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -1,15 +1,10 @@ +import { useCheckoutIsAvailableForUser } from '@graphcommerce/ecommerce-ui' import { Money } from '@graphcommerce/magento-store' -import { - iconChevronRight, - IconSvg, - extendableComponent, - useStorefrontConfig, -} from '@graphcommerce/next-ui' -import { Trans } from '@lingui/react' -import { Box, Button, ButtonProps, SxProps, Theme } from '@mui/material' +import { iconChevronRight, IconSvg, extendableComponent } from '@graphcommerce/next-ui' +import { Trans } from '@lingui/macro' +import { Box, Button, ButtonProps, Link, SxProps, Theme } from '@mui/material' import React from 'react' import { CartStartCheckoutFragment } from './CartStartCheckout.gql' -import { useCustomerSession } from '@graphcommerce/magento-customer' export type CartStartCheckoutProps = { children?: React.ReactNode @@ -23,12 +18,13 @@ export type CartStartCheckoutProps = { ) => void } -const name = 'CartStartCheckout' as const +const name = 'CartStartCheckout' const parts = [ 'checkoutButtonContainer', 'checkoutButton', 'checkoutButtonTotal', 'checkoutMoney', + 'loginContainer', ] as const const { classes } = extendableComponent(name, parts) @@ -42,9 +38,7 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { cart, } = props - const { signInMode } = useStorefrontConfig() - const { loggedIn } = useCustomerSession() - const disableGuestCheckout = signInMode === 'DISABLE_GUEST_CHECKOUT' && !loggedIn + const checkoutAvailable = useCheckoutIsAvailableForUser() const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0 const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0) @@ -53,12 +47,22 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { ({ textAlign: 'center', my: theme.spacings.md }), + (theme) => ({ + textAlign: 'center', + my: theme.spacings.md, + }), ...(Array.isArray(sx) ? sx : [sx]), ]} > + {!checkoutAvailable && ( + + + You must first login before you can continue + + + )} - )} - + endAdornment: showLogin && ( + ), }} /> diff --git a/packages/magento-cart/components/CartFab/CartFab.tsx b/packages/magento-cart/components/CartFab/CartFab.tsx index fc8b4f7ee2..3a24db9917 100644 --- a/packages/magento-cart/components/CartFab/CartFab.tsx +++ b/packages/magento-cart/components/CartFab/CartFab.tsx @@ -1,4 +1,4 @@ -import { WaitForQueries, useCartIsDisabled } from '@graphcommerce/ecommerce-ui' +import { WaitForQueries, useCartEnabled } from '@graphcommerce/ecommerce-ui' import { extendableComponent, iconShoppingBag, @@ -101,9 +101,8 @@ function CartFabContent(props: CartFabContentProps) { export function CartFab(props: CartFabProps) { const cartQuery = useCartQuery(CartFabDocument) - const cartDisabled = useCartIsDisabled() - - if (cartDisabled) return null + const cartEnabled = useCartEnabled() + if (!cartEnabled) return null return ( }> diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index e34db1278b..f5e5d948d9 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -1,4 +1,4 @@ -import { useCheckoutIsAvailableForUser } from '@graphcommerce/ecommerce-ui' +import { useCheckoutShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' import { Money } from '@graphcommerce/magento-store' import { iconChevronRight, IconSvg, extendableComponent } from '@graphcommerce/next-ui' import { Trans } from '@lingui/macro' @@ -38,8 +38,7 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { cart, } = props - const checkoutAvailable = useCheckoutIsAvailableForUser() - + const shouldLoginToContinue = useCheckoutShouldLoginToContinue() const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0 const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0) @@ -54,13 +53,14 @@ export function CartStartCheckout(props: CartStartCheckoutProps) { ...(Array.isArray(sx) ? sx : [sx]), ]} > - {!checkoutAvailable && ( + {shouldLoginToContinue && ( You must first login before you can continue )} + ) : ( button diff --git a/packages/magento-customer/components/ApolloCustomerError/useAuthorizationErrorMasked.ts b/packages/magento-customer/components/ApolloCustomerError/useAuthorizationErrorMasked.ts index 8ca7c8570b..2108b10dee 100644 --- a/packages/magento-customer/components/ApolloCustomerError/useAuthorizationErrorMasked.ts +++ b/packages/magento-customer/components/ApolloCustomerError/useAuthorizationErrorMasked.ts @@ -11,7 +11,7 @@ export function useAuthorizationErrorMasked(error?: ApolloError) { error, mask: token ? i18n._(/* i18n */ 'Please reauthenticate and try again') - : i18n._(/* i18n */ 'You must sign in to continue'), + : i18n._(/* i18n */ 'You must be signed in to continue'), extract: false, }) } diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index 07ef23c86b..a9e072883f 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -1,4 +1,4 @@ -import { useCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' +import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { iconPerson, DesktopHeaderBadge, @@ -53,10 +53,9 @@ export type CustomerFabProps = Omit export function CustomerFab(props: CustomerFabProps) { const session = useCustomerSession() + const canSignIn = useCustomerAccountCanSignIn() - const customerAccountDisabled = useCustomerAccountIsDisabled() - - if (customerAccountDisabled) return null + if (!canSignIn) return null return ( }> diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 05b72df60d..3bc6aa013f 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -1,4 +1,4 @@ -import { useCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' +import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { MenuFabSecondaryItem, iconPerson, IconSvg } from '@graphcommerce/next-ui' import { Badge, NoSsr, SxProps, Theme } from '@mui/material' import React, { MouseEventHandler } from 'react' @@ -41,9 +41,8 @@ function CustomerMenuFabItemContent(props: CustomerMenuFabItemProps) { export function CustomerMenuFabItem(props: CustomerMenuFabItemProps) { const session = useCustomerSession() - const customerAccountDisabled = useCustomerAccountIsDisabled() - - if (customerAccountDisabled) return null + const canSignIn = useCustomerAccountCanSignIn() + if (!canSignIn) return null return ( }> diff --git a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx b/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx index e19eab3d04..3f4c93c484 100644 --- a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx +++ b/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx @@ -1,8 +1,8 @@ +import { useCustomerAccountCanSignUp } from '@graphcommerce/ecommerce-ui' import { FullPageMessage, FullPageMessageProps, IconSvg, iconPerson } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { Button } from '@mui/material' import React from 'react' -import { useCustomerSession } from '../../hooks' type UnauthenticatedFullPageMessageProps = Omit & { icon?: React.ReactNode @@ -10,15 +10,15 @@ type UnauthenticatedFullPageMessageProps = Omit} - title={} + title={} button={ } {...props} diff --git a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx index 90bbf07831..ebd8b33e0e 100644 --- a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx +++ b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx @@ -1,4 +1,4 @@ -import { useCustomerAccountRegistrationDisabled } from '@graphcommerce/ecommerce-ui' +import { useCustomerAccountCanSignUp } from '@graphcommerce/ecommerce-ui' import { usePageContext } from '@graphcommerce/framer-next-pages' import { useQuery } from '@graphcommerce/graphql' import { useUrlQuery } from '@graphcommerce/next-ui' @@ -21,6 +21,10 @@ export type AccountSignInUpState = 'email' | 'signin' | 'signup' | 'signedin' | export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {}) { const { onSubmitted } = props const { token, valid } = useCustomerSession() + + const canSignUp = useCustomerAccountCanSignUp() + const isToggleMethod = !import.meta.graphCommerce.enableGuestCheckoutLogin || !canSignUp + const [queryState, setRouterQuery] = useUrlQuery<{ email?: string | null }>() const customerQuery = useQuery(CustomerDocument, { fetchPolicy: 'cache-only' }) @@ -42,11 +46,6 @@ export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {}) const { formState, data, handleSubmit, setValue, trigger } = form const { isSubmitSuccessful, isValid } = formState - const registrationDisabled = useCustomerAccountRegistrationDisabled() - - const isToggleMethod = - !import.meta.graphCommerce.enableGuestCheckoutLogin && !registrationDisabled - useEffect(() => { // eslint-disable-next-line @typescript-eslint/no-floating-promises ;(async () => { @@ -75,7 +74,7 @@ export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {}) mode = form.watch('requestedMode') ?? 'signin' } else { // 1. Nothing is entered - mode = registrationDisabled ? 'signin' : 'email' + mode = 'email' if (isValid && isSubmitSuccessful) mode = hasAccount ? 'signin' : 'signup' } diff --git a/packages/magento-customer/link/customerLink.ts b/packages/magento-customer/link/customerLink.ts index 9bc91d1072..9299496858 100644 --- a/packages/magento-customer/link/customerLink.ts +++ b/packages/magento-customer/link/customerLink.ts @@ -3,15 +3,25 @@ import { ApolloCache, ApolloLink, fromPromise, + GraphQLRequest, onError, setContext, + Observable, + FetchResult, } from '@graphcommerce/graphql/apollo' import { ErrorCategory } from '@graphcommerce/magento-graphql' -import type { GraphQLError } from 'graphql' +import { GraphQLError } from 'graphql' import { NextRouter } from 'next/router' import { signOut } from '../components/SignOutForm/signOut' import { CustomerTokenDocument } from '../hooks' +const isMutation = (operation: GraphQLRequest) => + operation.query.definitions.some( + (definition) => + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison + definition.kind === 'OperationDefinition' && definition.operation === 'mutation', + ) + export type PushRouter = Pick declare module '@apollo/client' { @@ -128,5 +138,23 @@ const customerErrorLink = (router: PushRouter) => }) }) +// const customerMaybelinkan = (router: PushRouter) => +// new ApolloLink((operation, forward) => { +// const { cache } = operation.getContext() + +// if (!isMutation(operation)) return forward(operation) + +// const loggedIn = cache?.readQuery({ query: CustomerTokenDocument }) + +// // sdnasdffasd +// if (loggedIn) forward(operation) + +// // forward(operation).map((result) => {}) +// // return forward(operation) +// const signInAgainPromise = pushWithPromise(router, '/account/signin') + +// fromPromise(signInAgainPromise) +// }) + export const customerLink = (router: PushRouter) => - ApolloLink.from([addTokenHeader, customerErrorLink(router)]) + ApolloLink.from([addTokenHeader, customerErrorLink(router), customerMaybelinkan(router)]) diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx index db96354a5e..d536b1664b 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-extraneous-dependencies -import { useCartIsAvailableForUser, useCartIsDisabled } from '@graphcommerce/ecommerce-ui' +import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' import { Button, ButtonProps } from '@graphcommerce/next-ui' import { Trans } from '@lingui/macro' import { useRouter } from 'next/router' @@ -24,27 +24,22 @@ export type AddProductsToCartButtonProps = UseAddProductsToCartActionProps & > export function AddProductsToCartButton(props: AddProductsToCartButtonProps) { - const { children, product, ...rest } = props + const { children, product, disabled, ...rest } = props const { showSuccess, ...action } = useAddProductsToCartAction(props) - const router = useRouter() - const cartDisabled = useCartIsDisabled() - const cartAvailable = useCartIsAvailableForUser() + const cartEnabled = useCartEnabled() - if (cartDisabled) return null + if (!cartEnabled) return null - return !cartAvailable ? ( + return ( - ) : ( - ) diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx index 62d585d177..ad89cd47ca 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx @@ -1,4 +1,4 @@ -import { useCartIsAvailableForUser, useCartIsDisabled } from '@graphcommerce/ecommerce-ui' +import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' import { Fab, FabProps, iconShoppingBag, iconCheckmark } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { t } from '@lingui/macro' @@ -20,12 +20,12 @@ export function AddProductsToCartFab(props: AddProductsToCartFabProps) { const { showSuccess, ...action } = useAddProductsToCartAction(props) const router = useRouter() - const cartDisabled = useCartIsDisabled() - const cartAvailable = useCartIsAvailableForUser() + const cartEnabled = useCartEnabled() + const shouldLoginToContinue = useCartShouldLoginToContinue() - if (cartDisabled) return null + if (!cartEnabled) return null - return !cartAvailable ? ( + return shouldLoginToContinue ? ( v !== undefined && v !== null; -exports.isDefinedNonNullAny = isDefinedNonNullAny; -exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v)); -exports.CartPermissionsSchema = zod_1.z.enum(['CUSTOMER_ONLY', 'DISABLED', 'ENABLED']); -exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']); -exports.CustomerAccountPermissionsSchema = zod_1.z.enum(['DISABLED', 'DISABLE_REGISTRATION', 'ENABLED']); -exports.PaginationVariantSchema = zod_1.z.enum(['COMPACT', 'EXTENDED']); -exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']); -exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); -exports.WebsitePermissionsSchema = zod_1.z.enum(['ENABLED']); +/* eslint-disable */ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + CartPermissionsSchema: function() { + return CartPermissionsSchema; + }, + CompareVariantSchema: function() { + return CompareVariantSchema; + }, + CustomerAccountPermissionsSchema: function() { + return CustomerAccountPermissionsSchema; + }, + DatalayerConfigSchema: function() { + return DatalayerConfigSchema; + }, + GraphCommerceConfigSchema: function() { + return GraphCommerceConfigSchema; + }, + GraphCommerceDebugConfigSchema: function() { + return GraphCommerceDebugConfigSchema; + }, + GraphCommercePermissionsSchema: function() { + return GraphCommercePermissionsSchema; + }, + GraphCommerceStorefrontConfigSchema: function() { + return GraphCommerceStorefrontConfigSchema; + }, + MagentoConfigurableVariantValuesSchema: function() { + return MagentoConfigurableVariantValuesSchema; + }, + PaginationVariantSchema: function() { + return PaginationVariantSchema; + }, + ProductFiltersLayoutSchema: function() { + return ProductFiltersLayoutSchema; + }, + RecentlyViewedProductsConfigSchema: function() { + return RecentlyViewedProductsConfigSchema; + }, + SidebarGalleryConfigSchema: function() { + return SidebarGalleryConfigSchema; + }, + SidebarGalleryPaginationVariantSchema: function() { + return SidebarGalleryPaginationVariantSchema; + }, + WebsitePermissionsSchema: function() { + return WebsitePermissionsSchema; + }, + definedNonNullAnySchema: function() { + return definedNonNullAnySchema; + }, + isDefinedNonNullAny: function() { + return isDefinedNonNullAny; + } +}); +const _zod = require("zod"); +const isDefinedNonNullAny = (v)=>v !== undefined && v !== null; +const definedNonNullAnySchema = _zod.z.any().refine((v)=>isDefinedNonNullAny(v)); +const CartPermissionsSchema = _zod.z.enum([ + 'CUSTOMER_ONLY', + 'DISABLED', + 'ENABLED' +]); +const CompareVariantSchema = _zod.z.enum([ + 'CHECKBOX', + 'ICON' +]); +const CustomerAccountPermissionsSchema = _zod.z.enum([ + 'DISABLED', + 'DISABLE_REGISTRATION', + 'ENABLED' +]); +const PaginationVariantSchema = _zod.z.enum([ + 'COMPACT', + 'EXTENDED' +]); +const ProductFiltersLayoutSchema = _zod.z.enum([ + 'DEFAULT', + 'SIDEBAR' +]); +const SidebarGalleryPaginationVariantSchema = _zod.z.enum([ + 'DOTS', + 'THUMBNAILS_BOTTOM' +]); +const WebsitePermissionsSchema = _zod.z.enum([ + 'ENABLED' +]); function DatalayerConfigSchema() { - return zod_1.z.object({ - coreWebVitals: zod_1.z.boolean().nullish() + return _zod.z.object({ + coreWebVitals: _zod.z.boolean().nullish() }); } function GraphCommerceConfigSchema() { - return zod_1.z.object({ - breadcrumbs: zod_1.z.boolean().default(false).nullish(), - canonicalBaseUrl: zod_1.z.string().min(1), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - compare: zod_1.z.boolean().nullish(), - compareVariant: exports.CompareVariantSchema.default("ICON").nullish(), - configurableVariantForSimple: zod_1.z.boolean().default(false).nullish(), + return _zod.z.object({ + breadcrumbs: _zod.z.boolean().default(false).nullish(), + canonicalBaseUrl: _zod.z.string().min(1), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + compare: _zod.z.boolean().nullish(), + compareVariant: CompareVariantSchema.default("ICON").nullish(), + configurableVariantForSimple: _zod.z.boolean().default(false).nullish(), configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(), - crossSellsHideCartItems: zod_1.z.boolean().default(false).nullish(), - crossSellsRedirectItems: zod_1.z.boolean().default(false).nullish(), - customerAddressNoteEnable: zod_1.z.boolean().nullish(), - customerCompanyFieldsEnable: zod_1.z.boolean().nullish(), - customerDeleteEnabled: zod_1.z.boolean().nullish(), - customerXMagentoCacheIdDisable: zod_1.z.boolean().nullish(), + crossSellsHideCartItems: _zod.z.boolean().default(false).nullish(), + crossSellsRedirectItems: _zod.z.boolean().default(false).nullish(), + customerAddressNoteEnable: _zod.z.boolean().nullish(), + customerCompanyFieldsEnable: _zod.z.boolean().nullish(), + customerDeleteEnabled: _zod.z.boolean().nullish(), + customerXMagentoCacheIdDisable: _zod.z.boolean().nullish(), dataLayer: DatalayerConfigSchema().nullish(), debug: GraphCommerceDebugConfigSchema().nullish(), - demoMode: zod_1.z.boolean().default(true).nullish(), - enableGuestCheckoutLogin: zod_1.z.boolean().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - hygraphEndpoint: zod_1.z.string().min(1), - hygraphManagementApi: zod_1.z.string().nullish(), - hygraphProjectId: zod_1.z.string().nullish(), - hygraphWriteAccessEndpoint: zod_1.z.string().nullish(), - hygraphWriteAccessToken: zod_1.z.string().nullish(), - limitSsg: zod_1.z.boolean().nullish(), - magentoEndpoint: zod_1.z.string().min(1), - magentoVersion: zod_1.z.number(), + demoMode: _zod.z.boolean().default(true).nullish(), + enableGuestCheckoutLogin: _zod.z.boolean().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + hygraphEndpoint: _zod.z.string().min(1), + hygraphManagementApi: _zod.z.string().nullish(), + hygraphProjectId: _zod.z.string().nullish(), + hygraphWriteAccessEndpoint: _zod.z.string().nullish(), + hygraphWriteAccessToken: _zod.z.string().nullish(), + limitSsg: _zod.z.boolean().nullish(), + magentoEndpoint: _zod.z.string().min(1), + magentoVersion: _zod.z.number(), permissions: GraphCommercePermissionsSchema().nullish(), - previewSecret: zod_1.z.string().nullish(), - productFiltersLayout: exports.ProductFiltersLayoutSchema.default("DEFAULT").nullish(), - productFiltersPro: zod_1.z.boolean().nullish(), - productListPaginationVariant: exports.PaginationVariantSchema.default("COMPACT").nullish(), - productRoute: zod_1.z.string().nullish(), + previewSecret: _zod.z.string().nullish(), + productFiltersLayout: ProductFiltersLayoutSchema.default("DEFAULT").nullish(), + productFiltersPro: _zod.z.boolean().nullish(), + productListPaginationVariant: PaginationVariantSchema.default("COMPACT").nullish(), + productRoute: _zod.z.string().nullish(), recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(), - robotsAllow: zod_1.z.boolean().nullish(), + robotsAllow: _zod.z.boolean().nullish(), sidebarGallery: SidebarGalleryConfigSchema().nullish(), - storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()), - wishlistHideForGuests: zod_1.z.boolean().nullish(), - wishlistShowFeedbackMessage: zod_1.z.boolean().nullish() + storefront: _zod.z.array(GraphCommerceStorefrontConfigSchema()), + wishlistHideForGuests: _zod.z.boolean().nullish(), + wishlistShowFeedbackMessage: _zod.z.boolean().nullish() }); } function GraphCommerceDebugConfigSchema() { - return zod_1.z.object({ - pluginStatus: zod_1.z.boolean().nullish(), - sessions: zod_1.z.boolean().nullish(), - webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(), - webpackDuplicatesPlugin: zod_1.z.boolean().nullish() + return _zod.z.object({ + pluginStatus: _zod.z.boolean().nullish(), + sessions: _zod.z.boolean().nullish(), + webpackCircularDependencyPlugin: _zod.z.boolean().nullish(), + webpackDuplicatesPlugin: _zod.z.boolean().nullish() }); } function GraphCommercePermissionsSchema() { - return zod_1.z.object({ - cart: exports.CartPermissionsSchema.nullish(), - checkout: exports.CartPermissionsSchema.nullish(), - customerAccount: exports.CustomerAccountPermissionsSchema.default("ENABLED").nullish(), - website: exports.WebsitePermissionsSchema.nullish() + return _zod.z.object({ + cart: CartPermissionsSchema.nullish(), + checkout: CartPermissionsSchema.nullish(), + customerAccount: CustomerAccountPermissionsSchema.nullish(), + website: WebsitePermissionsSchema.nullish() }); } function GraphCommerceStorefrontConfigSchema() { - return zod_1.z.object({ - canonicalBaseUrl: zod_1.z.string().nullish(), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - customerCompanyFieldsEnable: zod_1.z.boolean().nullish(), - defaultLocale: zod_1.z.boolean().nullish(), - domain: zod_1.z.string().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(), - linguiLocale: zod_1.z.string().nullish(), - locale: zod_1.z.string().min(1), - magentoStoreCode: zod_1.z.string().min(1), + return _zod.z.object({ + canonicalBaseUrl: _zod.z.string().nullish(), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + customerCompanyFieldsEnable: _zod.z.boolean().nullish(), + defaultLocale: _zod.z.boolean().nullish(), + domain: _zod.z.string().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + hygraphLocales: _zod.z.array(_zod.z.string().min(1)).nullish(), + linguiLocale: _zod.z.string().nullish(), + locale: _zod.z.string().min(1), + magentoStoreCode: _zod.z.string().min(1), permissions: GraphCommercePermissionsSchema().nullish(), - robotsAllow: zod_1.z.boolean().nullish() + robotsAllow: _zod.z.boolean().nullish() }); } function MagentoConfigurableVariantValuesSchema() { - return zod_1.z.object({ - content: zod_1.z.boolean().nullish(), - gallery: zod_1.z.boolean().nullish(), - url: zod_1.z.boolean().nullish() + return _zod.z.object({ + content: _zod.z.boolean().nullish(), + gallery: _zod.z.boolean().nullish(), + url: _zod.z.boolean().nullish() }); } function RecentlyViewedProductsConfigSchema() { - return zod_1.z.object({ - enabled: zod_1.z.boolean().nullish(), - maxCount: zod_1.z.number().nullish() + return _zod.z.object({ + enabled: _zod.z.boolean().nullish(), + maxCount: _zod.z.number().nullish() }); } function SidebarGalleryConfigSchema() { - return zod_1.z.object({ - paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish() + return _zod.z.object({ + paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() }); } diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 6102975855..59700ca1ef 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -302,6 +302,7 @@ export type GraphCommerceConfig = { * Values: 245, 246, 247 for Magento 2.4.5, 2.4.6, 2.4.7 respectively. */ magentoVersion: Scalars['Int']['input']; + /** Allows the option to require login or completely disable certain sections of the site, can be overriden per storeview with the storefrontConfig */ permissions?: InputMaybe; /** To enable next.js' preview mode, configure the secret you'd like to use. */ previewSecret?: InputMaybe; @@ -368,10 +369,7 @@ export type GraphCommerceDebugConfig = { }; export type GraphCommercePermissions = { - /** - * Changes the availability of the add to cart buttons and the cart page to either customer only or completely disables it. - * Note: Any value here will automatically be passed to `checkout`. For example: setting `cart` to `DISABLED` and `checkout` to `ENABLED` will result in the checkout being disabled. - */ + /** Changes the availability of the add to cart buttons and the cart page to either customer only or completely disables it. */ cart?: InputMaybe; /** Changes the availability of the checkout to either customer only or completely disables it. */ checkout?: InputMaybe; @@ -438,6 +436,7 @@ export type GraphCommerceStorefrontConfig = { * - b2b-us */ magentoStoreCode: Scalars['String']['input']; + /** Allows the option to require login or completely disable certain sections of the site on a per store basis */ permissions?: InputMaybe; /** * Allow the site to be indexed by search engines. @@ -582,7 +581,7 @@ export function GraphCommercePermissionsSchema(): z.ZodObject Date: Fri, 2 Aug 2024 17:22:18 +0200 Subject: [PATCH 39/48] Ook nog ff mee --- packages/magento-customer/link/customerLink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/magento-customer/link/customerLink.ts b/packages/magento-customer/link/customerLink.ts index 9299496858..a0bbabc959 100644 --- a/packages/magento-customer/link/customerLink.ts +++ b/packages/magento-customer/link/customerLink.ts @@ -157,4 +157,4 @@ const customerErrorLink = (router: PushRouter) => // }) export const customerLink = (router: PushRouter) => - ApolloLink.from([addTokenHeader, customerErrorLink(router), customerMaybelinkan(router)]) + ApolloLink.from([addTokenHeader, customerErrorLink(router)]) From 1a7734d5e699ce156f2a506bbe6743c5d094c61a Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Thu, 22 Aug 2024 13:38:14 +0200 Subject: [PATCH 40/48] Move presmissions to relevant packages --- .../components/Layout/Footer.tsx | 2 +- .../components/Layout/LayoutNavigation.tsx | 3 +- .../ProductView/AddProductsToCartView.tsx | 2 +- examples/magento-graphcms/pages/404.tsx | 2 +- .../pages/account/addresses/add.tsx | 2 +- .../pages/account/addresses/edit.tsx | 2 +- .../pages/account/addresses/index.tsx | 2 +- .../pages/account/authentication/index.tsx | 7 +- .../pages/account/contact/index.tsx | 2 +- .../pages/account/delete/index.tsx | 3 +- .../pages/account/forgot-password.tsx | 3 +- .../magento-graphcms/pages/account/index.tsx | 2 +- .../pages/account/name/index.tsx | 2 +- .../pages/account/orders/index.tsx | 2 +- .../pages/account/orders/view.tsx | 2 +- .../pages/account/reviews/add.tsx | 7 +- .../pages/account/reviews/index.tsx | 7 +- .../magento-graphcms/pages/account/signin.tsx | 3 +- examples/magento-graphcms/pages/cart.tsx | 12 ++- .../magento-graphcms/pages/checkout/added.tsx | 5 +- .../checkout/customer/addresses/edit.tsx | 5 +- .../pages/checkout/edit/billing-address.tsx | 2 +- .../magento-graphcms/pages/checkout/index.tsx | 4 +- .../pages/checkout/item/[url].tsx | 11 ++- .../pages/checkout/payment.tsx | 9 +-- .../pages/checkout/success.tsx | 8 +- .../pages/checkout/terms/[url].tsx | 7 +- .../pages/customer/account/confirm.tsx | 3 +- .../customer/account/createPassword/index.tsx | 3 +- packages/ecommerce-ui/hooks/usePermissions.ts | 78 ------------------- packages/ecommerce-ui/index.ts | 2 - .../ecommerce-ui/utils/permissionUtils.ts | 22 ------ packages/magento-cart-checkout/index.ts | 2 +- .../EmailForm/EmailForm.tsx | 8 +- .../components/CartFab/CartFab.tsx | 3 +- .../CartStartCheckout/CartStartCheckout.tsx | 2 +- .../CartStartCheckoutLinkOrButton.tsx | 2 +- .../InlineAccount/InlineAccount.tsx | 2 +- packages/magento-cart/hooks/index.ts | 8 +- .../magento-cart/hooks/useCartPermissions.ts | 21 +++++ .../hooks/useCheckoutPermissions.ts | 21 +++++ packages/magento-cart/index.ts | 7 +- .../{createCartErrorLink.ts => cartLink.ts} | 64 ++++++++++++++- .../link/isProtectedCartOperation.ts | 7 ++ packages/magento-cart/package.json | 1 + .../plugins/MagentoCartGraphqlProvider.tsx | 18 ++++- .../magento-cart/utils/cartPermissions.ts | 23 ++++++ .../magento-cart/utils/checkoutPermissions.ts | 13 ++++ packages/magento-cart/utils/index.ts | 2 + .../AccountSignInUpForm.tsx | 8 +- .../ApolloCustomerErrorFullPage.tsx | 7 +- .../components/CustomerFab/CustomerFab.tsx | 7 +- .../CustomerMenuFabItem.tsx | 2 +- .../UnauthenticatedFullPageMessage.tsx | 2 +- packages/magento-customer/hooks/index.ts | 1 + .../hooks/useAccountSignInUpForm.tsx | 2 +- .../hooks/useCustomerPermissions.ts | 17 ++++ .../magento-customer/link/customerLink.ts | 37 ++------- .../MagentoCustomerGraphqlProvider.tsx | 5 +- packages/magento-customer/tsconfig.json | 2 +- .../utils/customerPermissions.ts | 17 ++++ packages/magento-customer/utils/index.ts | 1 + .../AddProductsToCartButton.tsx | 4 +- .../AddProductsToCartFab.tsx | 2 +- yarn.lock | 1 + 65 files changed, 312 insertions(+), 233 deletions(-) delete mode 100644 packages/ecommerce-ui/hooks/usePermissions.ts delete mode 100644 packages/ecommerce-ui/utils/permissionUtils.ts create mode 100644 packages/magento-cart/hooks/useCartPermissions.ts create mode 100644 packages/magento-cart/hooks/useCheckoutPermissions.ts rename packages/magento-cart/link/{createCartErrorLink.ts => cartLink.ts} (51%) create mode 100644 packages/magento-cart/link/isProtectedCartOperation.ts create mode 100644 packages/magento-cart/utils/cartPermissions.ts create mode 100644 packages/magento-cart/utils/checkoutPermissions.ts create mode 100644 packages/magento-cart/utils/index.ts create mode 100644 packages/magento-customer/hooks/useCustomerPermissions.ts create mode 100644 packages/magento-customer/utils/customerPermissions.ts diff --git a/examples/magento-graphcms/components/Layout/Footer.tsx b/examples/magento-graphcms/components/Layout/Footer.tsx index 35344ee44e..ff92a7e573 100644 --- a/examples/magento-graphcms/components/Layout/Footer.tsx +++ b/examples/magento-graphcms/components/Layout/Footer.tsx @@ -1,5 +1,5 @@ -import { useCheckoutGuestEnabled } from '@graphcommerce/ecommerce-ui' import { Image } from '@graphcommerce/image' +import { useCheckoutGuestEnabled } from '@graphcommerce/magento-cart' import { StoreSwitcherButton } from '@graphcommerce/magento-store' import { Footer as FooterBase } from '@graphcommerce/next-ui' import { Trans } from '@lingui/macro' diff --git a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx index 7166fb728c..b5466e3c33 100644 --- a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx +++ b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx @@ -1,5 +1,4 @@ -import { useCartEnabled } from '@graphcommerce/ecommerce-ui' -import { CartFab } from '@graphcommerce/magento-cart' +import { CartFab, useCartEnabled } from '@graphcommerce/magento-cart' import { magentoMenuToNavigation } from '@graphcommerce/magento-category' import { CustomerFab, CustomerMenuFabItem } from '@graphcommerce/magento-customer' import { ProductFiltersProSearchField, SearchLink } from '@graphcommerce/magento-search' diff --git a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx index d717fae3de..6cf7dbc41d 100644 --- a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx +++ b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx @@ -1,4 +1,4 @@ -import { useCartEnabled } from '@graphcommerce/ecommerce-ui' +import { useCartEnabled } from '@graphcommerce/magento-cart' import { AddProductsToCartError, AddProductsToCartQuantity, diff --git a/examples/magento-graphcms/pages/404.tsx b/examples/magento-graphcms/pages/404.tsx index 73ad0c0e0a..a369c4b8d1 100644 --- a/examples/magento-graphcms/pages/404.tsx +++ b/examples/magento-graphcms/pages/404.tsx @@ -1,6 +1,6 @@ -import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' +import { useCustomerAccountCanSignIn } from '@graphcommerce/magento-customer' import { SearchLink } from '@graphcommerce/magento-search' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, Separator, icon404, IconSvg } from '@graphcommerce/next-ui' diff --git a/examples/magento-graphcms/pages/account/addresses/add.tsx b/examples/magento-graphcms/pages/account/addresses/add.tsx index ef1ddf5061..5a328fa900 100644 --- a/examples/magento-graphcms/pages/account/addresses/add.tsx +++ b/examples/magento-graphcms/pages/account/addresses/add.tsx @@ -1,4 +1,3 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { CreateCustomerAddressForm, @@ -6,6 +5,7 @@ import { useCustomerQuery, WaitForCustomer, AccountDashboardAddressesQuery, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/addresses/edit.tsx b/examples/magento-graphcms/pages/account/addresses/edit.tsx index abf04d2ddd..1f98b34bfb 100644 --- a/examples/magento-graphcms/pages/account/addresses/edit.tsx +++ b/examples/magento-graphcms/pages/account/addresses/edit.tsx @@ -1,10 +1,10 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { EditAddressForm, useCustomerQuery, WaitForCustomer, AccountDashboardAddressesDocument, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/addresses/index.tsx b/examples/magento-graphcms/pages/account/addresses/index.tsx index 69a0388bd1..4dc08c9172 100644 --- a/examples/magento-graphcms/pages/account/addresses/index.tsx +++ b/examples/magento-graphcms/pages/account/addresses/index.tsx @@ -1,10 +1,10 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { AccountAddresses, useCustomerQuery, WaitForCustomer, AccountDashboardAddressesDocument, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { CountryRegionsDocument, PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/authentication/index.tsx b/examples/magento-graphcms/pages/account/authentication/index.tsx index 5cd18cc32a..d07e3affda 100644 --- a/examples/magento-graphcms/pages/account/authentication/index.tsx +++ b/examples/magento-graphcms/pages/account/authentication/index.tsx @@ -1,6 +1,9 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { ChangePasswordForm, WaitForCustomer } from '@graphcommerce/magento-customer' +import { + ChangePasswordForm, + WaitForCustomer, + getCustomerAccountIsDisabled, +} from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, diff --git a/examples/magento-graphcms/pages/account/contact/index.tsx b/examples/magento-graphcms/pages/account/contact/index.tsx index 3b8ac9283f..765848a542 100644 --- a/examples/magento-graphcms/pages/account/contact/index.tsx +++ b/examples/magento-graphcms/pages/account/contact/index.tsx @@ -1,7 +1,7 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { CustomerDocument, + getCustomerAccountIsDisabled, UpdateCustomerEmailForm, useCustomerQuery, WaitForCustomer, diff --git a/examples/magento-graphcms/pages/account/delete/index.tsx b/examples/magento-graphcms/pages/account/delete/index.tsx index ce1cc33598..7a4a7913ad 100644 --- a/examples/magento-graphcms/pages/account/delete/index.tsx +++ b/examples/magento-graphcms/pages/account/delete/index.tsx @@ -1,6 +1,5 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { AccountDeleteForm } from '@graphcommerce/magento-customer' +import { AccountDeleteForm, getCustomerAccountIsDisabled } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, LayoutOverlayHeader, LayoutTitle, iconBin } from '@graphcommerce/next-ui' import { Trans, t } from '@lingui/macro' diff --git a/examples/magento-graphcms/pages/account/forgot-password.tsx b/examples/magento-graphcms/pages/account/forgot-password.tsx index 180a73898f..8cadf06fbb 100644 --- a/examples/magento-graphcms/pages/account/forgot-password.tsx +++ b/examples/magento-graphcms/pages/account/forgot-password.tsx @@ -1,6 +1,5 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { ForgotPasswordForm } from '@graphcommerce/magento-customer' +import { ForgotPasswordForm, getCustomerAccountIsDisabled } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' diff --git a/examples/magento-graphcms/pages/account/index.tsx b/examples/magento-graphcms/pages/account/index.tsx index 560e9c87ea..d6d2193def 100644 --- a/examples/magento-graphcms/pages/account/index.tsx +++ b/examples/magento-graphcms/pages/account/index.tsx @@ -1,4 +1,3 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst, useQuery } from '@graphcommerce/graphql' import { @@ -6,6 +5,7 @@ import { AccountMenu, AccountMenuItem, AddressSingleLine, + getCustomerAccountIsDisabled, OrderStateLabelInline, SignOutForm, useCustomerQuery, diff --git a/examples/magento-graphcms/pages/account/name/index.tsx b/examples/magento-graphcms/pages/account/name/index.tsx index a2f3e69d85..8a250a5e90 100644 --- a/examples/magento-graphcms/pages/account/name/index.tsx +++ b/examples/magento-graphcms/pages/account/name/index.tsx @@ -1,8 +1,8 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ChangeNameForm, CustomerDocument, + getCustomerAccountIsDisabled, useCustomerQuery, WaitForCustomer, } from '@graphcommerce/magento-customer' diff --git a/examples/magento-graphcms/pages/account/orders/index.tsx b/examples/magento-graphcms/pages/account/orders/index.tsx index 5873aeada9..4cfc31f4fd 100644 --- a/examples/magento-graphcms/pages/account/orders/index.tsx +++ b/examples/magento-graphcms/pages/account/orders/index.tsx @@ -1,10 +1,10 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useCustomerQuery, WaitForCustomer, AccountDashboardOrdersDocument, AccountOrders, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/orders/view.tsx b/examples/magento-graphcms/pages/account/orders/view.tsx index 890916f0b8..b2b1ffe058 100644 --- a/examples/magento-graphcms/pages/account/orders/view.tsx +++ b/examples/magento-graphcms/pages/account/orders/view.tsx @@ -1,4 +1,3 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useCustomerQuery, @@ -11,6 +10,7 @@ import { OrderStateLabel, ReorderItems, CancelOrderForm, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { CountryRegionsDocument, PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/reviews/add.tsx b/examples/magento-graphcms/pages/account/reviews/add.tsx index 74e05dbbe2..1680bc0079 100644 --- a/examples/magento-graphcms/pages/account/reviews/add.tsx +++ b/examples/magento-graphcms/pages/account/reviews/add.tsx @@ -1,7 +1,10 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { useQuery } from '@graphcommerce/graphql' -import { ApolloCustomerErrorFullPage, CustomerDocument } from '@graphcommerce/magento-customer' +import { + ApolloCustomerErrorFullPage, + CustomerDocument, + getCustomerAccountIsDisabled, +} from '@graphcommerce/magento-customer' import { ProductReviewProductNameDocument, CreateProductReviewForm, diff --git a/examples/magento-graphcms/pages/account/reviews/index.tsx b/examples/magento-graphcms/pages/account/reviews/index.tsx index 7309524d2e..35c12849f7 100644 --- a/examples/magento-graphcms/pages/account/reviews/index.tsx +++ b/examples/magento-graphcms/pages/account/reviews/index.tsx @@ -1,6 +1,9 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { useCustomerQuery, WaitForCustomer } from '@graphcommerce/magento-customer' +import { + getCustomerAccountIsDisabled, + useCustomerQuery, + WaitForCustomer, +} from '@graphcommerce/magento-customer' import { AccountDashboardReviewsDocument, AccountReviews } from '@graphcommerce/magento-review' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/account/signin.tsx b/examples/magento-graphcms/pages/account/signin.tsx index 1ad3c9f74f..0cb61e6a27 100644 --- a/examples/magento-graphcms/pages/account/signin.tsx +++ b/examples/magento-graphcms/pages/account/signin.tsx @@ -1,6 +1,5 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { AccountSignInUpForm } from '@graphcommerce/magento-customer' +import { AccountSignInUpForm, getCustomerAccountIsDisabled } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { useMergeGuestWishlistWithCustomer } from '@graphcommerce/magento-wishlist' import { GetStaticProps, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' diff --git a/examples/magento-graphcms/pages/cart.tsx b/examples/magento-graphcms/pages/cart.tsx index 85e630ea11..0e27fae36f 100644 --- a/examples/magento-graphcms/pages/cart.tsx +++ b/examples/magento-graphcms/pages/cart.tsx @@ -1,8 +1,4 @@ -import { - WaitForQueries, - getCartIsDisabled, - useCartIsAvailableForUser, -} from '@graphcommerce/ecommerce-ui' +import { WaitForQueries } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { ApolloCartErrorAlert, @@ -10,7 +6,9 @@ import { CartStartCheckoutLinkOrButton, CartTotals, EmptyCart, + getCartDisabled, useCartQuery, + useCartShouldLoginToContinue, } from '@graphcommerce/magento-cart' import { CartPageDocument } from '@graphcommerce/magento-cart-checkout' import { CouponAccordion } from '@graphcommerce/magento-cart-coupon' @@ -46,7 +44,7 @@ function CartPage() { (data?.cart?.total_quantity ?? 0) > 0 && typeof data?.cart?.prices?.grand_total?.value !== 'undefined' - const cartAvaialable = useCartIsAvailableForUser() + const cartAvaialable = useCartShouldLoginToContinue() return ( <> @@ -127,7 +125,7 @@ CartPage.pageOptions = pageOptions export default CartPage export const getStaticProps: GetPageStaticProps = async (context) => { - if (getCartIsDisabled(context.locale)) return { notFound: true } + if (getCartDisabled(context.locale)) return { notFound: true } const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/added.tsx b/examples/magento-graphcms/pages/checkout/added.tsx index a9daa8dd0f..6c1f07748c 100644 --- a/examples/magento-graphcms/pages/checkout/added.tsx +++ b/examples/magento-graphcms/pages/checkout/added.tsx @@ -1,7 +1,6 @@ -import { getCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { Image } from '@graphcommerce/image' -import { useCrosssellItems } from '@graphcommerce/magento-cart' +import { getCartDisabled, useCrosssellItems } from '@graphcommerce/magento-cart' import { AddProductsToCartForm, ProductScroller } from '@graphcommerce/magento-product' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { @@ -163,7 +162,7 @@ CheckoutAdded.pageOptions = pageOptions export default CheckoutAdded export const getStaticProps: GetPageStaticProps = async (context) => { - if (getCartIsDisabled(context.locale)) return { notFound: true } + if (getCartDisabled(context.locale)) return { notFound: true } const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx b/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx index da6cacc04f..f283eb238e 100644 --- a/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx +++ b/examples/magento-graphcms/pages/checkout/customer/addresses/edit.tsx @@ -1,10 +1,11 @@ -import { getCustomerAccountIsDisabled, getCartIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' +import { getCartDisabled } from '@graphcommerce/magento-cart' import { ApolloCustomerErrorFullPage, EditAddressForm, useCustomerQuery, AccountDashboardAddressesDocument, + getCustomerAccountIsDisabled, } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { @@ -91,7 +92,7 @@ CheckoutCustomerAddressesEdit.pageOptions = pageOptions export default CheckoutCustomerAddressesEdit export const getStaticProps: GetPageStaticProps = async (context) => { - if (getCartIsDisabled(context.locale) || getCustomerAccountIsDisabled(context.locale)) + if (getCartDisabled(context.locale) || getCustomerAccountIsDisabled(context.locale)) return { notFound: true } const client = graphqlSharedClient(context) const conf = client.query({ query: StoreConfigDocument }) diff --git a/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx b/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx index a50e6e0a76..c93d8fb8fa 100644 --- a/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx +++ b/examples/magento-graphcms/pages/checkout/edit/billing-address.tsx @@ -1,6 +1,6 @@ -import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' +import { getCheckoutIsDisabled } from '@graphcommerce/magento-cart' import { EditBillingAddressForm } from '@graphcommerce/magento-cart-billing-address' import { StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, PageMeta, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' diff --git a/examples/magento-graphcms/pages/checkout/index.tsx b/examples/magento-graphcms/pages/checkout/index.tsx index 3d76f3d37e..289d594385 100644 --- a/examples/magento-graphcms/pages/checkout/index.tsx +++ b/examples/magento-graphcms/pages/checkout/index.tsx @@ -4,8 +4,6 @@ import { ComposedForm, ComposedSubmit, WaitForQueries, - getCheckoutIsDisabled, - useCheckoutShouldLoginToContinue, } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' @@ -13,7 +11,9 @@ import { ApolloCartErrorAlert, ApolloCartErrorFullPage, EmptyCart, + getCheckoutIsDisabled, useCartQuery, + useCheckoutShouldLoginToContinue, } from '@graphcommerce/magento-cart' import { ShippingPageDocument } from '@graphcommerce/magento-cart-checkout' import { EmailForm } from '@graphcommerce/magento-cart-email' diff --git a/examples/magento-graphcms/pages/checkout/item/[url].tsx b/examples/magento-graphcms/pages/checkout/item/[url].tsx index 272299d5f5..aa52835c08 100644 --- a/examples/magento-graphcms/pages/checkout/item/[url].tsx +++ b/examples/magento-graphcms/pages/checkout/item/[url].tsx @@ -1,7 +1,12 @@ -import { WaitForQueries, getCartIsDisabled } from '@graphcommerce/ecommerce-ui' +import { WaitForQueries } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { flushMeasurePerf } from '@graphcommerce/graphql' -import { ApolloCartErrorAlert, EmptyCart, useCartQuery } from '@graphcommerce/magento-cart' +import { + ApolloCartErrorAlert, + EmptyCart, + getCartDisabled, + useCartQuery, +} from '@graphcommerce/magento-cart' import { CartPageDocument } from '@graphcommerce/magento-cart-checkout' import { EditCartItemButton, EditCartItemForm } from '@graphcommerce/magento-cart-items' import { ProductPageGallery, ProductPageName } from '@graphcommerce/magento-product' @@ -115,7 +120,7 @@ CartItemEdit.pageOptions = { export default CartItemEdit export const getServerSideProps: GetSSP = async (context) => { - if (getCartIsDisabled(context.locale)) return { notFound: true } + if (getCartDisabled(context.locale)) return { notFound: true } const result = await getStaticProps(context) delete result.revalidate diff --git a/examples/magento-graphcms/pages/checkout/payment.tsx b/examples/magento-graphcms/pages/checkout/payment.tsx index df06460213..effd2023e7 100644 --- a/examples/magento-graphcms/pages/checkout/payment.tsx +++ b/examples/magento-graphcms/pages/checkout/payment.tsx @@ -1,9 +1,4 @@ -import { - ComposedForm, - WaitForQueries, - getCheckoutIsDisabled, - useCheckoutShouldLoginToContinue, -} from '@graphcommerce/ecommerce-ui' +import { ComposedForm, WaitForQueries } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' import { @@ -12,7 +7,9 @@ import { CartSummary, CartTotals, EmptyCart, + getCheckoutIsDisabled, useCartQuery, + useCheckoutShouldLoginToContinue, } from '@graphcommerce/magento-cart' import { BillingPageDocument } from '@graphcommerce/magento-cart-checkout' import { CouponAccordion } from '@graphcommerce/magento-cart-coupon' diff --git a/examples/magento-graphcms/pages/checkout/success.tsx b/examples/magento-graphcms/pages/checkout/success.tsx index f8340309c4..f13d8e4f27 100644 --- a/examples/magento-graphcms/pages/checkout/success.tsx +++ b/examples/magento-graphcms/pages/checkout/success.tsx @@ -1,7 +1,11 @@ -import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' import { cacheFirst } from '@graphcommerce/graphql' -import { CartItemSummary, CartSummary, InlineAccount } from '@graphcommerce/magento-cart' +import { + CartItemSummary, + CartSummary, + InlineAccount, + getCheckoutIsDisabled, +} from '@graphcommerce/magento-cart' import { SignupNewsletter } from '@graphcommerce/magento-newsletter' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { diff --git a/examples/magento-graphcms/pages/checkout/terms/[url].tsx b/examples/magento-graphcms/pages/checkout/terms/[url].tsx index c7c343bd9c..8a7665cb49 100644 --- a/examples/magento-graphcms/pages/checkout/terms/[url].tsx +++ b/examples/magento-graphcms/pages/checkout/terms/[url].tsx @@ -1,6 +1,9 @@ -import { getCheckoutIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { CartAgreementsDocument, CartAgreementsQuery } from '@graphcommerce/magento-cart' +import { + CartAgreementsDocument, + CartAgreementsQuery, + getCheckoutIsDisabled, +} from '@graphcommerce/magento-cart' import { StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, PageMeta, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' import { Container, Typography } from '@mui/material' diff --git a/examples/magento-graphcms/pages/customer/account/confirm.tsx b/examples/magento-graphcms/pages/customer/account/confirm.tsx index b55dff3419..0145052831 100644 --- a/examples/magento-graphcms/pages/customer/account/confirm.tsx +++ b/examples/magento-graphcms/pages/customer/account/confirm.tsx @@ -1,6 +1,5 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { ConfirmCustomerForm } from '@graphcommerce/magento-customer' +import { ConfirmCustomerForm, getCustomerAccountIsDisabled } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' diff --git a/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx b/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx index dcbe544cf6..a36ac4f7fe 100644 --- a/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx +++ b/examples/magento-graphcms/pages/customer/account/createPassword/index.tsx @@ -1,6 +1,5 @@ -import { getCustomerAccountIsDisabled } from '@graphcommerce/ecommerce-ui' import { PageOptions } from '@graphcommerce/framer-next-pages' -import { ResetPasswordForm } from '@graphcommerce/magento-customer' +import { ResetPasswordForm, getCustomerAccountIsDisabled } from '@graphcommerce/magento-customer' import { PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' diff --git a/packages/ecommerce-ui/hooks/usePermissions.ts b/packages/ecommerce-ui/hooks/usePermissions.ts deleted file mode 100644 index ef78c161dd..0000000000 --- a/packages/ecommerce-ui/hooks/usePermissions.ts +++ /dev/null @@ -1,78 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { useCustomerSession } from '@graphcommerce/magento-customer/hooks/useCustomerSession' -import { useStorefrontConfig } from '@graphcommerce/next-ui' - -function useCartPermissions() { - return 'CUSTOMER_ONLY' - return ( - useStorefrontConfig().permissions?.cart ?? - import.meta.graphCommerce.permissions?.cart ?? - 'ENABLED' - ) -} - -// export function useCartIsAvailableForUser() { -// const { loggedIn } = useCustomerSession() -// const cart = useCartPermissions() -// return cart !== 'CUSTOMER_ONLY' || loggedIn -// } - -// export function useCartIsDisabled() { -// const cart = -// useStorefrontConfig().permissions?.cart ?? import.meta.graphCommerce.permissions?.cart -// return cart === 'DISABLED' -// } -export function useCartEnabled() { - return useCartPermissions() !== 'DISABLED' -} - -export function useCartGuestEnabled() { - return useCartPermissions() === 'ENABLED' -} - -export function useCartShouldLoginToContinue() { - const { loggedIn } = useCustomerSession() - const permission = useCartPermissions() - if (permission === 'ENABLED') return false - return !loggedIn -} - -function useCheckoutPermission() { - return ( - useStorefrontConfig().permissions?.checkout ?? - import.meta.graphCommerce.permissions?.checkout ?? - 'ENABLED' - ) -} - -export function useCheckoutGuestEnabled() { - return useCheckoutPermission() === 'ENABLED' -} - -export function useCheckoutShouldLoginToContinue() { - const { loggedIn } = useCustomerSession() - const permission = useCheckoutPermission() - if (permission === 'ENABLED') return false - return !loggedIn -} - -function useCustomerAccountPermission() { - return ( - useStorefrontConfig().permissions?.customerAccount ?? - import.meta.graphCommerce.permissions?.customerAccount ?? - 'ENABLED' - ) -} - -export function useCustomerAccountCanSignIn() { - return useCustomerAccountPermission() !== 'DISABLED' -} - -export function useCustomerAccountCanSignUp() { - // return false - return useCustomerAccountPermission() === 'ENABLED' -} - -export function useCustomerAccountRegistrationDisabled() { - return useCustomerAccountPermission() !== 'ENABLED' -} diff --git a/packages/ecommerce-ui/index.ts b/packages/ecommerce-ui/index.ts index df18ab5aa0..be947b5087 100644 --- a/packages/ecommerce-ui/index.ts +++ b/packages/ecommerce-ui/index.ts @@ -1,4 +1,2 @@ export * from './components' export * from '@graphcommerce/react-hook-form' -export * from './utils/permissionUtils' -export * from './hooks/usePermissions' diff --git a/packages/ecommerce-ui/utils/permissionUtils.ts b/packages/ecommerce-ui/utils/permissionUtils.ts deleted file mode 100644 index 2d804124ae..0000000000 --- a/packages/ecommerce-ui/utils/permissionUtils.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { storefrontConfig } from '@graphcommerce/next-ui' - -export function getCustomerAccountIsDisabled(locale: string | undefined) { - return ( - storefrontConfig(locale)?.permissions?.customerAccount ?? - import.meta.graphCommerce.permissions?.customerAccount === 'DISABLED' - ) -} - -export function getCartIsDisabled(locale: string | undefined) { - return ( - storefrontConfig(locale)?.permissions?.cart ?? - import.meta.graphCommerce.permissions?.cart === 'DISABLED' - ) -} - -export function getCheckoutIsDisabled(locale: string | undefined) { - return ( - storefrontConfig(locale)?.permissions?.checkout ?? - import.meta.graphCommerce.permissions?.checkout === 'DISABLED' - ) -} diff --git a/packages/magento-cart-checkout/index.ts b/packages/magento-cart-checkout/index.ts index 207655e40c..11a7ab68e3 100644 --- a/packages/magento-cart-checkout/index.ts +++ b/packages/magento-cart-checkout/index.ts @@ -1,3 +1,3 @@ +export * from './queries/BillingPage.gql' export * from './queries/CartPage.gql' export * from './queries/ShippingPage.gql' -export * from './queries/BillingPage.gql' diff --git a/packages/magento-cart-email/EmailForm/EmailForm.tsx b/packages/magento-cart-email/EmailForm/EmailForm.tsx index 25d61dd170..03fdb548ed 100644 --- a/packages/magento-cart-email/EmailForm/EmailForm.tsx +++ b/packages/magento-cart-email/EmailForm/EmailForm.tsx @@ -1,11 +1,15 @@ -import { EmailElement, useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' +import { EmailElement } from '@graphcommerce/ecommerce-ui' import { useQuery } from '@graphcommerce/graphql' import { ApolloCartErrorAlert, useCartQuery, useFormGqlMutationCart, } from '@graphcommerce/magento-cart' -import { IsEmailAvailableDocument, useCustomerSession } from '@graphcommerce/magento-customer' +import { + IsEmailAvailableDocument, + useCustomerAccountCanSignIn, + useCustomerSession, +} from '@graphcommerce/magento-customer' import { extendableComponent, FormRow } from '@graphcommerce/next-ui' import { FormAutoSubmit, diff --git a/packages/magento-cart/components/CartFab/CartFab.tsx b/packages/magento-cart/components/CartFab/CartFab.tsx index 3a24db9917..2a80d4db09 100644 --- a/packages/magento-cart/components/CartFab/CartFab.tsx +++ b/packages/magento-cart/components/CartFab/CartFab.tsx @@ -1,4 +1,4 @@ -import { WaitForQueries, useCartEnabled } from '@graphcommerce/ecommerce-ui' +import { WaitForQueries } from '@graphcommerce/ecommerce-ui' import { extendableComponent, iconShoppingBag, @@ -11,6 +11,7 @@ import { i18n } from '@lingui/core' import { alpha, Fab, FabProps, styled, useTheme, Box, SxProps, Theme } from '@mui/material' import { m, useTransform } from 'framer-motion' import React from 'react' +import { useCartEnabled } from '../../hooks' import { useCartQuery } from '../../hooks/useCartQuery' import { CartFabDocument } from './CartFab.gql' import { CartTotalQuantityFragment } from './CartTotalQuantity.gql' diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx index f5e5d948d9..684eda7202 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckout.tsx @@ -1,9 +1,9 @@ -import { useCheckoutShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' import { Money } from '@graphcommerce/magento-store' import { iconChevronRight, IconSvg, extendableComponent } from '@graphcommerce/next-ui' import { Trans } from '@lingui/macro' import { Box, Button, ButtonProps, Link, SxProps, Theme } from '@mui/material' import React from 'react' +import { useCheckoutShouldLoginToContinue } from '../../hooks' import { CartStartCheckoutFragment } from './CartStartCheckout.gql' export type CartStartCheckoutProps = { diff --git a/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx b/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx index 5028f0ba4e..18c5e09871 100644 --- a/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +++ b/packages/magento-cart/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx @@ -1,8 +1,8 @@ -import { useCheckoutShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' import { iconChevronRight, IconSvg, LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { SxProps, Theme } from '@mui/material' import React from 'react' +import { useCheckoutShouldLoginToContinue } from '../../hooks' import { CartStartCheckoutFragment } from './CartStartCheckout.gql' export type CartStartCheckoutLinkOrButtonProps = { diff --git a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx index 7e15f8fc79..10cafc37ed 100644 --- a/packages/magento-cart/components/InlineAccount/InlineAccount.tsx +++ b/packages/magento-cart/components/InlineAccount/InlineAccount.tsx @@ -1,9 +1,9 @@ -import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { SignUpFormInline, IsEmailAvailableDocument, useCustomerSession, useGuestQuery, + useCustomerAccountCanSignIn, } from '@graphcommerce/magento-customer' import { Button, FormRow, extendableComponent } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' diff --git a/packages/magento-cart/hooks/index.ts b/packages/magento-cart/hooks/index.ts index 5304d07ad0..374ee47227 100644 --- a/packages/magento-cart/hooks/index.ts +++ b/packages/magento-cart/hooks/index.ts @@ -1,8 +1,10 @@ export * from './useAssignCurrentCartId' -export * from './useCurrentCartId' +export * from './useCartIdCreate' +export * from './useCartPermissions' export * from './useCartQuery' +export * from './useCheckoutPermissions' export * from './useClearCurrentCartId' -export * from './useCartIdCreate' +export * from './useCurrentCartId' +export * from './useDisplayInclTax' export * from './useFormGqlMutationCart' export * from './useMergeCustomerCart' -export * from './useDisplayInclTax' diff --git a/packages/magento-cart/hooks/useCartPermissions.ts b/packages/magento-cart/hooks/useCartPermissions.ts new file mode 100644 index 0000000000..a309e4bdf9 --- /dev/null +++ b/packages/magento-cart/hooks/useCartPermissions.ts @@ -0,0 +1,21 @@ +import { useCustomerSession } from '@graphcommerce/magento-customer/hooks/useCustomerSession' +import { useStorefrontConfig } from '@graphcommerce/next-ui' + +function useCartPermissions() { + return ( + useStorefrontConfig().permissions?.cart ?? + import.meta.graphCommerce.permissions?.cart ?? + 'ENABLED' + ) +} + +export function useCartEnabled() { + return useCartPermissions() !== 'DISABLED' +} + +export function useCartShouldLoginToContinue() { + const { loggedIn } = useCustomerSession() + const permission = useCartPermissions() + if (permission === 'ENABLED') return false + return !loggedIn +} diff --git a/packages/magento-cart/hooks/useCheckoutPermissions.ts b/packages/magento-cart/hooks/useCheckoutPermissions.ts new file mode 100644 index 0000000000..c02cc5cb9d --- /dev/null +++ b/packages/magento-cart/hooks/useCheckoutPermissions.ts @@ -0,0 +1,21 @@ +import { useCustomerSession } from '@graphcommerce/magento-customer/hooks/useCustomerSession' +import { useStorefrontConfig } from '@graphcommerce/next-ui' + +function useCheckoutPermission() { + return ( + useStorefrontConfig().permissions?.checkout ?? + import.meta.graphCommerce.permissions?.checkout ?? + 'ENABLED' + ) +} + +export function useCheckoutGuestEnabled() { + return useCheckoutPermission() === 'ENABLED' +} + +export function useCheckoutShouldLoginToContinue() { + const { loggedIn } = useCustomerSession() + const permission = useCheckoutPermission() + if (permission === 'ENABLED') return false + return !loggedIn +} diff --git a/packages/magento-cart/index.ts b/packages/magento-cart/index.ts index fc36b47677..cc56cc8e23 100644 --- a/packages/magento-cart/index.ts +++ b/packages/magento-cart/index.ts @@ -1,6 +1,7 @@ export * from './Api/CartItemCountChanged.gql' -export * from './hooks' export * from './components' -export * from './typePolicies' -export * from './link/createCartErrorLink' export * from './components/CartDebugger/CartDebugger' +export * from './hooks' +export * from './link/cartLink' +export * from './typePolicies' +export * from './utils' diff --git a/packages/magento-cart/link/createCartErrorLink.ts b/packages/magento-cart/link/cartLink.ts similarity index 51% rename from packages/magento-cart/link/createCartErrorLink.ts rename to packages/magento-cart/link/cartLink.ts index 5ff5f64202..64a60ef014 100644 --- a/packages/magento-cart/link/createCartErrorLink.ts +++ b/packages/magento-cart/link/cartLink.ts @@ -1,9 +1,14 @@ import { fromPromise, globalApolloClient, Operation } from '@graphcommerce/graphql' -import { onError } from '@graphcommerce/graphql/apollo' +import { ApolloLink, Observable, onError } from '@graphcommerce/graphql/apollo' +import { CustomerTokenDocument, getCustomerAccountCanSignIn } from '@graphcommerce/magento-customer' +import { PushRouter, pushWithPromise } from '@graphcommerce/magento-customer/link/customerLink' import { ErrorCategory } from '@graphcommerce/magento-graphql' -import type { GraphQLError } from 'graphql' +import { t } from '@lingui/macro' +import { GraphQLError } from 'graphql' import { writeCartId } from '../hooks' import { CreateEmptyCartDocument } from '../hooks/CreateEmptyCart.gql' +import { getCartEnabledForUser } from '../utils' +import { isProtectedCartOperation } from './isProtectedCartOperation' type CartOperation = Operation & { variables: { cartId: string } } function isCartOperation(operation: Operation): operation is CartOperation { @@ -15,7 +20,7 @@ function errorIsIncluded(errorPath: readonly (string | number)[] | undefined, ke return keys.some((value) => value === error) } -export const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => { +const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => { if (!globalApolloClient.current) return undefined const client = globalApolloClient.current @@ -68,4 +73,55 @@ export const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => }) }) -export const createCartErrorLink = () => cartErrorLink +const cartPermissionLink = (router: PushRouter) => + new ApolloLink((operation, forward) => { + const { locale } = router + const { cache } = operation.getContext() + + if (!isProtectedCartOperation(operation)) return forward(operation) + + const check = () => Boolean(cache?.readQuery({ query: CustomerTokenDocument })) + if (getCartEnabledForUser(locale, check)) return forward(operation) + + if (!getCustomerAccountCanSignIn(locale)) + throw new Error( + 'Permission error: permissions.customerAccount is DISABLED, while permissions.cart is set to CUSTOMER_ONLY', + ) + + const oldHeaders = operation.getContext().headers + const signInAgainPromise = pushWithPromise(router, '/account/signin') + + return fromPromise(signInAgainPromise).flatMap(() => { + const tokenQuery = cache?.readQuery({ query: CustomerTokenDocument }) + + if (tokenQuery?.customerToken?.valid) { + // Customer is authenticated, retrying request. + operation.setContext({ + headers: { + ...oldHeaders, + authorization: `Bearer ${tokenQuery?.customerToken?.token}`, + }, + }) + return forward(operation) + } + + return Observable.of({ + data: null, + errors: [ + new GraphQLError(t`Please login to add products to your cart`, { + extensions: { category: 'graphql-authorization' }, + }), + ], + }) + }) + }) + +export const cartLink = (router: PushRouter) => { + const links = [cartErrorLink] + + if (!(import.meta.graphCommerce.permissions?.cart === 'ENABLED')) { + links.push(cartPermissionLink(router)) + } + + return ApolloLink.from(links) +} diff --git a/packages/magento-cart/link/isProtectedCartOperation.ts b/packages/magento-cart/link/isProtectedCartOperation.ts new file mode 100644 index 0000000000..19f94fc1f1 --- /dev/null +++ b/packages/magento-cart/link/isProtectedCartOperation.ts @@ -0,0 +1,7 @@ +import { Operation } from '@graphcommerce/graphql' + +// todo move to magento-cart +export function isProtectedCartOperation(operation: Operation): boolean { + const mutations = ['AddProductsToCart'] /* Todo: Determine what operations should be put here */ + return mutations.includes(operation.operationName) +} diff --git a/packages/magento-cart/package.json b/packages/magento-cart/package.json index 6ebbbaac3b..afc3babce5 100644 --- a/packages/magento-cart/package.json +++ b/packages/magento-cart/package.json @@ -31,6 +31,7 @@ "@lingui/react": "^4.2.1", "@mui/material": "^5.10.16", "framer-motion": "^10.0.0", + "graphql": "^16.0.0", "next": "*", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx b/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx index 9346264ff1..46cdeea7bf 100644 --- a/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx +++ b/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx @@ -1,6 +1,9 @@ import { GraphQLProviderProps } from '@graphcommerce/graphql' import type { PluginConfig, PluginProps } from '@graphcommerce/next-config' -import { cartErrorLink } from '../link/createCartErrorLink' +import { useEventCallback } from '@mui/material' +import { NextRouter } from 'next/router' +import { useMemo } from 'react' +import { cartLink } from '../link/cartLink' import { cartTypePolicies, migrateCart } from '../typePolicies' export const config: PluginConfig = { @@ -9,13 +12,22 @@ export const config: PluginConfig = { } export function GraphQLProvider(props: PluginProps) { - const { Prev, links = [], policies = [], migrations = [], ...rest } = props + const { Prev, router, links = [], policies = [], migrations = [], ...rest } = props + + const push = useEventCallback((...args) => router.push(...args)) + + const cartLinkMemo = useMemo( + () => cartLink({ push, events: router.events, locale: router.locale }), + [push, router.events, router.locale], + ) + return ( ) } diff --git a/packages/magento-cart/utils/cartPermissions.ts b/packages/magento-cart/utils/cartPermissions.ts new file mode 100644 index 0000000000..53512d46f3 --- /dev/null +++ b/packages/magento-cart/utils/cartPermissions.ts @@ -0,0 +1,23 @@ +import { storefrontConfig } from '@graphcommerce/next-ui' + +function getCartPermissions(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.cart ?? + import.meta.graphCommerce.permissions?.cart ?? + 'ENABLED' + ) +} + +export function getCartDisabled(locale: string | undefined) { + return getCartPermissions(locale) === 'DISABLED' +} + +export function getCartGuestEnabled(locale: string | undefined) { + return getCartPermissions(locale) === 'ENABLED' +} + +export function getCartEnabledForUser(locale: string | undefined, loggedIn: () => boolean) { + if (getCartGuestEnabled(locale)) return true + if (getCartDisabled(locale)) return false + return !!loggedIn() +} diff --git a/packages/magento-cart/utils/checkoutPermissions.ts b/packages/magento-cart/utils/checkoutPermissions.ts new file mode 100644 index 0000000000..ca1af447aa --- /dev/null +++ b/packages/magento-cart/utils/checkoutPermissions.ts @@ -0,0 +1,13 @@ +import { storefrontConfig } from '@graphcommerce/next-ui' + +function getCheckoutPermission(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.checkout ?? + import.meta.graphCommerce.permissions?.checkout ?? + 'ENABLED' + ) +} + +export function getCheckoutIsDisabled(locale: string | undefined) { + return getCheckoutPermission(locale) === 'DISABLED' +} diff --git a/packages/magento-cart/utils/index.ts b/packages/magento-cart/utils/index.ts new file mode 100644 index 0000000000..ceab99ce8b --- /dev/null +++ b/packages/magento-cart/utils/index.ts @@ -0,0 +1,2 @@ +export * from './cartPermissions' +export * from './checkoutPermissions' diff --git a/packages/magento-customer/components/AccountSignInUpForm/AccountSignInUpForm.tsx b/packages/magento-customer/components/AccountSignInUpForm/AccountSignInUpForm.tsx index 351f1f2946..7cc2ae75dc 100644 --- a/packages/magento-customer/components/AccountSignInUpForm/AccountSignInUpForm.tsx +++ b/packages/magento-customer/components/AccountSignInUpForm/AccountSignInUpForm.tsx @@ -1,8 +1,4 @@ -import { - EmailElement, - FormAutoSubmit, - useCustomerAccountCanSignUp, -} from '@graphcommerce/ecommerce-ui' +import { EmailElement, FormAutoSubmit } from '@graphcommerce/ecommerce-ui' import { useApolloClient } from '@graphcommerce/graphql' import { ActionCard, @@ -17,7 +13,7 @@ import { import { Trans } from '@lingui/react' import { Alert, Box, CircularProgress, Link, SxProps, Theme, Typography } from '@mui/material' import { useRouter } from 'next/router' -import { CustomerDocument, useAccountSignInUpForm } from '../../hooks' +import { CustomerDocument, useAccountSignInUpForm, useCustomerAccountCanSignUp } from '../../hooks' import { useCustomerQuery } from '../../hooks/useCustomerQuery' import { ApolloCustomerErrorAlert } from '../ApolloCustomerError' import { SignInForm } from '../SignInForm/SignInForm' diff --git a/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx b/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx index f18b332aa0..2490762262 100644 --- a/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx +++ b/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx @@ -1,12 +1,9 @@ -import { - ApolloErrorFullPage, - ApolloErrorFullPageProps, - useCustomerAccountCanSignUp, -} from '@graphcommerce/ecommerce-ui' +import { ApolloErrorFullPage, ApolloErrorFullPageProps } from '@graphcommerce/ecommerce-ui' import { iconPerson, IconSvg } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { Button } from '@mui/material' import type { SetOptional } from 'type-fest' +import { useCustomerAccountCanSignUp } from '../../hooks' import { useAuthorizationErrorMasked } from './useAuthorizationErrorMasked' export type ApolloCustomerErrorFullPageProps = { diff --git a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx index a9e072883f..dac69072db 100644 --- a/packages/magento-customer/components/CustomerFab/CustomerFab.tsx +++ b/packages/magento-customer/components/CustomerFab/CustomerFab.tsx @@ -1,4 +1,3 @@ -import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { iconPerson, DesktopHeaderBadge, @@ -8,7 +7,11 @@ import { import { i18n } from '@lingui/core' import { Fab, FabProps as FabPropsType, NoSsr, SxProps, Theme } from '@mui/material' import React from 'react' -import { useCustomerSession, UseCustomerSessionReturn } from '../../hooks' +import { + useCustomerAccountCanSignIn, + useCustomerSession, + UseCustomerSessionReturn, +} from '../../hooks' type CustomerFabContentProps = { icon?: React.ReactNode diff --git a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx index 3bc6aa013f..05de53b4d1 100644 --- a/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +++ b/packages/magento-customer/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx @@ -1,7 +1,7 @@ -import { useCustomerAccountCanSignIn } from '@graphcommerce/ecommerce-ui' import { MenuFabSecondaryItem, iconPerson, IconSvg } from '@graphcommerce/next-ui' import { Badge, NoSsr, SxProps, Theme } from '@mui/material' import React, { MouseEventHandler } from 'react' +import { useCustomerAccountCanSignIn } from '../../hooks' import { useCustomerSession, UseCustomerSessionReturn } from '../../hooks/useCustomerSession' type CustomerMenuFabItemProps = { diff --git a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx b/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx index 3f4c93c484..2459517bff 100644 --- a/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx +++ b/packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx @@ -1,8 +1,8 @@ -import { useCustomerAccountCanSignUp } from '@graphcommerce/ecommerce-ui' 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 diff --git a/packages/magento-customer/hooks/index.ts b/packages/magento-customer/hooks/index.ts index e62f1ae5cf..cdf9c53463 100644 --- a/packages/magento-customer/hooks/index.ts +++ b/packages/magento-customer/hooks/index.ts @@ -6,6 +6,7 @@ export * from './OrderCardItemImage.gql' export * from './OrderCardItemImages.gql' export * from './UseOrderCardItemImages.gql' export * from './useAccountSignInUpForm' +export * from './useCustomerPermissions' export * from './useCustomerQuery' export * from './useCustomerSession' export * from './useGuestQuery' diff --git a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx index ebd8b33e0e..7c9d964554 100644 --- a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx +++ b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx @@ -1,4 +1,3 @@ -import { useCustomerAccountCanSignUp } from '@graphcommerce/ecommerce-ui' import { usePageContext } from '@graphcommerce/framer-next-pages' import { useQuery } from '@graphcommerce/graphql' import { useUrlQuery } from '@graphcommerce/next-ui' @@ -10,6 +9,7 @@ import { IsEmailAvailableQuery, IsEmailAvailableQueryVariables, } from './IsEmailAvailable.gql' +import { useCustomerAccountCanSignUp } from './useCustomerPermissions' import { useCustomerSession } from './useCustomerSession' export type UseFormIsEmailAvailableProps = { diff --git a/packages/magento-customer/hooks/useCustomerPermissions.ts b/packages/magento-customer/hooks/useCustomerPermissions.ts new file mode 100644 index 0000000000..aa458230f5 --- /dev/null +++ b/packages/magento-customer/hooks/useCustomerPermissions.ts @@ -0,0 +1,17 @@ +import { useStorefrontConfig } from '@graphcommerce/next-ui' + +function useCustomerAccountPermission() { + return ( + useStorefrontConfig().permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount ?? + 'ENABLED' + ) +} + +export function useCustomerAccountCanSignIn() { + return useCustomerAccountPermission() !== 'DISABLED' +} + +export function useCustomerAccountCanSignUp() { + return useCustomerAccountPermission() === 'ENABLED' +} diff --git a/packages/magento-customer/link/customerLink.ts b/packages/magento-customer/link/customerLink.ts index a0bbabc959..9a6af1e979 100644 --- a/packages/magento-customer/link/customerLink.ts +++ b/packages/magento-customer/link/customerLink.ts @@ -3,11 +3,8 @@ import { ApolloCache, ApolloLink, fromPromise, - GraphQLRequest, onError, setContext, - Observable, - FetchResult, } from '@graphcommerce/graphql/apollo' import { ErrorCategory } from '@graphcommerce/magento-graphql' import { GraphQLError } from 'graphql' @@ -15,14 +12,7 @@ import { NextRouter } from 'next/router' import { signOut } from '../components/SignOutForm/signOut' import { CustomerTokenDocument } from '../hooks' -const isMutation = (operation: GraphQLRequest) => - operation.query.definitions.some( - (definition) => - // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison - definition.kind === 'OperationDefinition' && definition.operation === 'mutation', - ) - -export type PushRouter = Pick +export type PushRouter = Pick declare module '@apollo/client' { interface DefaultContext { @@ -31,7 +21,7 @@ declare module '@apollo/client' { } } -async function pushWithPromise(router: Pick, url: string) { +export async function pushWithPromise(router: Pick, url: string) { try { await router.push(url) } catch { @@ -138,23 +128,8 @@ const customerErrorLink = (router: PushRouter) => }) }) -// const customerMaybelinkan = (router: PushRouter) => -// new ApolloLink((operation, forward) => { -// const { cache } = operation.getContext() - -// if (!isMutation(operation)) return forward(operation) - -// const loggedIn = cache?.readQuery({ query: CustomerTokenDocument }) - -// // sdnasdffasd -// if (loggedIn) forward(operation) +export const customerLink = (router: PushRouter) => { + const links = [addTokenHeader, customerErrorLink(router)] -// // forward(operation).map((result) => {}) -// // return forward(operation) -// const signInAgainPromise = pushWithPromise(router, '/account/signin') - -// fromPromise(signInAgainPromise) -// }) - -export const customerLink = (router: PushRouter) => - ApolloLink.from([addTokenHeader, customerErrorLink(router)]) + return ApolloLink.from(links) +} diff --git a/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx b/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx index 6d6c1353a9..7a335c4b96 100644 --- a/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx +++ b/packages/magento-customer/plugins/MagentoCustomerGraphqlProvider.tsx @@ -15,9 +15,10 @@ export function GraphQLProvider(props: PluginProps) { const { Prev, links = [], policies = [], migrations = [], router, ...rest } = props const push = useEventCallback((...args) => router.push(...args)) + const customerLinkMemo = useMemo( - () => customerLink({ push, events: router.events }), - [push, router.events], + () => customerLink({ push, events: router.events, locale: router.locale }), + [push, router.events, router.locale], ) return ( diff --git a/packages/magento-customer/tsconfig.json b/packages/magento-customer/tsconfig.json index 7398153dd6..7d9f1656be 100644 --- a/packages/magento-customer/tsconfig.json +++ b/packages/magento-customer/tsconfig.json @@ -1,5 +1,5 @@ { "exclude": ["**/node_modules", "**/.*/"], - "include": ["**/*.ts", "**/*.tsx"], + "include": ["**/*.ts", "**/*.tsx", "../magento-cart/link/isProtectedCartOperation.ts"], "extends": "@graphcommerce/typescript-config-pwa/nextjs.json" } diff --git a/packages/magento-customer/utils/customerPermissions.ts b/packages/magento-customer/utils/customerPermissions.ts new file mode 100644 index 0000000000..79fb6f58e7 --- /dev/null +++ b/packages/magento-customer/utils/customerPermissions.ts @@ -0,0 +1,17 @@ +import { storefrontConfig } from '@graphcommerce/next-ui' + +function getCustomerAccountPermission(locale: string | undefined) { + return ( + storefrontConfig(locale)?.permissions?.customerAccount ?? + import.meta.graphCommerce.permissions?.customerAccount ?? + 'ENABLED' + ) +} + +export function getCustomerAccountIsDisabled(locale: string | undefined) { + return getCustomerAccountPermission(locale) === 'DISABLED' +} + +export function getCustomerAccountCanSignIn(locale: string | undefined) { + return getCustomerAccountPermission(locale) !== 'DISABLED' +} diff --git a/packages/magento-customer/utils/index.ts b/packages/magento-customer/utils/index.ts index 3008e19a50..74f9599cd0 100644 --- a/packages/magento-customer/utils/index.ts +++ b/packages/magento-customer/utils/index.ts @@ -1 +1,2 @@ +export * from './customerPermissions' export * from './orderState' diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx index d536b1664b..2701fef8ea 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartButton.tsx @@ -1,8 +1,6 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' +import { useCartEnabled } from '@graphcommerce/magento-cart' import { Button, ButtonProps } from '@graphcommerce/next-ui' import { Trans } from '@lingui/macro' -import { useRouter } from 'next/router' import { useAddProductsToCartAction, UseAddProductsToCartActionProps, diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx index ad89cd47ca..e51c3eb54e 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartFab.tsx @@ -1,4 +1,4 @@ -import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/ecommerce-ui' +import { useCartEnabled, useCartShouldLoginToContinue } from '@graphcommerce/magento-cart' import { Fab, FabProps, iconShoppingBag, iconCheckmark } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' import { t } from '@lingui/macro' diff --git a/yarn.lock b/yarn.lock index 15fc6a5132..3ab9709267 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3768,6 +3768,7 @@ __metadata: "@lingui/react": ^4.2.1 "@mui/material": ^5.10.16 framer-motion: ^10.0.0 + graphql: ^16.0.0 next: "*" react: ^18.2.0 react-dom: ^18.2.0 From a946a0b26525f441252e16c16f6dc0d109d46518 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Thu, 22 Aug 2024 17:10:45 +0200 Subject: [PATCH 41/48] Spul --- examples/magento-graphcms/pages/cart.tsx | 67 +++++++++---------- .../components/CartFab/CartFab.tsx | 7 +- packages/magento-cart/hooks/useCartQuery.ts | 29 +++++++- .../hooks/useFormGqlMutationCart.ts | 35 +++++++++- packages/magento-cart/link/cartLink.ts | 2 +- .../link/isProtectedCartOperation.ts | 10 ++- .../plugins/MagentoCartGraphqlProvider.tsx | 2 +- 7 files changed, 101 insertions(+), 51 deletions(-) diff --git a/examples/magento-graphcms/pages/cart.tsx b/examples/magento-graphcms/pages/cart.tsx index bea72053f3..44d8b80a78 100644 --- a/examples/magento-graphcms/pages/cart.tsx +++ b/examples/magento-graphcms/pages/cart.tsx @@ -8,12 +8,10 @@ import { EmptyCart, getCartDisabled, useCartQuery, - useCartShouldLoginToContinue, } from '@graphcommerce/magento-cart' import { CartPageDocument } from '@graphcommerce/magento-cart-checkout' import { CouponAccordion } from '@graphcommerce/magento-cart-coupon' import { CartItemsActionCards, CartCrosssellsScroller } from '@graphcommerce/magento-cart-items' -import { UnauthenticatedFullPageMessage } from '@graphcommerce/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage' import { Money, PageMeta, StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, @@ -44,8 +42,6 @@ function CartPage() { (data?.cart?.total_quantity ?? 0) > 0 && typeof data?.cart?.prices?.grand_total?.value !== 'undefined' - const cartAvaialable = useCartShouldLoginToContinue() - return ( <> - {hasItems && cartAvaialable ? ( + {hasItems ? ( }} @@ -72,38 +68,35 @@ function CartPage() { )} - {!cartAvaialable ? ( - - ) : ( - } title={}> - - - } - > - {hasItems ? ( - <> - - - ({ mt: theme.spacings.md })} /> - - - - ({ mt: theme.spacings.md })} - /> - - - - - ) : ( - {error && } - )} - - )} + + } title={}> + + + } + > + {hasItems ? ( + <> + + + ({ mt: theme.spacings.md })} /> + + + + ({ mt: theme.spacings.md })} + /> + + + + + ) : ( + {error && } + )} + ) } diff --git a/packages/magento-cart/components/CartFab/CartFab.tsx b/packages/magento-cart/components/CartFab/CartFab.tsx index 2a80d4db09..3f8b862ae8 100644 --- a/packages/magento-cart/components/CartFab/CartFab.tsx +++ b/packages/magento-cart/components/CartFab/CartFab.tsx @@ -11,7 +11,7 @@ import { i18n } from '@lingui/core' import { alpha, Fab, FabProps, styled, useTheme, Box, SxProps, Theme } from '@mui/material' import { m, useTransform } from 'framer-motion' import React from 'react' -import { useCartEnabled } from '../../hooks' +import { useCartEnabled, useCartShouldLoginToContinue } from '../../hooks' import { useCartQuery } from '../../hooks/useCartQuery' import { CartFabDocument } from './CartFab.gql' import { CartTotalQuantityFragment } from './CartTotalQuantity.gql' @@ -101,8 +101,11 @@ function CartFabContent(props: CartFabContentProps) { } export function CartFab(props: CartFabProps) { - const cartQuery = useCartQuery(CartFabDocument) const cartEnabled = useCartEnabled() + const shouldLoginToContinue = useCartShouldLoginToContinue() + const cartQuery = useCartQuery(CartFabDocument, { + skip: shouldLoginToContinue, + }) if (!cartEnabled) return null return ( diff --git a/packages/magento-cart/hooks/useCartQuery.ts b/packages/magento-cart/hooks/useCartQuery.ts index b62530fc68..9ea8d7cd69 100644 --- a/packages/magento-cart/hooks/useCartQuery.ts +++ b/packages/magento-cart/hooks/useCartQuery.ts @@ -1,5 +1,7 @@ -import { useQuery, TypedDocumentNode, QueryHookOptions } from '@graphcommerce/graphql' +import { useQuery, TypedDocumentNode, QueryHookOptions, ApolloError } from '@graphcommerce/graphql' +import { GraphQLError } from 'graphql' import { useRouter } from 'next/router' +import { useCartShouldLoginToContinue } from './useCartPermissions' import { useCurrentCartId } from './useCurrentCartId' /** @@ -22,12 +24,14 @@ export function useCartQuery) + const query = useQuery(document, { + ...(queryOptions as QueryHookOptions), + skip: queryOptions.skip || !cartId || shouldLoginToContinue, + }) + + // Heeft dit voorkeur over het openen van de login overlay? + if (shouldLoginToContinue && !queryOptions?.skip) { + console.log(document) + return { + ...query, + error: new ApolloError({ + graphQLErrors: [ + new GraphQLError('oepsie', { + extensions: { category: 'graphql-authorization' }, + }), + ], + }), + } + } + + return query } diff --git a/packages/magento-cart/hooks/useFormGqlMutationCart.ts b/packages/magento-cart/hooks/useFormGqlMutationCart.ts index 2a730c7c3b..968dd5e8e6 100644 --- a/packages/magento-cart/hooks/useFormGqlMutationCart.ts +++ b/packages/magento-cart/hooks/useFormGqlMutationCart.ts @@ -1,11 +1,19 @@ -import { MutationHookOptions, TypedDocumentNode, useApolloClient } from '@graphcommerce/graphql' +import { + ApolloError, + MutationHookOptions, + TypedDocumentNode, + useApolloClient, +} from '@graphcommerce/graphql' import { useFormGqlMutation, UseFormGqlMutationReturn, UseFormGraphQlOptions, } from '@graphcommerce/react-hook-form' +import { GraphQLError, Kind } from 'graphql' import { CurrentCartIdDocument } from './CurrentCartId.gql' import { useCartIdCreate } from './useCartIdCreate' +import { useCartShouldLoginToContinue } from './useCartPermissions' +import { isProtectedCartOperation } from '../link/isProtectedCartOperation' export function useFormGqlMutationCart< Q extends Record, @@ -17,12 +25,23 @@ export function useFormGqlMutationCart< ): UseFormGqlMutationReturn { const cartId = useCartIdCreate() const client = useApolloClient() + const shouldLoginToContinue = useCartShouldLoginToContinue() + + let shouldBlockOperation = false + document.definitions.forEach((defenition) => { + if (defenition.kind === Kind.OPERATION_DEFINITION) { + shouldBlockOperation = !isProtectedCartOperation(defenition.name?.value ?? '') + } + }) const result = useFormGqlMutation( document, { ...options, onBeforeSubmit: async (variables) => { + if (shouldLoginToContinue && shouldBlockOperation) { + return false + } const vars = { ...variables, cartId: await cartId() } const res = client.cache.readQuery({ query: CurrentCartIdDocument }) @@ -37,5 +56,19 @@ export function useFormGqlMutationCart< { errorPolicy: 'all', ...operationOptions }, ) + if (shouldLoginToContinue && result.formState.isSubmitted && shouldBlockOperation) { + console.log(document) + return { + ...result, + error: new ApolloError({ + graphQLErrors: [ + new GraphQLError('oepsie', { + extensions: { category: 'graphql-authorization' }, + }), + ], + }), + } + } + return result } diff --git a/packages/magento-cart/link/cartLink.ts b/packages/magento-cart/link/cartLink.ts index 64a60ef014..f5bde5a417 100644 --- a/packages/magento-cart/link/cartLink.ts +++ b/packages/magento-cart/link/cartLink.ts @@ -78,7 +78,7 @@ const cartPermissionLink = (router: PushRouter) => const { locale } = router const { cache } = operation.getContext() - if (!isProtectedCartOperation(operation)) return forward(operation) + if (!isProtectedCartOperation(operation.operationName)) return forward(operation) const check = () => Boolean(cache?.readQuery({ query: CustomerTokenDocument })) if (getCartEnabledForUser(locale, check)) return forward(operation) diff --git a/packages/magento-cart/link/isProtectedCartOperation.ts b/packages/magento-cart/link/isProtectedCartOperation.ts index 19f94fc1f1..b742dc9c98 100644 --- a/packages/magento-cart/link/isProtectedCartOperation.ts +++ b/packages/magento-cart/link/isProtectedCartOperation.ts @@ -1,7 +1,5 @@ -import { Operation } from '@graphcommerce/graphql' - -// todo move to magento-cart -export function isProtectedCartOperation(operation: Operation): boolean { - const mutations = ['AddProductsToCart'] /* Todo: Determine what operations should be put here */ - return mutations.includes(operation.operationName) +export function isProtectedCartOperation(name: string): boolean { + /* Todo: Determine what operations should be added here */ + const mutations = ['AddProductsToCart', 'CreateEmptyCart'] + return mutations.includes(name) } diff --git a/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx b/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx index 46cdeea7bf..166837b2ed 100644 --- a/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx +++ b/packages/magento-cart/plugins/MagentoCartGraphqlProvider.tsx @@ -24,10 +24,10 @@ export function GraphQLProvider(props: PluginProps) { return ( ) } From b6b7e7f2631d56b24151a0d0c6d342cc30dc481b Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Fri, 23 Aug 2024 11:56:48 +0200 Subject: [PATCH 42/48] feat(GCOM-1446): cleanup, replace FullPageMessage with ApolloCartErrorFullPage error handling --- .../components/Layout/Footer.tsx | 4 +-- examples/magento-graphcms/pages/cart.tsx | 1 - .../magento-graphcms/pages/checkout/index.tsx | 4 --- .../pages/checkout/payment.tsx | 4 --- packages/magento-cart/hooks/useCartQuery.ts | 4 +-- .../hooks/useFormGqlMutationCart.ts | 5 ++-- .../UnauthenticatedFullPageMessage.tsx | 27 ------------------- .../WaitForCustomer/WaitForCustomer.tsx | 22 ++++++++++++--- .../magento-customer/link/customerLink.ts | 9 +++---- .../MagentoCustomerGraphqlProvider.tsx | 4 +-- packages/magento-customer/tsconfig.json | 2 +- .../magento-graphql/graphqlErrorByCategory.ts | 2 +- .../AddProductsToCartFab.tsx | 22 ++------------- .../next-config/src/withGraphCommerce.ts | 1 - 14 files changed, 32 insertions(+), 79 deletions(-) delete mode 100644 packages/magento-customer/components/WaitForCustomer/UnauthenticatedFullPageMessage.tsx 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 ( Date: Fri, 23 Aug 2024 12:11:46 +0200 Subject: [PATCH 43/48] feat(GCOM-1446): add back locale to router type --- packages/magento-customer/link/customerLink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/magento-customer/link/customerLink.ts b/packages/magento-customer/link/customerLink.ts index 8aefc9d085..36fb9978ac 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 { From e2a8d787591f187dc7dde93730323aff9a0f6f67 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Tue, 27 Aug 2024 17:20:19 +0200 Subject: [PATCH 44/48] Add translations --- examples/magento-graphcms/locales/de.po | 20 ++++++++++---------- examples/magento-graphcms/locales/en.po | 20 ++++++++++---------- examples/magento-graphcms/locales/es.po | 20 ++++++++++---------- examples/magento-graphcms/locales/fr.po | 20 ++++++++++---------- examples/magento-graphcms/locales/it.po | 20 ++++++++++---------- examples/magento-graphcms/locales/nl.po | 20 ++++++++++---------- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/examples/magento-graphcms/locales/de.po b/examples/magento-graphcms/locales/de.po index c071bcb311..cbc288f26e 100644 --- a/examples/magento-graphcms/locales/de.po +++ b/examples/magento-graphcms/locales/de.po @@ -33,10 +33,6 @@ msgstr "Alle Produkte durchsuchen..." msgid "We couldn't find any results" msgstr "Wir konnten keine Ergebnisse finden" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Eintragen" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Versandart" @@ -79,9 +75,6 @@ msgstr "Bestätigung des Kontos" msgid "Account confirmed. You can now proceed to sign in." msgstr "Konto bestätigt. Sie können sich jetzt anmelden." -msgid "Account connected to that email could not be found" -msgstr "Das mit dieser E-Mail verbundene Konto konnte nicht gefunden werden" - msgid "Add address" msgstr "Adresse hinzufügen" @@ -630,6 +623,10 @@ msgstr "Ergebnisse für ‘{search}’" msgid "Telephone" msgstr "Telefon" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Bitte loggen Sie sich ein, um Produkte zu Ihrem Warenkorb hinzuzufügen" + msgid "Recently viewed products" msgstr "Kürzlich angesehene Produkte" @@ -726,6 +723,9 @@ msgstr "Abmelden" msgid "Sign up for our newsletter and stay updated" msgstr "Abonnieren Sie unseren Newsletter und bleiben Sie auf dem Laufenden" +msgid "Sign up is disabled, please contact us for more information." +msgstr "Die Anmeldung ist deaktiviert, bitte kontaktieren Sie uns für weitere Informationen." + msgid "Skip to main content" msgstr "Zum Hauptinhalt springen" @@ -819,9 +819,6 @@ msgstr "Das kann einen Moment dauern" msgid "Total <0/>" msgstr "Gesamt <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Versuchen Sie eine andere E-Mail-Adresse oder kontaktieren Sie uns, um ein Konto zu registrieren." - msgid "Try a different product" msgstr "Versuchen Sie ein anderes Produkt" @@ -933,6 +930,9 @@ msgstr "Sie haben noch keine Bewertungen abgegeben" msgid "You must be signed in to continue" msgstr "Sie müssen sich anmelden, um fortzufahren" +msgid "You must sign in to continue" +msgstr "Sie müssen sich anmelden, um fortzufahren" + msgid "Your address has been added" msgstr "Ihre Adresse wurde hinzugefügt" diff --git a/examples/magento-graphcms/locales/en.po b/examples/magento-graphcms/locales/en.po index a81bacf500..97482e6bb5 100644 --- a/examples/magento-graphcms/locales/en.po +++ b/examples/magento-graphcms/locales/en.po @@ -33,10 +33,6 @@ msgstr "Search all products..." msgid "We couldn't find any results" msgstr "We couldn't find any results" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Sign in" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Shipping method" @@ -79,9 +75,6 @@ msgstr "Account confirmation" msgid "Account confirmed. You can now proceed to sign in." msgstr "Account confirmed. You can now proceed to sign in." -msgid "Account connected to that email could not be found" -msgstr "Account connected to that email could not be found" - msgid "Add address" msgstr "Add address" @@ -630,6 +623,10 @@ msgstr "Results for ‘{search}’" msgid "Telephone" msgstr "Telephone" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Please login to add products to your cart" + msgid "Recently viewed products" msgstr "Recently viewed products" @@ -726,6 +723,9 @@ msgstr "Sign out" msgid "Sign up for our newsletter and stay updated" msgstr "Sign up for our newsletter and stay updated" +msgid "Sign up is disabled, please contact us for more information." +msgstr "Sign up is disabled, please contact us for more information." + msgid "Skip to main content" msgstr "Skip to main content" @@ -819,9 +819,6 @@ msgstr "This may take a second" msgid "Total <0/>" msgstr "Total <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Try a different email or contact us to register an account" - msgid "Try a different product" msgstr "Try a different product" @@ -933,6 +930,9 @@ msgstr "You haven't placed any reviews yet" msgid "You must be signed in to continue" msgstr "You must be signed in to continue" +msgid "You must sign in to continue" +msgstr "You must sign in to continue" + msgid "Your address has been added" msgstr "Your address has been added" diff --git a/examples/magento-graphcms/locales/es.po b/examples/magento-graphcms/locales/es.po index 45af72c01b..10aff8580e 100644 --- a/examples/magento-graphcms/locales/es.po +++ b/examples/magento-graphcms/locales/es.po @@ -33,10 +33,6 @@ msgstr "Buscar todos los productos..." msgid "We couldn't find any results" msgstr "No pudimos encontrar ningún resultado" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Iniciar sesión" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Método de envío" @@ -79,9 +75,6 @@ msgstr "Confirmación de cuenta" msgid "Account confirmed. You can now proceed to sign in." msgstr "Cuenta confirmada. Ahora puede proceder a iniciar sesión." -msgid "Account connected to that email could not be found" -msgstr "No se ha podido encontrar la cuenta conectada a ese correo electrónico" - msgid "Add address" msgstr "Añadir dirección" @@ -630,6 +623,10 @@ msgstr "Resultados para ‘{search}’" msgid "Telephone" msgstr "Teléfono" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Inicie sesión para añadir productos a su cesta" + msgid "Recently viewed products" msgstr "Productos vistos recientemente" @@ -726,6 +723,9 @@ msgstr "Cerrar sesión" msgid "Sign up for our newsletter and stay updated" msgstr "Regístrese para nuestro boletín y manténgase actualizado" +msgid "Sign up is disabled, please contact us for more information." +msgstr "La inscripción está deshabilitada, póngase en contacto con nosotros para obtener más información." + msgid "Skip to main content" msgstr "Saltar al contenido principal" @@ -819,9 +819,6 @@ msgstr "Esto puede tardar un segundo" msgid "Total <0/>" msgstr "Total <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Pruebe con otro correo electrónico o póngase en contacto con nosotros para registrar una cuenta" - msgid "Try a different product" msgstr "Pruebe un producto diferente" @@ -933,6 +930,9 @@ msgstr "Aún no ha escrito ningún comentario" msgid "You must be signed in to continue" msgstr "Debe iniciar sesión para continuar" +msgid "You must sign in to continue" +msgstr "Debe iniciar sesión para continuar" + msgid "Your address has been added" msgstr "Tu dirección ha sido añadida" diff --git a/examples/magento-graphcms/locales/fr.po b/examples/magento-graphcms/locales/fr.po index 4411a709e5..cce6c6c574 100644 --- a/examples/magento-graphcms/locales/fr.po +++ b/examples/magento-graphcms/locales/fr.po @@ -33,10 +33,6 @@ msgstr "Rechercher tous les produits..." msgid "We couldn't find any results" msgstr "Nous n'avons trouvé aucun résultat" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Identifiez-vous" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Méthode d'expédition" @@ -79,9 +75,6 @@ msgstr "Confirmation du compte" msgid "Account confirmed. You can now proceed to sign in." msgstr "Compte confirmé. Vous pouvez maintenant vous connecter." -msgid "Account connected to that email could not be found" -msgstr "Le compte lié à cet e-mail n'a pas pu être trouvé" - msgid "Add address" msgstr "Ajouter une adresse" @@ -630,6 +623,10 @@ msgstr "Résultats pour ‘{search}’" msgid "Telephone" msgstr "Téléphone" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Veuillez vous connecter pour ajouter des produits à votre panier" + msgid "Recently viewed products" msgstr "Derniers produits consultés" @@ -726,6 +723,9 @@ msgstr "Déconnexion" msgid "Sign up for our newsletter and stay updated" msgstr "Inscrivez-vous à notre newsletter et restez à jour" +msgid "Sign up is disabled, please contact us for more information." +msgstr "L'inscription est désactivée, veuillez nous contacter pour plus d'informations." + msgid "Skip to main content" msgstr "Passer au contenu principal" @@ -819,9 +819,6 @@ msgstr "Ceci peut prendre un instant" msgid "Total <0/>" msgstr "Total <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Essayez un autre courriel ou contactez-nous pour créer un compte" - msgid "Try a different product" msgstr "Essayez un autre produit" @@ -933,6 +930,9 @@ msgstr "Vous n'avez pas encore écrit d'évaluation" msgid "You must be signed in to continue" msgstr "Vous devez vous connecter pour continuer" +msgid "You must sign in to continue" +msgstr "Vous devez vous connecter pour continuer" + msgid "Your address has been added" msgstr "Votre adresse a été ajoutée" diff --git a/examples/magento-graphcms/locales/it.po b/examples/magento-graphcms/locales/it.po index 3d6c631302..2e3237c49e 100644 --- a/examples/magento-graphcms/locales/it.po +++ b/examples/magento-graphcms/locales/it.po @@ -33,10 +33,6 @@ msgstr "Cerca tutti i prodotti..." msgid "We couldn't find any results" msgstr "Non abbiamo trovato risultati" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Accedi" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Metodo di spedizione" @@ -79,9 +75,6 @@ msgstr "Conferma del conto" msgid "Account confirmed. You can now proceed to sign in." msgstr "Account confermato. Ora puoi procedere con l'accesso." -msgid "Account connected to that email could not be found" -msgstr "Impossibile trovare l'account collegato a quell'e-mail" - msgid "Add address" msgstr "Aggiungi indirizzo" @@ -630,6 +623,10 @@ msgstr "Risultati per ‘{search}’" msgid "Telephone" msgstr "Telefono" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Effettuare il login per aggiungere prodotti al carrello" + msgid "Recently viewed products" msgstr "Prodotti visionati recentemente" @@ -726,6 +723,9 @@ msgstr "Esci" msgid "Sign up for our newsletter and stay updated" msgstr "Iscriviti alla nostra newsletter e rimani aggiornato" +msgid "Sign up is disabled, please contact us for more information." +msgstr "L'iscrizione è disabilitata, contattateci per maggiori informazioni." + msgid "Skip to main content" msgstr "Passa al contenuto principale" @@ -819,9 +819,6 @@ msgstr "Questo potrebbe richiedere un secondo" msgid "Total <0/>" msgstr "Totale <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Provare con un'altra e-mail o contattarci per registrare un account." - msgid "Try a different product" msgstr "Prova un altro prodotto" @@ -933,6 +930,9 @@ msgstr "Non hai ancora scritto nessuna recensione" msgid "You must be signed in to continue" msgstr "Devi accedere per continuare" +msgid "You must sign in to continue" +msgstr "È necessario effettuare l'accesso per continuare" + msgid "Your address has been added" msgstr "Il tuo indirizzo è stato aggiunto" diff --git a/examples/magento-graphcms/locales/nl.po b/examples/magento-graphcms/locales/nl.po index 8b73bafa82..bb88301d29 100644 --- a/examples/magento-graphcms/locales/nl.po +++ b/examples/magento-graphcms/locales/nl.po @@ -33,10 +33,6 @@ msgstr "Zoek alle producten..." msgid "We couldn't find any results" msgstr "We konden geen resultaten vinden" -#. js-lingui-generated-id -msgid "Sign in" -msgstr "Inloggen" - #. js-lingui-generated-id msgid "Shipping method" msgstr "Verzendmethode" @@ -79,9 +75,6 @@ msgstr "Account bevestiging" msgid "Account confirmed. You can now proceed to sign in." msgstr "Account bevestigd. U kunt nu doorgaan met inloggen." -msgid "Account connected to that email could not be found" -msgstr "Account gekoppeld aan die e-mail kon niet worden gevonden" - msgid "Add address" msgstr "Adres toevoegen" @@ -630,6 +623,10 @@ msgstr "Resultaten voor ‘{search}’" msgid "Telephone" msgstr "Telefoon" +#. js-lingui-generated-id +msgid "Please login to add products to your cart" +msgstr "Log in om producten aan uw winkelwagen toe te voegen" + msgid "Recently viewed products" msgstr "Recent bekeken producten" @@ -726,6 +723,9 @@ msgstr "Uitloggen" msgid "Sign up for our newsletter and stay updated" msgstr "Abonneer u op onze nieuwsbrief en blijf op de hoogte" +msgid "Sign up is disabled, please contact us for more information." +msgstr "Inschrijven is niet mogelijk, neem contact met ons op voor meer informatie." + msgid "Skip to main content" msgstr "Ga naar hoofdinhoud" @@ -819,9 +819,6 @@ msgstr "Dit kan een seconde duren" msgid "Total <0/>" msgstr "Totaal <0/>" -msgid "Try a different email or contact us to register an account" -msgstr "Probeer een ander e-mailadres of neem contact met ons op om een account te registreren" - msgid "Try a different product" msgstr "Probeer een ander product" @@ -933,6 +930,9 @@ msgstr "Je hebt nog geen reviews geplaatst" msgid "You must be signed in to continue" msgstr "U moet ingelogd zijn om verder te gaan" +msgid "You must sign in to continue" +msgstr "U moet zich aanmelden om verder te gaan" + msgid "Your address has been added" msgstr "Uw adres is toegevoegd" From 1a42647f1d86833fece6953813d4d37f32c299a4 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Wed, 28 Aug 2024 15:17:28 +0200 Subject: [PATCH 45/48] Set error to onBeforeSubmitError or onCompleteError when present --- packages/magento-cart/hooks/useFormGqlMutationCart.ts | 5 +++-- packages/react-hook-form/src/useFormGql.tsx | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/magento-cart/hooks/useFormGqlMutationCart.ts b/packages/magento-cart/hooks/useFormGqlMutationCart.ts index 172c0f7d97..15c59e8958 100644 --- a/packages/magento-cart/hooks/useFormGqlMutationCart.ts +++ b/packages/magento-cart/hooks/useFormGqlMutationCart.ts @@ -46,8 +46,9 @@ export function useFormGqlMutationCart< const res = client.cache.readQuery({ query: CurrentCartIdDocument }) if (!options.submitWhileLocked && res?.currentCartId?.locked) { - console.log('Could not submit form, cart is locked', res.currentCartId.locked) - return false + throw Error('Could not submit form, cart is locked') + // console.log('Could not submit form, cart is locked', res.currentCartId.locked) + // return false } return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars diff --git a/packages/react-hook-form/src/useFormGql.tsx b/packages/react-hook-form/src/useFormGql.tsx index 52fd2f3fd3..d07dd27c80 100644 --- a/packages/react-hook-form/src/useFormGql.tsx +++ b/packages/react-hook-form/src/useFormGql.tsx @@ -115,6 +115,7 @@ export function useFormGql( const [execute, { data, error, loading }] = tuple const submittedVariables = useRef() + const returnedError = useRef() // automatically updates the default values const initital = useRef(true) @@ -153,6 +154,8 @@ export function useFormGql( return } + returnedError.current = error + // Combine defaults with the formValues and encode submittedVariables.current = undefined let variables = !deprecated_useV1 ? formValues : encode({ ...defaultValues, ...formValues }) @@ -160,7 +163,8 @@ export function useFormGql( // Wait for the onBeforeSubmit to complete const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables) if (onBeforeSubmitError) { - form.setError('root', { message: onBeforeSubmitError.message }) + returnedError.current = onBeforeSubmitError as ApolloError + form.setError('root.thrown', onBeforeSubmitError) return } if (onBeforeSubmitResult === false) return @@ -176,7 +180,8 @@ export function useFormGql( const [, onCompleteError] = await complete(result, variables) if (onCompleteError) { - form.setError('root', { message: onCompleteError.message }) + returnedError.current = onCompleteError as ApolloError + form.setError('root.thrown', onCompleteError) return } @@ -191,7 +196,7 @@ export function useFormGql( ...gqlDocumentHandler, handleSubmit, data, - error, + error: returnedError.current, submittedVariables: submittedVariables.current, } } From 718a195fb3daf426b4fb8933ee1895ecf8df9490 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Tue, 3 Sep 2024 17:29:23 +0200 Subject: [PATCH 46/48] When a useFormGql throws an error in the onBeforeSubmit method or onComplete method it will be set as an ApolloError with the message --- .changeset/green-flowers-double.md | 2 +- .../PaymentMethodButton.tsx | 9 ++--- .../AddProductsToCartSnackbar.tsx | 2 +- .../src/ComposedForm/ComposedSubmit.tsx | 11 +----- .../react-hook-form/src/ComposedForm/types.ts | 1 - packages/react-hook-form/src/useFormGql.tsx | 35 ++++++++++++++----- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.changeset/green-flowers-double.md b/.changeset/green-flowers-double.md index 0ccb611a33..9db781ada7 100644 --- a/.changeset/green-flowers-double.md +++ b/.changeset/green-flowers-double.md @@ -2,4 +2,4 @@ '@graphcommerce/react-hook-form': patch --- -When a useFormGql throws an error in the onBeforeSubmit method or onComplete method it will setError('root.thrown') with the message, allowing it to be displayed somewhere. PaymentMethodButton will now render this as an ErrorSnackbar. +When a useFormGql throws an error in the onBeforeSubmit method or onComplete method it will be set as an ApolloError with the message, allowing it to be displayed somewhere. PaymentMethodButton will now render this as an ErrorSnackbar. diff --git a/packages/magento-cart-payment-method/PaymentMethodButton/PaymentMethodButton.tsx b/packages/magento-cart-payment-method/PaymentMethodButton/PaymentMethodButton.tsx index 891071fe12..e516e83851 100644 --- a/packages/magento-cart-payment-method/PaymentMethodButton/PaymentMethodButton.tsx +++ b/packages/magento-cart-payment-method/PaymentMethodButton/PaymentMethodButton.tsx @@ -1,5 +1,5 @@ import { ApolloCartErrorSnackbar } from '@graphcommerce/magento-cart' -import { ErrorSnackbar, LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui' +import { LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui' import { ComposedSubmit, ComposedSubmitProps, @@ -50,9 +50,9 @@ export function PaymentMethodButton(props: PaymentMethodButtonProps) { return ( { + render={({ submit, buttonState, error }) => { const errorVal = buttonState.isSubmitting ? undefined : error - const rootMessage = buttonState.isSubmitting ? undefined : rootThrown?.message + const button = ( {button} - - <>{rootMessage} - ) }} diff --git a/packages/magento-product/components/AddProductsToCart/AddProductsToCartSnackbar.tsx b/packages/magento-product/components/AddProductsToCart/AddProductsToCartSnackbar.tsx index 2295c281a3..62b758a7dd 100644 --- a/packages/magento-product/components/AddProductsToCart/AddProductsToCartSnackbar.tsx +++ b/packages/magento-product/components/AddProductsToCart/AddProductsToCartSnackbar.tsx @@ -35,7 +35,7 @@ export function AddProductsToCartSnackbar(props: AddProductsToCartSnackbarProps) return ( item.itemInCart?.product.name).filter(nonNullable)} diff --git a/packages/react-hook-form/src/ComposedForm/ComposedSubmit.tsx b/packages/react-hook-form/src/ComposedForm/ComposedSubmit.tsx index a32fbc739d..fba45435e0 100644 --- a/packages/react-hook-form/src/ComposedForm/ComposedSubmit.tsx +++ b/packages/react-hook-form/src/ComposedForm/ComposedSubmit.tsx @@ -120,19 +120,10 @@ export function ComposedSubmit(props: ComposedSubmitProps) { } const errors: ApolloError[] = [] - let rootThrown: GlobalError | undefined formEntries.forEach(([, { form }]) => { if (form && isFormGqlOperation(form) && form.error) errors.push(form.error) - if (form && form.formState.errors.root?.thrown) rootThrown = form.formState.errors.root.thrown }) - return ( - - ) + return } diff --git a/packages/react-hook-form/src/ComposedForm/types.ts b/packages/react-hook-form/src/ComposedForm/types.ts index 275ecdc4ae..104c07a0c8 100644 --- a/packages/react-hook-form/src/ComposedForm/types.ts +++ b/packages/react-hook-form/src/ComposedForm/types.ts @@ -36,7 +36,6 @@ export type ComposedSubmitRenderComponentProps = { submit: () => Promise buttonState: ButtonState error?: ApolloError - rootThrown?: GlobalError } export type ComposedFormState = { diff --git a/packages/react-hook-form/src/useFormGql.tsx b/packages/react-hook-form/src/useFormGql.tsx index d07dd27c80..1c6d6c15d9 100644 --- a/packages/react-hook-form/src/useFormGql.tsx +++ b/packages/react-hook-form/src/useFormGql.tsx @@ -4,6 +4,7 @@ import { LazyQueryResultTuple, MutationTuple, TypedDocumentNode, + isApolloError, } from '@apollo/client' import { getOperationName } from '@apollo/client/utilities' import useEventCallback from '@mui/utils/useEventCallback' @@ -21,13 +22,13 @@ type UseFormGraphQLCallbacks = { * Mutation. * * When returning false, it will silently stop the submission. - * When an error is thrown, it will be set as a generic error with `setError('root.thrown', { message: error.message })` + * When an error is thrown, it will be set as an ApolloError */ onBeforeSubmit?: (variables: V) => V | false | Promise /** * Called after the mutation has been executed. Allows you to handle the result of the mutation. * - * When an error is thrown, it will be set as a generic error with `setError('root.thrown', { message: error.message })` + * When an error is thrown, it will be set as an ApolloError */ onComplete?: OnCompleteFn @@ -154,17 +155,24 @@ export function useFormGql( return } - returnedError.current = error + returnedError.current = undefined + submittedVariables.current = undefined // Combine defaults with the formValues and encode - submittedVariables.current = undefined let variables = !deprecated_useV1 ? formValues : encode({ ...defaultValues, ...formValues }) // Wait for the onBeforeSubmit to complete const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables) if (onBeforeSubmitError) { - returnedError.current = onBeforeSubmitError as ApolloError - form.setError('root.thrown', onBeforeSubmitError) + if (isApolloError(onBeforeSubmitError)) { + returnedError.current = onBeforeSubmitError + } else { + console.log( + 'A non ApolloError was thrown during the onBeforeSubmit handler.', + onBeforeSubmitError, + ) + } + return } if (onBeforeSubmitResult === false) return @@ -181,7 +189,18 @@ export function useFormGql( const [, onCompleteError] = await complete(result, variables) if (onCompleteError) { returnedError.current = onCompleteError as ApolloError - form.setError('root.thrown', onCompleteError) + return + } + if (onCompleteError) { + if (isApolloError(onCompleteError)) { + returnedError.current = onCompleteError + } else { + console.log( + 'A non ApolloError was thrown during the onComplete handler.', + onCompleteError, + ) + } + return } @@ -196,7 +215,7 @@ export function useFormGql( ...gqlDocumentHandler, handleSubmit, data, - error: returnedError.current, + error: error ?? returnedError.current, submittedVariables: submittedVariables.current, } } From 7307fe8f0ec01d4f60149338a33ebff4e1e2fb03 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Wed, 4 Sep 2024 10:03:17 +0200 Subject: [PATCH 47/48] Remove links from cart error alert --- .../ApolloCartError/ApolloCartErrorAlert.tsx | 47 +------------------ .../ApolloCustomerErrorAlert.tsx | 4 +- 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/packages/magento-cart/components/ApolloCartError/ApolloCartErrorAlert.tsx b/packages/magento-cart/components/ApolloCartError/ApolloCartErrorAlert.tsx index c1d12ce0df..a836c5fb6c 100644 --- a/packages/magento-cart/components/ApolloCartError/ApolloCartErrorAlert.tsx +++ b/packages/magento-cart/components/ApolloCartError/ApolloCartErrorAlert.tsx @@ -1,55 +1,10 @@ -import { useQuery } from '@graphcommerce/graphql' import { ApolloCustomerErrorAlert, ApolloCustomerErrorAlertProps, - CustomerDocument, } from '@graphcommerce/magento-customer' -import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql' -import { i18n } from '@lingui/core' -import { Trans } from '@lingui/react' -import { Button } from '@mui/material' -import { useClearCurrentCartId } from '../../hooks' export type ApolloCartErrorAlertProps = ApolloCustomerErrorAlertProps export function ApolloCartErrorAlert(props: ApolloCartErrorAlertProps) { - const { error, graphqlErrorAlertProps } = props - - const email = useQuery(CustomerDocument, { fetchPolicy: 'cache-only' }).data?.customer?.email - - const [newError, unauthorized] = graphqlErrorByCategory({ - category: 'graphql-authorization', - error, - mask: email - ? i18n._( - /* i18n */ 'This cart is assigned to {email}. Please sign in to continue shopping.', - { email }, - ) - : undefined, - extract: false, - }) - - const clear = useClearCurrentCartId() - - return ( - - {graphqlErrorAlertProps?.action} - - - - ) : ( - graphqlErrorAlertProps?.action - ), - }} - /> - ) + return } diff --git a/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx b/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx index 216537e695..cfbc765153 100644 --- a/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx +++ b/packages/magento-customer/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx @@ -1,7 +1,6 @@ import { ApolloErrorAlert, ApolloErrorAlertProps } from '@graphcommerce/ecommerce-ui' import { Button } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' -import { useCustomerSession } from '../../hooks/useCustomerSession' import { useAuthorizationErrorMasked } from './useAuthorizationErrorMasked' export type ApolloCustomerErrorAlertProps = ApolloErrorAlertProps @@ -9,7 +8,6 @@ export type ApolloCustomerErrorAlertProps = ApolloErrorAlertProps export function ApolloCustomerErrorAlert(props: ApolloCustomerErrorAlertProps) { const { error, graphqlErrorAlertProps } = props const [newError, unauthorized] = useAuthorizationErrorMasked(error) - const { query } = useCustomerSession() return ( {graphqlErrorAlertProps?.action} ) : ( From e8f8e3fe578a27bc0f3d1026b748e39b16c427c8 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Tue, 10 Sep 2024 13:33:32 +0200 Subject: [PATCH 48/48] Add translations, revert graphcommerce config changes --- .../graphcommerce.config.js.example | 4 ++-- examples/magento-graphcms/locales/de.po | 13 ++++++++++--- examples/magento-graphcms/locales/en.po | 13 ++++++++++--- examples/magento-graphcms/locales/es.po | 13 ++++++++++--- examples/magento-graphcms/locales/fr.po | 13 ++++++++++--- examples/magento-graphcms/locales/it.po | 13 ++++++++++--- examples/magento-graphcms/locales/nl.po | 13 ++++++++++--- 7 files changed, 62 insertions(+), 20 deletions(-) diff --git a/examples/magento-graphcms/graphcommerce.config.js.example b/examples/magento-graphcms/graphcommerce.config.js.example index 99a71f608a..fa4c969030 100644 --- a/examples/magento-graphcms/graphcommerce.config.js.example +++ b/examples/magento-graphcms/graphcommerce.config.js.example @@ -7,8 +7,8 @@ */ const config = { hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master', - magentoEndpoint: 'https://configurator.reachdigital.dev/graphql', - magentoVersion: 247, + magentoEndpoint: 'https://backend.reachdigital.dev/graphql', + magentoVersion: 246, canonicalBaseUrl: 'https://graphcommerce.vercel.app', storefront: [ { locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true }, diff --git a/examples/magento-graphcms/locales/de.po b/examples/magento-graphcms/locales/de.po index cbc288f26e..250a564d5b 100644 --- a/examples/magento-graphcms/locales/de.po +++ b/examples/magento-graphcms/locales/de.po @@ -615,6 +615,10 @@ msgstr "Produkt nicht verfügbar in {allLabels}" msgid "Products" msgstr "Produkte" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "Bei der Bearbeitung Ihrer Zahlung ist ein Fehler aufgetreten. Bitte kontaktieren Sie den Ladenbesitzer" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Ergebnisse für ‘{search}’" @@ -729,6 +733,9 @@ msgstr "Die Anmeldung ist deaktiviert, bitte kontaktieren Sie uns für weitere I msgid "Skip to main content" msgstr "Zum Hauptinhalt springen" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Einige Artikel in Ihrem Warenkorb enthalten Fehler, bitte aktualisieren oder entfernen Sie sie, und versuchen Sie es erneut." + msgid "Something went wrong" msgstr "Etwas ist schief gelaufen" @@ -741,6 +748,9 @@ msgstr "Sortieren" msgid "Sort By" msgstr "Sortieren nach" +msgid "Start Checkout" +msgstr "Zur Kasse gehen" + msgid "Store home" msgstr "Shop-Startseite" @@ -804,9 +814,6 @@ msgstr "Die Zahlung wurde abgelehnt, bitte versuchen Sie es erneut oder wählen msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "Es gibt maximal '{maxLength}' Zeichen" -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "Dieser Warenkorb ist {email} zugewiesen. Bitte melden Sie sich an, um mit dem Einkauf fortzufahren." - msgid "This field is invalid" msgstr "Dieses Feld ist ungültig" diff --git a/examples/magento-graphcms/locales/en.po b/examples/magento-graphcms/locales/en.po index 97482e6bb5..34ddd9ce93 100644 --- a/examples/magento-graphcms/locales/en.po +++ b/examples/magento-graphcms/locales/en.po @@ -615,6 +615,10 @@ msgstr "Product not available in {allLabels}" msgid "Products" msgstr "Products" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "An error occurred while processing your payment. Please contact the store owner" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Results for ‘{search}’" @@ -729,6 +733,9 @@ msgstr "Sign up is disabled, please contact us for more information." msgid "Skip to main content" msgstr "Skip to main content" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Some items in your cart contain errors, please update or remove them, then try again." + msgid "Something went wrong" msgstr "Something went wrong" @@ -741,6 +748,9 @@ msgstr "Sort" msgid "Sort By" msgstr "Sort By" +msgid "Start Checkout" +msgstr "Start Checkout" + msgid "Store home" msgstr "Store home" @@ -804,9 +814,6 @@ msgstr "The payment is refused, please try again or select a different payment m msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "There is a maximum of ‘{maxLength}’ characters" -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "This cart is assigned to {email}. Please sign in to continue shopping." - msgid "This field is invalid" msgstr "This field is invalid" diff --git a/examples/magento-graphcms/locales/es.po b/examples/magento-graphcms/locales/es.po index 10aff8580e..0e41c58c0e 100644 --- a/examples/magento-graphcms/locales/es.po +++ b/examples/magento-graphcms/locales/es.po @@ -615,6 +615,10 @@ msgstr "Producto no disponible en {allLabels}" msgid "Products" msgstr "Productos" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "Se ha producido un error al procesar su pago. Póngase en contacto con el propietario de la tienda" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Resultados para ‘{search}’" @@ -729,6 +733,9 @@ msgstr "La inscripción está deshabilitada, póngase en contacto con nosotros p msgid "Skip to main content" msgstr "Saltar al contenido principal" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Algunos artículos en su carrito contienen errores, por favor actualice o elimine ellos, y luego intente de nuevo." + msgid "Something went wrong" msgstr "Algo salió mal" @@ -741,6 +748,9 @@ msgstr "Ordenar" msgid "Sort By" msgstr "Ordenar por" +msgid "Start Checkout" +msgstr "Iniciar compra" + msgid "Store home" msgstr "Inicio de la tienda" @@ -804,9 +814,6 @@ msgstr "El pago se ha rechazado, inténtelo de nuevo o seleccione un método de msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "Hay un máximo de caracteres '{maxLength}'" -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "Este carrito está asignado a {email}. Inicie sesión para continuar comprando." - msgid "This field is invalid" msgstr "Este campo es inválido" diff --git a/examples/magento-graphcms/locales/fr.po b/examples/magento-graphcms/locales/fr.po index cce6c6c574..3e89a55472 100644 --- a/examples/magento-graphcms/locales/fr.po +++ b/examples/magento-graphcms/locales/fr.po @@ -615,6 +615,10 @@ msgstr "Produit non disponible dans {allLabels}" msgid "Products" msgstr "Produits" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "Se ha producido un error al procesar su pago. Póngase en contacto con el propietario de la tienda" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Résultats pour ‘{search}’" @@ -729,6 +733,9 @@ msgstr "L'inscription est désactivée, veuillez nous contacter pour plus d'info msgid "Skip to main content" msgstr "Passer au contenu principal" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Certains articles de votre panier contiennent des erreurs, veuillez les mettre à jour ou les supprimer, puis réessayer." + msgid "Something went wrong" msgstr "Quelque chose s'est mal passé" @@ -741,6 +748,9 @@ msgstr "Trier" msgid "Sort By" msgstr "Trier par" +msgid "Start Checkout" +msgstr "Commencer la commande" + msgid "Store home" msgstr "Accueil de la boutique" @@ -804,9 +814,6 @@ msgstr "Le paiement est refusé, veuillez réessayer ou sélectionner une autre msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "Il y a un maximum de caractères '{maxLength}'" -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "Ce panier est assigné à {email}. Veuillez vous connecter pour continuer vos achats." - msgid "This field is invalid" msgstr "Ce champ est invalide" diff --git a/examples/magento-graphcms/locales/it.po b/examples/magento-graphcms/locales/it.po index 2e3237c49e..702047e54d 100644 --- a/examples/magento-graphcms/locales/it.po +++ b/examples/magento-graphcms/locales/it.po @@ -615,6 +615,10 @@ msgstr "Prodotto non disponibile in {allLabels}" msgid "Products" msgstr "Prodotti" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "Si è verificato un errore durante il processo di pagamento. Si prega di contattare il proprietario del negozio" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Risultati per ‘{search}’" @@ -729,6 +733,9 @@ msgstr "L'iscrizione è disabilitata, contattateci per maggiori informazioni." msgid "Skip to main content" msgstr "Passa al contenuto principale" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Alcuni articoli nel tuo carrello contengono errori, per favore aggiorna o rimuovi, poi riprova." + msgid "Something went wrong" msgstr "Qualcosa è andato storto" @@ -741,6 +748,9 @@ msgstr "Ordinare" msgid "Sort By" msgstr "Ordina per" +msgid "Start Checkout" +msgstr "Inizia la checkout" + msgid "Store home" msgstr "Home del negozio" @@ -804,9 +814,6 @@ msgstr "Il pagamento è stato rifiutato, riprova o seleziona un metodo di pagame msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "È consentito un massimo di caratteri \"{maxLength}\"." -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "Questo carrello è assegnato a {email}. Accedi per continuare gli acquisti." - msgid "This field is invalid" msgstr "Questo campo non è valido" diff --git a/examples/magento-graphcms/locales/nl.po b/examples/magento-graphcms/locales/nl.po index bb88301d29..93c9c01c3e 100644 --- a/examples/magento-graphcms/locales/nl.po +++ b/examples/magento-graphcms/locales/nl.po @@ -615,6 +615,10 @@ msgstr "Product niet beschikbaar in {allLabels}" msgid "Products" msgstr "Producten" +#. js-lingui-generated-id +msgid "An error occurred while processing your payment. Please contact the store owner" +msgstr "Er is een fout opgetreden bij het verwerken van uw betaling. Neem contact op met de eigenaar van de winkel" + #. js-lingui-generated-id msgid "Results for ‘{search}’" msgstr "Resultaten voor ‘{search}’" @@ -729,6 +733,9 @@ msgstr "Inschrijven is niet mogelijk, neem contact met ons op voor meer informat msgid "Skip to main content" msgstr "Ga naar hoofdinhoud" +msgid "Some items in your cart contain errors, please update or remove them, then try again." +msgstr "Sommige artikelen in uw winkelwagen bevatten fouten, update of verwijder ze, en probeer het opnieuw." + msgid "Something went wrong" msgstr "Er is iets misgegaan" @@ -741,6 +748,9 @@ msgstr "Sorteer" msgid "Sort By" msgstr "Sorteer op" +msgid "Start Checkout" +msgstr "Start afrekenen" + msgid "Store home" msgstr "Winkel home" @@ -804,9 +814,6 @@ msgstr "De betaling is geweigerd, probeer het opnieuw of selecteer een andere be msgid "There is a maximum of ‘{maxLength}’ characters" msgstr "Er is een maximum van ‘{maxLength}’ karakters" -msgid "This cart is assigned to {email}. Please sign in to continue shopping." -msgstr "Deze winkelwagen is toegewezen aan {email}. Log in om verder te winkelen." - msgid "This field is invalid" msgstr "Dit veld is ongeldig"