diff --git a/src/app/(dashboard)/inventory/assets/[assetId]/page.tsx b/src/app/(dashboard)/inventory/assets/[assetId]/page.tsx new file mode 100644 index 0000000..1bbb435 --- /dev/null +++ b/src/app/(dashboard)/inventory/assets/[assetId]/page.tsx @@ -0,0 +1,137 @@ +"use server" + +import Link from "next/link" + +import PageHeader from "@/components/common/pageheader" +import { Button } from "@/components/ui/button" +import { getI18n } from "@/i18n/server" +import { AssetService } from "@/services/asset.service" + +import type { AssetDetailCopy, AssetStatusCopy } from "../_components/asset.copy" + +function formatAssetStatus( + status: string, + statusCopy: AssetStatusCopy, + fallback: { unknownStatus: string }, +) { + return status in statusCopy + ? statusCopy[status as keyof AssetStatusCopy] + : fallback.unknownStatus +} + +function formatDate(value: Date | null | undefined, missingValue: string) { + return value ? value.toISOString().slice(0, 10) : missingValue +} + +function formatPrice( + value: { toString(): string } | null | undefined, + missingValue: string, +) { + return value ? value.toString() : missingValue +} + +function formatPersonName( + person: + | { + firstName?: string | null + lastName?: string | null + } + | null + | undefined, + missingValue: string, +) { + if (!person) return missingValue + + const fullName = [person.firstName, person.lastName].filter(Boolean).join(" ") + return fullName || missingValue +} + +export default async function AssetDetailPage({ + params, +}: { + params: Promise<{ assetId: string }> +}) { + const { assetId } = await params + const asset = await AssetService.findById(assetId) + const { dictionary } = await getI18n() + const copy = dictionary.inventory.assets.detail as AssetDetailCopy + const statusCopy = dictionary.inventory.assets.status + const missingValue = copy.fallback?.missingValue ?? "N/A" + + if (!asset) { + return