@vtex/faststore-plugin-buyer-portal 2.0.48 → 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/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 +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 -9
- 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/hooks/index.ts +1 -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/SumaPageLayout.tsx +11 -5
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +17 -8
- 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/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/getSumaListingSidebarLinks.ts +8 -1
- 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
|
@@ -8,9 +8,12 @@ export const getSumaListingSidebarLinks = (
|
|
|
8
8
|
{
|
|
9
9
|
orgUnitId,
|
|
10
10
|
contractId,
|
|
11
|
+
organizationContractId,
|
|
11
12
|
}: {
|
|
12
13
|
orgUnitId: string;
|
|
13
14
|
contractId: string;
|
|
15
|
+
/** `contractId` for the Organization links; omitted under SUMA. */
|
|
16
|
+
organizationContractId?: string;
|
|
14
17
|
},
|
|
15
18
|
t: LocalizeFn
|
|
16
19
|
) => [
|
|
@@ -18,6 +21,10 @@ export const getSumaListingSidebarLinks = (
|
|
|
18
21
|
name: t("layouts.navigation.contracts"),
|
|
19
22
|
link: buyerPortalRoutes.contracts({ orgUnitId }),
|
|
20
23
|
},
|
|
21
|
-
...getOrganizationSettingsLinks({
|
|
24
|
+
...getOrganizationSettingsLinks({
|
|
25
|
+
orgUnitId,
|
|
26
|
+
contractId: organizationContractId,
|
|
27
|
+
t,
|
|
28
|
+
}),
|
|
22
29
|
...getFinanceSettingsLinks({ orgUnitId, contractId }, t),
|
|
23
30
|
];
|
|
@@ -49,6 +49,18 @@ export const ROUTE_TABS_LAYOUT_MAPPING: Record<string, RouteTabsLayoutConfig> =
|
|
|
49
49
|
pageName: "layouts.tabs.contract",
|
|
50
50
|
pageTitle: "layouts.titles.accountingField",
|
|
51
51
|
},
|
|
52
|
+
// Budgets have no own title key in the shared entry, so the skeleton and
|
|
53
|
+
// error states use the sidebar label.
|
|
54
|
+
"/pvt/organization-account/budgets/[orgUnitId]/[contractId]": {
|
|
55
|
+
layout: "FinanceTabsLayout",
|
|
56
|
+
pageName: "layouts.tabs.financeAndCompliance",
|
|
57
|
+
pageTitle: "layouts.navigation.budgets",
|
|
58
|
+
},
|
|
59
|
+
"/pvt/organization-account/budgets/[orgUnitId]/[contractId]/[budgetId]": {
|
|
60
|
+
layout: "FinanceTabsLayout",
|
|
61
|
+
pageName: "layouts.tabs.financeAndCompliance",
|
|
62
|
+
pageTitle: "layouts.navigation.budgets",
|
|
63
|
+
},
|
|
52
64
|
"/pvt/organization-account/buying-policies/[orgUnitId]/[contractId]": {
|
|
53
65
|
layout: "FinanceTabsLayout",
|
|
54
66
|
pageName: "layouts.tabs.financeAndCompliance",
|
|
@@ -86,12 +98,13 @@ export const ROUTE_TABS_LAYOUT_MAPPING: Record<string, RouteTabsLayoutConfig> =
|
|
|
86
98
|
pageName: "layouts.tabs.organization",
|
|
87
99
|
pageTitle: "layouts.titles.organizationDetails",
|
|
88
100
|
},
|
|
101
|
+
// Redirects to the unit's Contracts listing, so it shows that skeleton.
|
|
89
102
|
"/pvt/organization-account/org-unit/[orgUnitId]": {
|
|
90
|
-
layout: "
|
|
91
|
-
pageName: "layouts.
|
|
92
|
-
pageTitle: "layouts.
|
|
103
|
+
layout: "ContractListingLayout",
|
|
104
|
+
pageName: "layouts.navigation.contracts",
|
|
105
|
+
pageTitle: "layouts.navigation.contracts",
|
|
93
106
|
},
|
|
94
|
-
//
|
|
107
|
+
// Unit landing page: same skeleton shape as the destination listing,
|
|
95
108
|
// so going back from a contract page is not a blank frame.
|
|
96
109
|
"/pvt/organization-account/contracts/[orgUnitId]": {
|
|
97
110
|
layout: "ContractListingLayout",
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
usePageItems,
|
|
20
20
|
} from "../../../shared/hooks";
|
|
21
21
|
import { GlobalLayout } from "../../../shared/layouts";
|
|
22
|
-
import { OrgUnitTabsLayout } from "../../../shared/layouts/OrgUnitTabsLayout/OrgUnitTabLayout";
|
|
23
22
|
import { SumaPageLayout } from "../../../shared/layouts/SumaPageLayout/SumaPageLayout";
|
|
24
23
|
import { useLocalization } from "../../../shared/localization/LocalizationContext";
|
|
25
24
|
import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
|
|
@@ -55,7 +54,7 @@ export const UsersLayout = ({
|
|
|
55
54
|
page,
|
|
56
55
|
});
|
|
57
56
|
|
|
58
|
-
const { currentOrgUnit
|
|
57
|
+
const { currentOrgUnit } = useBuyerPortal();
|
|
59
58
|
const { t } = useLocalization();
|
|
60
59
|
|
|
61
60
|
const {
|
|
@@ -246,13 +245,7 @@ export const UsersLayout = ({
|
|
|
246
245
|
|
|
247
246
|
return (
|
|
248
247
|
<GlobalLayout>
|
|
249
|
-
{
|
|
250
|
-
<SumaPageLayout>{usersSection}</SumaPageLayout>
|
|
251
|
-
) : (
|
|
252
|
-
<OrgUnitTabsLayout pageName={t("shared.navigation.organization")}>
|
|
253
|
-
{usersSection}
|
|
254
|
-
</OrgUnitTabsLayout>
|
|
255
|
-
)}
|
|
248
|
+
<SumaPageLayout>{usersSection}</SumaPageLayout>
|
|
256
249
|
</GlobalLayout>
|
|
257
250
|
);
|
|
258
251
|
};
|
package/src/pages/contracts.tsx
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
withAuthLoader,
|
|
12
12
|
withProviders,
|
|
13
13
|
} from "../features/shared/utils";
|
|
14
|
-
import { buyerPortalRoutes } from "../features/shared/utils/buyerPortalRoutes";
|
|
15
14
|
import { getUserByIdService } from "../features/users/services";
|
|
16
15
|
|
|
17
16
|
import type { ContractData } from "../features/contracts/types";
|
|
@@ -51,51 +50,37 @@ const loaderFunction = async (
|
|
|
51
50
|
throw new Error(`Missing required query param: orgUnitId=${orgUnitId}`);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
return withAuthLoader(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
|
|
54
|
+
const [orgUnit, contracts, user, localizationLabels] = await Promise.all([
|
|
55
|
+
getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
|
|
56
|
+
listUnitContractsService({ orgUnitId, cookie }),
|
|
57
|
+
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
58
|
+
getLocalizationLabelsService({
|
|
59
|
+
entryIds: [
|
|
60
|
+
LOCALIZATION_ENTRY_IDS.contracts,
|
|
61
|
+
LOCALIZATION_ENTRY_IDS.orgUnits,
|
|
62
|
+
LOCALIZATION_ENTRY_IDS.addresses,
|
|
63
|
+
LOCALIZATION_ENTRY_IDS.accountingFields,
|
|
64
|
+
],
|
|
65
|
+
locale: data.locale,
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
LOCALIZATION_ENTRY_IDS.contracts,
|
|
75
|
-
LOCALIZATION_ENTRY_IDS.orgUnits,
|
|
76
|
-
LOCALIZATION_ENTRY_IDS.addresses,
|
|
77
|
-
LOCALIZATION_ENTRY_IDS.accountingFields,
|
|
78
|
-
],
|
|
79
|
-
locale: data.locale,
|
|
80
|
-
}),
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
data: {
|
|
85
|
-
orgUnit,
|
|
86
|
-
contracts: contracts ?? [],
|
|
87
|
-
user,
|
|
88
|
-
},
|
|
89
|
-
context: {
|
|
90
|
-
clientContext: { cookie, userId, ...clientContext },
|
|
91
|
-
localization: { labels: localizationLabels },
|
|
92
|
-
// Feeds the SUMA header unit control and the sidebar identity block.
|
|
93
|
-
currentOrgUnit: orgUnit,
|
|
94
|
-
currentUser: user,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
);
|
|
69
|
+
return {
|
|
70
|
+
data: {
|
|
71
|
+
orgUnit,
|
|
72
|
+
contracts: contracts ?? [],
|
|
73
|
+
user,
|
|
74
|
+
},
|
|
75
|
+
context: {
|
|
76
|
+
clientContext: { cookie, userId, ...clientContext },
|
|
77
|
+
localization: { labels: localizationLabels },
|
|
78
|
+
// Feeds the header unit control and the sidebar identity block.
|
|
79
|
+
currentOrgUnit: orgUnit,
|
|
80
|
+
currentUser: user,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
});
|
|
99
84
|
};
|
|
100
85
|
|
|
101
86
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
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(
|