Skip to content

Commit 606dd4b

Browse files
fix: request white labeling when module is off (revert #1881) (#1931)
revert PR #1881 This reverts commit 41fbef4. ## Description ## References ### Jira-link: https://virtocommerce.atlassian.net/browse/VCST-3935 ### Artifact URL: https://vc3prerelease.blob.core.windows.net/packages/vc-theme-b2b-vue-2.31.0-pr-1931-21fa-21fab439.zip
1 parent 30381b8 commit 606dd4b

File tree

5 files changed

+78
-142
lines changed

5 files changed

+78
-142
lines changed

client-app/app-runner.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { apolloClient, getStore } from "@/core/api/graphql";
55
import { useCurrency, useThemeContext, useNavigations, useWhiteLabeling } from "@/core/composables";
66
import { useHotjar } from "@/core/composables/useHotjar";
77
import { useLanguages } from "@/core/composables/useLanguages";
8-
import { useModuleSettings } from "@/core/composables/useModuleSettings";
98
import { FALLBACK_LOCALE, IS_DEVELOPMENT } from "@/core/constants";
109
import { setGlobals } from "@/core/globals";
1110
import {
@@ -81,13 +80,7 @@ export default async () => {
8180
const { currentCurrency } = useCurrency();
8281
const { init: initializeHotjar } = useHotjar();
8382
const { fetchCatalogMenu } = useNavigations();
84-
const {
85-
MODULE_KEYS: WHITE_LABELING_MODULE_KEYS,
86-
themePresetName,
87-
fetchWhiteLabelingSettings,
88-
applyWhiteLabelingSettings,
89-
fetchAndApplyFooterLinks,
90-
} = useWhiteLabeling();
83+
const { themePresetName, fetchWhiteLabelingSettings } = useWhiteLabeling();
9184

9285
const fallback = {
9386
locale: FALLBACK_LOCALE,
@@ -101,7 +94,7 @@ export default async () => {
10194
IS_DEVELOPMENT ? extractHostname(import.meta.env.APP_BACKEND_URL as string) : window.location.hostname,
10295
) as Promise<StoreResponseType>;
10396

104-
const [store] = await Promise.all([storePromise, fetchUser(), fallback.setMessage(), fetchWhiteLabelingSettings()]);
97+
const [store] = await Promise.all([storePromise, fetchUser(), fallback.setMessage()]);
10598

10699
if (!store) {
107100
alert("Related store not found. Please contact your site administrator.");
@@ -146,13 +139,7 @@ export default async () => {
146139
* Other settings
147140
*/
148141

149-
const { isEnabled } = useModuleSettings(WHITE_LABELING_MODULE_KEYS.ID);
150-
151-
if (isEnabled(WHITE_LABELING_MODULE_KEYS.ENABLE_STATE)) {
152-
void fetchAndApplyFooterLinks(currentLanguage.value.cultureName);
153-
applyWhiteLabelingSettings();
154-
}
155-
142+
await fetchWhiteLabelingSettings();
156143
addPresetToThemeContext(themePresetName.value ?? themeContext.value.defaultPresetName);
157144

158145
if (isAuthenticated.value || themeContext.value.storeSettings.anonymousUsersAllowed) {

client-app/core/api/graphql/whiteLabeling/queries/index.ts

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
import { gql } from "graphql-tag";
2+
import { globals } from "@/core/globals";
23
import { graphqlClient } from "../../client";
34
import type { Query, QueryWhiteLabelingSettingsArgs } from "@/core/api/graphql/types";
45
import type { DocumentNode } from "graphql";
56

6-
function getQueryDocument(): DocumentNode {
7-
return gql`
8-
query WhiteLabelingSettings($domain: String) {
9-
whiteLabelingSettings(domain: $domain) {
10-
logoUrl
11-
secondaryLogoUrl
12-
themePresetName
13-
isOrganizationLogoUploaded
14-
favicons {
15-
rel
16-
type
17-
sizes
18-
href
19-
}
20-
}
21-
}
22-
`;
23-
}
24-
257
const FOOTER_LINKS_DEPTH = 1;
268

279
function getFooterLinksTreeString(level: number): string {
@@ -37,27 +19,25 @@ function getFooterLinksTreeString(level: number): string {
3719
: "";
3820
}
3921

40-
export async function getGetWhiteLabelingSettings(domain: string) {
41-
const { data } = await graphqlClient.query<
42-
Required<Pick<Query, "whiteLabelingSettings">>,
43-
QueryWhiteLabelingSettingsArgs
44-
>({
45-
query: getQueryDocument(),
46-
variables: {
47-
domain,
48-
},
49-
});
50-
51-
return data.whiteLabelingSettings;
52-
}
53-
54-
function getFooterLinksDocument(maxLevelFooterLinks: number): DocumentNode {
22+
function getQueryDocument(maxLevelFooterLinks: number): DocumentNode {
5523
return gql`
56-
query WhiteLabelingSettings($domain: String, $cultureName: String) {
24+
query WhiteLabelingSettings($storeId: String, $userId: String, $cultureName: String, $organizationId: String) {
5725
whiteLabelingSettings(
58-
domain: $domain,
26+
storeId: $storeId
27+
userId: $userId
5928
cultureName: $cultureName
29+
organizationId: $organizationId
6030
) {
31+
logoUrl
32+
secondaryLogoUrl
33+
themePresetName
34+
isOrganizationLogoUploaded
35+
favicons {
36+
rel
37+
type
38+
sizes
39+
href
40+
}
6141
footerLinks {
6242
title
6343
url
@@ -69,14 +49,18 @@ function getFooterLinksDocument(maxLevelFooterLinks: number): DocumentNode {
6949
`;
7050
}
7151

72-
export async function getFooterLinks(domain: string, cultureName: string) {
52+
export async function getGetWhiteLabelingSettings() {
53+
const { storeId, userId, organizationId, cultureName } = globals;
54+
7355
const { data } = await graphqlClient.query<
7456
Required<Pick<Query, "whiteLabelingSettings">>,
7557
QueryWhiteLabelingSettingsArgs
7658
>({
77-
query: getFooterLinksDocument(FOOTER_LINKS_DEPTH),
59+
query: getQueryDocument(FOOTER_LINKS_DEPTH),
7860
variables: {
79-
domain,
61+
storeId,
62+
userId,
63+
organizationId,
8064
cultureName,
8165
},
8266
});

client-app/core/composables/useWhiteLabeling.ts

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,50 @@
11
import { createGlobalState, useEventBus } from "@vueuse/core";
2-
import { computed, ref, shallowRef } from "vue";
3-
import settingsData from "@/config/settings_data.json";
4-
import { getGetWhiteLabelingSettings, getFooterLinks } from "@/core/api/graphql/whiteLabeling/queries";
5-
import { IS_DEVELOPMENT } from "@/core/constants";
2+
import { computed, shallowRef } from "vue";
3+
import { getGetWhiteLabelingSettings } from "@/core/api/graphql/whiteLabeling/queries";
64
import { WHITE_LABELING_FETCHED_SETTINGS_EVENT } from "@/core/constants/modules-events";
7-
import { Logger, convertToExtendedMenuLink, extractHostname } from "@/core/utilities";
8-
import type { WhiteLabelingSettingsType, MenuLinkType } from "@/core/api/graphql/types";
5+
import { Logger, convertToExtendedMenuLink } from "@/core/utilities";
6+
import { useThemeContext } from "./useThemeContext";
7+
import type { WhiteLabelingSettingsType } from "@/core/api/graphql/types";
98

109
const whiteLabelingSettings = shallowRef<WhiteLabelingSettingsType>();
11-
const fetchedSettings = shallowRef<WhiteLabelingSettingsType>();
12-
const footerLinks = ref<MenuLinkType[]>();
10+
const { modulesSettings, themeContext } = useThemeContext();
1311

1412
const MODULE_KEYS = {
1513
ID: "VirtoCommerce.WhiteLabeling",
1614
ENABLE_STATE: "WhiteLabeling.WhiteLabelingEnabled",
1715
};
1816

19-
const { emit } = useEventBus(WHITE_LABELING_FETCHED_SETTINGS_EVENT);
17+
const moduleSettings = computed(() => modulesSettings.value?.find((module) => module.moduleId === MODULE_KEYS.ID));
18+
const moduleEnabled = computed(
19+
() => moduleSettings.value?.settings?.find((item) => item.name === MODULE_KEYS.ENABLE_STATE)?.value,
20+
);
2021

21-
const currentDomain = IS_DEVELOPMENT
22-
? extractHostname(import.meta.env.APP_BACKEND_URL as string)
23-
: window.location.hostname;
22+
const { emit } = useEventBus(WHITE_LABELING_FETCHED_SETTINGS_EVENT);
2423

25-
/**
26-
* Independent composable.
27-
* Does not rely on global context.
28-
*/
2924
function _useWhiteLabeling() {
30-
/**
31-
* Applies previously fetched white labeling settings.
32-
*
33-
* @remarks
34-
* - Use only after {@link fetchWhiteLabelingSettings}.
35-
*/
3625
async function fetchWhiteLabelingSettings(): Promise<void> {
37-
try {
38-
fetchedSettings.value = await getGetWhiteLabelingSettings(currentDomain);
39-
} catch (e) {
40-
Logger.error(`${_useWhiteLabeling.name}.${fetchWhiteLabelingSettings.name}`, e);
41-
throw e;
42-
}
43-
}
44-
45-
/**
46-
* Fetches and stores white labeling settings.
47-
*
48-
* @remarks
49-
* - Not for standalone use; must be followed by {@link applyWhiteLabelingSettings}.
50-
* - Purpose: load settings in parallel during app initialization.
51-
*/
52-
function applyWhiteLabelingSettings() {
53-
if (fetchedSettings.value) {
54-
whiteLabelingSettings.value = fetchedSettings.value;
55-
fetchedSettings.value = undefined;
56-
57-
emit(whiteLabelingSettings.value);
58-
}
59-
}
60-
61-
/**
62-
* Fetches and applies footer links.
63-
*
64-
* @param cultureName - Locale in 4-character format (e.g., "en-US").
65-
*
66-
* @remarks
67-
* - Asynchronous method.
68-
* - Locale-dependent.
69-
*/
70-
async function fetchAndApplyFooterLinks(cultureName: string) {
71-
try {
72-
footerLinks.value = (await getFooterLinks(currentDomain, cultureName))?.footerLinks;
73-
} catch (e) {
74-
Logger.error(`${_useWhiteLabeling.name}.${fetchAndApplyFooterLinks.name}`, e);
75-
throw e;
26+
if (moduleEnabled.value) {
27+
try {
28+
whiteLabelingSettings.value = await getGetWhiteLabelingSettings();
29+
emit(whiteLabelingSettings.value);
30+
} catch (e) {
31+
Logger.error(`${_useWhiteLabeling.name}.${fetchWhiteLabelingSettings.name}`, e);
32+
throw e;
33+
}
7634
}
7735
}
7836

7937
return {
80-
MODULE_KEYS,
81-
fetchWhiteLabelingSettings,
82-
applyWhiteLabelingSettings,
83-
fetchAndApplyFooterLinks,
84-
85-
logoUrl: computed(() => whiteLabelingSettings.value?.logoUrl ?? settingsData.settings.logo_image),
38+
logoUrl: computed(() => whiteLabelingSettings.value?.logoUrl ?? themeContext.value?.settings?.logo_image),
8639
secondaryLogoUrl: computed(
87-
() => whiteLabelingSettings.value?.secondaryLogoUrl ?? settingsData.settings.logo_inverted_image,
40+
() => whiteLabelingSettings.value?.secondaryLogoUrl ?? themeContext.value?.settings?.logo_inverted_image,
41+
),
42+
footerLinks: computed(() =>
43+
whiteLabelingSettings.value?.footerLinks?.map((item) => convertToExtendedMenuLink(item)),
8844
),
89-
footerLinks: computed(() => footerLinks.value?.map((item) => convertToExtendedMenuLink(item))),
9045
favIcons: computed(() => whiteLabelingSettings.value?.favicons),
9146
themePresetName: computed(() => whiteLabelingSettings.value?.themePresetName),
47+
fetchWhiteLabelingSettings,
9248
whiteLabelingLogoUrl: computed(() => whiteLabelingSettings.value?.logoUrl),
9349
isOrganizationLogoUploaded: computed(() => whiteLabelingSettings.value?.isOrganizationLogoUploaded),
9450
};

client-app/pages/company/info.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ const {
365365
options: fileOptions,
366366
hasFailedFiles,
367367
} = useFiles(DEFAULT_COMPANY_FILES_SCOPE);
368-
const { whiteLabelingLogoUrl, fetchWhiteLabelingSettings, isOrganizationLogoUploaded, applyWhiteLabelingSettings } =
369-
useWhiteLabeling();
368+
const { whiteLabelingLogoUrl, fetchWhiteLabelingSettings, isOrganizationLogoUploaded } = useWhiteLabeling();
370369
const newLogoUrl = ref(isOrganizationLogoUploaded.value ? whiteLabelingLogoUrl.value : "");
371370
372371
usePageHead({
@@ -543,7 +542,6 @@ void fetchAddresses();
543542
async function saveOrganizationLogo(): Promise<void> {
544543
await updateLogo(organizationId.value, newLogoUrl.value);
545544
await fetchWhiteLabelingSettings();
546-
applyWhiteLabelingSettings();
547545
548546
notifications.success({
549547
text: t("common.messages.logo_changed"),
@@ -582,7 +580,6 @@ async function onRemoveFiles() {
582580
void removeFiles(files.value);
583581
await updateLogo(organizationId.value, "");
584582
await fetchWhiteLabelingSettings();
585-
applyWhiteLabelingSettings();
586583
587584
notifications.warning({
588585
text: t("common.messages.logo_deleted"),
Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
export const dataChangedEvent = "data_changed";
2-
export const pageReloadEvent = "page_reload";
3-
export const userReloadEvent = "user_reload";
4-
export const userBeforeUnauthorizeEvent = "user_before_unauthorize";
5-
export const userLockedEvent = "user_locked";
6-
export const cartReloadEvent = "cart_reload";
7-
export const unauthorizedErrorEvent = "unauthorized_error";
8-
export const unhandledErrorEvent = "unhandled_error";
9-
export const openReturnUrl = "open_return_url";
10-
export const forbiddenEvent = "forbidden";
11-
// eslint-disable-next-line sonarjs/no-hardcoded-passwords
12-
export const passwordExpiredEvent = "password_expired";
13-
export const reloadAndOpenMainPage = "reload_and_open_main_page";
14-
export const graphqlErrorEvent = "graphql_error";
1+
/**
2+
* Designed to sync the value type between `emit()` and `on()`.
3+
*
4+
* Example:
5+
* const testEvent = "test_event" as InjectionEvent<boolean>;
6+
*
7+
* broadcast.on(testEvent, (data) => {
8+
* // The parameter `data` is of boolean type.
9+
* });
10+
*
11+
* broadcast.emit(testEvent, 123); // Error
12+
*/
13+
14+
export const dataChangedEvent = "data_changed" as string;
15+
export const pageReloadEvent = "page_reload" as string;
16+
export const userReloadEvent = "user_reload" as string;
17+
export const userBeforeUnauthorizeEvent = "user_before_unauthorize" as string;
18+
export const userLockedEvent = "user_locked" as string;
19+
export const cartReloadEvent = "cart_reload" as string;
20+
export const unauthorizedErrorEvent = "unauthorized_error" as string;
21+
export const unhandledErrorEvent = "unhandled_error" as string;
22+
export const openReturnUrl = "open_return_url" as string;
23+
export const forbiddenEvent = "forbidden" as string;
24+
export const passwordExpiredEvent = "password_expired" as string;
25+
export const reloadAndOpenMainPage = "reload_and_open_main_page" as string;
26+
export const graphqlErrorEvent = "graphql_error" as string;

0 commit comments

Comments
 (0)