@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.
- package/package.json +1 -1
- package/src/features/custom-fields/layouts/CustomFieldsLayout/CustomFieldsLayout.tsx +1 -0
- package/src/features/shared/clients/Auth.ts +25 -0
- package/src/features/shared/clients/Client.ts +11 -1
- package/src/features/shared/components/withErrorBoundary/withErrorBoundary.tsx +7 -6
- package/src/features/shared/services/index.ts +4 -0
- package/src/features/shared/services/validate-access.service.ts +11 -0
- package/src/features/shared/types/AuthRouteProps.ts +5 -0
- package/src/features/shared/types/index.ts +1 -0
- package/src/features/shared/utils/constants.ts +4 -4
- package/src/features/shared/utils/index.ts +5 -0
- package/src/features/shared/utils/withAuth.tsx +31 -0
- package/src/features/shared/utils/withAuthLoader.ts +47 -0
- package/src/features/shared/utils/withAuthProvider.tsx +38 -0
- package/src/features/shared/utils/withBuyerPortal.tsx +24 -0
- package/src/features/shared/utils/withLoaderErrorBoundary.ts +79 -71
- package/src/features/shared/utils/withProviders.tsx +35 -0
- package/src/pages/address-details.tsx +95 -91
- package/src/pages/addresses.tsx +63 -63
- package/src/pages/budgets-details.tsx +44 -43
- package/src/pages/budgets.tsx +58 -56
- package/src/pages/buying-policies.tsx +84 -78
- package/src/pages/buying-policy-details.tsx +43 -44
- package/src/pages/collections.tsx +59 -60
- package/src/pages/cost-centers.tsx +48 -51
- package/src/pages/credit-cards.tsx +44 -49
- package/src/pages/home.tsx +28 -23
- package/src/pages/org-unit-details.tsx +39 -36
- package/src/pages/org-units.tsx +86 -90
- package/src/pages/payment-methods.tsx +41 -42
- package/src/pages/po-numbers.tsx +43 -46
- package/src/pages/profile.tsx +54 -52
- package/src/pages/releases.tsx +43 -41
- package/src/pages/role-details.tsx +57 -60
- package/src/pages/roles.tsx +42 -39
- package/src/pages/user-details.tsx +58 -58
- package/src/pages/users.tsx +83 -80
package/src/pages/users.tsx
CHANGED
|
@@ -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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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,
|
|
134
|
-
|
|
134
|
+
const UsersPage = ({ data, hasError, error }: UsersPageData) => (
|
|
135
|
+
<>
|
|
135
136
|
{hasError ? <ErrorTabsLayout error={error} /> : <UsersLayout data={data} />}
|
|
136
|
-
|
|
137
|
+
</>
|
|
137
138
|
);
|
|
138
139
|
|
|
139
|
-
export default
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
140
|
+
export default withProviders(
|
|
141
|
+
withErrorBoundary(UsersPage, {
|
|
142
|
+
tags: {
|
|
143
|
+
component: "UsersPage",
|
|
144
|
+
errorType: "users_error",
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
);
|