@vtex/faststore-plugin-buyer-portal 2.0.48 → 2.0.50

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.
Files changed (77) hide show
  1. package/package.json +1 -1
  2. package/public/buyer-portal-icons.svg +9 -0
  3. package/src/features/accounting-fields/hooks/useListAccountingFields.ts +2 -1
  4. package/src/features/addresses/components/AddressLine/AddressLine.tsx +3 -6
  5. package/src/features/budgets/layouts/BudgetsDetailsLayout/BudgetsDetailsLayout.tsx +4 -9
  6. package/src/features/budgets/layouts/BudgetsLayout/BudgetsLayout.tsx +2 -9
  7. package/src/features/buying-policies/layouts/BuyingPoliciesLayout/BuyingPoliciesLayout.tsx +14 -31
  8. package/src/features/contracts/components/ContractListItem/ContractListItem.tsx +0 -5
  9. package/src/features/contracts/components/index.ts +0 -2
  10. package/src/features/contracts/hooks/useSwitchContract.ts +13 -5
  11. package/src/features/contracts/layouts/ContractListingLayout/ContractListingLayout.tsx +8 -1
  12. package/src/features/contracts/layouts/ContractListingLayout/ContractSettingsNav.tsx +39 -63
  13. package/src/features/contracts/layouts/ContractListingLayout/__tests__/utils.test.ts +51 -0
  14. package/src/features/contracts/layouts/ContractListingLayout/contract-listing-layout.scss +36 -10
  15. package/src/features/contracts/layouts/ContractListingLayout/utils.ts +53 -0
  16. package/src/features/org-units/components/CreateOrgUnitDrawer/CreateOrgUnitDrawer.tsx +4 -2
  17. package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +6 -2
  18. package/src/features/org-units/components/OrgUnitBreadcrumb/OrgUnitBreadcrumbLink.tsx +3 -4
  19. package/src/features/org-units/components/OrgUnitDetailsNavbar/OrgUnitDetailsNavbar.tsx +86 -4
  20. package/src/features/org-units/components/OrgUnitHeaderNav/OrgUnitHeaderNav.tsx +13 -2
  21. package/src/features/org-units/components/OrgUnitsHierarchyTree/OrgUnitsHierarchyTree.tsx +18 -10
  22. package/src/features/org-units/components/UpdateOrgUnitDrawer/UpdateOrgUnitDrawer.tsx +4 -2
  23. package/src/features/org-units/hooks/useOrgUnitByUser.ts +2 -0
  24. package/src/features/org-units/layouts/OrgUnitsLayout/OrgUnitsLayout.tsx +2 -9
  25. package/src/features/roles/layout/RolesLayout/RolesLayout.tsx +2 -9
  26. package/src/features/shared/components/BasicCard/BasicCard.tsx +6 -3
  27. package/src/features/shared/components/BasicCard/BasicCardLine.tsx +3 -5
  28. package/src/features/shared/components/BasicDrawer/BasicDrawer.tsx +3 -2
  29. package/src/features/shared/components/BasicDrawer/BasicDrawerHeading.tsx +4 -1
  30. package/src/features/shared/components/BuyerPortalProvider/BuyerPortalProvider.tsx +2 -0
  31. package/src/features/shared/components/HeaderInside/HeaderInside.tsx +2 -5
  32. package/src/features/shared/components/InternalTopbar/InternalTopbar.tsx +3 -4
  33. package/src/features/shared/components/PageLoadingIndicator/PageLoadingIndicator.tsx +129 -0
  34. package/src/features/shared/components/PageLoadingIndicator/page-loading-indicator.scss +49 -0
  35. package/src/features/shared/components/Table/TableRow/TableRow.tsx +2 -5
  36. package/src/features/shared/components/VerticalNav/VerticalNavLink.tsx +11 -10
  37. package/src/features/shared/hooks/index.ts +3 -0
  38. package/src/features/shared/hooks/useDisplayedOrgUnitName.ts +12 -0
  39. package/src/features/shared/hooks/useDrawerProps.ts +17 -4
  40. package/src/features/shared/hooks/usePageItems.ts +7 -1
  41. package/src/features/shared/hooks/usePageLoading.ts +11 -0
  42. package/src/features/shared/hooks/useQuery.ts +62 -20
  43. package/src/features/shared/hooks/useShellScrollReset.ts +27 -0
  44. package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +26 -65
  45. package/src/features/shared/layouts/FinanceTabsLayout/FinanceTabsLayout.tsx +4 -41
  46. package/src/features/shared/layouts/GlobalLayout/global-layout.scss +1 -0
  47. package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +5 -2
  48. package/src/features/shared/layouts/OrgUnitTabsLayout/OrgUnitTabLayout.tsx +4 -39
  49. package/src/features/shared/layouts/SumaPageLayout/SumaPageLayout.tsx +11 -5
  50. package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +17 -8
  51. package/src/features/shared/layouts/SumaPageLayout/SumaSidebarDrawer.tsx +44 -2
  52. package/src/features/shared/layouts/SumaPageLayout/suma-sidebar-drawer.scss +147 -5
  53. package/src/features/shared/localization/__tests__/page-loader-entries.test.ts +2 -2
  54. package/src/features/shared/utils/__tests__/getRouteKey.test.ts +29 -0
  55. package/src/features/shared/utils/__tests__/getSumaListingSidebarLinks.test.ts +30 -0
  56. package/src/features/shared/utils/__tests__/routeLayoutMapping.test.ts +21 -1
  57. package/src/features/shared/utils/constants.ts +1 -1
  58. package/src/features/shared/utils/getRouteKey.ts +4 -0
  59. package/src/features/shared/utils/getSumaListingSidebarLinks.ts +8 -1
  60. package/src/features/shared/utils/pageLoading/__tests__/keptSidebarDrawer.test.ts +170 -0
  61. package/src/features/shared/utils/pageLoading/__tests__/navigationLevel.test.ts +107 -0
  62. package/src/features/shared/utils/pageLoading/__tests__/orgUnitNames.test.ts +60 -0
  63. package/src/features/shared/utils/pageLoading/__tests__/pageLoadingStore.test.ts +266 -0
  64. package/src/features/shared/utils/pageLoading/keptSidebarDrawer.ts +133 -0
  65. package/src/features/shared/utils/pageLoading/navigationLevel.ts +89 -0
  66. package/src/features/shared/utils/pageLoading/orgUnitNames.ts +49 -0
  67. package/src/features/shared/utils/pageLoading/pageLoadingStore.ts +277 -0
  68. package/src/features/shared/utils/routeLayoutMapping.ts +17 -4
  69. package/src/features/shared/utils/withProviders.tsx +5 -1
  70. package/src/features/shared/utils/withRouteKey.ts +23 -0
  71. package/src/features/users/layouts/UsersLayout/UsersLayout.tsx +2 -9
  72. package/src/pages/contract-information.tsx +1 -1
  73. package/src/pages/contracts.tsx +30 -45
  74. package/src/pages/home.tsx +17 -25
  75. package/src/pages/org-unit-details.tsx +15 -102
  76. package/src/features/contracts/components/ContractSwitchOverlay/ContractSwitchOverlay.tsx +0 -47
  77. package/src/features/contracts/components/ContractSwitchOverlay/contract-switch-overlay.scss +0 -7
