@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
@@ -1,17 +1,15 @@
1
1
  import { getOrgUnitBasicDataService } from "../features/org-units/services";
2
2
  import { getRolesIdsService } from "../features/roles/services";
3
3
  import { RoleData } from "../features/roles/types";
4
- import {
5
- BuyerPortalProvider,
6
- withErrorBoundary,
7
- } from "../features/shared/components";
4
+ import { withErrorBoundary } from "../features/shared/components";
8
5
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
9
6
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
10
7
  import {
11
8
  type ClientContext,
12
- getClientContext,
13
9
  getValidPage,
14
10
  withLoaderErrorBoundary,
11
+ withAuthLoader,
12
+ withProviders,
15
13
  } from "../features/shared/utils";
16
14
  import { UsersLayout } from "../features/users/layouts";
17
15
  import {
@@ -20,7 +18,7 @@ import {
20
18
  } from "../features/users/services";
21
19
 
22
20
  import type { OrgUnitBasicData } from "../features/org-units/types";
23
- import type { LoaderData } from "../features/shared/types";
21
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
24
22
  import type {
25
23
  GetUsersByOrgUnitIdServiceProps,
26
24
  UserData,
@@ -52,77 +50,80 @@ export type UsersPageQuery = GetUsersByOrgUnitIdServiceProps & {
52
50
 
53
51
  const loaderFunction = async (
54
52
  data: LoaderData<UsersPageQuery>
55
- ): Promise<UsersPageData> => {
56
- const { cookie, userId, ...clientContext } = await getClientContext(data);
57
-
53
+ ): Promise<AuthRouteProps<UsersPageData>> => {
58
54
  const { orgUnitId, search = "", page = "1" } = data.query;
59
- const validPage = getValidPage(page);
60
55
 
61
- if (!orgUnitId) {
62
- return {
63
- data: {
64
- users: [],
65
- total: 0,
66
- search: "",
67
- page: 1,
68
- rolesOptions: [],
69
- },
70
- context: {
71
- clientContext: { cookie, userId, ...clientContext },
72
- currentUser: null,
73
- currentOrgUnit: null,
74
- rolesOptions: [],
75
- },
76
- };
77
- }
56
+ return withAuthLoader(
57
+ data,
58
+ async ({ cookie, userId, customerId, ...clientContext }) => {
59
+ const validPage = getValidPage(page);
78
60
 
79
- const [currentOrgUnit, usersResponse, user, rolesOptions] = await Promise.all(
80
- [
81
- getOrgUnitBasicDataService({
82
- id: orgUnitId,
83
- cookie,
84
- }),
85
- getUsersByOrgUnitIdService({
86
- cookie,
87
- orgUnitId,
88
- search: search ?? "",
89
- page: validPage ?? 1,
90
- }),
91
- getUserByIdService({ orgUnitId, userId, cookie }),
92
- getRolesIdsService({
93
- unitId: orgUnitId,
94
- cookie,
95
- customerId: clientContext.customerId,
96
- }),
97
- ]
98
- );
61
+ if (!orgUnitId) {
62
+ return {
63
+ data: {
64
+ users: [],
65
+ total: 0,
66
+ search: "",
67
+ page: 1,
68
+ rolesOptions: [],
69
+ },
70
+ context: {
71
+ clientContext: { cookie, userId, customerId, ...clientContext },
72
+ currentUser: null,
73
+ currentOrgUnit: null,
74
+ rolesOptions: [],
75
+ },
76
+ };
77
+ }
99
78
 
100
- const { users, total } = usersResponse;
79
+ const [currentOrgUnit, usersResponse, user, rolesOptions] =
80
+ await Promise.all([
81
+ getOrgUnitBasicDataService({
82
+ id: orgUnitId,
83
+ cookie,
84
+ }),
85
+ getUsersByOrgUnitIdService({
86
+ cookie,
87
+ orgUnitId,
88
+ search: search ?? "",
89
+ page: validPage ?? 1,
90
+ }),
91
+ getUserByIdService({ orgUnitId, userId, cookie }),
92
+ getRolesIdsService({
93
+ unitId: orgUnitId,
94
+ cookie,
95
+ customerId,
96
+ }),
97
+ ]);
101
98
 
102
- const mappedUsers = users.map((user) => ({
103
- ...user,
104
- id: user.id,
105
- name: user.name ?? user.email ?? "",
106
- email: user.email ?? "",
107
- }));
99
+ const { users, total } = usersResponse;
108
100
 
109
- return {
110
- data: {
111
- users: search
112
- ? mappedUsers.filter((user) => user.name.includes(search))
113
- : mappedUsers,
114
- total,
115
- search: search,
116
- page: validPage,
117
- rolesOptions,
118
- },
119
- context: {
120
- clientContext: { cookie, userId, ...clientContext },
121
- currentOrgUnit,
122
- currentUser: user,
123
- rolesOptions,
124
- },
125
- };
101
+ const mappedUsers = users.map((user) => ({
102
+ ...user,
103
+ id: user.id,
104
+ name: user.name ?? user.email ?? "",
105
+ email: user.email ?? "",
106
+ }));
107
+
108
+ return {
109
+ data: {
110
+ users: search
111
+ ? mappedUsers.filter((user) => user.name.includes(search))
112
+ : mappedUsers,
113
+ total,
114
+ search: search,
115
+ page: validPage,
116
+ rolesOptions,
117
+ },
118
+ context: {
119
+ clientContext: { cookie, userId, customerId, ...clientContext },
120
+ currentOrgUnit,
121
+ currentUser: user,
122
+ rolesOptions,
123
+ },
124
+ };
125
+ }
126
+ );
126
127
  };
127
128
 
128
129
  export const loader = withLoaderErrorBoundary(loaderFunction, {
@@ -130,15 +131,17 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
130
131
  redirectToError: true,
131
132
  });
132
133
 
133
- const UsersPage = ({ data, context, hasError, error }: UsersPageData) => (
134
- <BuyerPortalProvider {...context}>
134
+ const UsersPage = ({ data, hasError, error }: UsersPageData) => (
135
+ <>
135
136
  {hasError ? <ErrorTabsLayout error={error} /> : <UsersLayout data={data} />}
136
- </BuyerPortalProvider>
137
+ </>
137
138
  );
138
139
 
139
- export default withErrorBoundary(UsersPage, {
140
- tags: {
141
- component: "UsersPage",
142
- errorType: "users_error",
143
- },
144
- });
140
+ export default withProviders(
141
+ withErrorBoundary(UsersPage, {
142
+ tags: {
143
+ component: "UsersPage",
144
+ errorType: "users_error",
145
+ },
146
+ })
147
+ );