feat(i18n): integrate multilingual support into clients views and forms
This commit is contained in:
@@ -1,8 +1,26 @@
|
||||
import { ClientsClient, type ClientListItem } from "@/app/(dashboard)/clients/clients-client";
|
||||
import { requireFreelancerBackend } from "@/server/web/freelancer";
|
||||
import { resolveFreelancerLocale } from "@/server/i18n/resolver";
|
||||
import { getClientI18nPayload } from "@/server/i18n/translator";
|
||||
import { I18nProvider } from "@/components/i18n/i18n-provider";
|
||||
import type { ContentTranslationRow } from "@/server/i18n/content";
|
||||
|
||||
function buildTranslations(rows: ContentTranslationRow[] | undefined) {
|
||||
if (!rows) return undefined;
|
||||
const result: Record<string, Record<string, string>> = {};
|
||||
for (const row of rows) {
|
||||
if (!result[row.locale]) result[row.locale] = {};
|
||||
result[row.locale][row.field] = row.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default async function ClientsPage() {
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
const { context, actor, service } = await requireFreelancerBackend();
|
||||
const resolvedLocale = await resolveFreelancerLocale(context);
|
||||
const payload = getClientI18nPayload(resolvedLocale.locale, ["clients"]);
|
||||
const activeLocales = service.listLocales(actor).filter(l => l.status !== "archived").map(l => ({ code: l.code, name: l.nativeName }));
|
||||
|
||||
const clientsData = service.listClients(actor);
|
||||
const projects = service.listProjects(actor);
|
||||
const finance = service.listFinanceTransactions(actor);
|
||||
@@ -32,6 +50,8 @@ export default async function ClientsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const translationsMap = service.contentTranslations.listBatch("client", clientsData.map(c => c.id));
|
||||
|
||||
const clients: ClientListItem[] = clientsData.map((client) => {
|
||||
return {
|
||||
id: client.id,
|
||||
@@ -49,14 +69,18 @@ export default async function ClientsPage() {
|
||||
created_at: client.createdAt.toISOString(),
|
||||
projectCount: projectCountByClient.get(client.id) ?? 0,
|
||||
revenueTotal: revenueByClient.get(client.id) ?? 0,
|
||||
translations: buildTranslations(translationsMap.get(client.id)),
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<ClientsClient
|
||||
clients={clients}
|
||||
totalRevenue={clients.reduce((sum, client) => sum + client.revenueTotal, 0)}
|
||||
activeCount={clients.filter((client) => client.status === "active").length}
|
||||
/>
|
||||
<I18nProvider payload={payload}>
|
||||
<ClientsClient
|
||||
clients={clients}
|
||||
totalRevenue={clients.reduce((sum, client) => sum + client.revenueTotal, 0)}
|
||||
activeCount={clients.filter((client) => client.status === "active").length}
|
||||
activeLocales={activeLocales}
|
||||
/>
|
||||
</I18nProvider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user