@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.
- package/package.json +1 -1
- package/public/buyer-portal-icons.svg +9 -0
- package/src/features/accounting-fields/hooks/useListAccountingFields.ts +2 -1
- package/src/features/addresses/components/AddressLine/AddressLine.tsx +3 -6
- package/src/features/budgets/layouts/BudgetsDetailsLayout/BudgetsDetailsLayout.tsx +4 -9
- package/src/features/budgets/layouts/BudgetsLayout/BudgetsLayout.tsx +2 -9
- package/src/features/buying-policies/layouts/BuyingPoliciesLayout/BuyingPoliciesLayout.tsx +14 -31
- 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/ContractListingLayout.tsx +8 -1
- package/src/features/contracts/layouts/ContractListingLayout/ContractSettingsNav.tsx +39 -63
- package/src/features/contracts/layouts/ContractListingLayout/__tests__/utils.test.ts +51 -0
- package/src/features/contracts/layouts/ContractListingLayout/contract-listing-layout.scss +36 -10
- package/src/features/contracts/layouts/ContractListingLayout/utils.ts +53 -0
- 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 +86 -4
- 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/org-units/layouts/OrgUnitsLayout/OrgUnitsLayout.tsx +2 -9
- package/src/features/roles/layout/RolesLayout/RolesLayout.tsx +2 -9
- 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/BasicDrawer/BasicDrawer.tsx +3 -2
- package/src/features/shared/components/BasicDrawer/BasicDrawerHeading.tsx +4 -1
- 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 +3 -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/hooks/useShellScrollReset.ts +27 -0
- package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +26 -65
- package/src/features/shared/layouts/FinanceTabsLayout/FinanceTabsLayout.tsx +4 -41
- 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/OrgUnitTabsLayout/OrgUnitTabLayout.tsx +4 -39
- package/src/features/shared/layouts/SumaPageLayout/SumaPageLayout.tsx +11 -5
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +17 -8
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebarDrawer.tsx +44 -2
- package/src/features/shared/layouts/SumaPageLayout/suma-sidebar-drawer.scss +147 -5
- package/src/features/shared/localization/__tests__/page-loader-entries.test.ts +2 -2
- package/src/features/shared/utils/__tests__/getRouteKey.test.ts +29 -0
- package/src/features/shared/utils/__tests__/getSumaListingSidebarLinks.test.ts +30 -0
- package/src/features/shared/utils/__tests__/routeLayoutMapping.test.ts +21 -1
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/getRouteKey.ts +4 -0
- package/src/features/shared/utils/getSumaListingSidebarLinks.ts +8 -1
- 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/routeLayoutMapping.ts +17 -4
- package/src/features/shared/utils/withProviders.tsx +5 -1
- package/src/features/shared/utils/withRouteKey.ts +23 -0
- package/src/features/users/layouts/UsersLayout/UsersLayout.tsx +2 -9
- package/src/pages/contract-information.tsx +1 -1
- package/src/pages/contracts.tsx +30 -45
- package/src/pages/home.tsx +17 -25
- package/src/pages/org-unit-details.tsx +15 -102
- 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,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";
|
|
@@ -23,3 +25,4 @@ export { useSetScopeConfig } from "./useSetScopeConfig";
|
|
|
23
25
|
export { useUrlPaginatedSearch } from "./useUrlPaginatedSearch";
|
|
24
26
|
export { useReloadOnBfcacheRestore } from "./useReloadOnBfcacheRestore";
|
|
25
27
|
export { useRefreshPageData } from "./useRefreshPageData";
|
|
28
|
+
export { useShellScrollReset } from "./useShellScrollReset";
|
|
@@ -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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The page shell scrolls its content section, not the window, so Next.js's
|
|
7
|
+
* scroll to the top on navigation doesn't reach it. Resets the section's
|
|
8
|
+
* scroll after every non-shallow route change, as Next.js does for the window.
|
|
9
|
+
*
|
|
10
|
+
* Returns a ref for the `[data-fs-bp-contract-listing-section]` element.
|
|
11
|
+
*/
|
|
12
|
+
export function useShellScrollReset<T extends HTMLElement = HTMLElement>() {
|
|
13
|
+
const sectionRef = useRef<T>(null);
|
|
14
|
+
const { events } = useRouter();
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const resetScroll = (_url: string, { shallow }: { shallow: boolean }) => {
|
|
18
|
+
if (!shallow) sectionRef.current?.scrollTo({ top: 0 });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
events.on("routeChangeComplete", resetScroll);
|
|
22
|
+
|
|
23
|
+
return () => events.off("routeChangeComplete", resetScroll);
|
|
24
|
+
}, [events]);
|
|
25
|
+
|
|
26
|
+
return sectionRef;
|
|
27
|
+
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
|
|
3
|
-
import { DropdownItem } from "@faststore/ui";
|
|
4
|
-
|
|
5
3
|
import { OrgUnitDetailsNavbar } from "../../../org-units/components";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import {
|
|
5
|
+
useBuyerPortal,
|
|
6
|
+
useReloadOnBfcacheRestore,
|
|
7
|
+
useShellScrollReset,
|
|
8
|
+
} from "../../hooks";
|
|
11
9
|
import { SumaSidebar } from "../SumaPageLayout/SumaSidebar";
|
|
12
10
|
|
|
13
11
|
export type ContractTabsLayoutProps = {
|
|
@@ -21,15 +19,13 @@ export type ContractTabsLayoutProps = {
|
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
export const ContractTabsLayout = ({
|
|
24
|
-
pageName,
|
|
25
22
|
loading = false,
|
|
26
23
|
children,
|
|
27
24
|
orgUnitId,
|
|
28
25
|
contractId,
|
|
29
26
|
}: ContractTabsLayoutProps) => {
|
|
30
|
-
const { currentOrgUnit, currentUser, currentContract
|
|
31
|
-
|
|
32
|
-
const { t } = useLocalization();
|
|
27
|
+
const { currentOrgUnit, currentUser, currentContract } = useBuyerPortal();
|
|
28
|
+
const sectionRef = useShellScrollReset();
|
|
33
29
|
|
|
34
30
|
useReloadOnBfcacheRestore();
|
|
35
31
|
|
|
@@ -40,70 +36,35 @@ export const ContractTabsLayout = ({
|
|
|
40
36
|
currentOrgUnit?.customerGroup.customerIds[0] ??
|
|
41
37
|
"";
|
|
42
38
|
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
45
|
-
<div data-fs-bp-contract-listing-page>
|
|
46
|
-
<OrgUnitDetailsNavbar
|
|
47
|
-
orgId={resolvedOrgUnitId}
|
|
48
|
-
contractId={resolvedContractId}
|
|
49
|
-
person={{
|
|
50
|
-
name: currentUser?.name ?? "",
|
|
51
|
-
email: currentUser?.email ?? "",
|
|
52
|
-
}}
|
|
53
|
-
loading={loading}
|
|
54
|
-
sidebarVariant="contract"
|
|
55
|
-
showBackLink
|
|
56
|
-
/>
|
|
57
|
-
<div data-fs-bp-contract-listing-body>
|
|
58
|
-
<SumaSidebar
|
|
59
|
-
orgUnitId={resolvedOrgUnitId}
|
|
60
|
-
contractId={resolvedContractId}
|
|
61
|
-
variant="contract"
|
|
62
|
-
showBackLink
|
|
63
|
-
loading={loading}
|
|
64
|
-
/>
|
|
65
|
-
<section data-fs-bp-contract-listing-section>{children}</section>
|
|
66
|
-
</div>
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
39
|
+
if (!resolvedOrgUnitId) {
|
|
40
|
+
return <>{children}</>;
|
|
69
41
|
}
|
|
70
42
|
|
|
71
|
-
const verticalLinks = getContractSettingsLinks(
|
|
72
|
-
{
|
|
73
|
-
contractId: resolvedContractId,
|
|
74
|
-
orgUnitId: resolvedOrgUnitId,
|
|
75
|
-
},
|
|
76
|
-
t,
|
|
77
|
-
featureFlags
|
|
78
|
-
);
|
|
79
|
-
|
|
80
43
|
return (
|
|
81
|
-
<
|
|
82
|
-
<
|
|
44
|
+
<div data-fs-bp-contract-listing-page>
|
|
45
|
+
<OrgUnitDetailsNavbar
|
|
46
|
+
orgId={resolvedOrgUnitId}
|
|
83
47
|
contractId={resolvedContractId}
|
|
84
|
-
orgUnit={currentOrgUnit}
|
|
85
|
-
pageName={pageName}
|
|
86
48
|
person={{
|
|
87
49
|
name: currentUser?.name ?? "",
|
|
88
|
-
|
|
89
|
-
id: currentUser?.id ?? "",
|
|
50
|
+
email: currentUser?.email ?? "",
|
|
90
51
|
}}
|
|
91
52
|
loading={loading}
|
|
53
|
+
sidebarVariant="contract"
|
|
54
|
+
showBackLink
|
|
92
55
|
/>
|
|
93
|
-
<
|
|
94
|
-
<
|
|
56
|
+
<div data-fs-bp-contract-listing-body>
|
|
57
|
+
<SumaSidebar
|
|
58
|
+
orgUnitId={resolvedOrgUnitId}
|
|
59
|
+
contractId={resolvedContractId}
|
|
60
|
+
variant="contract"
|
|
61
|
+
showBackLink
|
|
95
62
|
loading={loading}
|
|
96
|
-
dropdownOptions={
|
|
97
|
-
<DropdownItem>
|
|
98
|
-
<Icon name="DoNotDisturbOn" width={20} height={20} />
|
|
99
|
-
{t("layouts.actions.removeFromUnit")}
|
|
100
|
-
</DropdownItem>
|
|
101
|
-
}
|
|
102
|
-
verticalLinks={verticalLinks}
|
|
103
|
-
name={currentContract?.name ?? ""}
|
|
104
63
|
/>
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
64
|
+
<section data-fs-bp-contract-listing-section ref={sectionRef}>
|
|
65
|
+
{children}
|
|
66
|
+
</section>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
108
69
|
);
|
|
109
70
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { useLocalization } from "../../localization/LocalizationContext";
|
|
5
|
-
import { getFinanceSettingsLinks } from "../../utils";
|
|
6
|
-
import { BaseTabsLayout } from "../BaseTabsLayout/BaseTabsLayout";
|
|
3
|
+
import { SumaPageLayout } from "../SumaPageLayout/SumaPageLayout";
|
|
7
4
|
|
|
8
5
|
export type FinanceTabsLayoutProps = {
|
|
9
6
|
pageName: string;
|
|
@@ -12,42 +9,8 @@ export type FinanceTabsLayoutProps = {
|
|
|
12
9
|
};
|
|
13
10
|
|
|
14
11
|
export const FinanceTabsLayout = ({
|
|
15
|
-
pageName,
|
|
16
12
|
children,
|
|
17
13
|
loading = false,
|
|
18
|
-
}: FinanceTabsLayoutProps) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const verticalLinks = getFinanceSettingsLinks(
|
|
23
|
-
{
|
|
24
|
-
contractId: currentContract?.id ?? "",
|
|
25
|
-
orgUnitId: currentOrgUnit?.id ?? "",
|
|
26
|
-
},
|
|
27
|
-
t
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<BaseTabsLayout data-fs-bp-finance-tabs-layout>
|
|
32
|
-
<BaseTabsLayout.Navbar
|
|
33
|
-
contractId={currentContract?.id ?? ""}
|
|
34
|
-
orgUnit={currentOrgUnit}
|
|
35
|
-
pageName={pageName}
|
|
36
|
-
person={{
|
|
37
|
-
name: currentUser?.name ?? "",
|
|
38
|
-
roles: currentUser?.roles ?? [],
|
|
39
|
-
id: currentUser?.id ?? "",
|
|
40
|
-
}}
|
|
41
|
-
loading={loading}
|
|
42
|
-
/>
|
|
43
|
-
<BaseTabsLayout.Container>
|
|
44
|
-
<BaseTabsLayout.SidebarMenu
|
|
45
|
-
verticalLinks={verticalLinks}
|
|
46
|
-
showLetterHighlight={false}
|
|
47
|
-
loading={loading}
|
|
48
|
-
/>
|
|
49
|
-
<BaseTabsLayout.Content>{children}</BaseTabsLayout.Content>
|
|
50
|
-
</BaseTabsLayout.Container>
|
|
51
|
-
</BaseTabsLayout>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
14
|
+
}: FinanceTabsLayoutProps) => (
|
|
15
|
+
<SumaPageLayout loading={loading}>{children}</SumaPageLayout>
|
|
16
|
+
);
|
|
@@ -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,9 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { useLocalization } from "../../localization/LocalizationContext";
|
|
5
|
-
import { getOrganizationSettingsLinks } from "../../utils";
|
|
6
|
-
import { BaseTabsLayout } from "../BaseTabsLayout/BaseTabsLayout";
|
|
3
|
+
import { SumaPageLayout } from "../SumaPageLayout/SumaPageLayout";
|
|
7
4
|
|
|
8
5
|
export type OrgUnitTabsLayoutProps = {
|
|
9
6
|
pageName: string;
|
|
@@ -12,40 +9,8 @@ export type OrgUnitTabsLayoutProps = {
|
|
|
12
9
|
};
|
|
13
10
|
|
|
14
11
|
export const OrgUnitTabsLayout = ({
|
|
15
|
-
pageName,
|
|
16
12
|
children,
|
|
17
13
|
loading = false,
|
|
18
|
-
}: OrgUnitTabsLayoutProps) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const verticalLinks = getOrganizationSettingsLinks({
|
|
23
|
-
orgUnitId: currentOrgUnit?.id ?? "",
|
|
24
|
-
contractId: currentContract?.id ?? "",
|
|
25
|
-
t,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<BaseTabsLayout data-fs-bp-org-unit-tabs-layout>
|
|
30
|
-
<BaseTabsLayout.Navbar
|
|
31
|
-
contractId={currentContract?.id ?? ""}
|
|
32
|
-
orgUnit={currentOrgUnit}
|
|
33
|
-
pageName={pageName}
|
|
34
|
-
person={{
|
|
35
|
-
name: currentUser?.name ?? "",
|
|
36
|
-
roles: currentUser?.roles ?? [],
|
|
37
|
-
id: currentUser?.id ?? "",
|
|
38
|
-
}}
|
|
39
|
-
loading={loading}
|
|
40
|
-
/>
|
|
41
|
-
<BaseTabsLayout.Container>
|
|
42
|
-
<BaseTabsLayout.SidebarMenu
|
|
43
|
-
verticalLinks={verticalLinks}
|
|
44
|
-
showLetterHighlight={false}
|
|
45
|
-
loading={loading}
|
|
46
|
-
/>
|
|
47
|
-
<BaseTabsLayout.Content>{children}</BaseTabsLayout.Content>
|
|
48
|
-
</BaseTabsLayout.Container>
|
|
49
|
-
</BaseTabsLayout>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
14
|
+
}: OrgUnitTabsLayoutProps) => (
|
|
15
|
+
<SumaPageLayout loading={loading}>{children}</SumaPageLayout>
|
|
16
|
+
);
|
|
@@ -3,7 +3,11 @@ import type { ReactNode } from "react";
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
5
|
import { OrgUnitDetailsNavbar } from "../../../org-units/components";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
useBuyerPortal,
|
|
8
|
+
useReloadOnBfcacheRestore,
|
|
9
|
+
useShellScrollReset,
|
|
10
|
+
} from "../../hooks";
|
|
7
11
|
import { resolveContractId } from "../../utils";
|
|
8
12
|
|
|
9
13
|
import { SumaSidebar } from "./SumaSidebar";
|
|
@@ -23,13 +27,13 @@ export const SumaPageLayout = ({
|
|
|
23
27
|
sidebarVariant = "unit",
|
|
24
28
|
showBackLink = true,
|
|
25
29
|
}: SumaPageLayoutProps) => {
|
|
26
|
-
const {
|
|
27
|
-
useBuyerPortal();
|
|
30
|
+
const { currentOrgUnit, currentUser, currentContract } = useBuyerPortal();
|
|
28
31
|
const router = useRouter();
|
|
32
|
+
const sectionRef = useShellScrollReset();
|
|
29
33
|
|
|
30
34
|
useReloadOnBfcacheRestore();
|
|
31
35
|
|
|
32
|
-
if (!
|
|
36
|
+
if (!currentOrgUnit?.id) {
|
|
33
37
|
return <>{children}</>;
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -60,7 +64,9 @@ export const SumaPageLayout = ({
|
|
|
60
64
|
showBackLink={showBackLink}
|
|
61
65
|
loading={loading}
|
|
62
66
|
/>
|
|
63
|
-
<section data-fs-bp-contract-listing-section
|
|
67
|
+
<section data-fs-bp-contract-listing-section ref={sectionRef}>
|
|
68
|
+
{children}
|
|
69
|
+
</section>
|
|
64
70
|
</div>
|
|
65
71
|
</div>
|
|
66
72
|
);
|