Skip to content

Commit f2dadfc

Browse files
ivan-kalachikovCopilotLenajava1
authored
fix(VCST-4278): change language behavior (#2059)
## Description ## References ### Jira-link: https://virtocommerce.atlassian.net/browse/VCST-4278 ### Artifact URL: https://vc3prerelease.blob.core.windows.net/packages/vc-theme-b2b-vue-2.35.0-pr-2059-3256-32563244.zip --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Elena Mutykova <[email protected]>
1 parent 3f0a45a commit f2dadfc

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
import { useQuery } from "@vue/apollo-composable";
22
import { GetSlugInfoDocument } from "@/core/api/graphql/types";
3-
import type { QuerySlugInfoArgs } from "@/core/api/graphql/types";
3+
import { globals } from "@/core/globals";
4+
import { Logger } from "@/core/utilities/logger";
5+
import { graphqlClient } from "../../../client";
6+
import type { Query, QuerySlugInfoArgs } from "@/core/api/graphql/types";
47
import type { MaybeRefOrGetter } from "vue";
58

69
export function useGetSlugInfo(payload: MaybeRefOrGetter<QuerySlugInfoArgs>) {
710
return useQuery(GetSlugInfoDocument, payload, { fetchPolicy: "cache-and-network" });
811
}
12+
13+
export async function getSlugInfo({ permalink, cultureName }: { permalink?: string; cultureName?: string }) {
14+
const { storeId, userId } = globals;
15+
const variables = { permalink, storeId, userId, cultureName };
16+
17+
try {
18+
const response = await graphqlClient.query<Required<Pick<Query, "slugInfo">>, QuerySlugInfoArgs>({
19+
query: GetSlugInfoDocument,
20+
variables,
21+
});
22+
23+
return response.data?.slugInfo;
24+
} catch (error) {
25+
Logger.error(`Failed to get slug info for permalink: ${permalink} and cultureName: ${cultureName}`, error);
26+
27+
return null;
28+
}
29+
}

client-app/shared/account/composables/useUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
userLockedEvent,
2626
userReloadEvent,
2727
passwordExpiredEvent,
28-
reloadAndOpenMainPage,
28+
pageReloadEvent,
2929
} from "@/shared/broadcast";
3030
import { useModal } from "@/shared/modal";
3131
import PasswordExpirationModal from "../components/password-expiration-modal.vue";
@@ -356,7 +356,7 @@ export function _useUser() {
356356

357357
localStorage.setItem(`organization-id-${user.value?.userName}`, organizationId);
358358

359-
void broadcast.emit(reloadAndOpenMainPage, null, TabsType.ALL);
359+
void broadcast.emit(pageReloadEvent, null, TabsType.ALL);
360360
} catch (e) {
361361
Logger.error(switchOrganization.name, e);
362362
} finally {

client-app/shared/layout/components/language-selector/language-selector.vue

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</template>
6060

6161
<script setup lang="ts">
62+
import { getSlugInfo } from "@/core/api/graphql/slugInfo/queries/getSlugInfo";
6263
import { useLanguages } from "@/core/composables/useLanguages";
6364
import { languageToCountryMap } from "@/core/constants";
6465
import { dataChangedEvent, useBroadcast } from "@/shared/broadcast";
@@ -75,20 +76,31 @@ const {
7576
} = useLanguages();
7677
const broadcast = useBroadcast();
7778
78-
function select(cultureName: string) {
79+
async function select(cultureName: string) {
7980
pinLocale(cultureName);
80-
previousCultureSlug.value = {
81-
cultureName: currentLanguage.value?.cultureName,
82-
slug: getUrlWithoutLocale(location.pathname).slice(1),
83-
};
81+
const permalink = location.pathname.slice(1);
8482
85-
if (cultureName !== currentLanguage.value?.cultureName) {
86-
removeLocaleFromUrl();
87-
88-
void broadcast.emit(dataChangedEvent);
83+
if (cultureName === currentLanguage.value?.cultureName) {
84+
return;
85+
}
8986
90-
void location.reload();
87+
const slugInfo = await getSlugInfo({ permalink, cultureName });
88+
89+
if (!slugInfo?.entityInfo) {
90+
previousCultureSlug.value = {
91+
cultureName: currentLanguage.value?.cultureName,
92+
slug: getUrlWithoutLocale(location.pathname).slice(1),
93+
};
94+
} else {
95+
previousCultureSlug.value = {
96+
cultureName: "",
97+
slug: "",
98+
};
9199
}
100+
101+
removeLocaleFromUrl();
102+
void broadcast.emit(dataChangedEvent);
103+
location.reload();
92104
}
93105
94106
function getCountryCode(language: ILanguage): string {

0 commit comments

Comments
 (0)