feat: localize auth and portal pages
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { getSqliteConnection } from "@/server/db/client";
|
||||
import { DomainError } from "@/server/domain/errors";
|
||||
import { ContentTranslationService, getContentFallbackLocale } from "@/server/i18n/content";
|
||||
import { resolveRequestLocale } from "@/server/i18n/resolver";
|
||||
import { requirePortalBackend } from "@/server/web/portal";
|
||||
import {
|
||||
PortalProjectClient,
|
||||
@@ -11,7 +14,11 @@ import {
|
||||
|
||||
export default async function PortalProjectPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const locale = await resolveRequestLocale();
|
||||
const { actor, service } = await requirePortalBackend();
|
||||
const content = new ContentTranslationService(getSqliteConnection().db);
|
||||
const localization = content.getPublicLocalizationContext();
|
||||
const fallbackLocale = getContentFallbackLocale(locale.locale, localization);
|
||||
let data: {
|
||||
project: PortalProjectDetail;
|
||||
sections: PortalPlanningSection[];
|
||||
@@ -21,32 +28,57 @@ export default async function PortalProjectPage({ params }: { params: Promise<{
|
||||
|
||||
try {
|
||||
const row = service.getProject(actor, id);
|
||||
const projectTranslations = content.listEntityTranslations("project", row.id);
|
||||
const projectRow = content.resolveEntity("project", row, {
|
||||
locale: locale.locale,
|
||||
fallbackLocale,
|
||||
defaultLocale: locale.defaultLocale,
|
||||
translations: projectTranslations,
|
||||
});
|
||||
const allowance = service.getRevisionAllowance(actor, id);
|
||||
const sectionRows = service.listPlanningSections(actor, id);
|
||||
const sectionTranslations = content.listBatch("planning_section", sectionRows.map((section) => section.id));
|
||||
const taskRows = service.listTasks(actor, id).filter((task) => task.status !== "cancelled");
|
||||
const taskTranslations = content.listBatch("task", taskRows.map((task) => task.id));
|
||||
data = {
|
||||
project: {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
status: row.status,
|
||||
progress: row.progress,
|
||||
due_date: row.dueDate,
|
||||
id: projectRow.id,
|
||||
name: projectRow.name,
|
||||
description: projectRow.description,
|
||||
status: projectRow.status,
|
||||
progress: projectRow.progress,
|
||||
due_date: projectRow.dueDate,
|
||||
revision_quota: allowance.remaining,
|
||||
can_request_revision: allowance.canRequest,
|
||||
},
|
||||
sections: service.listPlanningSections(actor, id).map((section) => ({
|
||||
id: section.id,
|
||||
title: section.title,
|
||||
content: section.content,
|
||||
type: section.category,
|
||||
})),
|
||||
tasks: service.listTasks(actor, id)
|
||||
.filter((task) => task.status !== "cancelled")
|
||||
.map((task) => ({
|
||||
sections: sectionRows.map((section) => {
|
||||
const sectionRow = content.resolveEntity("planning_section", section, {
|
||||
locale: locale.locale,
|
||||
fallbackLocale,
|
||||
defaultLocale: locale.defaultLocale,
|
||||
translations: sectionTranslations.get(section.id) ?? [],
|
||||
});
|
||||
return {
|
||||
id: sectionRow.id,
|
||||
title: sectionRow.title,
|
||||
content: sectionRow.content,
|
||||
type: sectionRow.category,
|
||||
};
|
||||
}),
|
||||
tasks: taskRows.map((task) => {
|
||||
const taskRow = content.resolveEntity("task", task, {
|
||||
locale: locale.locale,
|
||||
fallbackLocale,
|
||||
defaultLocale: locale.defaultLocale,
|
||||
translations: taskTranslations.get(task.id) ?? [],
|
||||
});
|
||||
return {
|
||||
id: task.id,
|
||||
title: task.title,
|
||||
title: taskRow.title,
|
||||
status: task.status as PortalTask["status"],
|
||||
date: task.dueAt?.toISOString() ?? task.scheduledDate,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
revisions: service.listRevisions(actor, id).map((revision) => ({
|
||||
id: revision.id,
|
||||
description: revision.description,
|
||||
@@ -65,6 +97,7 @@ export default async function PortalProjectPage({ params }: { params: Promise<{
|
||||
sections={data.sections}
|
||||
tasks={data.tasks}
|
||||
revisions={data.revisions}
|
||||
locale={locale.locale}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user