Compare commits

...

2 Commits

Author SHA1 Message Date
Atash03 c7c5f4c158 bui;d 2026-04-06 19:27:08 +05:00
Atash03 ecfaff6bbd refactor: centralize Accept-Language header via axios interceptor
Add a request interceptor to the axios instance that automatically sets
the Accept-Language header from the Zustand language store, ensuring all
requests (including POST) send the locale. Remove redundant lang params
from service functions and hooks, and refactor B2B form to use the
shared service layer instead of raw axios with a hardcoded URL.
2026-04-06 19:25:53 +05:00
20 changed files with 68 additions and 112 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/index.html vendored
View File

@ -66,9 +66,9 @@
})(window, document, "script", "dataLayer", "GTM-NK394LVK"); })(window, document, "script", "dataLayer", "GTM-NK394LVK");
</script> </script>
<title>Turkmen Textile</title> <title>Turkmen Textile</title>
<script type="module" crossorigin src="/assets/index-C9G0Csqa.js"></script> <script type="module" crossorigin src="/assets/index-MPr5X3aY.js"></script>
<link rel="modulepreload" crossorigin href="/assets/react-vendor-B--yIoPF.js"> <link rel="modulepreload" crossorigin href="/assets/react-vendor-B--yIoPF.js">
<link rel="modulepreload" crossorigin href="/assets/ui-library-CuSScUdV.js"> <link rel="modulepreload" crossorigin href="/assets/ui-library-BuCxlbiR.js">
<link rel="stylesheet" crossorigin href="/assets/index-BOfvbFOj.css"> <link rel="stylesheet" crossorigin href="/assets/index-BOfvbFOj.css">
</head> </head>
<body> <body>

View File

