@vtex/faststore-plugin-buyer-portal 2.0.43 → 2.0.45
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/addresses/utils/countryRules.ts +2 -8
- package/src/features/shared/localization/__tests__/page-loader-entries.test.ts +57 -0
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/pages/org-unit-details.tsx +1 -0
- package/src/pages/org-units.tsx +4 -1
- package/src/pages/profile.tsx +4 -1
package/package.json
CHANGED
|
@@ -53,7 +53,6 @@ export type AddressFormValues = Pick<
|
|
|
53
53
|
export type ClearableAddressField = "state" | "streetNumber" | "neighborhood";
|
|
54
54
|
|
|
55
55
|
const NEIGHBORHOOD_LABEL = "addresses.forms.neighborhood";
|
|
56
|
-
const COLONIA_LABEL = "addresses.forms.colonia";
|
|
57
56
|
|
|
58
57
|
const FALLBACK_RULE: CountryRule = {
|
|
59
58
|
zip: { required: true, pattern: null, renderFirst: false },
|
|
@@ -148,7 +147,7 @@ const COUNTRY_RULES: Record<SupportedCountryCode, CountryRule> = {
|
|
|
148
147
|
neighborhood: {
|
|
149
148
|
visible: true,
|
|
150
149
|
required: true,
|
|
151
|
-
labelKey:
|
|
150
|
+
labelKey: NEIGHBORHOOD_LABEL,
|
|
152
151
|
},
|
|
153
152
|
state: { visible: true, required: true },
|
|
154
153
|
streetAddress: { separated: true },
|
|
@@ -376,12 +375,7 @@ export function collectAddressIssues(
|
|
|
376
375
|
rule.neighborhood.required &&
|
|
377
376
|
isBlank(values.neighborhood)
|
|
378
377
|
) {
|
|
379
|
-
pushRequired(
|
|
380
|
-
"neighborhood",
|
|
381
|
-
rule.neighborhood.labelKey === COLONIA_LABEL
|
|
382
|
-
? "addresses.validation.coloniaRequired"
|
|
383
|
-
: "addresses.validation.neighborhoodRequired"
|
|
384
|
-
);
|
|
378
|
+
pushRequired("neighborhood", "addresses.validation.neighborhoodRequired");
|
|
385
379
|
}
|
|
386
380
|
|
|
387
381
|
return issues;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { LOCALIZATION_ENTRY_IDS } from "../constants";
|
|
8
|
+
|
|
9
|
+
import type { LocalizationFeature } from "../constants";
|
|
10
|
+
|
|
11
|
+
const PAGES_DIR = path.join(
|
|
12
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
13
|
+
"../../../../pages"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// Returns the text of the `entryIds` option passed to getLocalizationLabelsService,
|
|
17
|
+
// e.g. `[LOCALIZATION_ENTRY_IDS.orgUnits, LOCALIZATION_ENTRY_IDS.users]`.
|
|
18
|
+
const getRequestedEntries = (page: string): LocalizationFeature[] => {
|
|
19
|
+
const source = fs.readFileSync(path.join(PAGES_DIR, `${page}.tsx`), "utf8");
|
|
20
|
+
const call = source.match(
|
|
21
|
+
/getLocalizationLabelsService\(\{\s*entryIds:\s*([\s\S]*?)\s*,\s*locale/
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (!call) throw new Error(`No getLocalizationLabelsService call in ${page}`);
|
|
25
|
+
|
|
26
|
+
return Array.from(call[1].matchAll(/LOCALIZATION_ENTRY_IDS\.(\w+)/g)).map(
|
|
27
|
+
([, name]) => name as LocalizationFeature
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Components rendered by a page resolve `t("<feature>.…")` keys from the entries
|
|
32
|
+
// its loader requests. A shared component whose entry is not requested renders
|
|
33
|
+
// the raw key (B2BTEAM-4276, B2BTEAM-4277).
|
|
34
|
+
const REQUIRED_ENTRIES: Record<string, LocalizationFeature[]> = {
|
|
35
|
+
// Sidebar → AccountingFieldDropdown, CreateAccountingFieldDrawer
|
|
36
|
+
profile: ["accountingFields"],
|
|
37
|
+
// OrgUnitsDropdownMenu → CreateUserDrawerSelector → CreateUserDrawer*
|
|
38
|
+
"org-units": ["users"],
|
|
39
|
+
// AddAllToOrgUnitDropdown → CreateUserDrawerSelector → CreateUserDrawer*
|
|
40
|
+
"org-unit-details": ["users"],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe("page loaders request the localization entries their components use", () => {
|
|
44
|
+
it("knows every required entry", () => {
|
|
45
|
+
Object.values(REQUIRED_ENTRIES)
|
|
46
|
+
.flat()
|
|
47
|
+
.forEach((feature) => {
|
|
48
|
+
expect(LOCALIZATION_ENTRY_IDS).toHaveProperty(feature);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
Object.entries(REQUIRED_ENTRIES).forEach(([page, features]) => {
|
|
53
|
+
it.each(features)(`${page} requests %s`, (feature) => {
|
|
54
|
+
expect(getRequestedEntries(page)).toContain(feature);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
package/src/pages/org-units.tsx
CHANGED
|
@@ -87,7 +87,10 @@ const loaderFunction = async (
|
|
|
87
87
|
}),
|
|
88
88
|
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
89
89
|
getLocalizationLabelsService({
|
|
90
|
-
entryIds:
|
|
90
|
+
entryIds: [
|
|
91
|
+
LOCALIZATION_ENTRY_IDS.orgUnits,
|
|
92
|
+
LOCALIZATION_ENTRY_IDS.users,
|
|
93
|
+
],
|
|
91
94
|
locale: data.locale,
|
|
92
95
|
}),
|
|
93
96
|
contractDetailsPromise,
|
package/src/pages/profile.tsx
CHANGED
|
@@ -46,7 +46,10 @@ export async function loaderFunction(
|
|
|
46
46
|
data,
|
|
47
47
|
async ({ customerId, cookie, userId, ...clientContext }) => {
|
|
48
48
|
const labelsPromise = getLocalizationLabelsService({
|
|
49
|
-
entryIds:
|
|
49
|
+
entryIds: [
|
|
50
|
+
LOCALIZATION_ENTRY_IDS.profile,
|
|
51
|
+
LOCALIZATION_ENTRY_IDS.accountingFields,
|
|
52
|
+
],
|
|
50
53
|
locale: data.locale,
|
|
51
54
|
});
|
|
52
55
|
|