@vtex/faststore-plugin-buyer-portal 1.1.106 → 1.1.108

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 (37) hide show
  1. package/package.json +1 -1
  2. package/src/features/custom-fields/layouts/CustomFieldsLayout/CustomFieldsLayout.tsx +1 -0
  3. package/src/features/shared/clients/Auth.ts +25 -0
  4. package/src/features/shared/clients/Client.ts +11 -1
  5. package/src/features/shared/components/withErrorBoundary/withErrorBoundary.tsx +7 -6
  6. package/src/features/shared/services/index.ts +4 -0
  7. package/src/features/shared/services/validate-access.service.ts +11 -0
  8. package/src/features/shared/types/AuthRouteProps.ts +5 -0
  9. package/src/features/shared/types/index.ts +1 -0
  10. package/src/features/shared/utils/constants.ts +4 -4
  11. package/src/features/shared/utils/index.ts +5 -0
  12. package/src/features/shared/utils/withAuth.tsx +31 -0
  13. package/src/features/shared/utils/withAuthLoader.ts +47 -0
  14. package/src/features/shared/utils/withAuthProvider.tsx +38 -0
  15. package/src/features/shared/utils/withBuyerPortal.tsx +24 -0
  16. package/src/features/shared/utils/withLoaderErrorBoundary.ts +79 -71
  17. package/src/features/shared/utils/withProviders.tsx +35 -0
  18. package/src/pages/address-details.tsx +95 -91
  19. package/src/pages/addresses.tsx +63 -63
  20. package/src/pages/budgets-details.tsx +44 -43
  21. package/src/pages/budgets.tsx +58 -56
  22. package/src/pages/buying-policies.tsx +84 -78
  23. package/src/pages/buying-policy-details.tsx +43 -44
  24. package/src/pages/collections.tsx +59 -60
  25. package/src/pages/cost-centers.tsx +48 -51
  26. package/src/pages/credit-cards.tsx +44 -49
  27. package/src/pages/home.tsx +28 -23
  28. package/src/pages/org-unit-details.tsx +39 -36
  29. package/src/pages/org-units.tsx +86 -90
  30. package/src/pages/payment-methods.tsx +41 -42
  31. package/src/pages/po-numbers.tsx +43 -46
  32. package/src/pages/profile.tsx +54 -52
  33. package/src/pages/releases.tsx +43 -41
  34. package/src/pages/role-details.tsx +57 -60
  35. package/src/pages/roles.tsx +42 -39
  36. package/src/pages/user-details.tsx +58 -58
  37. package/src/pages/users.tsx +83 -80
@@ -2,23 +2,21 @@ import { BudgetsLayout } from "../features/budgets/layouts";
2
2
  import { listBudgetsService } from "../features/budgets/services";
3
3
  import { getContractDetailsService } from "../features/contracts/services";
4
4
  import { getOrgUnitBasicDataService } from "../features/org-units/services";
5
- import {
6
- BuyerPortalProvider,
7
- withErrorBoundary,
8
- } from "../features/shared/components";
5
+ import { withErrorBoundary } from "../features/shared/components";
9
6
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
10
7
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
11
8
  import {
12
9
  type ClientContext,
13
- getClientContext,
14
10
  withLoaderErrorBoundary,
11
+ withAuthLoader,
12
+ withProviders,
15
13
  } from "../features/shared/utils";
16
14
  import { getUserByIdService } from "../features/users/services";
17
15
 
18
16
  import type { BudgetListResponse } from "../features/budgets/types";
19
17
  import type { ContractData } from "../features/contracts/types";
20
18
  import type { OrgUnitBasicData } from "../features/org-units/types";
21
- import type { LoaderData } from "../features/shared/types";
19
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
22
20
  import type { UserData } from "../features/users/types";
23
21
 
