chore: finish workspace cleanup

This commit is contained in:
2026-07-03 04:04:54 -07:00
parent 901e36b7a7
commit c4d5222ddd
9 changed files with 278 additions and 175 deletions

View File

@@ -377,7 +377,7 @@ await database
- Good: use one additive `care_tasks` table for MVP execution records instead of building a full recurring care-plan engine. - Good: use one additive `care_tasks` table for MVP execution records instead of building a full recurring care-plan engine.
- Good: preserve `/app/health` separation; care execution is operational and not the health admin settings page. - Good: preserve `/app/health` separation; care execution is operational and not the health admin settings page.
- Base: `elderId` can be nullable for future public-area checks, but seeded MVP examples should use real elders. - Base: `elderId` can be nullable for future public-area checks, but seeded MVP examples should use real elders.
- Bad: render fake care metrics in `ModulePage` after the module becomes real. - Bad: render fake care metrics in a static placeholder after the module becomes real.
- Bad: update task status by ID alone without `organizationId`. - Bad: update task status by ID alone without `organizationId`.
- Bad: only disable buttons in the UI while leaving Route Handlers on broad elder permissions. - Bad: only disable buttons in the UI while leaving Route Handlers on broad elder permissions.

View File

@@ -165,44 +165,17 @@ The project Dialog adapter must:
### Static Module Data Contract ### Static Module Data Contract
Static or reserved module pages must not fabricate operational data. If a module does Operational module pages must not fabricate data. If a module does not have a
not have a Drizzle-backed query/API and real persisted records, render a clear empty or Drizzle-backed query/API and real persisted records, render a clear empty or
not-connected state instead of generated counters, fake workflows, sample records, or not-connected state inside that module's own route/component instead of generated
mock priority/status rows. counters, fake workflows, sample records, or mock priority/status rows.
`modules/shared/components/ModulePage.tsx` is the shared placeholder for these modules. The old shared reserved-module placeholder components were removed after devices,
Its props should stay descriptive only: notices, alerts, family, health, care, and emergency became real persisted workspaces.
Do not reintroduce a generic `ReservedModulePages` layer for operational modules.
```typescript When a module becomes real, implement the route as a Server Component that loads data
type ModulePageProps = { from the server boundary and passes only persisted, permission-filtered data into
title: string;
eyebrow: string;
description: string;
icon: LucideIcon;
phase: "待接入" | "二期预留" | "三期预留";
};
```
```typescript
// Bad: static pages pretending to have live business data.
<ModulePage
title="Care"
metrics={[{ label: "Today", value: "184", detail: "142 done" }]}
workflows={["Create plan", "Dispatch task"]}
/>
// Good: no fabricated records until a real data source exists.
<ModulePage
title="Care"
eyebrow="Plans and inspections"
description="Pending connection to care plans, task dispatch, and execution records."
icon={ClipboardCheck}
phase="待接入"
/>
```
When a module becomes real, replace the placeholder with a Server Component that loads
data from the server boundary and pass only persisted, permission-filtered data into
client components. client components.
### App Shell Tenant and Account Menu Contract ### App Shell Tenant and Account Menu Contract

View File

@@ -21,9 +21,9 @@ the rest conversationally.
## Status (update the checkboxes as you complete each item) ## Status (update the checkboxes as you complete each item)
- [ ] Fill backend guidelines - [x] Fill backend guidelines
- [ ] Fill frontend guidelines - [x] Fill frontend guidelines
- [ ] Add code examples - [x] Add code examples
--- ---

View File

@@ -3,7 +3,7 @@
"name": "00-bootstrap-guidelines", "name": "00-bootstrap-guidelines",
"title": "Bootstrap Guidelines", "title": "Bootstrap Guidelines",
"description": "Fill in project development guidelines for AI agents", "description": "Fill in project development guidelines for AI agents",
"status": "in_progress", "status": "completed",
"dev_type": "docs", "dev_type": "docs",
"scope": null, "scope": null,
"package": null, "package": null,
@@ -11,7 +11,7 @@
"creator": "TalexDreamSoul", "creator": "TalexDreamSoul",
"assignee": "TalexDreamSoul", "assignee": "TalexDreamSoul",
"createdAt": "2026-07-01", "createdAt": "2026-07-01",
"completedAt": null, "completedAt": "2026-07-03",
"branch": null, "branch": null,
"base_branch": null, "base_branch": null,
"worktree_path": null, "worktree_path": null,

