HooStore-UI/src/lib/data/locales.ts
2026-10-27 15:09:07 +07:00

29 lines
609 B
TypeScript

"use server"
import { sdk } from "@lib/config"
import { getCacheOptions } from "./cookies"
export type Locale = {
code: string
name: string
}
/**
* Fetches available locales from the backend.
* Returns null if the endpoint returns 404 (locales not configured).
*/
export const listLocales = async (): Promise<Locale[] | null> => {
const next = {
...(await getCacheOptions("locales")),
}
return sdk.client
.fetch<{ locales: Locale[] }>(`/store/locales`, {
method: "GET",
next,
cache: "force-cache",
})
.then(({ locales }) => locales)
.catch(() => null)
}