Skip to content

Commit 8413af6

Browse files
committed
feat: ShopAPI의 다국어 지원 추가
1 parent e9e6b28 commit 8413af6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/shop/src/apis/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ type AxiosRequestWithPayload = <T = unknown, R = AxiosResponse<T>, D = unknown>(
6363

6464
export class ShopAPIClient {
6565
readonly baseURL: string;
66+
readonly language: "ko" | "en";
6667
protected readonly csrfCookieName: string;
6768
private readonly shopAPI: AxiosInstance;
6869

69-
constructor(baseURL: string, csrfCookieName: string, timeout: number) {
70+
constructor(baseURL: string, csrfCookieName: string, timeout: number, language: "ko" | "en") {
7071
this.baseURL = baseURL;
72+
this.language = language;
7173
this.csrfCookieName = csrfCookieName;
7274
this.shopAPI = axios.create({
7375
baseURL,
7476
timeout,
7577
withCredentials: true,
76-
headers: { "Content-Type": "application/json" },
78+
headers: { "Content-Type": "application/json", "Accept-Language": language },
7779
});
7880
this.shopAPI.interceptors.request.use(
7981
(config) => {

packages/shop/src/hooks/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ namespace ShopHooks {
3636
};
3737

3838
export const useShopClient = () => {
39-
const { shopApiDomain, shopApiCSRFCookieName, shopApiTimeout } = useShopContext();
40-
return new ShopAPIClient(shopApiDomain, shopApiCSRFCookieName, shopApiTimeout);
39+
const { shopApiDomain, shopApiCSRFCookieName, shopApiTimeout, language } = useShopContext();
40+
return new ShopAPIClient(shopApiDomain, shopApiCSRFCookieName, shopApiTimeout, language);
4141
};
4242

4343
export const useUserStatus = (client: ShopAPIClient) =>
4444
useSuspenseQuery({
45-
queryKey: QUERY_KEYS.USER,
45+
queryKey: [client.language, ...QUERY_KEYS.USER],
4646
queryFn: ShopAPIs.retrieveUserInfo(client),
4747
retry: 3,
4848
});
@@ -71,13 +71,13 @@ namespace ShopHooks {
7171

7272
export const useProducts = (client: ShopAPIClient, qs?: ShopSchemas.ProductListQueryParams) =>
7373
useSuspenseQuery({
74-
queryKey: [...QUERY_KEYS.PRODUCT_LIST, qs ? JSON.stringify(qs) : ""],
74+
queryKey: [client.language, ...QUERY_KEYS.PRODUCT_LIST, qs ? JSON.stringify(qs) : ""],
7575
queryFn: () => ShopAPIs.listProducts(client)(qs),
7676
});
7777

7878
export const useCart = (client: ShopAPIClient) =>
7979
useSuspenseQuery({
80-
queryKey: QUERY_KEYS.CART_INFO,
80+
queryKey: [client.language, ...QUERY_KEYS.CART_INFO],
8181
queryFn: ShopAPIs.retrieveCart(client),
8282
});
8383

@@ -111,7 +111,7 @@ namespace ShopHooks {
111111

112112
export const useOrders = (client: ShopAPIClient) =>
113113
useSuspenseQuery({
114-
queryKey: QUERY_KEYS.ORDER_LIST,
114+
queryKey: [client.language, ...QUERY_KEYS.ORDER_LIST],
115115
queryFn: ShopAPIs.listOrders(client),
116116
});
117117

0 commit comments

Comments
 (0)