View File

@@ -1,5 +1,5 @@
import { renderHealthWorkspacePage } from "@/modules/health/components/HealthWorkspacePage"; import { renderHealthSettingsPage } from "@/modules/health/components/HealthWorkspacePage";
export default async function HealthSettingsPage(): Promise<React.ReactElement> { export default async function HealthSettingsPage(): Promise<React.ReactElement> {
return renderHealthWorkspacePage(); return renderHealthSettingsPage();
} }

View File

@@ -1,13 +1,52 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { HeartPulse } from "lucide-react"; import { Activity, FileText, HeartPulse, ShieldAlert, Stethoscope } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Table } from "@/components/ui/table";
import { getCurrentAuthContext } from "@/modules/core/server/auth"; import { getCurrentAuthContext } from "@/modules/core/server/auth";
import { hasPermission } from "@/modules/core/server/permissions"; import { hasPermission } from "@/modules/core/server/permissions";
import { HealthAdminClient } from "@/modules/health/components/HealthAdminClient"; import { HealthAdminClient } from "@/modules/health/components/HealthAdminClient";
import { listHealthAdminData } from "@/modules/health/server/operations"; import { listHealthAdminData } from "@/modules/health/server/operations";
import type { HealthReviewSeverity, HealthReviewStatus } from "@/modules/health/types";
import {
CHRONIC_CONDITION_STATUS_LABELS,
HEALTH_REVIEW_SEVERITY_LABELS,
HEALTH_REVIEW_STATUS_LABELS,
VITAL_SOURCE_LABELS,
} from "@/modules/health/types";
import { getWorkspaceHref } from "@/modules/shared/lib/workspace-routing"; import { getWorkspaceHref } from "@/modules/shared/lib/workspace-routing";
export async function renderHealthWorkspacePage(): Promise<React.ReactElement> { type HealthPageData = {
canManage: boolean;
data: Awaited<ReturnType<typeof listHealthAdminData>>;
};
function formatDateTime(value: string | undefined): string {
return value ? new Date(value).toLocaleString("zh-CN") : "-";
}
function formatTenths(value: number | undefined, suffix = ""): string {
return value === undefined ? "-" : `${(value / 10).toFixed(1)}${suffix}`;
}
function severityBadgeVariant(severity: HealthReviewSeverity): "secondary" | "warning" | "danger" {
if (severity === "critical") {
return "danger";
}
return severity === "warning" ? "warning" : "secondary";
}
function reviewStatusBadgeVariant(status: HealthReviewStatus): "success" | "secondary" | "warning" {
if (status === "pending") {
return "warning";
}
return status === "resolved" ? "success" : "secondary";
}
async function loadHealthPageData(): Promise<HealthPageData> {
const context = await getCurrentAuthContext(); const context = await getCurrentAuthContext();
if (!context) { if (!context) {
redirect("/login"); redirect("/login");
@@ -23,6 +62,17 @@ export async function renderHealthWorkspacePage(): Promise<React.ReactElement> {
} }
const data = await listHealthAdminData(organizationId); const data = await listHealthAdminData(organizationId);
return {
canManage: hasPermission(context.permissions, "health:manage"),
data,
};
}
export async function renderHealthWorkspacePage(): Promise<React.ReactElement> {
const { data } = await loadHealthPageData();
const pendingReviews = data.reviews.filter((review) => review.status === "pending").slice(0, 8);
const recentVitals = data.vitals.slice(0, 8);
const activeConditions = data.chronicConditions.filter((condition) => condition.status === "active").slice(0, 8);
return ( return (
<div className="mx-auto flex w-full max-w-7xl flex-col gap-5"> <div className="mx-auto flex w-full max-w-7xl flex-col gap-5">
@@ -33,12 +83,172 @@ export async function renderHealthWorkspacePage(): Promise<React.ReactElement> {
</span> </span>
<div className="min-w-0"> <div className="min-w-0">
<h1 className="truncate text-xl font-semibold tracking-normal"></h1> <h1 className="truncate text-xl font-semibold tracking-normal"></h1>
<p className="mt-1 truncate text-sm text-muted-foreground"></p> <p className="mt-1 truncate text-sm text-muted-foreground"></p>
</div> </div>
</div> </div>
</section> </section>
<HealthAdminClient canManage={hasPermission(context.permissions, "health:manage")} initialData={data} /> <section className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
<MetricCard icon={<FileText className="size-4" aria-hidden="true" />} label="健康档案" value={data.metrics.eldersWithProfiles} />
<MetricCard icon={<Activity className="size-4" aria-hidden="true" />} label="今日体征" value={data.metrics.vitalsToday} />
<MetricCard icon={<Stethoscope className="size-4" aria-hidden="true" />} label="慢病管理" value={data.metrics.activeChronicConditions} />
<MetricCard icon={<ShieldAlert className="size-4" aria-hidden="true" />} label="待复核" value={data.metrics.pendingReviews} />
</section>
<section className="grid gap-4 xl:grid-cols-[1.1fr_0.9fr]">
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="overflow-x-auto">
<Table className="w-full min-w-[720px] text-sm">
<Table.Header className="bg-secondary text-left text-xs text-muted-foreground">
<Table.Row>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
</Table.Row>
</Table.Header>
<Table.Body className="divide-y bg-card">
{pendingReviews.map((review) => (
<Table.Row key={review.id}>
<Table.Cell className="px-4 py-3 font-medium">{review.elderName}</Table.Cell>
<Table.Cell className="px-4 py-3">
<p className="font-medium">{review.title}</p>
<p className="text-xs text-muted-foreground">{review.description}</p>
</Table.Cell>
<Table.Cell className="px-4 py-3">
<Badge variant={severityBadgeVariant(review.severity)}>
{HEALTH_REVIEW_SEVERITY_LABELS[review.severity]}
</Badge>
</Table.Cell>
<Table.Cell className="px-4 py-3">
<Badge variant={reviewStatusBadgeVariant(review.status)}>
{HEALTH_REVIEW_STATUS_LABELS[review.status]}
</Badge>
</Table.Cell>
<Table.Cell className="px-4 py-3 text-muted-foreground">{formatDateTime(review.createdAt)}</Table.Cell>
</Table.Row>
))}
{pendingReviews.length === 0 ? (
<Table.Row>
<Table.Cell className="px-4 py-8 text-center text-muted-foreground" colSpan={5}>
</Table.Cell>
</Table.Row>
) : null}
</Table.Body>
</Table>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="grid gap-2">
{activeConditions.map((condition) => (
<div className="rounded-md border p-3" key={condition.id}>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<p className="truncate text-sm font-medium">{condition.elderName}</p>
<p className="mt-1 text-xs text-muted-foreground">{condition.name}</p>
</div>
<Badge variant="warning">{CHRONIC_CONDITION_STATUS_LABELS[condition.status]}</Badge>
</div>
<p className="mt-2 text-xs text-muted-foreground">{condition.followUpNotes || condition.treatmentNotes || "暂无随访备注"}</p>
</div>
))}
{activeConditions.length === 0 ? <p className="text-sm text-muted-foreground"></p> : null}
</CardContent>
</Card>
</section>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="overflow-x-auto">
<Table className="w-full min-w-[820px] text-sm">
<Table.Header className="bg-secondary text-left text-xs text-muted-foreground">
<Table.Row>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
<Table.Head className="px-4 py-3 font-medium"></Table.Head>
</Table.Row>
</Table.Header>
<Table.Body className="divide-y bg-card">
{recentVitals.map((vital) => (
<Table.Row key={vital.id}>
<Table.Cell className="px-4 py-3 font-medium">{vital.elderName}</Table.Cell>
<Table.Cell className="px-4 py-3 text-muted-foreground">{formatDateTime(vital.recordedAt)}</Table.Cell>
<Table.Cell className="px-4 py-3">{VITAL_SOURCE_LABELS[vital.source]}</Table.Cell>
<Table.Cell className="px-4 py-3">
{vital.systolicBp && vital.diastolicBp ? `${vital.systolicBp}/${vital.diastolicBp}` : "-"}
</Table.Cell>
<Table.Cell className="px-4 py-3">{vital.heartRate?.toString() ?? "-"}</Table.Cell>
<Table.Cell className="px-4 py-3">{formatTenths(vital.temperatureTenths, "°C")}</Table.Cell>
<Table.Cell className="px-4 py-3">{vital.spo2 === undefined ? "-" : `${vital.spo2}%`}</Table.Cell>
<Table.Cell className="px-4 py-3 text-muted-foreground">{vital.notes || "-"}</Table.Cell>
</Table.Row>
))}
{recentVitals.length === 0 ? (
<Table.Row>
<Table.Cell className="px-4 py-8 text-center text-muted-foreground" colSpan={8}>
</Table.Cell>
</Table.Row>
) : null}
</Table.Body>
</Table>
</CardContent>
</Card>
</div> </div>
); );
} }
export async function renderHealthSettingsPage(): Promise<React.ReactElement> {
const { canManage, data } = await loadHealthPageData();
return (
<div className="mx-auto flex w-full max-w-7xl flex-col gap-5">
<section className="flex flex-col gap-3 border-b pb-4 lg:flex-row lg:items-start lg:justify-between">
<div className="flex min-w-0 items-center gap-3">
<span className="inline-flex size-9 items-center justify-center rounded-md bg-secondary text-primary">
<HeartPulse className="size-4" aria-hidden="true" />
</span>
<div className="min-w-0">
<h1 className="truncate text-xl font-semibold tracking-normal"></h1>
<p className="mt-1 truncate text-sm text-muted-foreground"></p>
</div>
</div>
</section>
<HealthAdminClient canManage={canManage} initialData={data} />
</div>
);
}
function MetricCard({ icon, label, value }: { icon: React.ReactNode; label: string; value: number }): React.ReactElement {
return (
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardDescription>{label}</CardDescription>
<span className="text-primary">{icon}</span>
</CardHeader>
<CardContent>
<CardTitle className="text-3xl">{value}</CardTitle>
</CardContent>
</Card>
);
}

View File

@@ -11,6 +11,7 @@ import {
HeartPulse, HeartPulse,
LayoutDashboard, LayoutDashboard,
ListChecks, ListChecks,
LockKeyhole,
Radio, Radio,
Settings, Settings,
ShieldAlert, ShieldAlert,
@@ -49,7 +50,15 @@ type AppSidebarNavProps = {
permissions: Permission[]; permissions: Permission[];
}; };
type SidebarNavItem = NavItem & {
canAccess: boolean;
};
function canViewNavItem(item: NavItem, permissions: readonly Permission[]): boolean { function canViewNavItem(item: NavItem, permissions: readonly Permission[]): boolean {
if (permissions.includes("platform:manage")) {
return true;
}
if (item.permission && !permissions.includes(item.permission)) { if (item.permission && !permissions.includes(item.permission)) {
return false; return false;
} }
@@ -63,12 +72,13 @@ function canViewNavItem(item: NavItem, permissions: readonly Permission[]): bool
export function AppSidebarNav({ organizationSlug, permissions }: AppSidebarNavProps): React.ReactElement { export function AppSidebarNav({ organizationSlug, permissions }: AppSidebarNavProps): React.ReactElement {
const pathname = usePathname(); const pathname = usePathname();
const visibleNavGroups = navGroups const visibleNavGroups = navGroups.map((group): { label: string; items: SidebarNavItem[] } => ({
.map((group) => ({ ...group,
...group, items: group.items.map((item) => ({
items: group.items.filter((item) => canViewNavItem(item, permissions)), ...item,
})) canAccess: canViewNavItem(item, permissions),
.filter((group) => group.items.length > 0); })),
}));
return ( return (
<nav className="min-h-0 flex-1 overflow-y-auto px-3 py-4" aria-label="主导航"> <nav className="min-h-0 flex-1 overflow-y-auto px-3 py-4" aria-label="主导航">
@@ -80,29 +90,42 @@ export function AppSidebarNav({ organizationSlug, permissions }: AppSidebarNavPr
{group.items.map((item) => { {group.items.map((item) => {
const Icon = iconMap[item.icon]; const Icon = iconMap[item.icon];
const href = getWorkspaceHref(organizationSlug, item.path); const href = getWorkspaceHref(organizationSlug, item.path);
const isActive = isWorkspacePathActive(pathname, item.path); const isActive = item.canAccess && isWorkspacePathActive(pathname, item.path);
return ( return (
<li key={item.path}> <li key={item.path}>
<Link {item.canAccess ? (
href={href} <Link
aria-current={isActive ? "page" : undefined} href={href}
className={cn( aria-current={isActive ? "page" : undefined}
"group flex min-h-11 items-center gap-3 rounded-md px-3 text-sm transition-colors",
isActive
? "bg-primary text-primary-foreground shadow-sm"
: "text-foreground hover:bg-secondary hover:text-primary",
)}
>
<Icon
className={cn( className={cn(
"size-4 shrink-0 transition-colors", "group flex min-h-11 items-center gap-3 rounded-md px-3 text-sm transition-colors",
isActive ? "text-primary-foreground" : "text-muted-foreground group-hover:text-primary", isActive
? "bg-primary text-primary-foreground shadow-sm"
: "text-foreground hover:bg-secondary hover:text-primary",
)} )}
aria-hidden="true" >
/> <Icon
<span className="min-w-0 truncate font-medium">{item.label}</span> className={cn(
</Link> "size-4 shrink-0 transition-colors",
isActive ? "text-primary-foreground" : "text-muted-foreground group-hover:text-primary",
)}
aria-hidden="true"
/>
<span className="min-w-0 truncate font-medium">{item.label}</span>
</Link>
) : (
<span
className="flex min-h-11 cursor-not-allowed items-center gap-3 rounded-md px-3 text-sm text-muted-foreground/70"
aria-disabled="true"
title="当前角色无权访问"
>
<Icon className="size-4 shrink-0 text-muted-foreground/60" aria-hidden="true" />
<span className="min-w-0 flex-1 truncate font-medium">{item.label}</span>
<LockKeyhole className="size-3.5 shrink-0 text-muted-foreground/55" aria-hidden="true" />
<span className="sr-only">访</span>
</span>
)}
</li> </li>
); );
})} })}

View File

@@ -1,52 +0,0 @@
import type { LucideIcon } from "lucide-react";
import { Database } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
type ModulePageProps = {
title: string;
eyebrow: string;
description: string;
icon: LucideIcon;
phase: "待接入" | "二期预留" | "三期预留";
};
export function ModulePage({ title, eyebrow, description, icon: Icon, phase }: ModulePageProps): React.ReactElement {
return (
<div className="mx-auto flex w-full max-w-7xl flex-col gap-6">
<section className="flex flex-col gap-3 border-b pb-4 lg:flex-row lg:items-start lg:justify-between">
<div className="flex min-w-0 items-center gap-3">
<span className="inline-flex size-9 items-center justify-center rounded-md bg-secondary text-primary">
<Icon className="size-4" aria-hidden="true" />
</span>
<div className="min-w-0">
<div className="flex items-center gap-2">
<h1 className="truncate text-xl font-semibold tracking-normal">{title}</h1>
<Badge variant="secondary">{phase}</Badge>
</div>
<p className="mt-1 truncate text-sm text-muted-foreground">{eyebrow}</p>
<p className="mt-2 max-w-3xl text-sm text-muted-foreground">{description}</p>
</div>
</div>
</section>
<section>
<Card className="max-w-3xl">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-base">
<Database className="size-5 text-primary" aria-hidden="true" />
</CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
Drizzle API
</p>
</CardContent>
</Card>
</section>
</div>
);
}

View File

@@ -1,51 +0,0 @@
import { Bell, Radio, TabletSmartphone, Wrench } from "lucide-react";
import { ModulePage } from "@/modules/shared/components/ModulePage";
export function DevicesModulePage(): React.ReactElement {
return (
<ModulePage
title="设备运维"
eyebrow="设备台账与维修工单"
description="待接入设备台账、故障上报、维修派单、处理记录和状态恢复数据源。"
icon={Wrench}
phase="待接入"
/>
);
}
export function FamilyModulePage(): React.ReactElement {
return (
<ModulePage
title="家属服务"
eyebrow="家属端与探访反馈"
description="二期计划接入家属授权、老人动态、探访预约和服务反馈数据源。"
icon={TabletSmartphone}
phase="二期预留"
/>
);
}
export function NoticesModulePage(): React.ReactElement {
return (
<ModulePage
title="公告通知"
eyebrow="公告发布与阅读状态"
description="待接入公告草稿、发布范围、阅读状态和通知记录数据源。"
icon={Bell}
phase="待接入"
/>
);
}
export function AlertsModulePage(): React.ReactElement {
return (
<ModulePage
title="规则预警"
eyebrow="规则中心与风险识别"
description="三期计划接入健康阈值、任务逾期、设备故障、应急事件和风险老人识别规则。"
icon={Radio}
phase="三期预留"
/>
);
}