@vtex/faststore-plugin-buyer-portal 1.1.107 → 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/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/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
|
@@ -3,23 +3,21 @@ import {
|
|
|
3
3
|
getOrgUnitByUserIdService,
|
|
4
4
|
} from "../features/org-units/services";
|
|
5
5
|
import { getRolesIdsService } from "../features/roles/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
|
withLoaderErrorBoundary,
|
|
12
|
+
withAuthLoader,
|
|
13
|
+
withProviders,
|
|
16
14
|
} from "../features/shared/utils";
|
|
17
15
|
import { UserDetailsLayout } from "../features/users/layouts";
|
|
18
16
|
import { getUserByIdService } from "../features/users/services/get-user-by-id.service";
|
|
19
17
|
|
|
20
18
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
21
19
|
import type { RoleData } from "../features/roles/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
|
type UserDetailsPageQuery = {
|
|
@@ -44,49 +42,54 @@ export type UserDetailsPageData = {
|
|
|
44
42
|
|
|
45
43
|
const loaderFunction = async (
|
|
46
44
|
data: LoaderData<UserDetailsPageQuery>
|
|
47
|
-
): Promise<UserDetailsPageData
|
|
48
|
-
const { cookie, customerId, ...clientContext } = await getClientContext(data);
|
|
49
|
-
|
|
45
|
+
): Promise<AuthRouteProps<UserDetailsPageData>> => {
|
|
50
46
|
const { userId, orgUnitId } = data.query;
|
|
51
47
|
|
|
52
|
-
|
|
48
|
+
return withAuthLoader(
|
|
49
|
+
data,
|
|
50
|
+
async ({ cookie, customerId, ...clientContext }) => {
|
|
51
|
+
const user = await getUserByIdService({ orgUnitId, userId, cookie });
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
if (!user) {
|
|
54
|
+
data.res?.writeHead(302, { Location: "/pvt/organization-account" });
|
|
55
|
+
data.res?.end();
|
|
56
|
+
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
const [currentOrgUnit, orgUnitFromUser, rolesOptions] = await Promise.all(
|
|
59
|
+
[
|
|
60
|
+
getOrgUnitBasicDataService({
|
|
61
|
+
id: orgUnitId,
|
|
62
|
+
cookie,
|
|
63
|
+
}),
|
|
64
|
+
getOrgUnitByUserIdService({
|
|
65
|
+
userId,
|
|
66
|
+
cookie,
|
|
67
|
+
}),
|
|
68
|
+
getRolesIdsService({
|
|
69
|
+
unitId: orgUnitId,
|
|
70
|
+
customerId,
|
|
71
|
+
cookie,
|
|
72
|
+
}),
|
|
73
|
+
]
|
|
74
|
+
);
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
return {
|
|
77
|
+
data: {
|
|
78
|
+
user,
|
|
79
|
+
orgUnit: {
|
|
80
|
+
id: orgUnitFromUser?.id ?? "",
|
|
81
|
+
name: orgUnitFromUser?.name ?? "",
|
|
82
|
+
},
|
|
83
|
+
rolesOptions,
|
|
84
|
+
},
|
|
85
|
+
context: {
|
|
86
|
+
clientContext: { cookie, customerId, ...clientContext },
|
|
87
|
+
currentOrgUnit,
|
|
88
|
+
currentUser: user,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
);
|
|
90
93
|
};
|
|
91
94
|
|
|
92
95
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -94,24 +97,21 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
94
97
|
redirectToError: true,
|
|
95
98
|
});
|
|
96
99
|
|
|
97
|
-
const UserDetailsPage = ({
|
|
98
|
-
|
|
99
|
-
context,
|
|
100
|
-
hasError,
|
|
101
|
-
error,
|
|
102
|
-
}: UserDetailsPageData) => (
|
|
103
|
-
<BuyerPortalProvider {...context}>
|
|
100
|
+
const UserDetailsPage = ({ data, hasError, error }: UserDetailsPageData) => (
|
|
101
|
+
<>
|
|
104
102
|
{hasError ? (
|
|
105
103
|
<ErrorTabsLayout error={error} />
|
|
106
104
|
) : (
|
|
107
105
|
<UserDetailsLayout data={data} />
|
|
108
106
|
)}
|
|
109
|
-
|
|
107
|
+
</>
|
|
110
108
|
);
|
|
111
109
|
|
|
112
|
-
export default
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
110
|
+
export default withProviders(
|
|
111
|
+
withErrorBoundary(UserDetailsPage, {
|
|
112
|
+
tags: {
|
|
113
|
+
component: "UserDetailsPage",
|
|
114
|
+
errorType: "user_details_error",
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
);
|
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
|
+
);
|