@vtex/faststore-plugin-buyer-portal 2.0.35 → 2.0.36

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": "2.0.35",
3
+ "version": "2.0.36",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -32,6 +32,7 @@ import {
32
32
  ABOUT_QUERY_PARAM,
33
33
  shouldOpenAboutDrawer,
34
34
  } from "../../../shared/layouts/BaseTabsLayout/about-drawer/aboutQueryParam";
35
+ import { SidebarDrawer } from "../../../shared/layouts/BaseTabsLayout/sidebar-drawer/SidebarDrawer";
35
36
  import { SumaSidebarDrawer } from "../../../shared/layouts/SumaPageLayout/SumaSidebarDrawer";
36
37
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
37
38
  import { doLogout } from "../../../shared/utils";
@@ -51,8 +52,15 @@ export type OrgUnitDetailsNavbarProps = {
51
52
  email?: string;
52
53
  };
53
54
  loading?: boolean;
54
- sidebarVariant?: SumaSidebarVariant;
55
+ /**
56
+ * Navigation shown by the mobile Menu drawer: a SUMA sidebar variant, or
57
+ * `"full"` for the pages that render `BaseTabsLayout.SidebarMenu`. No
58
+ * value, no Menu button.
59
+ */
60
+ sidebarVariant?: SumaSidebarVariant | "full";
55
61
  showBackLink?: boolean;
62
+ /** Page name shown by the `"full"` drawer. */
63
+ pageName?: string;
56
64
  };
57
65
 
