@vtex/faststore-plugin-buyer-portal 2.0.47 → 2.0.49
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/components/AccountingFieldDropdown/AccountingFieldDropdown.tsx +5 -2
- 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/layouts/ContractListingLayout/ContractListingLayout.tsx +123 -108
- 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 +106 -61
- package/src/features/contracts/layouts/ContractListingLayout/utils.ts +53 -0
- package/src/features/org-units/components/OrgUnitDetailsNavbar/OrgUnitDetailsNavbar.tsx +4 -1
- 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/BasicDrawer/BasicDrawer.tsx +3 -2
- package/src/features/shared/components/BasicDrawer/BasicDrawerHeading.tsx +4 -1
- package/src/features/shared/components/VerticalNav/VerticalNavLink.tsx +3 -10
- package/src/features/shared/components/VerticalNav/VerticalNavTree.tsx +5 -30
- package/src/features/shared/components/VerticalNav/vertical-nav.scss +42 -29
- package/src/features/shared/hooks/index.ts +2 -0
- package/src/features/shared/hooks/useDropdownAlign.ts +27 -0
- 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/OrgUnitTabsLayout/OrgUnitTabLayout.tsx +4 -39
- package/src/features/shared/layouts/SumaPageLayout/FullSidebarNav.tsx +0 -1
- package/src/features/shared/layouts/SumaPageLayout/SumaPageLayout.tsx +13 -7
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +32 -47
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebarDrawer.tsx +25 -1
- package/src/features/shared/layouts/SumaPageLayout/suma-sidebar-drawer.scss +133 -5
- package/src/features/shared/localization/__tests__/page-loader-entries.test.ts +2 -2
- package/src/features/shared/types/VerticalNav.ts +0 -1
- package/src/features/shared/utils/__tests__/getDropdownAlign.test.ts +17 -0
- package/src/features/shared/utils/__tests__/getSumaListingSidebarLinks.test.ts +30 -0
- package/src/features/shared/utils/__tests__/isNavLinkActive.test.ts +117 -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/getDropdownAlign.ts +11 -0
- package/src/features/shared/utils/getSumaListingSidebarLinks.ts +8 -1
- package/src/features/shared/utils/isNavLinkActive.ts +40 -0
- package/src/features/shared/utils/routeLayoutMapping.ts +17 -4
- 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/pages/home.tsx
CHANGED
|
@@ -25,39 +25,31 @@ type HomePageQuery = {
|
|
|
25
25
|
const loaderFunction = async (
|
|
26
26
|
data: LoaderData<HomePageQuery>
|
|
27
27
|
): Promise<AuthRouteProps<HomePageData>> => {
|
|
28
|
-
return withAuthLoader(
|
|
29
|
-
|
|
30
|
-
async ({ userId, cookie, featureFlagsPromise }) => {
|
|
31
|
-
// Reuse the loader's in-flight flags fetch instead of a second request:
|
|
32
|
-
// the landing page depends on `suma`, and two independent fetches could
|
|
33
|
-
// disagree (e.g. one failing closed to `false`) and send the user down
|
|
34
|
-
// the pre-SUMA `/org-unit/[id]` path.
|
|
35
|
-
const [userOrgUnit, featureFlags] = await Promise.all([
|
|
36
|
-
getOrgUnitByUserIdService({ userId, cookie }),
|
|
37
|
-
featureFlagsPromise,
|
|
38
|
-
]);
|
|
28
|
+
return withAuthLoader(data, async ({ userId, cookie }) => {
|
|
29
|
+
const userOrgUnit = await getOrgUnitByUserIdService({ userId, cookie });
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
if (userOrgUnit) {
|
|
32
|
+
// Every account lands on its unit's Contracts listing: the list of
|
|
33
|
+
// contracts, or the single contract's card.
|
|
34
|
+
const location = buyerPortalRoutes.contracts({
|
|
35
|
+
orgUnitId: userOrgUnit.id,
|
|
36
|
+
});
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
data.res?.end();
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
redirected: true,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
data.res?.writeHead(302, { Location: "/" });
|
|
38
|
+
data.res?.writeHead(302, { Location: location });
|
|
54
39
|
data.res?.end();
|
|
55
40
|
|
|
56
41
|
return {
|
|
57
42
|
redirected: true,
|
|
58
43
|
};
|
|
59
44
|
}
|
|
60
|
-
|
|
45
|
+
|
|
46
|
+
data.res?.writeHead(302, { Location: "/" });
|
|
47
|
+
data.res?.end();
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
redirected: true,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
61
53
|
};
|
|
62
54
|
|
|
63
55
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -1,56 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getOrgUnitBasicDataService,
|
|
5
|
-
getOrgUnitSettingsService,
|
|
6
|
-
} from "../features/org-units/services";
|
|
1
|
+
import { useRouter } from "next/router";
|
|
2
|
+
|
|
7
3
|
import { withErrorBoundary } from "../features/shared/components";
|
|
8
|
-
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
9
|
-
import { LOCALIZATION_ENTRY_IDS } from "../features/shared/localization/constants";
|
|
10
|
-
import { getLocalizationLabelsService } from "../features/shared/localization/services/get-localization-labels.service";
|
|
11
|
-
import { getBuyerPortalFeatureFlags } from "../features/shared/services/feature-flags/get-feature-flags.service";
|
|
12
4
|
import {
|
|
13
|
-
type ClientContext,
|
|
14
5
|
withLoaderErrorBoundary,
|
|
15
6
|
withAuthLoader,
|
|
16
7
|
withProviders,
|
|
17
8
|
} from "../features/shared/utils";
|
|
18
9
|
import { buyerPortalRoutes } from "../features/shared/utils/buyerPortalRoutes";
|
|
19
|
-
import { getUserByIdService } from "../features/users/services";
|
|
20
10
|
|
|
21
|
-
import type { ContractData } from "../features/contracts/types";
|
|
22
|
-
import type {
|
|
23
|
-
OrgUnitBasicData,
|
|
24
|
-
OrgUnitSettings,
|
|
25
|
-
} from "../features/org-units/types";
|
|
26
|
-
import type { LabelMap } from "../features/shared/localization/types";
|
|
27
11
|
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
28
|
-
import type { UserData } from "../features/users/types";
|
|
29
12
|
|
|
30
13
|
export type OrgUnitDetailsPageData = {
|
|
31
|
-
redirected
|
|
32
|
-
data: {
|
|
33
|
-
orgUnit: OrgUnitBasicData;
|
|
34
|
-
contracts: ContractData[];
|
|
35
|
-
user: UserData | null;
|
|
36
|
-
settings: OrgUnitSettings;
|
|
37
|
-
};
|
|
38
|
-
context: {
|
|
39
|
-
clientContext: ClientContext;
|
|
40
|
-
localization?: { labels: LabelMap };
|
|
41
|
-
};
|
|
42
|
-
hasError?: boolean;
|
|
43
|
-
error?: {
|
|
44
|
-
error: {
|
|
45
|
-
message: string;
|
|
46
|
-
name: string;
|
|
47
|
-
stack?: string;
|
|
48
|
-
};
|
|
49
|
-
tags: {
|
|
50
|
-
component: string;
|
|
51
|
-
errorType: string;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
14
|
+
redirected: boolean;
|
|
54
15
|
};
|
|
55
16
|
|
|
56
17
|
type OrgUnitDetailsPageQuery = {
|
|
@@ -67,53 +28,16 @@ const loaderFunction = async (
|
|
|
67
28
|
throw new Error(`Missing required query param: orgUnitId=${orgUnitId}`);
|
|
68
29
|
}
|
|
69
30
|
|
|
70
|
-
return withAuthLoader(data, async (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// storefront's "Organization Account" links and the Organizational
|
|
79
|
-
// Units tree point to, so they all land on the same page as the home.
|
|
80
|
-
data.res?.writeHead(302, {
|
|
81
|
-
Location: buyerPortalRoutes.contracts({ orgUnitId }),
|
|
82
|
-
});
|
|
83
|
-
data.res?.end();
|
|
84
|
-
|
|
85
|
-
return { redirected: true } as unknown as OrgUnitDetailsPageData;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const [orgUnit, user, contracts, settings, localizationLabels] =
|
|
89
|
-
await Promise.all([
|
|
90
|
-
getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
|
|
91
|
-
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
92
|
-
getContractsByOrgUnitIdService({ orgUnitId, cookie }),
|
|
93
|
-
getOrgUnitSettingsService({ unitId: orgUnitId, cookie }),
|
|
94
|
-
getLocalizationLabelsService({
|
|
95
|
-
entryIds: [
|
|
96
|
-
LOCALIZATION_ENTRY_IDS.orgUnits,
|
|
97
|
-
LOCALIZATION_ENTRY_IDS.addresses,
|
|
98
|
-
LOCALIZATION_ENTRY_IDS.accountingFields,
|
|
99
|
-
LOCALIZATION_ENTRY_IDS.users,
|
|
100
|
-
],
|
|
101
|
-
locale: data.locale,
|
|
102
|
-
}),
|
|
103
|
-
]);
|
|
31
|
+
return withAuthLoader(data, async () => {
|
|
32
|
+
// A unit's landing page is its Contracts listing. This route is what the
|
|
33
|
+
// storefront's "Organization Account" links and the Organizational Units
|
|
34
|
+
// tree point to, so they all land on the same page as the home.
|
|
35
|
+
data.res?.writeHead(302, {
|
|
36
|
+
Location: buyerPortalRoutes.contracts({ orgUnitId }),
|
|
37
|
+
});
|
|
38
|
+
data.res?.end();
|
|
104
39
|
|
|
105
|
-
return {
|
|
106
|
-
data: {
|
|
107
|
-
contracts,
|
|
108
|
-
orgUnit,
|
|
109
|
-
user,
|
|
110
|
-
settings,
|
|
111
|
-
},
|
|
112
|
-
context: {
|
|
113
|
-
clientContext: { cookie, userId, ...clientContext },
|
|
114
|
-
localization: { labels: localizationLabels },
|
|
115
|
-
},
|
|
116
|
-
};
|
|
40
|
+
return { redirected: true };
|
|
117
41
|
});
|
|
118
42
|
};
|
|
119
43
|
|
|
@@ -122,20 +46,9 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
122
46
|
redirectToError: true,
|
|
123
47
|
});
|
|
124
48
|
|
|
125
|
-
const OrgUnitDetailsPage = ({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
error,
|
|
129
|
-
}: OrgUnitDetailsPageData) => {
|
|
130
|
-
return (
|
|
131
|
-
<>
|
|
132
|
-
{hasError ? (
|
|
133
|
-
<ErrorTabsLayout error={error} />
|
|
134
|
-
) : (
|
|
135
|
-
<OrgUnitsDetailsLayout data={data} />
|
|
136
|
-
)}
|
|
137
|
-
</>
|
|
138
|
-
);
|
|
49
|
+
const OrgUnitDetailsPage = () => {
|
|
50
|
+
useRouter().reload();
|
|
51
|
+
return null;
|
|
139
52
|
};
|
|
140
53
|
|
|
141
54
|
export default withProviders(
|