@vtex/faststore-plugin-buyer-portal 1.1.73 → 1.1.74-experimental.1

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-experimental.1",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- import Link from "next/link";
4
-
5
3
  import { Dropdown } from "@faststore/components";
6
4
 
7
5
  import { BasicDropdownMenu } from "../../BasicDropdownMenu/BasicDropdownMenu";
@@ -36,7 +34,7 @@ export const TableRow = ({
36
34
  enabled = true,
37
35
  ...otherProps
38
36
  }: TableRowProps) => {
39
- const ClickComponent = href ? Link : "button";
37
+ const ClickComponent = href ? "a" : "button";
40
38
 
41
39
  return (
42
40
  <tr
@@ -1,7 +1,5 @@
1
1
  import { useState } from "react";
2
2
 
3
- import { useRouter } from "next/router";
4
-
5
3
  import { useUI } from "@faststore/ui";
6
4
 
7
5
  import { RoleData } from "../../../roles/types";
@@ -29,7 +27,6 @@ export const CreateUserDrawer = ({
29
27
  ...props
30
28
  }: CreateUserDrawerProps) => {
31
29
  const { pushToast } = useUI();
32
- const router = useRouter();
33
30
  const [drawerState, setDrawerState] = useState<
34
31
  "CREATE_USER" | "USER_ALREADY_EXISTS"
35
32
  >("CREATE_USER");
@@ -79,12 +76,10 @@ export const CreateUserDrawer = ({
79
76
  data-fs-bp-toast-view-button
80
77
  type="button"
81
78
  onClick={() => {
82
- router.push(
83
- buyerPortalRoutes.userDetails({
84
- userId: user.id,
85
- orgUnitId: orgUnitId,
86
- })
87
- );
79
+ window.location.href = buyerPortalRoutes.userDetails({
80
+ userId: user.id,
81
+ orgUnitId: orgUnitId,
82
+ });
88
83
  }}
89
84
  >
90
85
  View
@@ -56,12 +56,10 @@ export const UserDropdownMenu = ({
56
56
  <BasicDropdownMenu>
57
57
  <DropdownItem
58
58
  onClick={() =>
59
- route.push(
60
- buyerPortalRoutes.userDetails({
61
- orgUnitId: currentOrgUnit?.id ?? "",
62
- userId: user.id,
63
- })
64
- )
59
+ (window.location.href = buyerPortalRoutes.userDetails({
60
+ orgUnitId: currentOrgUnit?.id ?? "",
61
+ userId: user.id,
62
+ }))
65
63
  }
66
64
  >
67
65
  <Icon name="OpenInNew" {...sizeProps} />
@@ -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
  },