@vtex/faststore-plugin-buyer-portal 2.0.49 → 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.
- package/package.json +1 -1
- package/src/features/accounting-fields/hooks/useListAccountingFields.ts +2 -1
- package/src/features/addresses/components/AddressLine/AddressLine.tsx +3 -6
- package/src/features/contracts/components/ContractListItem/ContractListItem.tsx +0 -5
- package/src/features/contracts/components/index.ts +0 -2
- package/src/features/contracts/hooks/useSwitchContract.ts +13 -5
- package/src/features/contracts/layouts/ContractListingLayout/contract-listing-layout.scss +0 -1
- package/src/features/org-units/components/CreateOrgUnitDrawer/CreateOrgUnitDrawer.tsx +4 -2
- package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +6 -2
- package/src/features/org-units/components/OrgUnitBreadcrumb/OrgUnitBreadcrumbLink.tsx +3 -4
- package/src/features/org-units/components/OrgUnitDetailsNavbar/OrgUnitDetailsNavbar.tsx +82 -3
- package/src/features/org-units/components/OrgUnitHeaderNav/OrgUnitHeaderNav.tsx +13 -2
- package/src/features/org-units/components/OrgUnitsHierarchyTree/OrgUnitsHierarchyTree.tsx +18 -10
- package/src/features/org-units/components/UpdateOrgUnitDrawer/UpdateOrgUnitDrawer.tsx +4 -2
- package/src/features/org-units/hooks/useOrgUnitByUser.ts +2 -0
- package/src/features/shared/components/BasicCard/BasicCard.tsx +6 -3
- package/src/features/shared/components/BasicCard/BasicCardLine.tsx +3 -5
- package/src/features/shared/components/BuyerPortalProvider/BuyerPortalProvider.tsx +2 -0
- package/src/features/shared/components/HeaderInside/HeaderInside.tsx +2 -5
- package/src/features/shared/components/InternalTopbar/InternalTopbar.tsx +3 -4
- package/src/features/shared/components/PageLoadingIndicator/PageLoadingIndicator.tsx +129 -0
- package/src/features/shared/components/PageLoadingIndicator/page-loading-indicator.scss +49 -0
- package/src/features/shared/components/Table/TableRow/TableRow.tsx +2 -5
- package/src/features/shared/components/VerticalNav/VerticalNavLink.tsx +11 -10
- package/src/features/shared/hooks/index.ts +2 -0
- package/src/features/shared/hooks/useDisplayedOrgUnitName.ts +12 -0
- package/src/features/shared/hooks/useDrawerProps.ts +17 -4
- package/src/features/shared/hooks/usePageItems.ts +7 -1
- package/src/features/shared/hooks/usePageLoading.ts +11 -0
- package/src/features/shared/hooks/useQuery.ts +62 -20
- package/src/features/shared/layouts/GlobalLayout/global-layout.scss +1 -0
- package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +5 -2
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebarDrawer.tsx +20 -2
- package/src/features/shared/layouts/SumaPageLayout/suma-sidebar-drawer.scss +14 -0
- package/src/features/shared/utils/__tests__/getRouteKey.test.ts +29 -0
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/getRouteKey.ts +4 -0
- package/src/features/shared/utils/pageLoading/__tests__/keptSidebarDrawer.test.ts +170 -0
- package/src/features/shared/utils/pageLoading/__tests__/navigationLevel.test.ts +107 -0
- package/src/features/shared/utils/pageLoading/__tests__/orgUnitNames.test.ts +60 -0
- package/src/features/shared/utils/pageLoading/__tests__/pageLoadingStore.test.ts +266 -0
- package/src/features/shared/utils/pageLoading/keptSidebarDrawer.ts +133 -0
- package/src/features/shared/utils/pageLoading/navigationLevel.ts +89 -0
- package/src/features/shared/utils/pageLoading/orgUnitNames.ts +49 -0
- package/src/features/shared/utils/pageLoading/pageLoadingStore.ts +277 -0
- package/src/features/shared/utils/withProviders.tsx +5 -1
- package/src/features/shared/utils/withRouteKey.ts +23 -0
- package/src/features/contracts/components/ContractSwitchOverlay/ContractSwitchOverlay.tsx +0 -47
- package/src/features/contracts/components/ContractSwitchOverlay/contract-switch-overlay.scss +0 -7
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The loading region is hidden while a page of the shell loads, and shown
|
|
2
|
+
// at once when it's ready. The animation shows it anyway if the script never
|
|
3
|
+
// runs (e.g. a hard load that fails to hydrate). Descendants can set
|
|
4
|
+
// `visibility: visible` back (e.g. the sidebar's "+" actions), so `opacity`
|
|
5
|
+
// hides them too.
|
|
6
|
+
:root:has([data-fs-bp-page-loading-region="body"])
|
|
7
|
+
[data-fs-bp-contract-listing-body],
|
|
8
|
+
:root:has([data-fs-bp-page-loading-region="content"])
|
|
9
|
+
[data-fs-bp-contract-listing-section]
|
|
10
|
+
> * {
|
|
11
|
+
visibility: hidden;
|
|
12
|
+
opacity: 0;
|
|
13
|
+
animation: bp-page-loading-fallback 0s 10s forwards;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@keyframes bp-page-loading-fallback {
|
|
17
|
+
to {
|
|
18
|
+
visibility: visible;
|
|
19
|
+
opacity: 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[data-fs-bp-page-loading-bar] {
|
|
24
|
+
position: fixed;
|
|
25
|
+
z-index: var(--fs-z-index-highest);
|
|
26
|
+
height: var(--fs-border-width-thickest);
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
background-color: var(--fs-bp-color-accent-2);
|
|
30
|
+
transform: scaleX(0);
|
|
31
|
+
transform-origin: left;
|
|
32
|
+
|
|
33
|
+
&[data-fs-bp-page-loading-bar-placed] {
|
|
34
|
+
visibility: visible;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-fs-bp-page-loading-phase="idle"] & {
|
|
38
|
+
opacity: 0;
|
|
39
|
+
transition: transform var(--fs-transition-timing)
|
|
40
|
+
var(--fs-transition-function),
|
|
41
|
+
opacity var(--fs-transition-timing) var(--fs-transition-function)
|
|
42
|
+
var(--fs-transition-timing);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@media (prefers-reduced-motion: reduce) {
|
|
46
|
+
transform: none !important;
|
|
47
|
+
transition: none;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
|
|
3
3
|
import { Dropdown } from "@faststore/components";
|
|
4
|
-
import {
|
|
5
|
-
import { Link } from "@faststore/ui";
|
|
4
|
+
import { Link_unstable as Link } from "@faststore/core/experimental";
|
|
6
5
|
|
|
7
6
|
import { BasicDropdownMenu } from "../../BasicDropdownMenu/BasicDropdownMenu";
|
|
8
7
|
import { Icon } from "../../Icon";
|
|
@@ -39,8 +38,6 @@ export const TableRow = ({
|
|
|
39
38
|
prependColumns,
|
|
40
39
|
...otherProps
|
|
41
40
|
}: TableRowProps) => {
|
|
42
|
-
const { resolveLink } = useLink();
|
|
43
|
-
|
|
44
41
|
const classNames = () => {
|
|
45
42
|
const classes: string[] = [];
|
|
46
43
|
|
|
@@ -104,7 +101,7 @@ export const TableRow = ({
|
|
|
104
101
|
</Table.Cell>
|
|
105
102
|
{href && (
|
|
106
103
|
<Table.Cell data-fs-bp-table-row-link>
|
|
107
|
-
<Link href={
|
|
104
|
+
<Link href={href} onClick={onClick} />
|
|
108
105
|
</Table.Cell>
|
|
109
106
|
)}
|
|
110
107
|
</tr>
|
|
@@ -2,9 +2,9 @@ import React, { type ReactNode } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { Link } from "@faststore/ui";
|
|
5
|
+
import { Link_unstable as Link } from "@faststore/core/experimental";
|
|
7
6
|
|
|
7
|
+
import { usePageLoading } from "../../hooks/usePageLoading";
|
|
8
8
|
import { isNavLinkActive } from "../../utils/isNavLinkActive";
|
|
9
9
|
|
|
10
10
|
export type VerticalNavLinkProps = {
|
|
@@ -19,24 +19,25 @@ export const VerticalNavLink = ({
|
|
|
19
19
|
depth = 0,
|
|
20
20
|
}: VerticalNavLinkProps) => {
|
|
21
21
|
const { asPath } = useRouter();
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const { phase, targetPath } = usePageLoading();
|
|
23
|
+
// The clicked item is active right away, while its page loads.
|
|
24
|
+
const currentPath =
|
|
25
|
+
phase === "navigating" && targetPath ? targetPath : asPath;
|
|
26
|
+
const isActive = isNavLinkActive(currentPath, link);
|
|
26
27
|
|
|
27
28
|
return (
|
|
28
|
-
<li key={
|
|
29
|
+
<li key={link} data-fs-vertical-nav-menu-item>
|
|
29
30
|
<Link
|
|
30
|
-
href={
|
|
31
|
+
href={link}
|
|
31
32
|
data-fs-vertical-nav-menu-link
|
|
32
33
|
data-fs-vertical-nav-menu-link-is-active={isActive}
|
|
33
34
|
style={
|
|
34
35
|
{
|
|
35
36
|
"--fs-bp-vertical-nav-depth": depth > 0 ? depth : 0,
|
|
36
|
-
} as React.
|
|
37
|
+
} as React.ComponentProps<typeof Link>["style"]
|
|
37
38
|
}
|
|
38
39
|
>
|
|
39
|
-
{children}
|
|
40
|
+
<>{children}</>
|
|
40
41
|
</Link>
|
|
41
42
|
</li>
|
|
42
43
|
);
|
|
@@ -14,6 +14,8 @@ export { useAddToScope } from "./useAddToScope";
|
|
|
14
14
|
export { useRemoveFromScope } from "./useRemoveFromScope";
|
|
15
15
|
export { usePageItems, type UsePageItemsProps } from "./usePageItems";
|
|
16
16
|
export { useRouterLoading } from "./useRouterLoading";
|
|
17
|
+
export { usePageLoading } from "./usePageLoading";
|
|
18
|
+
export { useDisplayedOrgUnitName } from "./useDisplayedOrgUnitName";
|
|
17
19
|
export { useLogger } from "./useLogger";
|
|
18
20
|
export { useGetDependenciesVersion } from "./useGetDependenciesVersion";
|
|
19
21
|
export { useAnalytics } from "./analytics/useAnalytics";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getDisplayedOrgUnitName } from "../utils/pageLoading/orgUnitNames";
|
|
2
|
+
|
|
3
|
+
import { usePageLoading } from "./usePageLoading";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The unit's name, or the destination unit's while navigating to another
|
|
7
|
+
* unit, so the header switches to it when the buyer clicks.
|
|
8
|
+
*/
|
|
9
|
+
export const useDisplayedOrgUnitName = (orgUnit: {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}) => getDisplayedOrgUnitName(orgUnit, usePageLoading());
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { useFadeEffect } from "@faststore/ui";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type UseDrawerPropsOptions = {
|
|
6
|
+
// Mounts the drawer already open, without its entry transition.
|
|
7
|
+
initiallyOpen?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useDrawerProps = ({
|
|
11
|
+
initiallyOpen = false,
|
|
12
|
+
}: UseDrawerPropsOptions = {}) => {
|
|
13
|
+
const { fade: currentFade, fadeOut, fadeIn } = useFadeEffect();
|
|
14
|
+
const [isOpen, setIsOpen] = useState(initiallyOpen);
|
|
15
|
+
const [hasMounted, setHasMounted] = useState(false);
|
|
16
|
+
|
|
17
|
+
useEffect(() => setHasMounted(true), []);
|
|
18
|
+
|
|
19
|
+
// `useFadeEffect` starts "out" and fades in after mount.
|
|
20
|
+
const fade = initiallyOpen && !hasMounted ? "in" : currentFade;
|
|
8
21
|
|
|
9
22
|
const close = () => {
|
|
10
23
|
fadeOut();
|
|
@@ -61,7 +61,13 @@ export const usePageItems = <T>({
|
|
|
61
61
|
}, [search]);
|
|
62
62
|
|
|
63
63
|
useEffect(() => {
|
|
64
|
-
|
|
64
|
+
// Callers may pass a new empty array on each render (e.g. `data ?? []`):
|
|
65
|
+
// keeping the previous one skips the re-render, which would loop.
|
|
66
|
+
setItems((previous) =>
|
|
67
|
+
previous.length === 0 && initialItems.length === 0
|
|
68
|
+
? previous
|
|
69
|
+
: initialItems
|
|
70
|
+
);
|
|
65
71
|
setIsLoading(false);
|
|
66
72
|
}, [initialItems]);
|
|
67
73
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
import { pageLoadingStore } from "../utils/pageLoading/pageLoadingStore";
|
|
4
|
+
|
|
5
|
+
/** The loading state of the page navigation, shared by every page. */
|
|
6
|
+
export const usePageLoading = () =>
|
|
7
|
+
useSyncExternalStore(
|
|
8
|
+
pageLoadingStore.subscribe,
|
|
9
|
+
pageLoadingStore.getSnapshot,
|
|
10
|
+
pageLoadingStore.getServerSnapshot
|
|
11
|
+
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback } from "react";
|
|
2
2
|
|
|
3
|
+
import { pageLoadingStore } from "../utils/pageLoading/pageLoadingStore";
|
|
4
|
+
|
|
3
5
|
import { useBuyerPortal } from "./useBuyerPortal";
|
|
4
6
|
|
|
5
7
|
import type { ClientContext } from "../utils";
|
|
@@ -8,6 +10,11 @@ export type QueryOptions<TData> = {
|
|
|
8
10
|
onSuccess?: (data: TData) => void;
|
|
9
11
|
onError?: (error: Error) => void;
|
|
10
12
|
lazy?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Keeps the data across pages: the next page that runs the same query shows
|
|
15
|
+
* it right away and refreshes it in the background, without loading state.
|
|
16
|
+
*/
|
|
17
|
+
cache?: boolean;
|
|
11
18
|
};
|
|
12
19
|
|
|
13
20
|
type QueryResult<T> = {
|
|
@@ -17,40 +24,75 @@ type QueryResult<T> = {
|
|
|
17
24
|
refetch: () => void;
|
|
18
25
|
};
|
|
19
26
|
|
|
27
|
+
const queryCache = new Map<string, unknown>();
|
|
28
|
+
|
|
20
29
|
export const useQuery = <TData>(
|
|
21
30
|
key: string,
|
|
22
31
|
fetcher: (clientContext: ClientContext) => Promise<TData>,
|
|
23
32
|
options?: QueryOptions<TData>
|
|
24
33
|
): QueryResult<TData> => {
|
|
25
|
-
const
|
|
34
|
+
const cachedData =
|
|
35
|
+
options?.cache && queryCache.has(key)
|
|
36
|
+
? (queryCache.get(key) as TData)
|
|
37
|
+
: null;
|
|
38
|
+
const [data, setData] = useState<TData | null>(cachedData);
|
|
26
39
|
const [error, setError] = useState<Error | null>(null);
|
|
27
40
|
const [isLoading, setIsLoading] = useState<boolean>(
|
|
28
|
-
options?.lazy ? false : true
|
|
41
|
+
options?.lazy || cachedData !== null ? false : true
|
|
29
42
|
);
|
|
30
43
|
const { clientContext } = useBuyerPortal();
|
|
31
44
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const load = useCallback(
|
|
46
|
+
async (background: boolean) => {
|
|
47
|
+
if (!background) {
|
|
48
|
+
setIsLoading(true);
|
|
49
|
+
setError(null);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const result = await fetcher(clientContext);
|
|
54
|
+
if (options?.cache) {
|
|
55
|
+
queryCache.set(key, result);
|
|
56
|
+
}
|
|
57
|
+
setData(result);
|
|
58
|
+
options?.onSuccess?.(result);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
const error = err as Error;
|
|
61
|
+
setError(error);
|
|
62
|
+
options?.onError?.(error);
|
|
63
|
+
} finally {
|
|
64
|
+
if (!background) {
|
|
65
|
+
setIsLoading(false);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[
|
|
70
|
+
key,
|
|
71
|
+
fetcher,
|
|
72
|
+
clientContext,
|
|
73
|
+
options?.cache,
|
|
74
|
+
options?.onError,
|
|
75
|
+
options?.onSuccess,
|
|
76
|
+
]
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const fetchData = useCallback(() => load(false), [load]);
|
|
48
80
|
|
|
49
81
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
50
82
|
useEffect(() => {
|
|
51
|
-
if (
|
|
52
|
-
|
|
83
|
+
if (options?.lazy) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (options?.cache && queryCache.has(key)) {
|
|
88
|
+
setData(queryCache.get(key) as TData);
|
|
89
|
+
load(true);
|
|
90
|
+
return;
|
|
53
91
|
}
|
|
92
|
+
|
|
93
|
+
// The page shows once its first requests end (see `pageLoadingStore`).
|
|
94
|
+
const end = pageLoadingStore.track();
|
|
95
|
+
load(false).finally(end);
|
|
54
96
|
}, [key]);
|
|
55
97
|
|
|
56
98
|
return { data, error, isLoading, refetch: fetchData };
|
|
@@ -5,7 +5,7 @@ import { Skeleton } from "@faststore/ui";
|
|
|
5
5
|
import { ContractListingLayout } from "../../../contracts/layouts/ContractListingLayout/ContractListingLayout";
|
|
6
6
|
import { OrgUnitsDetailsLayout } from "../../../org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout";
|
|
7
7
|
import { HeaderInside } from "../../components";
|
|
8
|
-
import { useBuyerPortal, useRouterLoading } from "../../hooks";
|
|
8
|
+
import { useBuyerPortal, usePageLoading, useRouterLoading } from "../../hooks";
|
|
9
9
|
import { useLocalization } from "../../localization/LocalizationContext";
|
|
10
10
|
import {
|
|
11
11
|
getTabsLayoutConfigFromRoute,
|
|
@@ -38,6 +38,7 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
|
|
|
38
38
|
const { t } = useLocalization();
|
|
39
39
|
const { featureFlags, currentOrgUnit, currentUser } = useBuyerPortal();
|
|
40
40
|
const { routerLoading, nextRoute } = useRouterLoading();
|
|
41
|
+
const { handled } = usePageLoading();
|
|
41
42
|
const [shouldShowLoading, setShouldShowLoading] = useState(false);
|
|
42
43
|
const wasLoadingRef = useRef(false);
|
|
43
44
|
|
|
@@ -55,7 +56,9 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
|
|
|
55
56
|
}
|
|
56
57
|
}, [routerLoading]);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
// Pages with the shell keep the current page while the next one loads
|
|
60
|
+
// (see `PageLoadingIndicator`).
|
|
61
|
+
if (handled || !shouldShowLoading || !nextRoute) {
|
|
59
62
|
return <>{children}</>;
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransitionEvent } from "react";
|
|
1
|
+
import type { MouseEvent, TransitionEvent } from "react";
|
|
2
2
|
|
|
3
3
|
import storeConfig from "discovery.config";
|
|
4
4
|
|
|
@@ -33,6 +33,21 @@ export const SumaSidebarDrawer = ({
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
// A link closes the drawer on the click, while the next page loads behind
|
|
37
|
+
// it. Clicks that open a new tab keep it open.
|
|
38
|
+
const closeOnLinkClick = (event: MouseEvent) => {
|
|
39
|
+
const isPlainClick =
|
|
40
|
+
event.button === 0 &&
|
|
41
|
+
!event.metaKey &&
|
|
42
|
+
!event.ctrlKey &&
|
|
43
|
+
!event.shiftKey &&
|
|
44
|
+
!event.altKey;
|
|
45
|
+
|
|
46
|
+
if (isPlainClick && (event.target as Element).closest("a[href]")) {
|
|
47
|
+
close();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
36
51
|
return (
|
|
37
52
|
<BasicDrawer
|
|
38
53
|
data-fs-bp-suma-sidebar-drawer
|
|
@@ -51,7 +66,10 @@ export const SumaSidebarDrawer = ({
|
|
|
51
66
|
onClose={close}
|
|
52
67
|
closeIcon={<Icon name="CloseSymbol" width={20} height={20} />}
|
|
53
68
|
/>
|
|
54
|
-
<BasicDrawer.Body
|
|
69
|
+
<BasicDrawer.Body
|
|
70
|
+
data-fs-bp-suma-sidebar-drawer-body
|
|
71
|
+
onClick={closeOnLinkClick}
|
|
72
|
+
>
|
|
55
73
|
{currentOrgUnit?.name && (
|
|
56
74
|
<div data-fs-bp-suma-sidebar-drawer-unit>
|
|
57
75
|
<Icon name="FilledFolder" width={20} height={20} />
|
|
@@ -163,3 +163,17 @@ $suma-sidebar-drawer-easing: cubic-bezier(0.4, 0, 0.2, 1);
|
|
|
163
163
|
padding: var(--fs-bp-padding-0);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
|
|
167
|
+
// A drawer kept open across a page load shows as it was, without the entry
|
|
168
|
+
// motion or the overlay fading in again.
|
|
169
|
+
[data-fs-bp-suma-sidebar-drawer][data-fs-bp-suma-sidebar-drawer-kept][data-fs-bp-basic-drawer][data-fs-slide-over] {
|
|
170
|
+
animation: none;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@layer theme {
|
|
174
|
+
[data-fs-overlay]:has([data-fs-bp-suma-sidebar-drawer][data-fs-bp-suma-sidebar-drawer-kept][data-fs-slide-over]) {
|
|
175
|
+
@starting-style {
|
|
176
|
+
background-color: var(--fs-bp-color-transparent-overlay) !important;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { getRouteKey } from "../getRouteKey";
|
|
4
|
+
|
|
5
|
+
describe("getRouteKey", () => {
|
|
6
|
+
it("keeps the path", () => {
|
|
7
|
+
expect(getRouteKey("/pvt/organization-account/users/unit-a")).toBe(
|
|
8
|
+
"/pvt/organization-account/users/unit-a"
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("drops the query string", () => {
|
|
13
|
+
expect(
|
|
14
|
+
getRouteKey("/pvt/organization-account/users/unit-a?contractId=c&page=2")
|
|
15
|
+
).toBe("/pvt/organization-account/users/unit-a");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("drops the hash", () => {
|
|
19
|
+
expect(getRouteKey("/pvt/organization-account/roles/unit-a#top")).toBe(
|
|
20
|
+
"/pvt/organization-account/roles/unit-a"
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("tells apart two units of the same page", () => {
|
|
25
|
+
expect(getRouteKey("/pvt/organization-account/users/unit-a")).not.toBe(
|
|
26
|
+
getRouteKey("/pvt/organization-account/users/unit-b")
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
});
|