@ -2,12 +2,12 @@ import { AnimatePresence } from "motion/react";
import { FC, useMemo } from "react"; import { FC, useMemo } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import axios from "axios";
import { import {
defaultValuesOfB2b, defaultValuesOfB2b,
createFormSchema, createFormSchema,
FormType, FormType,
} from "@/lib/get-b2b-form-details"; } from "@/lib/get-b2b-form-details";
import { postB2b } from "@/services/service";
import { Form } from "@/components/ui/form"; import { Form } from "@/components/ui/form";
import { FormSuccesStatus } from "../form-succes-status"; import { FormSuccesStatus } from "../form-succes-status";
import { Stage1, Stage2, Stage3 } from "../b2b"; import { Stage1, Stage2, Stage3 } from "../b2b";
@ -96,17 +96,9 @@ export const B2bForm: FC<Props> = ({
} }
}); });
const res = await axios.post( const success = await postB2b(formData);
"https://turkmentextile.turkmenexpo.com/app/api/v1/form",
formData,
{
headers: {
"Content-Type": "multipart/form-data",
},
}
);
if (res.status === 201) { if (success) {
setSuccess(true); setSuccess(true);
} }
} catch (error) { } catch (error) {

View File

@ -9,7 +9,7 @@ import { Container } from "@/components/layout";
export const HomeNews: FC = () => { export const HomeNews: FC = () => {
const lang = useLangStore((state) => state.lang); const lang = useLangStore((state) => state.lang);
const { data, isPending } = useNews(lang); const { data, isPending } = useNews();
if (isPending) return <Loader />; if (isPending) return <Loader />;

View File

@ -7,7 +7,7 @@ export const useContacts = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["contacts", lang], queryKey: ["contacts", lang],
queryFn: () => getContacts(lang), queryFn: () => getContacts(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -7,7 +7,7 @@ export const useDesigners = (id: number) => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["designers", lang], queryKey: ["designers", lang],
queryFn: () => getDesigners(lang, id), queryFn: () => getDesigners(id),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -20,7 +20,7 @@ export const useExhibitionTime = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["exhibiton-time", lang], queryKey: ["exhibiton-time", lang],
queryFn: () => getExhibitionTime(lang), queryFn: () => getExhibitionTime(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -7,7 +7,7 @@ export const useHomeContacts = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["home-contacts", lang], queryKey: ["home-contacts", lang],
queryFn: () => getHomeContacts(lang), queryFn: () => getHomeContacts(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -24,7 +24,7 @@ export const useIndustries = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["industries", lang], queryKey: ["industries", lang],
queryFn: () => getIndustries(lang), queryFn: () => getIndustries(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -1,10 +1,13 @@
import { getNewsInner } from "@/services/service"; import { getNewsInner } from "@/services/service";
import { useLangStore } from "@/store/lang";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
export const useNewsInner = (id: number, lang: string) => { export const useNewsInner = (id: number) => {
const lang = useLangStore((state) => state.lang);
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["news-inner", id, lang], queryKey: ["news-inner", id, lang],
queryFn: () => getNewsInner(id, lang), queryFn: () => getNewsInner(id),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -1,10 +1,13 @@
import { getNews } from "@/services/service"; import { getNews } from "@/services/service";
import { useLangStore } from "@/store/lang";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
export const useNews = (lang: "ru" | "en" | "tm") => { export const useNews = () => {
const lang = useLangStore((state) => state.lang);
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["news", lang], queryKey: ["news", lang],
queryFn: () => getNews(lang), queryFn: () => getNews(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -7,7 +7,7 @@ export const useParticipants = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["participants", lang], queryKey: ["participants", lang],
queryFn: () => getParticipants(lang), queryFn: () => getParticipants(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -23,7 +23,7 @@ export const usePartners = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["partners", lang], queryKey: ["partners", lang],
queryFn: () => getPartners(lang), queryFn: () => getPartners(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -7,7 +7,7 @@ export const useSponsors = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["sponsors", lang], queryKey: ["sponsors", lang],
queryFn: () => getSponsors(lang), queryFn: () => getSponsors(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -37,7 +37,7 @@ export const useStaticWords = (id: string) => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["static-words", lang, id], queryKey: ["static-words", lang, id],
queryFn: () => getStaticWords(lang, id), queryFn: () => getStaticWords(id),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -20,7 +20,7 @@ export const useStats = () => {
const { data, isPending } = useQuery({ const { data, isPending } = useQuery({
queryKey: ["stats", lang], queryKey: ["stats", lang],
queryFn: () => getStats(lang), queryFn: () => getStats(),
select: ({ data }) => data.data, select: ({ data }) => data.data,
}); });

View File

@ -15,8 +15,8 @@ export default function NewsInner() {
const pageId = Number(id); const pageId = Number(id);
useScrollTop(pageId); useScrollTop(pageId);
const { data, isPending } = useNewsInner(pageId, lang); const { data, isPending } = useNewsInner(pageId);
const { data: news } = useNews(lang); const { data: news } = useNews();
if (isPending) return <Loader />; if (isPending) return <Loader />;

View File

@ -11,7 +11,7 @@ export default function News() {
const lang = useLangStore((state) => state.lang); const lang = useLangStore((state) => state.lang);
const { data, isPending } = useNews(lang); const { data, isPending } = useNews();
if (isPending) return <Loader />; if (isPending) return <Loader />;

View File

@ -3,7 +3,6 @@ import { SponsorFormType } from "@/lib/get-sponsor-form-details";
import { StandFormType } from "@/lib/get-stend-form-details"; import { StandFormType } from "@/lib/get-stend-form-details";
import axios from "axios"; import axios from "axios";
import { ContactsPageType } from "./types/contacts.type"; import { ContactsPageType } from "./types/contacts.type";
import { LangState } from "@/store/lang";
import { StatsType } from "@/hooks/tanstack/use-stats"; import { StatsType } from "@/hooks/tanstack/use-stats";
import { HomeContactsType } from "./types/home-contacts.type"; import { HomeContactsType } from "./types/home-contacts.type";
import { StaticType } from "@/hooks/tanstack/use-static-words"; import { StaticType } from "@/hooks/tanstack/use-static-words";
@ -15,11 +14,18 @@ import { ParticipantsType } from "./types/participants.type";
import { PhotoTypes } from "./types/photo.type"; import { PhotoTypes } from "./types/photo.type";
import { DesignersType } from "./types/designers.type"; import { DesignersType } from "./types/designers.type";
import { VideoTypes } from "./types/videos.type"; import { VideoTypes } from "./types/videos.type";
import { useLangStore } from "@/store/lang";
const axios_url = axios.create({ const axios_url = axios.create({
baseURL: "https://turkmentextile.turkmenexpo.com/app/api/v1/", baseURL: "https://turkmentextile.turkmenexpo.com/app/api/v1/",
}); });
axios_url.interceptors.request.use((config) => {
const lang = useLangStore.getState().lang;
config.headers["Accept-Language"] = lang;
return config;
});
export const postStend = async (data: StandFormType): Promise<boolean> => { export const postStend = async (data: StandFormType): Promise<boolean> => {
const res = axios_url.post(`book_stand_form`, data); const res = axios_url.post(`book_stand_form`, data);
@ -50,102 +56,62 @@ export const postSubscribe = async (data: { email: string }) => {
return (await res).status === 201; return (await res).status === 201;
}; };
export const getStaticWords = async (lang: LangState["lang"], id: string) => { export const getStaticWords = async (id: string) => {
const data = axios_url.get<StaticType>(`pages/${id}`, { const data = axios_url.get<StaticType>(`pages/${id}`);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getPartners = async (lang: LangState["lang"]) => { export const getPartners = async () => {
const data = axios_url.get<PartnersType>("partners", { const data = axios_url.get<PartnersType>("partners");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getStats = async (lang: LangState["lang"]) => { export const getStats = async () => {
const data = axios_url.get<StatsType>("stats", { const data = axios_url.get<StatsType>("stats");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getContacts = async (lang: LangState["lang"]) => { export const getContacts = async () => {
const data = axios_url.get<ContactsPageType>("contact_info", { const data = axios_url.get<ContactsPageType>("contact_info");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getHomeContacts = async (lang: LangState["lang"]) => { export const getHomeContacts = async () => {
const data = axios_url.get<HomeContactsType>("contact_data", { const data = axios_url.get<HomeContactsType>("contact_data");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getIndustries = async (lang: LangState["lang"]) => { export const getIndustries = async () => {
const data = axios_url.get<IndustriesType>(`industries`, { const data = axios_url.get<IndustriesType>(`industries`);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getExhibitionTime = async (lang: LangState["lang"]) => { export const getExhibitionTime = async () => {
const data = axios_url.get<TimeType>(`exhibition_time`, { const data = axios_url.get<TimeType>(`exhibition_time`);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getNews = async (lang: "ru" | "en" | "tm") => { export const getNews = async () => {
const data = axios_url.get<NewsType>(`news?per_page=100`, { const data = axios_url.get<NewsType>(`news?per_page=100`);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getNewsInner = async (id: number, lang: string) => { export const getNewsInner = async (id: number) => {
const data = axios_url.get<NewsInnerType>(`news/${id}`, { const data = axios_url.get<NewsInnerType>(`news/${id}`);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getParticipants = async (lang: LangState["lang"]) => { export const getParticipants = async () => {
const data = axios_url<ParticipantsType>("participants", { const data = axios_url<ParticipantsType>("participants");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
@ -162,22 +128,14 @@ export const getVideos = async (id: number) => {
return data; return data;
}; };
export const getSponsors = async (lang: LangState["lang"]) => { export const getSponsors = async () => {
const data = axios_url<PartnersType>("sponsors_and_partners", { const data = axios_url<PartnersType>("sponsors_and_partners");
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };
export const getDesigners = async (lang: LangState["lang"], id: number) => { export const getDesigners = async (id: number) => {
const data = axios_url<DesignersType>("designers/category/" + id, { const data = axios_url<DesignersType>("designers/category/" + id);
headers: {
"Accept-Language": lang,
},
});
return data; return data;
}; };