diff --git a/src/pages/EditSightPage/index.tsx b/src/pages/EditSightPage/index.tsx index 63d5887..240e94f 100644 --- a/src/pages/EditSightPage/index.tsx +++ b/src/pages/EditSightPage/index.tsx @@ -24,7 +24,7 @@ export const EditSightPage = observer(() => { const { getArticles } = articlesStore; const { language } = languageStore; const { id } = useParams(); - const { getCities } = cityStore; + const { getRuCities } = cityStore; let blocker = useBlocker( ({ currentLocation, nextLocation }) => @@ -40,7 +40,7 @@ export const EditSightPage = observer(() => { if (id) { await getSightInfo(+id, language); await getArticles(language); - await getCities(); + await getRuCities(); } }; fetchData(); diff --git a/src/shared/store/CityStore/index.tsx b/src/shared/store/CityStore/index.tsx index 130b0a7..81f169f 100644 --- a/src/shared/store/CityStore/index.tsx +++ b/src/shared/store/CityStore/index.tsx @@ -1,4 +1,4 @@ -import { authInstance } from "@shared"; +import { authInstance, languageInstance } from "@shared"; import { makeAutoObservable, runInAction } from "mobx"; type City = { @@ -11,7 +11,9 @@ type City = { class CityStore { cities: City[] = []; + ruCities: City[] = []; city: City | null = null; + constructor() { makeAutoObservable(this); } @@ -24,6 +26,14 @@ class CityStore { }); }; + getRuCities = async () => { + const response = await languageInstance("ru").get("/city"); + + runInAction(() => { + this.ruCities = response.data; + }); + }; + deleteCity = async (id: number) => { await authInstance.delete(`/city/${id}`); diff --git a/src/shared/store/CreateSightStore/index.tsx b/src/shared/store/CreateSightStore/index.tsx index 8150845..93b28e9 100644 --- a/src/shared/store/CreateSightStore/index.tsx +++ b/src/shared/store/CreateSightStore/index.tsx @@ -106,10 +106,17 @@ class CreateSightStore { try { this.needLeaveAgree = true; const articleRes = await authInstance.post("/article", { - translation: { - ru: articleRuData, - en: articleEnData, - zh: articleZhData, + translations: { + heading: { + ru: articleRuData.heading, + en: articleEnData.heading, + zh: articleZhData.heading, + }, + body: { + ru: articleRuData.body, + en: articleEnData.body, + zh: articleZhData.body, + }, }, }); const { id } = articleRes.data; // New article's ID diff --git a/src/shared/store/EditSightStore/index.tsx b/src/shared/store/EditSightStore/index.tsx index 98d6ba7..29562e0 100644 --- a/src/shared/store/EditSightStore/index.tsx +++ b/src/shared/store/EditSightStore/index.tsx @@ -265,18 +265,16 @@ class EditSightStore { this.sight.common.left_article != null ) { await authInstance.patch(`/article/${this.sight.common.left_article}`, { - translation: { - ru: { - heading: this.sight.ru.left.heading, - body: this.sight.ru.left.body, + translations: { + heading: { + ru: this.sight.ru.left.heading, + en: this.sight.en.left.heading, + zh: this.sight.zh.left.heading, }, - en: { - heading: this.sight.en.left.heading, - body: this.sight.en.left.body, - }, - zh: { - heading: this.sight.zh.left.heading, - body: this.sight.zh.left.body, + body: { + ru: this.sight.ru.left.body, + en: this.sight.en.left.body, + zh: this.sight.zh.left.body, }, }, }); @@ -284,39 +282,36 @@ class EditSightStore { await authInstance.patch(`/sight/${this.sight.common.id}`, { ...this.sight.common, - translation: { - ru: { - name: this.sight.ru.name, - address: this.sight.ru.address, + translations: { + name: { + ru: this.sight.ru.name, + en: this.sight.en.name, + zh: this.sight.zh.name, }, - en: { - name: this.sight.en.name, - address: this.sight.en.address, - }, - zh: { - name: this.sight.zh.name, - address: this.sight.zh.address, + address: { + ru: this.sight.ru.address, + en: this.sight.en.address, + zh: this.sight.zh.address, }, }, }); - for (const article of this.sight.ru.right) { + for (let index = 0; index < this.sight.ru.right.length; index++) { + const article = this.sight.ru.right[index]; if (article.id == 0 || article.id == null) { continue; } await authInstance.patch(`/article/${article.id}`, { - translation: { - ru: { - heading: article.heading, - body: article.body, + translations: { + heading: { + ru: this.sight.ru.right[index].heading, + en: this.sight.en.right[index].heading, + zh: this.sight.zh.right[index].heading, }, - en: { - heading: article.heading, - body: article.body, - }, - zh: { - heading: article.heading, - body: article.body, + body: { + ru: this.sight.ru.right[index].body, + en: this.sight.en.right[index].body, + zh: this.sight.zh.right[index].body, }, }, }); @@ -604,10 +599,17 @@ class EditSightStore { body: "Новый текст (ZH)", }; const articleId = await authInstance.post("/article", { - translation: { - ru: articleRuData, - en: articleEnData, - zh: articleZhData, + translations: { + heading: { + ru: articleRuData.heading, + en: articleEnData.heading, + zh: articleZhData.heading, + }, + body: { + ru: articleRuData.body, + en: articleEnData.body, + zh: articleZhData.body, + }, }, }); const { id } = articleId.data; diff --git a/src/widgets/LanguageSwitcher/index.tsx b/src/widgets/LanguageSwitcher/index.tsx index 6ae59aa..ecce76d 100644 --- a/src/widgets/LanguageSwitcher/index.tsx +++ b/src/widgets/LanguageSwitcher/index.tsx @@ -44,7 +44,7 @@ export const LanguageSwitcher = observer(() => { }; return ( -
+
{/* Added some styling for better visualization */} {LANGUAGES.map((lang) => (