feat: wire i18n services and shared UI

This commit is contained in:
poyrazavsever
2026-07-19 03:06:56 +03:00
parent 805beccf95
commit 826410f53e
11 changed files with 1330 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
"use client";
import { useState, useTransition } from "react";
import { Label } from "poyraz-ui/atoms";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "poyraz-ui/molecules";
type LocaleOption = {
code: string;
nativeName: string;
name: string;
};
type LocaleSelectFormProps = {
label: string;
value: string;
locales: LocaleOption[];
};
export function LocaleSelectForm({ label, value, locales }: LocaleSelectFormProps) {
const [currentLocale, setCurrentLocale] = useState(value);
const [pending, startTransition] = useTransition();
function handleChange(locale: string) {
setCurrentLocale(locale);
startTransition(async () => {
await fetch("/api/i18n/locale", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ locale }),
});
window.location.reload();
});
}
return (
<div className="space-y-2">
<Label htmlFor="auth-locale">{label}</Label>
<Select value={currentLocale} onValueChange={handleChange} disabled={pending}>
<SelectTrigger id="auth-locale" aria-label={label}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{locales.map((locale) => (
<SelectItem key={locale.code} value={locale.code}>
{locale.nativeName || locale.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
);
}