58
66
  export const OrgUnitDetailsNavbar = ({
@@ -61,12 +69,14 @@ export const OrgUnitDetailsNavbar = ({
61
69
  contractId = "",
62
70
  sidebarVariant,
63
71
  showBackLink = false,
72
+ pageName = "",
64
73
  }: OrgUnitDetailsNavbarProps) => {
65
74
  const { t } = useLocalization();
66
75
  const { resolveLink } = useLink();
67
76
  const router = useRouter();
68
- const { currentOrgUnit, currentUser, featureFlags } = useBuyerPortal();
69
- const isSuma = Boolean(featureFlags?.suma);
77
+ // Same header for every account, with or without SUMA: nothing here
78
+ // depends on `featureFlags.suma`.
79
+ const { currentOrgUnit, currentUser } = useBuyerPortal();
70
80
  // The unit the user belongs to — not the one being viewed. Feeds both the
71
81
  // unit navigation (how far up the user may go) and the account dropdown.
72
82
  const { orgUnit: userOrgUnit } = useOrgUnitByUser(currentUser?.id ?? "");
@@ -83,8 +93,8 @@ export const OrgUnitDetailsNavbar = ({
83
93
  } = useDrawerProps();
84
94
 
85
95
  // `?about=1` opens the About/version drawer and is stripped from the URL.
86
- // Under SUMA there is no visible trigger (QA-11), so this is the way to
87
- // read the installed versions on any Organization Account page.
96
+ // The header has no visible trigger (QA-11), so this is the way to read
97
+ // the installed versions on any Organization Account page.
88
98
  const aboutParam = router.query[ABOUT_QUERY_PARAM];
89
99
  useEffect(() => {
90
100
  if (!shouldOpenAboutDrawer(aboutParam)) return;
@@ -113,7 +123,7 @@ export const OrgUnitDetailsNavbar = ({
113
123
  {storeConfig.seo.title}
114
124
  </Link>
115
125
  </div>
116
- {isSuma && currentOrgUnit && (
126
+ {currentOrgUnit && (
117
127
  <div data-fs-bp-org-unit-details-navbar-unit>
118
128
  <OrgUnitHeaderNav
119
129
  orgUnit={currentOrgUnit}
@@ -139,30 +149,6 @@ export const OrgUnitDetailsNavbar = ({
139
149
  </Tooltip>
140
150
 
141
151
  <LocalizationIconButtonTrigger />
142
- {!isSuma && (
143
- <Link
144
- target="_blank"
145
- href={resolveLink("/")}
146
- data-fs-bp-org-unit-details-navbar-start-shopping-link
147
- >
148
- {t("layouts.navigation.startShopping")}
149
- </Link>
150
- )}
151
- {!isSuma && (
152
- <IconButton
153
- data-fs-bp-nav-about-trigger
154
- icon={
155
- <Icon
156
- name="CircleQuestionMark"
157
- width={24}
158
- height={24}
159
- weight="regular"
160
- />
161
- }
162
- aria-label={"open about menu"}
163
- onClick={openAboutMenu}
164
- />
165
- )}
166
152
  <Dropdown>
167
153
  <BasicDropdownMenu.Trigger iconSize={20} iconName="AccountCircle" />
168
154
  <DropdownMenu align="right" data-fs-bp-org-unit-details-navbar-menu>
@@ -182,7 +168,15 @@ export const OrgUnitDetailsNavbar = ({
182
168
  unitId={orgId}
183
169
  />
184
170
  )}
185
- {sidebarVariant && isOpenSidebarMenu && (
171
+ {sidebarVariant === "full" && isOpenSidebarMenu && (
172
+ <SidebarDrawer
173
+ orgUnitName={currentOrgUnit?.name ?? ""}
174
+ pageName={pageName}
175
+ {...sidebarMenuDrawerProps}
176
+ isOpen={isOpenSidebarMenu}
177
+ />
178
+ )}
179
+ {sidebarVariant && sidebarVariant !== "full" && isOpenSidebarMenu && (
186
180
  <SumaSidebarDrawer
187
181
  orgUnitId={orgId}
188
182
  contractId={contractId}
@@ -20,8 +20,8 @@
20
20
  }
21
21
 
22
22
  @include u.media(">=tablet") {
23
- padding-left: var(--fs-bp-padding-8);
24
- padding-right: var(--fs-bp-padding-8);
23
+ padding-left: var(--fs-bp-padding-9);
24
+ padding-right: var(--fs-bp-padding-9);
25
25
  }
26
26
 
27
27
  [data-fs-bp-org-unit-details-navbar-heading] {
@@ -73,8 +73,8 @@
73
73
  }
74
74
 
75
75
  // Phones: the unit control takes the logo's place (see `-unit` above). Only
76
- // when that control renders (SUMA with a current unit) — otherwise the logo
77
- // stays.
76
+ // when that control renders (a current unit, or its loading placeholder) —
77
+ // otherwise the logo stays.
78
78
  &:has([data-fs-bp-org-unit-details-navbar-unit]) [data-fs-bp-org-unit-details-navbar-link] {
79
79
  @include u.media("<tablet") {
80
80
  display: none;
@@ -120,38 +120,6 @@
120
120
  }
121
121
  }
122
122
 
123
- [data-fs-bp-org-unit-details-navbar-start-shopping-link] {
124
- display: none;
125
-
126
- padding: 0 var(--fs-bp-padding-5);
127
- @include text-style('action');
128
- color: var(--fs-bp-color-neutral-8);
129
- border-radius: var(--fs-bp-border-radius-full);
130
-
131
- height: var(--fs-bp-spacing-9);
132
- justify-content: center;
133
- align-items: center;
134
- text-decoration: none;
135
-
136
- &:hover {
137
- background-color: var(--fs-bp-color-transparent-0);
138
- }
139
-
140
- &:active {
141
- background-color: var(--fs-bp-color-transparent-1);
142
- }
143
-
144
- @include u.media(">=tablet") {
145
- display: inline-flex;
146
- }
147
- }
148
-
149
- [data-fs-bp-nav-about-trigger] {
150
- --fs-button-height: var(--fs-bp-spacing-9);
151
- --fs-button-border-radius: var(--fs-bp-border-radius-full);
152
- --fs-button-tertiary-text-color: var(--fs-bp-color-black);
153
- }
154
-
155
123
  // Prototype's header tooltip: black, 12px, pill-ish radius, soft shadow.
156
124
  [data-fs-tooltip] {
157
125
  --fs-tooltip-background: var(--fs-bp-color-black);
@@ -8,7 +8,6 @@ import {
8
8
  } from "@faststore/ui";
9
9
 
10
10
  import { Icon } from "../../../shared/components";
11
- import { useBuyerPortal } from "../../../shared/hooks";
12
11
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
13
12
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
14
13
 
@@ -24,10 +23,11 @@ export type OrgUnitHeaderNavProps = {
24
23
  };
25
24
 
26
25
  /**
27
- * Header control of the SUMA shell: a pill with the current Organization Unit
28
- * and, when the user may go up the hierarchy, a dropdown listing the parent
29
- * units (root first) with the current unit highlighted at the bottom.
30
- * Selecting a unit lands on its Contracts listing (unit view).
26
+ * Header control of every Organization Account page: a pill with the current
27
+ * Organization Unit and, when the user may go up the hierarchy, a dropdown
28
+ * listing the parent units (root first) with the current unit highlighted at
29
+ * the bottom. Selecting a unit lands on its Contracts listing, the unit's
30
+ * home page, however many contracts it has.
31
31
  * Mirrors `Header.tsx` in the `multiple-contracts` prototype.
32
32
  */
33
33
  export const OrgUnitHeaderNav = ({
@@ -37,16 +37,11 @@ export const OrgUnitHeaderNav = ({
37
37
  }: OrgUnitHeaderNavProps) => {
38
38
  const { t } = useLocalization();
39
39
  const { push } = useRouter();
40
- const { featureFlags } = useBuyerPortal();
41
-
42
40
  const { ancestors, canNavigate } = getOrgUnitHeaderNavItems({
43
41
  orgUnit,
44
42
  userUnitId,
45
43
  userRoles,
46
- buildLink: (orgUnitId) =>
47
- featureFlags?.suma
48
- ? buyerPortalRoutes.contracts({ orgUnitId })
49
- : buyerPortalRoutes.orgUnitDetails({ orgUnitId }),
44
+ buildLink: (orgUnitId) => buyerPortalRoutes.contracts({ orgUnitId }),
50
45
  });
51
46
 
52
47
  return (
@@ -1,34 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- import dynamic from "next/dynamic";
4
-
5
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
6
- import {
7
- Dropdown,
8
- DropdownMenu,
9
- IconButton,
10
- Link,
11
- Skeleton,
12
- } from "@faststore/ui";
13
-
14
- const LocalizationButton = dynamic(
15
- () =>
16
- import("@faststore/core/experimental").then(
17
- (m) => m.LocalizationButton_unstable
18
- ),
19
- { ssr: false }
20
- );
21
-
22
- import { OrgUnitBreadcrumb } from "../../../org-units/components";
23
- import { ProfileSummary } from "../../../profile/components";
24
- import { BasicDropdownMenu } from "../../components";
25
- import { Icon } from "../../components/Icon";
26
- import { useDrawerProps } from "../../hooks";
27
- import { useLocalization } from "../../localization/LocalizationContext";
28
- import { doLogout } from "../../utils";
29
-
30
- import { AboutDrawer } from "./about-drawer/AboutDrawer";
31
- import { SidebarDrawer } from "./sidebar-drawer/SidebarDrawer";
3
+ import { OrgUnitDetailsNavbar } from "../../../org-units/components";
4
+ import { useBuyerPortal } from "../../hooks";
32
5
 
33
6
  import type { OrgUnitBasicData } from "../../../org-units/types";
34
7
 
@@ -46,103 +19,31 @@ export type NavbarProps = {
46
19
  loading?: boolean;
47
20
  };
48
21
 
22
+ /**
23
+ * The Organization Account has a single header for every account, with or
24
+ * without SUMA: the tabs layouts render the same `OrgUnitDetailsNavbar` as
25
+ * the other pages, with the Menu drawer showing their full navigation.
26
+ */
49
27
  export const Navbar = ({
50
28
  orgUnit,
51
29
  person,
52
30
  pageName,
53
31
  loading = false,
54
32
  contractId = "",
55
- ...otherProps
56
33
  }: NavbarProps) => {
57
- const { t } = useLocalization();
58
- const { resolveLink } = useLink();
59
- const {
60
- open: openSidebarMenu,
61
- isOpen: isOpenSidebarMenuDrawerOpen,
62
- ...deleteOpenSidebarMenuDrawerProps
63
- } = useDrawerProps();
64
-
65
- const {
66
- open: openAboutMenu,
67
- isOpen: isOpenAboutMenu,
68
- ...aboutMenuDrawerProps
69
- } = useDrawerProps();
34
+ const { currentUser } = useBuyerPortal();
70
35
 
71
36
  return (
72
- <>
73
- <nav data-fs-bp-nav {...otherProps}>
74
- <IconButton
75
- data-fs-bp-sidebar-drawer-btn
76
- icon={<Icon name="Menu" width={18} height={12} />}
77
- aria-label={"open sidebar menu"}
78
- onClick={() => {
79
- openSidebarMenu();
80
- }}
81
- />
82
- {loading ? (
83
- <Skeleton
84
- data-fs-bp-nav-breadcrumb-skeleton
85
- size={{ width: "22rem", height: "2.5rem" }}
86
- />
87
- ) : (
88
- <OrgUnitBreadcrumb
89
- orgUnit={orgUnit}
90
- userId={person.id}
91
- userRoles={person.roles ?? []}
92
- maxItems={1}
93
- hasDropdown
94
- />
95
- )}
96
- <div data-fs-bp-nav-menu-actions>
97
- <LocalizationButton
98
- saveLabel={t("shared.buttons.save")}
99
- currencyLabel={t("layouts.labels.currency")}
100
- languageLabel={t("layouts.labels.language")}
101
- icon="Globe"
102
- />
103
- <Link
104
- href={resolveLink("/")}
105
- target="_blank"
106
- data-fs-bp-nav-menu-start-shopping-link
107
- >
108
- {t("layouts.navigation.startShopping")}
109
- </Link>
110
-
111
- <IconButton
112
- data-fs-bp-nav-about-trigger
113
- icon={<Icon name="CircleQuestionMark" width={24} height={24} />}
114
- aria-label={"open about menu"}
115
- onClick={openAboutMenu}
116
- />
117
- <Dropdown>
118
- <BasicDropdownMenu.Trigger iconSize={20} iconName="AccountCircle" />
119
- <DropdownMenu align="right" data-fs-bp-nav-menu>
120
- <ProfileSummary
121
- data-fs-bp-nav-menu-profile-summary
122
- onLogoutClick={doLogout}
123
- orgName={orgUnit?.name ?? ""}
124
- person={person}
125
- />
126
- </DropdownMenu>
127
- </Dropdown>
128
- </div>
129
- </nav>
130
- {isOpenSidebarMenuDrawerOpen && (
131
- <SidebarDrawer
132
- orgUnitName={orgUnit?.name ?? ""}
133
- pageName={pageName}
134
- {...deleteOpenSidebarMenuDrawerProps}
135
- isOpen={isOpenSidebarMenuDrawerOpen}
136
- />
137
- )}
138
- {isOpenAboutMenu && (
139
- <AboutDrawer
140
- contractId={contractId}
141
- {...aboutMenuDrawerProps}
142
- unitId={orgUnit?.id ?? ""}
143
- isOpen={isOpenAboutMenu}
144
- />
145
- )}
146
- </>
37
+ <OrgUnitDetailsNavbar
38
+ orgId={orgUnit?.id ?? ""}
39
+ contractId={contractId}
40
+ person={{
41
+ name: person.name,
42
+ email: person.email ?? currentUser?.email ?? "",
43
+ }}
44
+ loading={loading}
45
+ sidebarVariant="full"
46
+ pageName={pageName}
47
+ />
147
48
  );
148
49
  };
@@ -8,112 +8,6 @@
8
8
  height: 100vh;
9
9
  overflow: hidden;
10
10
 
11
- [data-fs-bp-nav] {
12
- display: flex;
13
- justify-content: space-between;
14
- align-items: center;
15
- background-color: var(--fs-bp-color-neutral-0);
16
- padding: var(--fs-bp-padding-3) var(--fs-bp-padding-5);
17
- border-bottom: 1px solid var(--fs-bp-color-neutral-2);
18
- min-height: 4.25rem;
19
-
20
- @include u.media(">=tablet") {
21
- padding-left: var(--fs-bp-padding-10);
22
- padding-right: var(--fs-bp-padding-10);
23
- }
24
-
25
- [data-fs-localization-button] {
26
- [data-fs-button-wrapper] {
27
- span {
28
- display: inline-flex;
29
- align-items: center;
30
- gap: var(--fs-bp-gap-3);
31
- }
32
- }
33
- }
34
-
35
- [data-fs-bp-breadcrumb-nav] {
36
- [data-fs-bp-breadcrumb-current],
37
- [data-fs-bp-breadcrumb-dropdown-trigger] {
38
- font-size: var(--fs-bp-text-body);
39
-
40
- @include u.media(">=phonemid") {
41
- font-size: var(--fs-bp-text-body-big);
42
- }
43
- }
44
- }
45
-
46
- [data-fs-bp-sidebar-drawer-btn] {
47
- --fs-button-height: var(--fs-bp-spacing-9);
48
- margin-right: var(--fs-bp-margin-2);
49
- }
50
-
51
- [data-fs-bp-nav-breadcrumb-skeleton] {
52
- margin-right: var(--fs-bp-margin-auto);
53
- }
54
-
55
- [data-fs-bp-nav-page-name] {
56
- position: absolute;
57
- left: 50%;
58
- transform: translateX(-50%);
59
-
60
- @include text-style('display-6');
61
- }
62
-
63
- [data-fs-bp-nav-about-trigger] {
64
- --fs-button-height: var(--fs-bp-spacing-9);
65
- --fs-button-border-radius: var(--fs-bp-border-radius-full);
66
- --fs-button-tertiary-text-color: var(--fs-bp-color-black);
67
- }
68
-
69
- [data-fs-bp-nav-account-menu-trigger] {
70
- cursor: pointer;
71
- }
72
-
73
- [data-fs-bp-nav-menu] {
74
- --fs-profile-dropdown-menu-width: 22.5rem;
75
- width: auto;
76
-
77
- background-color: white;
78
-
79
- [data-fs-bp-nav-menu-profile-summary] {
80
- min-width: var(--fs-profile-dropdown-menu-width);
81
- }
82
- }
83
-
84
- [data-fs-bp-nav-menu-actions] {
85
- display: flex;
86
- align-items: center;
87
- gap: var(--fs-bp-gap-4);
88
- }
89
-
90
- [data-fs-bp-nav-menu-start-shopping-link] {
91
- display: none;
92
-
93
- padding: var(--fs-bp-padding-0) var(--fs-bp-padding-5);
94
- @include text-style('action');
95
- color: var(--fs-bp-color-neutral-8);
96
- border-radius: var(--fs-bp-border-radius-full);
97
-
98
- height: var(--fs-bp-spacing-9);
99
- justify-content: center;
100
- align-items: center;
101
- text-decoration: none;
102
-
103
- &:hover {
104
- background-color: var(--fs-bp-color-transparent-0);
105
- }
106
-
107
- &:active {
108
- background-color: var(--fs-bp-color-transparent-1);
109
- }
110
-
111
- @include u.media(">=tablet") {
112
- display: inline-flex;
113
- }
114
- }
115
- }
116
-
117
11
  [data-fs-bp-base-tabs-layout-container] {
118
12
  display: grid;
119
13
  grid-template-columns: 26.25rem 1fr;
@@ -33,4 +33,4 @@ export const STOREFRONT_RESOURCE_NAMES = {
33
33
  export type StorefrontResourceName =
34
34
  (typeof STOREFRONT_RESOURCE_NAMES)[keyof typeof STOREFRONT_RESOURCE_NAMES];
35
35
 
36
- export const CURRENT_VERSION = "2.0.35";
36
+ export const CURRENT_VERSION = "2.0.36";
@@ -51,7 +51,9 @@ const loaderFunction = async (
51
51
 
52
52
  return withAuthLoader(
53
53
  data,
54
- async ({ cookie, customerId, ...clientContext }) => {
54
+ async ({ cookie, customerId, userId: currentUserId, ...clientContext }) => {
55
+ // `userId` (query) is the user being viewed; `currentUserId` is the
56
+ // signed-in user, who feeds the header like on every other page.
55
57
  const user = await getUserByIdService({ orgUnitId, userId, cookie });
56
58
 
57
59
  if (!user) {
@@ -61,6 +63,7 @@ const loaderFunction = async (
61
63
 
62
64
  const [
63
65
  currentOrgUnit,
66
+ currentUser,
64
67
  orgUnitFromUser,
65
68
  rolesOptions,
66
69
  localizationLabels,
@@ -69,6 +72,7 @@ const loaderFunction = async (
69
72
  id: orgUnitId,
70
73
  cookie,
71
74
  }),
75
+ getUserByIdService({ orgUnitId, userId: currentUserId, cookie }),
72
76
  getOrgUnitByUserIdService({
73
77
  userId,
74
78
  cookie,
@@ -94,9 +98,14 @@ const loaderFunction = async (
94
98
  rolesOptions,
95
99
  },
96
100
  context: {
97
- clientContext: { cookie, customerId, ...clientContext },
101
+ clientContext: {
102
+ cookie,
103
+ customerId,
104
+ userId: currentUserId,
105
+ ...clientContext,
106
+ },
98
107
  currentOrgUnit,
99
- currentUser: user,
108
+ currentUser,
100
109
  localization: { labels: localizationLabels },
101
110
  },
102
111
  };