24
22
  export type BudgetPageData = {
@@ -40,51 +38,53 @@ export type BudgetPageQuery = {
40
38
 
41
39
  const loaderFunction = async (
42
40
  data: LoaderData<BudgetPageQuery>
43
- ): Promise<BudgetPageData> => {
44
- const { customerId, cookie, userId, ...clientContext } =
45
- await getClientContext(data);
46
-
41
+ ): Promise<AuthRouteProps<BudgetPageData>> => {
47
42
  const { contractId, orgUnitId } = data.query;
48
43
 
49
- if (!contractId || !orgUnitId) {
50
- return {
51
- data: { data: [], total: 0 },
52
- context: {
53
- clientContext: { cookie, userId, customerId, ...clientContext },
54
- currentOrgUnit: null,
55
- currentContract: null,
56
- currentUser: null,
57
- },
58
- };
59
- }
44
+ return withAuthLoader(
45
+ data,
46
+ async ({ customerId, cookie, userId, ...clientContext }) => {
47
+ if (!contractId || !orgUnitId) {
48
+ return {
49
+ data: { data: [], total: 0 },
50
+ context: {
51
+ clientContext: { customerId, cookie, userId, ...clientContext },
52
+ currentOrgUnit: null,
53
+ currentContract: null,
54
+ currentUser: null,
55
+ },
56
+ };
57
+ }
60
58
 
61
- const [orgUnit, contract, user, budgetsData] = await Promise.all([
62
- getOrgUnitBasicDataService({
63
- cookie,
64
- id: orgUnitId,
65
- }),
66
- getContractDetailsService({
67
- contractId,
68
- unitId: orgUnitId,
69
- cookie,
70
- }),
71
- getUserByIdService({ orgUnitId, userId, cookie }),
72
- listBudgetsService({
73
- customerId,
74
- cookie,
75
- unitId: orgUnitId,
76
- }),
77
- ]);
59
+ const [orgUnit, contract, user, budgetsData] = await Promise.all([
60
+ getOrgUnitBasicDataService({
61
+ cookie,
62
+ id: orgUnitId,
63
+ }),
64
+ getContractDetailsService({
65
+ contractId,
66
+ unitId: orgUnitId,
67
+ cookie,
68
+ }),
69
+ getUserByIdService({ orgUnitId, userId, cookie }),
70
+ listBudgetsService({
71
+ customerId,
72
+ cookie,
73
+ unitId: orgUnitId,
74
+ }),
75
+ ]);
78
76
 
79
- return {
80
- data: budgetsData,
81
- context: {
82
- clientContext: { customerId, cookie, userId, ...clientContext },
83
- currentOrgUnit: orgUnit,
84
- currentContract: contract,
85
- currentUser: user,
86
- },
87
- };
77
+ return {
78
+ data: budgetsData,
79
+ context: {
80
+ clientContext: { customerId, cookie, userId, ...clientContext },
81
+ currentOrgUnit: orgUnit,
82
+ currentContract: contract,
83
+ currentUser: user,
84
+ },
85
+ };
86
+ }
87
+ );
88
88
  };
89
89
 
90
90
  export const loader = withLoaderErrorBoundary(loaderFunction, {
@@ -92,19 +92,21 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
92
92
  redirectToError: true,
93
93
  });
94
94
 
95
- const ContractsPage = ({ data, context, hasError, error }: BudgetPageData) => (
96
- <BuyerPortalProvider {...context}>
95
+ const ContractsPage = ({ data, hasError, error }: BudgetPageData) => (
96
+ <>
97
97
  {hasError ? (
98
98
  <ErrorTabsLayout error={error} />
99
99
  ) : (
100
100
  <BudgetsLayout data={data} />
101
101
  )}
102
- </BuyerPortalProvider>
102
+ </>
103
103
  );
104
104
 
105
- export default withErrorBoundary(ContractsPage, {
106
- tags: {
107
- component: "BudgetsPage",
108
- errorType: "budgets_error",
109
- },
110
- });
105
+ export default withProviders(
106
+ withErrorBoundary(ContractsPage, {
107
+ tags: {
108
+ component: "BudgetsPage",
109
+ errorType: "budgets_error",
110
+ },
111
+ })
112
+ );
@@ -3,17 +3,15 @@ import { BuyingPoliciesLayout } from "../features/buying-policies/layouts";
3
3
  import { getBuyingPoliciesService } from "../features/buying-policies/services";
4
4
  import { getContractDetailsService } from "../features/contracts/services";
5
5
  import { getOrgUnitBasicDataService } from "../features/org-units/services";
6
- import {
7
- BuyerPortalProvider,
8
- withErrorBoundary,
9
- } from "../features/shared/components";
6
+ import { withErrorBoundary } from "../features/shared/components";
10
7
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
11
8
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
12
9
  import {
13
10
  type ClientContext,
14
- getClientContext,
15
11
  getValidPage,
16
12
  withLoaderErrorBoundary,
13
+ withAuthLoader,
14
+ withProviders,
17
15
  } from "../features/shared/utils";
18
16
  import { getUserByIdService } from "../features/users/services";
19
17
 
@@ -22,7 +20,7 @@ import type { BudgetListResponse } from "../features/budgets/types";
22
20
  import type { BuyingPolicy } from "../features/buying-policies/types";
23
21
  import type { ContractData } from "../features/contracts/types";
24
22
  import type { OrgUnitBasicData } from "../features/org-units/types";
25
- import type { LoaderData } from "../features/shared/types";
23
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
26
24
  import type { UserData } from "../features/users/types";
27
25
 
28
26
  export type BuyingPoliciesPageData = {
@@ -50,77 +48,84 @@ export type BuyingPoliciesPageQuery = GetAddressesServiceProps & {
50
48
 
51
49
  const loaderFunction = async (
52
50
  data: LoaderData<BuyingPoliciesPageQuery>
53
- ): Promise<BuyingPoliciesPageData> => {
51
+ ): Promise<AuthRouteProps<BuyingPoliciesPageData>> => {
54
52
  const { contractId, orgUnitId, search = "", page: pageString } = data.query;
55
53
 
56
54
  const page = getValidPage(pageString);
57
55
 
58
- const { cookie, userId, ...clientContext } = await getClientContext(data);
59
-
60
- if (!contractId || !orgUnitId) {
61
- return {
62
- buyingPolicies: [],
63
- total: 0,
64
- search: search ?? "",
65
- page: page ?? 1,
66
- context: {
67
- clientContext: { cookie, userId, ...clientContext },
68
- currentOrgUnit: null,
69
- currentContract: null,
70
- currentUser: null,
71
- },
72
- };
73
- }
56
+ return withAuthLoader(
57
+ data,
58
+ async ({ cookie, userId, customerId, ...clientContext }) => {
59
+ if (!contractId || !orgUnitId) {
60
+ return {
61
+ buyingPolicies: [],
62
+ total: 0,
63
+ search: search ?? "",
64
+ page: page ?? 1,
65
+ context: {
66
+ clientContext: { cookie, userId, customerId, ...clientContext },
67
+ currentOrgUnit: null,
68
+ currentContract: null,
69
+ currentUser: null,
70
+ },
71
+ budgetData: { data: [], total: 0 },
72
+ };
73
+ }
74
74
 
75
- const [currentOrgUnit, user, contract, budgetData, buyingPoliciesResponse] =
76
- await Promise.all([
77
- getOrgUnitBasicDataService({
78
- id: orgUnitId,
79
- cookie,
80
- }),
81
- getUserByIdService({ orgUnitId, userId, cookie }),
82
- getContractDetailsService({
83
- contractId,
84
- cookie,
85
- unitId: orgUnitId,
86
- }),
75
+ const [
76
+ currentOrgUnit,
77
+ user,
78
+ contract,
79
+ budgetData,
80
+ buyingPoliciesResponse,
81
+ ] = await Promise.all([
82
+ getOrgUnitBasicDataService({
83
+ id: orgUnitId,
84
+ cookie,
85
+ }),
86
+ getUserByIdService({ orgUnitId, userId, cookie }),
87
+ getContractDetailsService({
88
+ contractId,
89
+ cookie,
90
+ unitId: orgUnitId,
91
+ }),
92
+ listBudgetsService({
93
+ customerId,
94
+ cookie,
95
+ unitId: orgUnitId,
96
+ }),
97
+ getBuyingPoliciesService({
98
+ orgUnitId,
99
+ contractId,
100
+ cookie,
101
+ page,
102
+ search,
103
+ }),
104
+ ]);
87
105
 
88
- listBudgetsService({
89
- customerId: clientContext.customerId,
90
- cookie,
91
- unitId: orgUnitId,
92
- }),
106
+ const { data: buyingPolicies = [], total = 0 } = buyingPoliciesResponse;
93
107
 
94
- getBuyingPoliciesService({
95
- orgUnitId,
96
- contractId,
97
- cookie,
98
- page,
108
+ return {
109
+ buyingPolicies: search
110
+ ? buyingPolicies.filter((buyingPolicy) =>
111
+ buyingPolicy.name
112
+ .toLocaleLowerCase()
113
+ .includes(search.toLocaleLowerCase())
114
+ )
115
+ : buyingPolicies,
116
+ total,
99
117
  search,
100
- }),
101
- ]);
102
-
103
- const { data: buyingPolicies = [], total = 0 } = buyingPoliciesResponse;
104
-
105
- return {
106
- buyingPolicies: search
107
- ? buyingPolicies.filter((buyingPolicy) =>
108
- buyingPolicy.name
109
- .toLocaleLowerCase()
110
- .includes(search.toLocaleLowerCase())
111
- )
112
- : buyingPolicies,
113
- total,
114
- search,
115
- page,
116
- context: {
117
- clientContext: { cookie, userId, ...clientContext },
118
- currentOrgUnit,
119
- currentUser: user,
120
- currentContract: contract,
121
- },
122
- budgetData: budgetData ?? { data: [], total: 0 },
123
- };
118
+ page,
119
+ context: {
120
+ clientContext: { cookie, userId, customerId, ...clientContext },
121
+ currentOrgUnit,
122
+ currentUser: user,
123
+ currentContract: contract,
124
+ },
125
+ budgetData: budgetData ?? { data: [], total: 0 },
126
+ };
127
+ }
128
+ );
124
129
  };
125
130
 
126
131
  export const loader = withLoaderErrorBoundary(loaderFunction, {
@@ -132,13 +137,12 @@ const BuyingPoliciesPage = ({
132
137
  buyingPolicies,
133
138
  search,
134
139
  page,
135
- context,
136
140
  total,
137
141
  hasError,
138
142
  error,
139
143
  budgetData = { data: [], total: 0 },
140
144
  }: BuyingPoliciesPageData) => (
141
- <BuyerPortalProvider {...context}>
145
+ <>
142
146
  {hasError ? (
143
147
  <ErrorTabsLayout error={error} />
144
148
  ) : (
@@ -150,12 +154,14 @@ const BuyingPoliciesPage = ({
150
154
  budgetData={budgetData}
151
155
  />
152
156
  )}
153
- </BuyerPortalProvider>
157
+ </>
154
158
  );
155
159
 
156
- export default withErrorBoundary(BuyingPoliciesPage, {
157
- tags: {
158
- component: "BuyingPoliciesPage",
159
- errorType: "buying_policies_error",
160
- },
161
- });
160
+ export default withProviders(
161
+ withErrorBoundary(BuyingPoliciesPage, {
162
+ tags: {
163
+ component: "BuyingPoliciesPage",
164
+ errorType: "buying_policies_error",
165
+ },
166
+ })
167
+ );
@@ -2,16 +2,14 @@ import { BuyingPolicyDetailsLayout } from "../features/buying-policies/layouts/B
2
2
  import { getBuyingPolicyService } from "../features/buying-policies/services";
3
3
  import { getContractDetailsService } from "../features/contracts/services";
4
4
  import { getOrgUnitBasicDataService } from "../features/org-units/services";
5
- import {
6
- BuyerPortalProvider,
7
- withErrorBoundary,
8
- } from "../features/shared/components";
5
+ import { withErrorBoundary } from "../features/shared/components";
9
6
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
10
7
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
11
8
  import {
12
9
  type ClientContext,
13
- getClientContext,
14
10
  withLoaderErrorBoundary,
11
+ withAuthLoader,
12
+ withProviders,
15
13
  } from "../features/shared/utils";
16
14
  import { getUserByIdService } from "../features/users/services";
17
15
 
@@ -19,7 +17,7 @@ import type { GetAddressesServiceProps } from "../features/addresses/services";
19
17
  import type { BuyingPolicy } from "../features/buying-policies/types";
20
18
  import type { ContractData } from "../features/contracts/types";
21
19
  import type { OrgUnitBasicData } from "../features/org-units/types";
22
- import type { LoaderData } from "../features/shared/types";
20
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
23
21
  import type { UserData } from "../features/users/types";
24
22
 
25
23
  export type BuyingPolicyDetailsPageData = {
@@ -42,42 +40,42 @@ export type BuyingPolicyDetailsPageQuery = GetAddressesServiceProps & {
42
40
 
43
41
  const loaderFunction = async (
44
42
  data: LoaderData<BuyingPolicyDetailsPageQuery>
45
- ): Promise<BuyingPolicyDetailsPageData> => {
43
+ ): Promise<AuthRouteProps<BuyingPolicyDetailsPageData>> => {
46
44
  const { contractId, orgUnitId, buyingPolicyId } = data.query;
47
45
 
48
- const { cookie, userId, ...clientContext } = await getClientContext(data);
46
+ return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
47
+ const currentOrgUnit = await getOrgUnitBasicDataService({
48
+ id: orgUnitId,
49
+ cookie,
50
+ });
49
51
 
50
- const currentOrgUnit = await getOrgUnitBasicDataService({
51
- id: orgUnitId,
52
- cookie,
53
- });
52
+ const user = await getUserByIdService({ orgUnitId, userId, cookie });
54
53
 
55
- const user = await getUserByIdService({ orgUnitId, userId, cookie });
54
+ const contract = await getContractDetailsService({
55
+ contractId,
56
+ cookie,
57
+ unitId: orgUnitId,
58
+ });
56
59
 
57
- const contract = await getContractDetailsService({
58
- contractId,
59
- cookie,
60
- unitId: orgUnitId,
61
- });
60
+ const buyingPolicy = await getBuyingPolicyService({
61
+ orgUnitId,
62
+ contractId,
63
+ buyingPolicyId,
64
+ cookie,
65
+ });
62
66
 
63
- const buyingPolicy = await getBuyingPolicyService({
64
- orgUnitId,
65
- contractId,
66
- buyingPolicyId,
67
- cookie,
67
+ return {
68
+ data: {
69
+ buyingPolicy,
70
+ },
71
+ context: {
72
+ clientContext: { cookie, userId, ...clientContext },
73
+ currentOrgUnit,
74
+ currentUser: user,
75
+ currentContract: contract,
76
+ },
77
+ };
68
78
  });
69
-
70
- return {
71
- data: {
72
- buyingPolicy,
73
- },
74
- context: {
75
- clientContext: { cookie, userId, ...clientContext },
76
- currentOrgUnit,
77
- currentUser: user,
78
- currentContract: contract,
79
- },
80
- };
81
79
  };
82
80
 
83
81
  export const loader = withLoaderErrorBoundary(loaderFunction, {
@@ -87,22 +85,23 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
87
85
 
88
86
  const BuyingPolicyDetailsPage = ({
89
87
  data,
90
- context,
91
88
  hasError,
92
89
  error,
93
90
  }: BuyingPolicyDetailsPageData) => (
94
- <BuyerPortalProvider {...context}>
91
+ <>
95
92
  {hasError ? (
96
93
  <ErrorTabsLayout error={error} />
97
94
  ) : (
98
95
  <BuyingPolicyDetailsLayout data={data} />
99
96
  )}
100
- </BuyerPortalProvider>
97
+ </>
101
98
  );
102
99
 
103
- export default withErrorBoundary(BuyingPolicyDetailsPage, {
104
- tags: {
105
- component: "BuyingPolicyDetailsPage",
106
- errorType: "buying_policy_details_error",
107
- },
108
- });
100
+ export default withProviders(
101
+ withErrorBoundary(BuyingPolicyDetailsPage, {
102
+ tags: {
103
+ component: "BuyingPolicyDetailsPage",
104
+ errorType: "buying_policy_details_error",
105
+ },
106
+ })
107
+ );
@@ -5,21 +5,19 @@ import { ScopeCollection } from "../features/collections/types";
5
5
  import { getContractDetailsService } from "../features/contracts/services";
6
6
  import { ContractData } from "../features/contracts/types";
7
7
  import { getOrgUnitBasicDataService } from "../features/org-units/services";
8
- import {
9
- BuyerPortalProvider,
10
- withErrorBoundary,
11
- } from "../features/shared/components";
8
+ import { withErrorBoundary } from "../features/shared/components";
12
9
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
13
10
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
14
11
  import {
15
12
  type ClientContext,
16
- getClientContext,
17
13
  getValidPage,
18
14
  withLoaderErrorBoundary,
15
+ withAuthLoader,
16
+ withProviders,
19
17
  } from "../features/shared/utils";
20
18
 
21
19
  import type { OrgUnitBasicData } from "../features/org-units/types";
22
- import type { LoaderData } from "../features/shared/types";
20
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
23
21
 
24
22
  export type CollectionsData = {
25
23
  collections: ScopeCollection[];
@@ -45,58 +43,58 @@ export type CollectionsQuery = {
45
43
 
46
44
  const loaderFunction = async (
47
45
  data: LoaderData<CollectionsQuery>
48
- ): Promise<CollectionsData> => {
46
+ ): Promise<AuthRouteProps<CollectionsData>> => {
49
47
  const { contractId, orgUnitId, search = "", page: pageString } = data.query;
50
48
 
51
49
  const page = getValidPage(pageString);
52
50
 
53
- const { cookie, ...clientContext } = await getClientContext(data);
54
-
55
- const [currentOrgUnit, contract] = await Promise.all([
56
- getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
57
- getContractDetailsService({ contractId, cookie, unitId: orgUnitId }),
58
- ]);
59
-
60
- const [enabledCollections, allCollections, contractCollections] =
61
- await Promise.all([
62
- getCollectionsFromScopeService({
63
- cookie,
64
- contractId,
65
- unitId: orgUnitId,
66
- filterByScope: true,
67
- name: search,
68
- page,
69
- }),
70
- getCollectionsFromScopeService({
71
- cookie,
72
- contractId,
73
- unitId: orgUnitId,
74
- filterByScope: false,
75
- page: 1,
76
- }),
77
- getCollectionsFromContractService({
78
- contractId,
79
- cookie,
80
- unitId: orgUnitId,
81
- }),
51
+ return withAuthLoader(data, async ({ cookie, ...clientContext }) => {
52
+ const [currentOrgUnit, contract] = await Promise.all([
53
+ getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
54
+ getContractDetailsService({ contractId, cookie, unitId: orgUnitId }),
82
55
  ]);
83
56
 
84
- const isContractEmpty =
85
- !Array.isArray(contractCollections) || contractCollections?.length === 0;
86
- const drawerCollections = allCollections.filter((col) => !col.isEnabled);
57
+ const [enabledCollections, allCollections, contractCollections] =
58
+ await Promise.all([
59
+ getCollectionsFromScopeService({
60
+ cookie,
61
+ contractId,
62
+ unitId: orgUnitId,
63
+ filterByScope: true,
64
+ name: search,
65
+ page,
66
+ }),
67
+ getCollectionsFromScopeService({
68
+ cookie,
69
+ contractId,
70
+ unitId: orgUnitId,
71
+ filterByScope: false,
72
+ page: 1,
73
+ }),
74
+ getCollectionsFromContractService({
75
+ contractId,
76
+ cookie,
77
+ unitId: orgUnitId,
78
+ }),
79
+ ]);
87
80
 
88
- return {
89
- collections: enabledCollections,
90
- drawerCollections,
91
- isContractEmpty,
92
- search,
93
- page,
94
- context: {
95
- clientContext: { cookie, ...clientContext },
96
- currentContract: contract,
97
- currentOrgUnit,
98
- },
99
- };
81
+ const isContractEmpty =
82
+ !Array.isArray(contractCollections) || contractCollections?.length === 0;
83
+ const drawerCollections = allCollections.filter((col) => !col.isEnabled);
84
+
85
+ return {
86
+ collections: enabledCollections,
87
+ drawerCollections,
88
+ isContractEmpty,
89
+ search,
90
+ page,
91
+ context: {
92
+ clientContext: { cookie, ...clientContext },
93
+ currentContract: contract,
94
+ currentOrgUnit,
95
+ },
96
+ };
97
+ });
100
98
  };
101
99
 
102
100
  export const loader = withLoaderErrorBoundary(loaderFunction, {
@@ -105,7 +103,6 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
105
103
  });
106
104
 
107
105
  const CollectionsPage = ({
108
- context,
109
106
  collections,
110
107
  drawerCollections,
111
108
  isContractEmpty,
@@ -114,7 +111,7 @@ const CollectionsPage = ({
114
111
  hasError,
115
112
  error,
116
113
  }: CollectionsData) => (
117
- <BuyerPortalProvider {...context}>
114
+ <>
118
115
  {hasError ? (
119
116
  <ErrorTabsLayout error={error} />
120
117
  ) : (
@@ -126,12 +123,14 @@ const CollectionsPage = ({
126
123
  isContractEmpty={isContractEmpty}
127
124
  />
128
125
  )}
129
- </BuyerPortalProvider>
126
+ </>
130
127
  );
131
128
 
132
- export default withErrorBoundary(CollectionsPage, {
133
- tags: {
134
- component: "CollectionsPage",
135
- errorType: "collections_error",
136
- },
137
- });
129
+ export default withProviders(
130
+ withErrorBoundary(CollectionsPage, {
131
+ tags: {
132
+ component: "CollectionsPage",
133
+ errorType: "collections_error",
134
+ },
135
+ })
136
+ );