@evenicanpm/storefront-core 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/api-manager/datasources/d365/d365-cart.datasource.ts +4 -3
  4. package/src/api-manager/datasources/d365/d365-user.datasource.ts +3 -3
  5. package/src/api-manager/datasources/d365/utils/get-context-cookie.ts +1 -0
  6. package/src/api-manager/datasources/e4/address/e4-address.datasource.ts +5 -14
  7. package/src/api-manager/datasources/e4/address/e4-address.translator.ts +4 -3
  8. package/src/api-manager/datasources/e4/categories/e4-categories.translator.ts +1 -1
  9. package/src/api-manager/datasources/e4/graphqlRequestSdk.ts +29 -3
  10. package/src/api-manager/datasources/e4/product/e4-product.translator.ts +1 -1
  11. package/src/api-manager/index.ts +1 -1
  12. package/src/api-manager/lib/get-graphql-client.ts +1 -1
  13. package/src/api-manager/services/cart/mutations/add-discount-code.ts +0 -11
  14. package/src/api-manager/services/create-query.ts +13 -7
  15. package/src/api-manager/services/user/mutations/add-to-wishlist.ts +1 -1
  16. package/src/api-manager/services/user/mutations/remove-from-wishlist.ts +1 -1
  17. package/src/auth/AUTH GUIDE.md +880 -0
  18. package/src/cms/blocks/components/featured-categories.tsx +18 -15
  19. package/src/cms/blocks/components/featured-products.tsx +3 -2
  20. package/src/cms/blocks/components/footer/sections/footer-contact.tsx +0 -2
  21. package/src/cms/blocks/components/footer/sections/footer-logo.tsx +2 -1
  22. package/src/components/SearchInput.stories.tsx +12 -10
  23. package/src/components/base-layout.tsx +42 -0
  24. package/src/components/categories/category-list/category-list.tsx +32 -12
  25. package/src/components/header/__tests__/header.test.tsx +0 -24
  26. package/src/components/header/components/mobile-header.tsx +16 -8
  27. package/src/components/header/header.tsx +6 -3
  28. package/src/components/mini-cart/components/bottom-actions.tsx +7 -2
  29. package/src/components/mini-cart/components/cart-item.tsx +16 -13
  30. package/src/components/mini-cart/components/empty-view.tsx +12 -6
  31. package/src/components/mini-cart/components/top-header.tsx +9 -8
  32. package/src/components/mini-cart/mini-cart-trigger.tsx +11 -5
  33. package/src/components/mini-cart/mini-cart.tsx +30 -15
  34. package/src/components/mobile-navigation/mobile-navigation-bar.tsx +6 -2
  35. package/src/components/navbar/categories.tsx +8 -2
  36. package/src/components/navbar/category-based-menu/category-based-menu.tsx +6 -2
  37. package/src/components/navbar/mega-menu/mega-menu.tsx +22 -14
  38. package/src/components/navbar/mobile-menu/mobile-menu.test.tsx +8 -11
  39. package/src/components/navbar/mobile-menu/mobile-menu.tsx +13 -11
  40. package/src/components/navbar/nav-list/nav-list.tsx +3 -2
  41. package/src/components/navbar/navbar.tsx +4 -2
  42. package/src/components/product-cards/product-card/product-card.tsx +50 -26
  43. package/src/components/product-cards/product-card-plp/product-card.tsx +37 -16
  44. package/src/components/product-cards/product-card-plp-list/product-card.tsx +38 -16
  45. package/src/components/product-cards/product-card-search/product-card.tsx +34 -13
  46. package/src/components/product-dialog/ProductDialog.stories.tsx +20 -18
  47. package/src/components/product-dialog/compound/product-dialog.tsx +7 -4
  48. package/src/components/product-dimensions/compound/dimensions-group.tsx +4 -2
  49. package/src/components/product-dimensions/compound/dimensions.tsx +15 -6
  50. package/src/components/product-quantity-buttons/compound/quantity-buttons-root.tsx +21 -13
  51. package/src/components/products-view/compound/products-grid-view.tsx +11 -4
  52. package/src/components/products-view/compound/products-list-view.tsx +11 -4
  53. package/src/components/search-bar/compound/search-bar-root.tsx +6 -4
  54. package/src/components/search-bar/compound/textfield-adornment-category.tsx +25 -8
  55. package/src/components/search-bar/hooks/use-click-outside.ts +7 -1
  56. package/src/components/search-bar/hooks/use-search.ts +3 -3
  57. package/src/components/user/index.ts +3 -0
  58. package/src/components/user/use-user-auth.ts +163 -0
  59. package/src/components/user/user.tsx +215 -0
  60. package/src/components/wishlist-dialogs/add-to-wishlist/AddToWishlist.stories.tsx +20 -15
  61. package/src/components/wishlist-dialogs/add-to-wishlist/compound/add-to-wishlist-dialog.tsx +11 -8
  62. package/src/components/wishlist-dialogs/add-to-wishlist/compound/add-to-wishlist-list.tsx +18 -3
  63. package/src/components/wishlist-dialogs/add-to-wishlist/index.tsx +0 -1
  64. package/src/components/wishlist-dialogs/create-wishlist/compound/create-wishlist-dialog.tsx +6 -2
  65. package/src/hooks/use-overflow-detect.ts +4 -4
  66. package/src/lib/page-slugs.ts +16 -0
  67. package/src/pages/account/account-navigation.tsx +7 -14
  68. package/src/pages/account/account-routes.ts +4 -9
  69. package/src/pages/account/addresses/address-form.tsx +38 -16
  70. package/src/pages/account/addresses/address-item.tsx +18 -8
  71. package/src/pages/account/dashboard-header.tsx +20 -13
  72. package/src/pages/account/orders/order-history-filters-panel.tsx +21 -20
  73. package/src/pages/account/orders/order-history-header.tsx +14 -4
  74. package/src/pages/account/orders/order-history-root.tsx +3 -1
  75. package/src/pages/account/orders/order-history-row.tsx +12 -4
  76. package/src/pages/account/orders/order-history-search-and-filter.tsx +88 -59
  77. package/src/pages/account/orders/order-history-search-dropdown.tsx +26 -9
  78. package/src/pages/account/orders/order-history-sort.tsx +3 -1
  79. package/src/pages/account/orders/order-history-table.tsx +27 -5
  80. package/src/pages/account/orders/order-progress.tsx +12 -6
  81. package/src/pages/account/orders/order-row.tsx +18 -6
  82. package/src/pages/account/orders/order-summary.tsx +24 -8
  83. package/src/pages/account/orders/ordered-products.tsx +15 -5
  84. package/src/pages/account/profile/user-info.tsx +11 -3
  85. package/src/pages/account/table-row-skeleton.tsx +1 -1
  86. package/src/pages/account/wishlist/create-new-list.tsx +33 -9
  87. package/src/pages/account/wishlist/wishlist-item.tsx +18 -6
  88. package/src/pages/cart/cart-item.tsx +21 -7
  89. package/src/pages/cart/checkout-form.tsx +55 -22
  90. package/src/pages/cart/coupon-entry.tsx +143 -36
  91. package/src/pages/cart/estimate-shipping.tsx +45 -21
  92. package/src/pages/checkout/checkout-alt-form/checkout-form.tsx +22 -14
  93. package/src/pages/checkout/checkout-alt-form/checkout-step.tsx +37 -16
  94. package/src/pages/checkout/checkout-alt-form/steps/address/address-card.tsx +9 -3
  95. package/src/pages/checkout/checkout-alt-form/steps/address/delivery-address.tsx +84 -51
  96. package/src/pages/checkout/checkout-alt-form/steps/address/new-address-form.tsx +41 -19
  97. package/src/pages/checkout/checkout-alt-form/steps/customer-info/customer-information.tsx +17 -10
  98. package/src/pages/checkout/checkout-alt-form/steps/payment/payment-details.tsx +15 -6
  99. package/src/pages/checkout/checkout-alt-form/steps/shipping/delivery-options.tsx +6 -2
  100. package/src/pages/checkout/checkout-alt-summary/cart-item.tsx +12 -4
  101. package/src/pages/checkout/checkout-alt-summary/checkout-alt-summary.tsx +12 -5
  102. package/src/pages/checkout/checkout-alt-summary/list-item.tsx +17 -10
  103. package/src/pages/confirmation/address.tsx +6 -2
  104. package/src/pages/confirmation/confirmation-summary.tsx +12 -4
  105. package/src/pages/confirmation/ordered-products.tsx +12 -4
  106. package/src/pages/product-details/bopis/store-card/shop-card.tsx +2 -2
  107. package/src/pages/product-details/bopis/store-card/utils/getDaysResources.ts +1 -1
  108. package/src/pages/product-details/product-intro/compound/product-info.tsx +41 -18
  109. package/src/pages/product-details/product-intro/compound/product-intro-images.tsx +18 -12
  110. package/src/pages/product-details/product-intro/compound/product-intro.tsx +20 -10
  111. package/src/pages/product-details/product-intro/compound/thumbnail-with-skeleton.tsx +1 -1
  112. package/src/pages/product-details/product-tabs.tsx +20 -12
  113. package/src/pages/product-list/product-list-view.tsx +4 -2
  114. package/src/pages/product-list/search-bar.tsx +7 -7
  115. package/src/pages/product-list/side-nav.tsx +5 -3
  116. package/src/pages/quickorder/order-upload.tsx +1 -1
  117. package/src/pages/quickorder/provider.tsx +26 -14
  118. package/src/pages/quickorder/quick-order.tsx +49 -22
  119. package/src/providers/nav-provider/index.tsx +16 -11
  120. package/tsconfig.json +0 -5
  121. package/src/components/header/components/user.tsx +0 -322
  122. /package/src/components/{header → user}/__tests__/user.test.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @evenicanpm/storefront-core
