@vtex/faststore-plugin-buyer-portal 1.1.73 → 1.1.74

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.73",
3
+ "version": "1.1.74",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,5 @@
1
1
  import { Dropdown } from "@faststore/ui";
2
2
 
3
- import { useGetRolesOptions } from "../../../roles/hooks";
4
3
  import {
5
4
  BasicDropdownMenu,
6
5
  HeaderInside,
@@ -13,22 +12,22 @@ import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
13
12
  import { ReassignOrgUnitDrawer, UpdateUserDrawer } from "../../components";
14
13
  import { UserDropdownMenu } from "../../components/UserDropdownMenu/UserDropdownMenu";
15
14
 
15
+ import type { RoleData } from "../../../roles/types";
16
16
  import type { UserData } from "../../types/UserData";
17
17
 
18
18
  export type UserDetailsLayoutProps = {
19
19
  data: {
20
20
  user?: UserData | null;
21
21
  orgUnit: { id: string; name: string };
22
+ rolesOptions?: RoleData[] | null;
22
23
  };
23
24
  };
24
25
 
25
26
  export const UserDetailsLayout = ({
26
- data: { user },
27
+ data: { user, rolesOptions },
27
28
  }: UserDetailsLayoutProps) => {
28
29
  const { currentOrgUnit } = useBuyerPortal();
29
30
 
30
- const { rolesOptions } = useGetRolesOptions(currentOrgUnit?.id ?? "");
31
-
32
31
  const {
33
32
  open: openReassignDrawer,
34
33
  isOpen: isReassignDrawerOpen,
@@ -57,7 +56,7 @@ export const UserDetailsLayout = ({
57
56
  <BasicDropdownMenu.Trigger />
58
57
  <UserDropdownMenu
59
58
  user={{ name: user?.name ?? "", id: user?.id ?? "" }}
60
- rolesOptions={rolesOptions}
59
+ rolesOptions={rolesOptions ?? []}
61
60
  />
62
61
  </Dropdown>
63
62
  </HeaderInside>
@@ -128,7 +127,7 @@ export const UserDetailsLayout = ({
128
127
  )}
129
128
  {isUpdateUserDrawerOpen && (
130
129
  <UpdateUserDrawer
131
- rolesOptions={rolesOptions}
130
+ rolesOptions={rolesOptions ?? []}
132
131
  userId={user?.id ?? ""}
133
132
  orgUnitId={currentOrgUnit?.id ?? ""}
134
133
  isOpen={isUpdateUserDrawerOpen}
@@ -2,12 +2,14 @@ import {
2
2
  getOrgUnitBasicDataService,
3
3
  getOrgUnitByUserIdService,
4
4
  } from "../features/org-units/services";
5
+ import { getRolesIdsService } from "../features/roles/services";
5
6
  import { BuyerPortalProvider } from "../features/shared/components";
6
7
  import { type ClientContext, getClientContext } from "../features/shared/utils";
7
8
  import { UserDetailsLayout } from "../features/users/layouts";
8
9
  import { getUserByIdService } from "../features/users/services/get-user-by-id.service";
9
10
 
10
11
  import type { OrgUnitBasicData } from "../features/org-units/types";
12
+ import type { RoleData } from "../features/roles/types";
11
13
  import type { LoaderData } from "../features/shared/types";
12
14
  import type { UserData } from "../features/users/types";
13
15
 
@@ -20,6 +22,7 @@ export type UserDetailsPageData = {
20
22
  data: {
21
23
  user?: UserData | null;
22
24
  orgUnit: { id: string; name: string };
25
+ rolesOptions?: RoleData[] | null;
23
26
  };
24
27
  context: {
25
28
  clientContext: ClientContext;
@@ -31,7 +34,7 @@ export type UserDetailsPageData = {
31
34
  export async function loader(
32
35
  data: LoaderData<UserDetailsPageQuery>
33
36
  ): Promise<UserDetailsPageData> {
34
- const { cookie, ...clientContext } = await getClientContext(data);
37
+ const { cookie, customerId, ...clientContext } = await getClientContext(data);
35
38
 
36
39
  const { userId, orgUnitId } = data.query;
37
40
 
@@ -42,15 +45,21 @@ export async function loader(
42
45
  data.res?.end();
43
46
  }
44
47
 
45
- const currentOrgUnit = await getOrgUnitBasicDataService({
46
- id: orgUnitId,
47
- cookie,
48
- });
49
-
50
- const orgUnitFromUser = await getOrgUnitByUserIdService({
51
- userId,
52
- cookie,
53
- });
48
+ const [currentOrgUnit, orgUnitFromUser, rolesOptions] = await Promise.all([
49
+ getOrgUnitBasicDataService({
50
+ id: orgUnitId,
51
+ cookie,
52
+ }),
53
+ getOrgUnitByUserIdService({
54
+ userId,
55
+ cookie,
56
+ }),
57
+ getRolesIdsService({
58
+ unitId: orgUnitId,
59
+ customerId,
60
+ cookie,
61
+ }),
62
+ ]);
54
63
 
55
64
  return {
56
65
  data: {
@@ -59,9 +68,10 @@ export async function loader(
59
68
  id: orgUnitFromUser?.id ?? "",
60
69
  name: orgUnitFromUser?.name ?? "",
61
70
  },
71
+ rolesOptions,
62
72
  },
63
73
  context: {
64
- clientContext: { cookie, ...clientContext },
74
+ clientContext: { cookie, customerId, ...clientContext },
65
75
  currentOrgUnit,
66
76
  currentUser: user,
67
77
  },