@@ -35,7 +35,7 @@ export const DeleteOrgUnitDrawer = ({
35
35
  ...props
36
36
  }: DeleteOrgUnitDrawerProps) => {
37
37
  const router = useRouter();
38
- const { currentOrgUnit, currentContract } = useBuyerPortal();
38
+ const { currentOrgUnit, currentContract, featureFlags } = useBuyerPortal();
39
39
  const contractId = resolveContractId({
40
40
  queryContractId: router.query.contractId,
41
41
  currentContract,
@@ -87,7 +87,11 @@ export const DeleteOrgUnitDrawer = ({
87
87
 
88
88
  if (ids.length >= 2) {
89
89
  const parentId = ids[ids.length - 2];
90
- const redirectUrl = buyerPortalRoutes.orgUnitDetails({
90
+ const redirectUrl = (
91
+ featureFlags?.suma
92
+ ? buyerPortalRoutes.contracts
93
+ : buyerPortalRoutes.orgUnitDetails
94
+ )({
91
95
  orgUnitId: parentId,
92
96
  contractId,
93
97
  });
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
2
 
3
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
4
- import { Link, Tooltip } from "@faststore/ui";
3
+ import { Link_unstable as Link } from "@faststore/core/experimental";
4
+ import { Tooltip } from "@faststore/ui";
5
5
 
6
6
  import { OrgUnitBreadcrumbItemProps } from "../../types";
7
7
 
@@ -11,7 +11,6 @@ export const OrgUnitBreadcrumbLink = ({
11
11
  isLast,
12
12
  enabled,
13
13
  }: OrgUnitBreadcrumbItemProps) => {
14
- const { resolveLink } = useLink();
15
14
  const [truncate, setTruncate] = useState(false);
16
15
  const linkRef = useRef<HTMLParagraphElement | HTMLAnchorElement>(null);
17
16
 
@@ -38,7 +37,7 @@ export const OrgUnitBreadcrumbLink = ({
38
37
  <Link
39
38
  ref={linkRef as React.RefObject<HTMLAnchorElement>}
40
39
  data-fs-bp-breadcrumb-text
41
- href={resolveLink(item)}
40
+ href={item}
42
41
  >
43
42
  {name}
44
43
  </Link>
@@ -1,4 +1,4 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
2
 
3
3
  import storeConfig from "discovery.config";
4
4
 
@@ -27,6 +27,16 @@ import { SumaSidebarDrawer } from "../../../shared/layouts/SumaPageLayout/SumaSi
27
27
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
28
28
  import { doLogout } from "../../../shared/utils";
29
29
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
30
+ import {
31
+ forgetSidebarDrawerKeptAcrossLoad,
32
+ isFullLoadEnd,
33
+ isNavigationStart,
34
+ isSidebarDrawerKept,
35
+ keepSidebarDrawer,
36
+ releaseSidebarDrawer,
37
+ takeSidebarDrawerKeptAcrossLoad,
38
+ } from "../../../shared/utils/pageLoading/keptSidebarDrawer";
39
+ import { pageLoadingStore } from "../../../shared/utils/pageLoading/pageLoadingStore";
30
40
  import { useOrgUnitByUser } from "../../hooks";
31
41
  import { OrgUnitHeaderNav } from "../OrgUnitHeaderNav/OrgUnitHeaderNav";
32
42
 
@@ -55,6 +65,8 @@ export type OrgUnitDetailsNavbarProps = {
55
65
  * value, no Menu button.
56
66
  */
57
67
  sidebarVariant?: SumaSidebarVariant | "full";
68
+ /** Contract the drawer's links point to, when it differs from `contractId`. */
69
+ sidebarContractId?: string;
58
70
  showBackLink?: boolean;
59
71
  /** Page name shown by the `"full"` drawer. */
60
72
  pageName?: string;
@@ -65,6 +77,7 @@ export const OrgUnitDetailsNavbar = ({
65
77
  orgId,
66
78
  contractId = "",
67
79
  sidebarVariant,
80
+ sidebarContractId = contractId,
68
81
  showBackLink = false,
69
82
  pageName = "",
70
83
  }: OrgUnitDetailsNavbarProps) => {
@@ -83,11 +96,77 @@ export const OrgUnitDetailsNavbar = ({
83
96
  ...aboutMenuDrawerProps
84
97
  } = useDrawerProps();
85
98
 
99
+ const [isSidebarDrawerRestored, setIsSidebarDrawerRestored] = useState(
100
+ () => Boolean(sidebarVariant) && isSidebarDrawerKept()
101
+ );
86
102
  const {
87
- open: openSidebarMenu,
103
+ open: openSidebarDrawer,
88
104
  isOpen: isOpenSidebarMenu,
89
105
  ...sidebarMenuDrawerProps
90
- } = useDrawerProps();
106
+ } = useDrawerProps({ initiallyOpen: isSidebarDrawerRestored });
107
+ const { close: closeSidebarDrawer } = sidebarMenuDrawerProps;
108
+ const openSidebarMenu = () => {
109
+ keepSidebarDrawer(pageLoadingStore.getSnapshot());
110
+ setIsSidebarDrawerRestored(false);
111
+ openSidebarDrawer();
112
+ };
113
+
114
+ // A drawer opened during the full load that opened this page (e.g. a
115
+ // contract) shows open. Read after hydration, as the server renders it closed.
116
+ useEffect(() => {
117
+ if (!sidebarVariant || !takeSidebarDrawerKeptAcrossLoad(router.asPath)) {
118
+ return;
119
+ }
120
+
121
+ keepSidebarDrawer();
122
+ setIsSidebarDrawerRestored(true);
123
+ openSidebarDrawer();
124
+ }, []);
125
+
126
+ // A drawer open when a navigation starts closes; one opened after it
127
+ // started stays open when that page shows.
128
+ useEffect(() => {
129
+ let previous = pageLoadingStore.getSnapshot();
130
+
131
+ const unsubscribe = pageLoadingStore.subscribe(() => {
132
+ const next = pageLoadingStore.getSnapshot();
133
+
134
+ if (isNavigationStart(previous, next)) {
135
+ releaseSidebarDrawer();
136
+ closeSidebarDrawer();
137
+ } else if (isFullLoadEnd(previous, next)) {
138
+ forgetSidebarDrawerKeptAcrossLoad();
139
+ }
140
+ previous = next;
141
+ });
142
+
143
+ // A page restored from the back-forward cache was left by a navigation.
144
+ const closeOnRestore = (event: PageTransitionEvent) => {
145
+ if (!event.persisted) return;
146
+ releaseSidebarDrawer();
147
+ closeSidebarDrawer();
148
+ };
149
+
150
+ window.addEventListener("pageshow", closeOnRestore);
151
+
152
+ return () => {
153
+ unsubscribe();
154
+ window.removeEventListener("pageshow", closeOnRestore);
155
+ };
156
+ }, []);
157
+
158
+ // Only the buyer closing it releases it: a header that mounts without the
159
+ // drawer (e.g. while the page loads) doesn't.
160
+ const isSidebarDrawerShown =
161
+ isOpenSidebarMenu && sidebarMenuDrawerProps.fade === "in";
162
+ const wasSidebarDrawerShown = useRef(isSidebarDrawerShown);
163
+
164
+ useEffect(() => {
165
+ if (wasSidebarDrawerShown.current && !isSidebarDrawerShown) {
166
+ releaseSidebarDrawer();
167
+ }
168
+ wasSidebarDrawerShown.current = isSidebarDrawerShown;
169
+ }, [isSidebarDrawerShown]);
91
170
 
92
171
  // `?about=1` opens the About/version drawer and is stripped from the URL.
93
172
  // The header has no visible trigger (QA-11), so this is the way to read
@@ -176,11 +255,14 @@ export const OrgUnitDetailsNavbar = ({
176
255
  {sidebarVariant && sidebarVariant !== "full" && isOpenSidebarMenu && (
177
256
  <SumaSidebarDrawer
178
257
  orgUnitId={orgId}
179
- contractId={contractId}
258
+ contractId={sidebarContractId}
180
259
  variant={sidebarVariant}
181
260
  showBackLink={showBackLink}
182
261
  {...sidebarMenuDrawerProps}
183
262
  isOpen={isOpenSidebarMenu}
263
+ data-fs-bp-suma-sidebar-drawer-kept={
264
+ isSidebarDrawerRestored || undefined
265
+ }
184
266
  />
185
267
  )}
186
268
  </header>
@@ -1,3 +1,5 @@
1
+ import { useEffect } from "react";
2
+
1
3
  import { useRouter } from "next/router";
2
4
 
3
5
  import {
@@ -8,8 +10,10 @@ import {
8
10
  } from "@faststore/ui";
9
11
 
10
12
  import { Icon } from "../../../shared/components";
13
+ import { useDisplayedOrgUnitName } from "../../../shared/hooks";
11
14
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
12
15
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
16
+ import { rememberOrgUnitPath } from "../../../shared/utils/pageLoading/orgUnitNames";
13
17
 
14
18
  import { getOrgUnitHeaderNavItems } from "./getOrgUnitHeaderNavItems";
15
19
 
@@ -44,6 +48,13 @@ export const OrgUnitHeaderNav = ({
44
48
  buildLink: (orgUnitId) => buyerPortalRoutes.contracts({ orgUnitId }),
45
49
  });
46
50
 
51
+ const orgUnitName = useDisplayedOrgUnitName(orgUnit);
52
+
53
+ // The dropdown and the breadcrumb link to the units of this path.
54
+ useEffect(() => {
55
+ rememberOrgUnitPath(orgUnit.path);
56
+ }, [orgUnit.path]);
57
+
47
58
  return (
48
59
  <div data-fs-bp-org-unit-header-nav>
49
60
  <Dropdown>
@@ -60,7 +71,7 @@ export const OrgUnitHeaderNav = ({
60
71
  height={20}
61
72
  data-fs-bp-org-unit-header-nav-icon
62
73
  />
63
- <span data-fs-bp-org-unit-header-nav-name>{orgUnit.name}</span>
74
+ <span data-fs-bp-org-unit-header-nav-name>{orgUnitName}</span>
64
75
  {canNavigate && (
65
76
  <Icon
66
77
  name="ArrowDropDown"
@@ -96,7 +107,7 @@ export const OrgUnitHeaderNav = ({
96
107
  dismissOnClick
97
108
  >
98
109
  <Icon name="FilledFolder" width={20} height={20} />
99
- <span data-fs-bp-org-unit-header-nav-item-name>{orgUnit.name}</span>
110
+ <span data-fs-bp-org-unit-header-nav-item-name>{orgUnitName}</span>
100
111
  </DropdownItem>
101
112
  </DropdownMenu>
102
113
  </Dropdown>
@@ -1,7 +1,7 @@
1
1
  import { useRouter } from "next/router";
2
2
 
3
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
4
- import { Dropdown, Link } from "@faststore/ui";
3
+ import { Link_unstable as Link } from "@faststore/core/experimental";
4
+ import { Dropdown } from "@faststore/ui";
5
5
 
6
6
  import { OrgUnitsDropdownMenu } from "..";
7
7
  import {
@@ -11,6 +11,7 @@ import {
11
11
  } from "../../../shared/components";
12
12
  import { useBuyerPortal } from "../../../shared/hooks";
13
13
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
14
+ import { rememberOrgUnitNames } from "../../../shared/utils/pageLoading/orgUnitNames";
14
15
  import { resolveContractId } from "../../../shared/utils/resolveContractId";
15
16
  import { useChildrenOrgUnits, useOrgUnitStructure } from "../../hooks";
16
17
 
@@ -27,10 +28,9 @@ export const OrgUnitsHierarchyTree = ({
27
28
  readonly,
28
29
  enableChildren = true,
29
30
  }: OrgUnitsHierarchyTreeProps) => {
30
- const { resolveLink } = useLink();
31
31
  const { structure, setNode } = useOrgUnitStructure(orgUnitHierarchyData);
32
32
  const router = useRouter();
33
- const { currentContract, currentOrgUnit } = useBuyerPortal();
33
+ const { currentContract, currentOrgUnit, featureFlags } = useBuyerPortal();
34
34
  const contractId = resolveContractId({
35
35
  queryContractId: router.query.contractId,
36
36
  currentContract,
@@ -59,12 +59,20 @@ export const OrgUnitsHierarchyTree = ({
59
59
  {!readonly && (
60
60
  <Link
61
61
  data-fs-org-unit-item-click-area
62
- href={resolveLink(
63
- buyerPortalRoutes.orgUnitDetails({
64
- orgUnitId: id,
65
- contractId,
66
- })
67
- )}
62
+ onClick={() => rememberOrgUnitNames([{ id, name }])}
63
+ // Under SUMA the unit details route only redirects to the
64
+ // Contracts listing, which made the click load twice.
65
+ href={
66
+ featureFlags?.suma
67
+ ? buyerPortalRoutes.contracts({
68
+ orgUnitId: id,
69
+ contractId,
70
+ })
71
+ : buyerPortalRoutes.orgUnitDetails({
72
+ orgUnitId: id,
73
+ contractId,
74
+ })
75
+ }
68
76
  />
69
77
  )}
70
78
  {enableChildren && (
@@ -34,7 +34,7 @@ export const UpdateOrgUnitDrawer = ({
34
34
  }: UpdateOrgUnitDrawerProps) => {
35
35
  const router = useRouter();
36
36
  const { pushToast } = useUI();
37
- const { currentContract, currentOrgUnit } = useBuyerPortal();
37
+ const { currentContract, currentOrgUnit, featureFlags } = useBuyerPortal();
38
38
  const contractId = resolveContractId({
39
39
  queryContractId: router.query.contractId,
40
40
  currentContract,
@@ -69,7 +69,9 @@ export const UpdateOrgUnitDrawer = ({
69
69
  type="button"
70
70
  onClick={() =>
71
71
  router.push(
72
- buyerPortalRoutes.orgUnitDetails({
72
+ (featureFlags?.suma
73
+ ? buyerPortalRoutes.contracts
74
+ : buyerPortalRoutes.orgUnitDetails)({
73
75
  orgUnitId: id,
74
76
  contractId,
75
77
  })
@@ -9,6 +9,8 @@ export const useOrgUnitByUser = (
9
9
  `api/org-unit-by-user-id/${userId}`,
10
10
  ({ cookie }) => getOrgUnitByUserIdService({ cookie, userId }),
11
11
  {
12
+ // The header shows the user's unit on every page.
13
+ cache: true,
12
14
  ...options,
13
15
  lazy: !userId || options?.lazy,
14
16
  }
@@ -12,7 +12,6 @@ import {
12
12
  useQueryParams,
13
13
  } from "../../../shared/hooks";
14
14
  import { GlobalLayout } from "../../../shared/layouts";
15
- import { OrgUnitTabsLayout } from "../../../shared/layouts/OrgUnitTabsLayout/OrgUnitTabLayout";
16
15
  import { SumaPageLayout } from "../../../shared/layouts/SumaPageLayout/SumaPageLayout";
17
16
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
18
17
  import { CreateOrgUnitDrawer, OrgUnitsHierarchyTree } from "../../components";
@@ -27,7 +26,7 @@ export type OrgUnitsLayoutProps = {
27
26
 
28
27
  export const OrgUnitsLayout = ({ data, search }: OrgUnitsLayoutProps) => {
29
28
  const { setQueryString, removeQueryString } = useQueryParams();
30
- const { currentOrgUnit, featureFlags } = useBuyerPortal();
29
+ const { currentOrgUnit } = useBuyerPortal();
31
30
  const { t } = useLocalization();
32
31
 
33
32
  const { open, ...drawerProps } = useDrawerProps();
@@ -108,13 +107,7 @@ export const OrgUnitsLayout = ({ data, search }: OrgUnitsLayoutProps) => {
108
107
 
109
108
  return (
110
109
  <GlobalLayout>
111
- {featureFlags?.suma ? (
112
- <SumaPageLayout>{orgUnitsSection}</SumaPageLayout>
113
- ) : (
114
- <OrgUnitTabsLayout pageName={t("orgUnits.titles.organization")}>
115
- {orgUnitsSection}
116
- </OrgUnitTabsLayout>
117
- )}
110
+ <SumaPageLayout>{orgUnitsSection}</SumaPageLayout>
118
111
  </GlobalLayout>
119
112
  );
120
113
  };
@@ -3,7 +3,6 @@ import { Table } from "../../../shared/components/Table/Table";
3
3
  import { getTableColumns } from "../../../shared/components/Table/utils/tableColumns";
4
4
  import { useBuyerPortal } from "../../../shared/hooks";
5
5
  import { GlobalLayout } from "../../../shared/layouts";
6
- import { OrgUnitTabsLayout } from "../../../shared/layouts/OrgUnitTabsLayout/OrgUnitTabLayout";
7
6
  import { SumaPageLayout } from "../../../shared/layouts/SumaPageLayout/SumaPageLayout";
8
7
  import { useLocalization } from "../../../shared/localization/LocalizationContext";
9
8
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
@@ -19,7 +18,7 @@ export type RolesLayoutProps = {
19
18
  export const RolesLayout = ({
20
19
  data: { rolesAndPermissions },
21
20
  }: RolesLayoutProps) => {
22
- const { currentOrgUnit, featureFlags } = useBuyerPortal();
21
+ const { currentOrgUnit } = useBuyerPortal();
23
22
  const { t } = useLocalization();
24
23
 
25
24
  const columns = getTableColumns({ nameColumnLabel: t("shared.labels.name") });
@@ -49,13 +48,7 @@ export const RolesLayout = ({
49
48
 
50
49
  return (
51
50
  <GlobalLayout>
52
- {featureFlags?.suma ? (
53
- <SumaPageLayout>{rolesSection}</SumaPageLayout>
54
- ) : (
55
- <OrgUnitTabsLayout pageName={t("shared.labels.organization")}>
56
- {rolesSection}
57
- </OrgUnitTabsLayout>
58
- )}
51
+ <SumaPageLayout>{rolesSection}</SumaPageLayout>
59
52
  </GlobalLayout>
60
53
  );
61
54
  };
@@ -2,8 +2,11 @@ import type { ReactNode } from "react";
2
2
 
3
3
  import { useRouter } from "next/router";
4
4
 
5
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
6
- import { Icon as UIIcon, IconButton, Link } from "@faststore/ui";
5
+ import {
6
+ Link_unstable as Link,
7
+ useLink_unstable as useLink,
8
+ } from "@faststore/core/experimental";
9
+ import { Icon as UIIcon, IconButton } from "@faststore/ui";
7
10
 
8
11
  import { Card, CardBody, CardFooter, CardHeader } from "../Card";
9
12
  import { Icon } from "../Icon";
@@ -60,7 +63,7 @@ export const BasicCard = ({
60
63
  <CardBody>{children}</CardBody>
61
64
  {enableFooter && (
62
65
  <CardFooter>
63
- <Link href={resolvedFooterLink} data-fs-card-footer-link>
66
+ <Link href={footerLink} data-fs-card-footer-link>
64
67
  <span>{footerMessage}</span>
65
68
  </Link>
66
69
  <IconButton
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
4
- import { Dropdown, Link } from "@faststore/ui";
3
+ import { Link_unstable as Link } from "@faststore/core/experimental";
4
+ import { Dropdown } from "@faststore/ui";
5
5
 
6
6
  import { BasicDropdownMenu } from "../BasicDropdownMenu/BasicDropdownMenu";
7
7
 
@@ -18,11 +18,9 @@ export const BasicCardLine = ({
18
18
  menu,
19
19
  href,
20
20
  }: BasicCardLineProps) => {
21
- const { resolveLink } = useLink();
22
-
23
21
  return (
24
22
  <span data-fs-basic-card-line title={title}>
25
- {href && <Link data-fs-basic-card-line-link href={resolveLink(href)} />}
23
+ {href && <Link data-fs-basic-card-line-link href={href} />}
26
24
  {!!icon && <span data-fs-basic-card-line-icon>{icon}</span>}
27
25
  <span data-fs-basic-card-line-title>{title}</span>
28
26
  {!!menu && (
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { type TransitionEventHandler } from "react";
2
2
 
3
3
  import { SlideOver, useFadeEffect } from "@faststore/ui";
4
4
 
@@ -9,8 +9,9 @@ import { BasicDrawerButton } from "./BasicDrawerButton";
9
9
  import { BasicDrawerFooter } from "./BasicDrawerFooter";
10
10
  import { BasicDrawerHeading } from "./BasicDrawerHeading";
11
11
 
12
- export type BasicDrawerProps = Omit<DrawerProps, "open"> & {
12
+ export type BasicDrawerProps = Omit<DrawerProps, "open" | "onTransitionEnd"> & {
13
13
  children: React.ReactNode;
14
+ onTransitionEnd: TransitionEventHandler<HTMLDivElement>;
14
15
  id?: string;
15
16
  isOpen: boolean;
16
17
  onDismiss?: () => void;
@@ -8,12 +8,15 @@ export type BasicDrawerHeadingProps = {
8
8
  title: React.ReactNode;
9
9
  onClose?: () => void;
10
10
  onBack?: () => void;
11
+ /** Overrides the default close icon. */
12
+ closeIcon?: React.ReactNode;
11
13
  } & Omit<ComponentProps<"header">, "title">;
12
14
 
13
15
  export const BasicDrawerHeading = ({
14
16
  title,
15
17
  onClose,
16
18
  onBack,
19
+ closeIcon = <Icon name="Close" width={14} height={14} />,
17
20
  ...props
18
21
  }: BasicDrawerHeadingProps) => {
19
22
  return (
@@ -31,7 +34,7 @@ export const BasicDrawerHeading = ({
31
34
  data-fs-bp-basic-drawer-heading-close-button
32
35
  aria-label="close drawer btn"
33
36
  onClick={onClose}
34
- icon={<Icon name="Close" width={14} height={14} />}
37
+ icon={closeIcon}
35
38
  />
36
39
  </header>
37
40
  );
@@ -2,6 +2,7 @@ import { createContext, type ReactNode } from "react";
2
2
 
3
3
  import { LoadingTabsLayout } from "../../layouts";
4
4
  import { ErrorBoundary } from "../ErrorBoundary/ErrorBoundary";
5
+ import { PageLoadingIndicator } from "../PageLoadingIndicator/PageLoadingIndicator";
5
6
 
6
7
  import type { ContractData } from "../../../contracts/types";
7
8
  import type { OrgUnitBasicData } from "../../../org-units/types";
@@ -50,6 +51,7 @@ export const BuyerPortalProvider = ({
50
51
  }: BuyerPortalProviderProps) => {
51
52
  return (
52
53
  <BuyerPortalContext.Provider value={value}>
54
+ <PageLoadingIndicator />
53
55
  <ErrorBoundary>
54
56
  <LoadingTabsLayout>{children}</LoadingTabsLayout>
55
57
  </ErrorBoundary>
@@ -1,7 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
4
- import { Link } from "@faststore/ui";
3
+ import { Link_unstable as Link } from "@faststore/core/experimental";
5
4
 
6
5
  import { Icon } from "../Icon";
7
6
 
@@ -21,12 +20,10 @@ export const HeaderInside = ({
21
20
  info,
22
21
  ...otherProps
23
22
  }: HeaderInsideProps) => {
24
- const { resolveLink } = useLink();
25
-
26
23
  return (
27
24
  <header data-fs-bp-header-inside {...otherProps}>
28
25
  {!!backLink && (
29
- <Link href={resolveLink(backLink)} data-fs-bp-back-link>
26
+ <Link href={backLink} data-fs-bp-back-link>
30
27
  <Icon name="Back" />
31
28
  </Link>
32
29
  )}
@@ -1,8 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { HTMLAttributes } from "react";
3
3
 
4
- import { useLink_unstable as useLink } from "@faststore/core/experimental";
5
- import { IconButton, Dropdown, DropdownButton, Link } from "@faststore/ui";
4
+ import { Link_unstable as Link } from "@faststore/core/experimental";
5
+ import { IconButton, Dropdown, DropdownButton } from "@faststore/ui";
6
6
 
7
7
  import { useBuyerPortal } from "../../hooks/useBuyerPortal";
8
8
  import { useLocalization } from "../../localization/LocalizationContext";
@@ -29,12 +29,11 @@ export const InternalTopBar = ({
29
29
  }: InternapTopBarProps) => {
30
30
  const { currentOrgUnit } = useBuyerPortal();
31
31
  const { t } = useLocalization();
32
- const { resolveLink } = useLink();
33
32
 
34
33
  return (
35
34
  <header data-fs-buyer-portal-topbar>
36
35
  <div data-fs-buyer-portal-topbar-navigation>
37
- <Link href={resolveLink(href)}>
36
+ <Link href={href}>
38
37
  <IconButton
39
38
  size="small"
40
39
  icon={
@@ -0,0 +1,129 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ import Router from "next/router";
4
+
5
+ import { usePageLoading } from "../../hooks/usePageLoading";
6
+ import { useLocalization } from "../../localization/LocalizationContext";
7
+ import {
8
+ LOADING_REGION_SELECTORS,
9
+ SHELL_HEADER_SELECTOR,
10
+ pageLoadingStore,
11
+ } from "../../utils/pageLoading/pageLoadingStore";
12
+
13
+ import type { LoadingRegion } from "../../utils/pageLoading/navigationLevel";
14
+
15
+ /** How fast the bar grows: it reaches ~63% of its run after this time. */
16
+ const PROGRESS_DURATION = 1500;
17
+
18
+ /** The bar never fills up before the page shows. */
19
+ const MAX_PROGRESS = 0.9;
20
+
21
+ const getProgress = (startedAt: number | null) => {
22
+ const elapsed = performance.now() - (startedAt ?? performance.now());
23
+
24
+ return MAX_PROGRESS * (1 - Math.exp(-elapsed / PROGRESS_DURATION));
25
+ };
26
+
27
+ /** Places the bar right below the header, across the loading region. */
28
+ const placeBar = (bar: HTMLElement, region: LoadingRegion) => {
29
+ const header = document.querySelector(SHELL_HEADER_SELECTOR);
30
+ const area = document.querySelector(LOADING_REGION_SELECTORS[region]);
31
+
32
+ if (!header || !area) {
33
+ bar.removeAttribute("data-fs-bp-page-loading-bar-placed");
34
+ return;
35
+ }
36
+
37
+ const { left, width } = area.getBoundingClientRect();
38
+
39
+ bar.style.top = `${Math.max(0, header.getBoundingClientRect().bottom)}px`;
40
+ bar.style.left = `${left}px`;
41
+ bar.style.width = `${width}px`;
42
+ bar.setAttribute("data-fs-bp-page-loading-bar-placed", "");
43
+ };
44
+
45
+ /**
46
+ * The bar shown while a page of the shell loads. It also hides the loading
47
+ * region (see `page-loading-indicator.scss`) and marks it busy.
48
+ */
49
+ export const PageLoadingIndicator = () => {
50
+ const { t } = useLocalization();
51
+ const { phase, region, startedAt } = usePageLoading();
52
+ const barRef = useRef<HTMLDivElement>(null);
53
+ const isLoading = phase !== "idle";
54
+
55
+ useEffect(() => {
56
+ pageLoadingStore.attach(Router.events, () => Router.asPath);
57
+ pageLoadingStore.init();
58
+
59
+ // A page left by a full load and restored from the back-forward cache
60
+ // comes back as it was left, still loading.
61
+ const showRestoredPage = (event: PageTransitionEvent) => {
62
+ if (event.persisted) pageLoadingStore.fail();
63
+ };
64
+
65
+ window.addEventListener("pageshow", showRestoredPage);
66
+
67
+ return () => window.removeEventListener("pageshow", showRestoredPage);
68
+ }, []);
69
+
70
+ useEffect(() => {
71
+ const bar = barRef.current;
72
+
73
+ if (!bar) return;
74
+
75
+ if (!isLoading) {
76
+ bar.style.transform = "scaleX(1)";
77
+ return;
78
+ }
79
+
80
+ let frame = 0;
81
+
82
+ const tick = () => {
83
+ placeBar(bar, region);
84
+ bar.style.transform = `scaleX(${getProgress(startedAt)})`;
85
+ frame = requestAnimationFrame(tick);
86
+ };
87
+
88
+ tick();
89
+
90
+ return () => cancelAnimationFrame(frame);
91
+ }, [isLoading, region, startedAt]);
92
+
93
+ // The phase is a dependency: the next page mounts a new region element.
94
+ useEffect(() => {
95
+ if (!isLoading) return;
96
+
97
+ const area = document.querySelector(LOADING_REGION_SELECTORS[region]);
98
+
99
+ if (!area) return;
100
+
101
+ const previous = area.getAttribute("aria-busy");
102
+
103
+ area.setAttribute("aria-busy", "true");
104
+
105
+ return () => {
106
+ if (previous === null) {
107
+ area.removeAttribute("aria-busy");
108
+ } else {
109
+ area.setAttribute("aria-busy", previous);
110
+ }
111
+ };
112
+ }, [isLoading, region, phase]);
113
+
114
+ return (
115
+ <div
116
+ data-fs-bp-page-loading
117
+ data-fs-bp-page-loading-phase={phase}
118
+ data-fs-bp-page-loading-region={isLoading ? region : undefined}
119
+ >
120
+ <div
121
+ ref={barRef}
122
+ role="progressbar"
123
+ aria-label={t("shared.labels.loading")}
124
+ aria-hidden={!isLoading}
125
+ data-fs-bp-page-loading-bar
126
+ />
127
+ </div>
128
+ );
129
+ };