2
2
 
3
+ ## 2.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @evenicanpm/cms@2.5.0
8
+ - @evenicanpm/ui@2.5.0
9
+
10
+ ## 2.4.2
11
+
12
+ ### Patch Changes
13
+
14
+ - fix: bumping all versions and then re-publishing to properly strip out the workspace: deps.
15
+ - Updated dependencies
16
+ - @evenicanpm/cms@2.4.2
17
+ - @evenicanpm/ui@2.4.2
18
+
3
19
  ## 2.4.1
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evenicanpm/storefront-core",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Core module for D365/e4 Headless Storefront",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -21,15 +21,16 @@ function serializeError(error: unknown): string {
21
21
  for (const key of allKeys) {
22
22
  if (key !== "constructor") {
23
23
  try {
24
- // biome-ignore lint: api datasources should not be typed
25
- result[key] = (value as any)[key];
24
+ result[key] = value[key];
26
25
  } catch {}
27
26
  }
28
27
  }
29
28
  return Object.keys(result).length ? result : value;
30
29
  });
31
30
  } catch {
32
- return String(error);
31
+ if (error instanceof Error) return error.message;
32
+ if (typeof error === "string") return error;
33
+ return "Unable to serialize error";
33
34
  }
34
35
  }
35
36
 
@@ -67,10 +67,10 @@ function extractEmailFromClaims(token: IdTokenClaims): string | undefined {
67
67
 
68
68
  function decodeIdTokenClaims(token: string): IdTokenClaims {
69
69
  const decoded = jwt.decode(token);
70
- if (!decoded || typeof decoded !== "object") {
71
- return {} as IdTokenClaims;
70
+ if (decoded && typeof decoded === "object") {
71
+ return decoded;
72
72
  }
73
- return decoded as IdTokenClaims;
73
+ return {};
74
74
  }
75
75
 
76
76
  const tracer = trace.getTracer("d365-user-datasource");
@@ -74,6 +74,7 @@ export async function getContextFromCookie(): Promise<ICallerContext> {
74
74
  token: accessToken,
75
75
  };
76
76
  context.requestContext.locale = locale;
77
+ context.requestContext.apiSettings.catalogId = 0;
77
78
  return context;
78
79
  }
79
80
  throw new Error("D365Context cookie not found");
@@ -1,6 +1,5 @@
1
1
  import { addressMap } from "@evenicanpm/storefront-core/src/api-manager/datasources/e4/address/e4-address.remaps";
2
2
  import * as addressTranslator from "@evenicanpm/storefront-core/src/api-manager/datasources/e4/address/e4-address.translator";
3
- import type { Shipping } from "@evenicanpm/storefront-core/src/api-manager/datasources/e4/graphqlRequestSdk";
4
3
  import getGraphqlClient from "@evenicanpm/storefront-core/src/api-manager/lib/get-graphql-client";
5
4
  import type {
6
5
  Address,
@@ -57,7 +56,9 @@ const address = {
57
56
  }
58
57
 
59
58
  return addressTranslator.deliveryOptionsTransformValidate(
60
- (data?.shippingbyCarrier as Shipping[]) ?? [],
59
+ (data?.shippingbyCarrier ?? []).filter(
60
+ (s): s is NonNullable<typeof s> => s !== null,
61
+ ),
61
62
  ) as DeliveryOption[];
62
63
  },
63
64
  async createAddress(address: Address): Promise<Address> {
@@ -70,12 +71,7 @@ const address = {
70
71
  throw new Error("Error creating address");
71
72
  }
72
73
 
73
- return (
74
- merge(
75
- [data?.createAddress],
76
- addressMap as unknown as Address[],
77
- ) as Address[]
78
- )[0];
74
+ return (merge([data?.createAddress], addressMap) as Address[])[0];
79
75
  },
80
76
  async updateAddress(address: Address): Promise<Address> {
81
77
  const e4Api = await getGraphqlClient(true);
@@ -87,12 +83,7 @@ const address = {
87
83
  throw new Error("Error updating address");
88
84
  }
89
85
 
90
- return (
91
- merge(
92
- [data?.updateAddress],
93
- addressMap as unknown as Address[],
94
- ) as Address[]
95
- )[0];
86
+ return (merge([data?.updateAddress], addressMap) as Address[])[0];
96
87
  },
97
88
  async deleteAddress(addressId: string): Promise<string> {
98
89
  const e4Api = await getGraphqlClient(true);
@@ -47,8 +47,9 @@ export const getCountryId = async (code: string) => {
47
47
  } else {
48
48
  const e4Api = await getGraphqlClient();
49
49
  const { data } = await e4Api.e4CountryList();
50
- countriesCache.set(cacheKey, data?.countries as Country[]);
51
- countries = data?.countries as Country[];
50
+ const fetchedCountries = data?.countries ?? [];
51
+ countriesCache.set(cacheKey, fetchedCountries);
52
+ countries = fetchedCountries;
52
53
  }
53
54
  const country = countries.find(
54
55
  (c: { isoAlpha3Code: string }) => c?.isoAlpha3Code === code,
@@ -71,7 +72,7 @@ const getStateId = async (stateCode: string, countryId: string) => {
71
72
  } else {
72
73
  const e4Api = await getGraphqlClient();
73
74
  const { data } = await e4Api.e4Country({ id: countryId });
74
- country = data?.country as Country;
75
+ country = data?.country ?? country;
75
76
  countryCache.set(cacheKey, country);
76
77
  }
77
78
 
@@ -146,7 +146,7 @@ export const categoryTransformValidate = (
146
146
  }
147
147
  });
148
148
 
149
- for (const rootNode of rootNodes as TransformedCategoryNode[]) {
149
+ for (const rootNode of rootNodes) {
150
150
  calculateUrls(rootNode, "", urlPrefix);
151
151
  }
152
152
  rootNodes.sort(
@@ -5430,7 +5430,9 @@ export type Process = {
5430
5430
  };
5431
5431
 
5432
5432
  export type ProcessConfigMerge = {
5433
- config?: InputMaybe<Array<InputMaybe<ConfigMerge>>>;
5433
+ sourceConfig?: InputMaybe<ConfigMerge>;
5434
+ targetConfig?: InputMaybe<ConfigMerge>;
5435
+ targetSourcesConfig?: InputMaybe<ConfigMerge>;
5434
5436
  };
5435
5437
 
5436
5438
  export type ProcessConnection = {
@@ -5811,6 +5813,7 @@ export type ProcessTask = {
5811
5813
  __typename?: 'ProcessTask';
5812
5814
  code?: Maybe<Scalars['String']['output']>;
5813
5815
  created: Scalars['DateTime']['output'];
5816
+ directionTypeId?: Maybe<Scalars['Int']['output']>;
5814
5817
  endpoint?: Maybe<Endpoint>;
5815
5818
  executionProcedure?: Maybe<Scalars['String']['output']>;
5816
5819
  extendedFields?: Maybe<Scalars['JSON']['output']>;
@@ -5825,6 +5828,7 @@ export type ProcessTask = {
5825
5828
  preExecutionProcedure?: Maybe<Scalars['String']['output']>;
5826
5829
  process: Process;
5827
5830
  processTaskType?: Maybe<ProcessTaskType>;
5831
+ processTemplateId?: Maybe<Scalars['ID']['output']>;
5828
5832
  properties?: Maybe<Scalars['JSON']['output']>;
5829
5833
  sort?: Maybe<Scalars['Int']['output']>;
5830
5834
  };
@@ -5889,6 +5893,7 @@ export type ProcessTaskExecution = {
5889
5893
 
5890
5894
  export type ProcessTaskExport = {
5891
5895
  __typename?: 'ProcessTaskExport';
5896
+ DirectionTypeId?: Maybe<Scalars['Int']['output']>;
5892
5897
  Endpoint?: Maybe<Scalars['String']['output']>;
5893
5898
  Name?: Maybe<Scalars['String']['output']>;
5894
5899
  OrchestrationType?: Maybe<Scalars['String']['output']>;
@@ -5899,10 +5904,12 @@ export type ProcessTaskExport = {
5899
5904
  ProcessTask?: Maybe<Scalars['String']['output']>;
5900
5905
  ProcessTaskId?: Maybe<Scalars['ID']['output']>;
5901
5906
  ProcessTaskType?: Maybe<Scalars['String']['output']>;
5907
+ ProcessTemplateId?: Maybe<Scalars['Int']['output']>;
5902
5908
  Sort?: Maybe<Scalars['Int']['output']>;
5903
5909
  };
5904
5910
 
5905
5911
  export type ProcessTaskImport = {
5912
+ DirectionTypeId?: InputMaybe<Scalars['Int']['input']>;
5906
5913
  Endpoint?: InputMaybe<Scalars['String']['input']>;
5907
5914
  Name?: InputMaybe<Scalars['String']['input']>;
5908
5915
  OrchestrationType?: InputMaybe<Scalars['String']['input']>;
@@ -5913,6 +5920,7 @@ export type ProcessTaskImport = {
5913
5920
  ProcessTask?: InputMaybe<Scalars['String']['input']>;
5914
5921
  ProcessTaskId?: InputMaybe<Scalars['ID']['input']>;
5915
5922
  ProcessTaskType?: InputMaybe<Scalars['String']['input']>;
5923
+ ProcessTemplateId?: InputMaybe<Scalars['ID']['input']>;
5916
5924
  Properties?: InputMaybe<Scalars['JSON']['input']>;
5917
5925
  Sort?: InputMaybe<Scalars['Int']['input']>;
5918
5926
  };
@@ -6009,8 +6017,10 @@ export type ProcessTaskUpdate = {
6009
6017
  export type ProcessTemplate = {
6010
6018
  __typename?: 'ProcessTemplate';
6011
6019
  created: Scalars['DateTime']['output'];
6020
+ directionTypeId?: Maybe<Scalars['Int']['output']>;
6012
6021
  id: Scalars['ID']['output'];
6013
6022
  isActive?: Maybe<Scalars['Boolean']['output']>;
6023
+ mappings?: Maybe<Array<Maybe<ProcessTemplateInputMapping>>>;
6014
6024
  modified: Scalars['DateTime']['output'];
6015
6025
  name?: Maybe<Scalars['String']['output']>;
6016
6026
  pages?: Maybe<Array<Maybe<ProcessTemplatePage>>>;
@@ -6024,8 +6034,8 @@ export type ProcessTemplateConnection = {
6024
6034
  };
6025
6035
 
6026
6036
  export type ProcessTemplateFilter = {
6027
- processTemplateGroupId?: InputMaybe<Scalars['ID']['input']>;
6028
- processTemplateId?: InputMaybe<Scalars['ID']['input']>;
6037
+ sourceTemplateId?: InputMaybe<Scalars['ID']['input']>;
6038
+ targetTemplateId?: InputMaybe<Scalars['ID']['input']>;
6029
6039
  };
6030
6040
 
6031
6041
  export type ProcessTemplateGroup = {
@@ -6063,6 +6073,15 @@ export type ProcessTemplateInput = {
6063
6073
  validationRegex?: Maybe<Scalars['String']['output']>;
6064
6074
  };
6065
6075
 
6076
+ export type ProcessTemplateInputMapping = {
6077
+ __typename?: 'ProcessTemplateInputMapping';
6078
+ fieldName?: Maybe<Scalars['String']['output']>;
6079
+ format?: Maybe<Scalars['String']['output']>;
6080
+ inputTypeCode?: Maybe<Scalars['String']['output']>;
6081
+ jsonPath?: Maybe<Scalars['String']['output']>;
6082
+ jsonValuePath?: Maybe<Scalars['String']['output']>;
6083
+ };
6084
+
6066
6085
  export type ProcessTemplateInputSchema = {
6067
6086
  __typename?: 'ProcessTemplateInputSchema';
6068
6087
  defaultValue?: Maybe<Scalars['String']['output']>;
@@ -6629,6 +6648,7 @@ export type Query = {
6629
6648
  processTasksByProcess?: Maybe<ProcessTaskConnection>;
6630
6649
  processTemplate?: Maybe<Array<Maybe<ProcessTemplate>>>;
6631
6650
  processTemplateGroups?: Maybe<ProcessTemplateGroupConnection>;
6651
+ processTemplateInputMappings?: Maybe<Array<Maybe<ProcessTemplateInputMapping>>>;
6632
6652
  processTemplateRecords?: Maybe<ProcessTemplateRecordConnection>;
6633
6653
  processTemplates?: Maybe<ProcessTemplateConnection>;
6634
6654
  processes?: Maybe<ProcessConnection>;
@@ -7529,12 +7549,18 @@ export type QueryProcessTemplateGroupsArgs = {
7529
7549
  };
7530
7550
 
7531
7551
 
7552
+ export type QueryProcessTemplateInputMappingsArgs = {
7553
+ processTemplateId?: InputMaybe<Scalars['Int']['input']>;
7554
+ };
7555
+
7556
+
7532
7557
  export type QueryProcessTemplateRecordsArgs = {
7533
7558
  input?: InputMaybe<FilterQueryInput>;
7534
7559
  };
7535
7560
 
7536
7561
 
7537
7562
  export type QueryProcessTemplatesArgs = {
7563
+ directionTypeId?: InputMaybe<Scalars['ID']['input']>;
7538
7564
  input?: InputMaybe<FilterQueryInput>;
7539
7565
  };
7540
7566
 
@@ -146,7 +146,7 @@ export const productListInputTransform = async (
146
146
  acc[key].push(ref?.LeftValueBoundString ?? "");
147
147
  return acc;
148
148
  },
149
- {} as Record<string, string[]>,
149
+ {},
150
150
  );
151
151
 
152
152
  const filters = Object.entries(grouped).map(([key, values]) => ({
@@ -60,7 +60,7 @@ async function createApiManager(): Promise<Datasource> {
60
60
 
61
61
  if (datasource[entityName]) {
62
62
  // Merge override methods into the existing entity
63
- Object.assign(datasource[entityName] as object, entityOverrides);
63
+ Object.assign(datasource[entityName], entityOverrides);
64
64
  } else {
65
65
  // Non-core entity added entirely from overrides
66
66
  // biome-ignore lint: api datasources should not be typed
@@ -36,7 +36,7 @@ const getGraphQLClient = async (withAuth = false) => {
36
36
  };
37
37
 
38
38
  const cookieStore = await cookies();
39
- const sessionCookie = cookieStore.get("storefront"); // cookie is set in middleware - setE4SessionCookies
39
+ const sessionCookie = cookieStore.get("storefront"); // cookie is set in proxy - setE4SessionCookies
40
40
  // This session cookie solution only works when all api calls are through server actions.
41
41
  // If not we need to route all e4 client api calls through an custom api route.
42
42
  if (sessionCookie) {
@@ -5,27 +5,16 @@ import type {
5
5
  import getCart from "@evenicanpm/storefront-core/src/api-manager/services/cart/queries/get-cart";
6
6
  import { useCreateMutation } from "@evenicanpm/storefront-core/src/api-manager/services/create-mutation";
7
7
  import { createApiPath } from "@evenicanpm/storefront-core/src/api-manager/services/create-query";
8
- import { useNotification } from "@evenicanpm/storefront-core/src/providers/notifications/use-notification";
9
8
  import { useQueryClient } from "@tanstack/react-query";
10
- import { useTranslations } from "next-intl";
11
9
 
12
10
  const apiPath = createApiPath("cart", "addDiscountCode");
13
11
 
14
12
  const useAddDiscountCode = () => {
15
13
  const queryClient = useQueryClient();
16
- const { setNotification } = useNotification();
17
- const t = useTranslations("Cart.Messages");
18
14
  return useCreateMutation<ManageDiscountCodeInput, Cart>(apiPath, {
19
15
  onSuccess: (result) => {
20
16
  getCart.setQueryData(queryClient, result);
21
17
  },
22
- onError: () => {
23
- setNotification({
24
- message: t("couponError"),
25
- severity: "error",
26
- type: "cart",
27
- });
28
- },
29
18
  });
30
19
  };
31
20
 
@@ -1,6 +1,10 @@
1
1
  import createApiManager from "@evenicanpm/storefront-core/src/api-manager/index";
2
2
  import type { DatasourceApis } from "@evenicanpm/storefront-core/src/api-manager/types/Datasource";
3
- import { isServer, type QueryClient } from "@tanstack/query-core";
3
+ import {
4
+ type DefaultError,
5
+ isServer,
6
+ type QueryClient,
7
+ } from "@tanstack/query-core";
4
8
  import {
5
9
  type UseQueryResult,
6
10
  type UseSuspenseQueryResult,
@@ -104,12 +108,14 @@ export const createQuery = <TInput, TOutput>(
104
108
  return {
105
109
  useData: (
106
110
  input?: TInput,
107
- options?: { enabled: boolean },
108
- ): UseQueryResult<TOutput> =>
109
- useQuery({
110
- ...getQueryOptions(input),
111
- ...(options?.enabled !== undefined && { enabled: options.enabled }),
112
- }),
111
+ queryOptions?: { enabled?: boolean },
112
+ ): UseQueryResult<NoInfer<TOutput>, DefaultError> => {
113
+ const baseOptions = getQueryOptions(input);
114
+ return useQuery({
115
+ ...baseOptions,
116
+ enabled: baseOptions.enabled && (queryOptions?.enabled ?? true),
117
+ });
118
+ },
113
119
  useSuspenseData: (input?: TInput): UseSuspenseQueryResult<TOutput> =>
114
120
  useSuspenseQuery(getQueryOptions(input)),
115
121
  fetchData: (queryClient: QueryClient, input?: TInput) =>
@@ -24,7 +24,7 @@ const useAddToWishlist = () => {
24
24
  // Based on Tanstack Optimistic Update Pattern
25
25
  // https://tanstack.com/query/latest/docs/reference/QueryClient
26
26
  await queryClient.cancelQueries({ queryKey: [getWishlistsQueryKey] });
27
- const previousWishlists = await getWishlists.getData(queryClient);
27
+ const previousWishlists = getWishlists.getData(queryClient);
28
28
  const optimisticData = previousWishlists?.map((list) => {
29
29
  if (list.Id === input.Id) {
30
30
  // Add the input product line to list
@@ -25,7 +25,7 @@ const useRemoveFromWishlist = () => {
25
25
  // Based on Tanstack Optimistic Update Pattern
26
26
  // https://tanstack.com/query/latest/docs/reference/QueryClient
27
27
  await queryClient.cancelQueries({ queryKey: [getWishlistsQueryKey] });
28
- const previousWishlists = await getWishlists.getData(queryClient);
28
+ const previousWishlists = getWishlists.getData(queryClient);
29
29
  const optimisticData = previousWishlists?.map((list) => {
30
30
  if (list.Id === input.Id) {
31
31
  // Remove the product line of our input id