feat(health): health card share link, PDF export, weight chart in card
- ShareDialog: expiry selector (7/14/30/60/90 days, default 14), shows expiry date after generation, "Als PDF öffnen / drucken" button - WeightChart extracted to standalone component (WeightChart.tsx) so it can be shared between HealthDashboard and the public health card page - Health card page: renders WeightChart when 2+ weight entries exist - AutoPrint client component: auto-triggers window.print() when card is opened with ?print=1 (600ms delay for render to settle) - README: Phase 6 + Phase 7 marked complete with full feature summaries; project structure and router list updated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9f786c87f
commit
80559c3b3f
12 files changed
+780
-371
No files matched your search
@@ -5,9 +5,13 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { getAvatarUrl } from "@/lib/avatar-url";
|
||||
import { PrintButton } from "@/components/health/PrintButton";
|
||||
import { AutoPrint } from "@/components/health/AutoPrint";
|
||||
import { WeightChart } from "@/components/health/WeightChart";
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ token: string }>;
|
||||
searchParams: Promise<{ print?: string }>;
|
||||
}
|
||||
|
||||
function formatDate(d: Date | string) {
|
||||
@@ -27,8 +31,10 @@ function isOverdue(date: Date | string): boolean {
|
||||
return new Date(date) < new Date();
|
||||
}
|
||||
|
||||
export default async function HealthCardPage({ params }: PageProps) {
|
||||
export default async function HealthCardPage({ params, searchParams }: PageProps) {
|
||||
const { token } = await params;
|
||||
const { print } = await searchParams;
|
||||
const autoPrint = print === "1";
|
||||
|
||||
const card = await prisma.healthCard.findUnique({
|
||||
where: { token },
|
||||
@@ -47,16 +53,48 @@ export default async function HealthCardPage({ params }: PageProps) {
|
||||
|
||||
if (!card) notFound();
|
||||
|
||||
// Expired link
|
||||
if (card.expiresAt && card.expiresAt < new Date()) {
|
||||
return (
|
||||
<div className="min-h-screen bg-muted/30 flex items-center justify-center px-4">
|
||||
<div className="bg-card border rounded-xl p-8 max-w-sm text-center space-y-4">
|
||||
<div className="flex justify-center">
|
||||
<div className="w-12 h-12 rounded-full bg-destructive/10 flex items-center justify-center">
|
||||
<AlertTriangle className="h-6 w-6 text-destructive" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-lg font-semibold">Link abgelaufen</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Dieser Health-Card-Link ist am{" "}
|
||||
<strong>{formatDate(card.expiresAt)}</strong> abgelaufen.
|
||||
Bitte den Besitzer um einen neuen Link.
|
||||
</p>
|
||||
<div className="flex items-center justify-center gap-2 pt-2">
|
||||
<PawPrint className="h-4 w-4 text-orange-500" />
|
||||
<span className="text-sm font-medium text-muted-foreground">PawFeed</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { pet } = card;
|
||||
const avatarUrl = getAvatarUrl(pet.avatarKey);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-muted/30">
|
||||
{autoPrint && <AutoPrint />}
|
||||
{/* Header bar */}
|
||||
<div className="bg-card border-b px-4 py-3 flex items-center gap-2">
|
||||
<div className="bg-card border-b px-4 py-3 flex items-center gap-2 print:hidden">
|
||||
<PawPrint className="h-4 w-4 text-orange-500" aria-hidden="true" />
|
||||
<span className="text-sm font-semibold text-foreground">PawFeed</span>
|
||||
<span className="text-xs text-muted-foreground ml-auto">Health Card</span>
|
||||
<span className="text-xs text-muted-foreground">· Health Card</span>
|
||||
{card.expiresAt && (
|
||||
<span className="text-xs text-muted-foreground ml-auto">
|
||||
Gültig bis {formatDate(card.expiresAt)}
|
||||
</span>
|
||||
)}
|
||||
<PrintButton />
|
||||
</div>
|
||||
|
||||
<div className="max-w-[600px] mx-auto px-4 py-8 space-y-6">
|
||||
@@ -80,21 +118,32 @@ export default async function HealthCardPage({ params }: PageProps) {
|
||||
{/* Vaccines */}
|
||||
{pet.vaccines.length > 0 && (
|
||||
<div className="bg-card rounded-xl border p-5 space-y-3">
|
||||
<h2 className="text-base font-semibold">Vaccines</h2>
|
||||
<h2 className="text-base font-semibold flex items-center gap-2">
|
||||
<span className="w-1 h-5 rounded-full bg-orange-500 inline-block" />
|
||||
Impfungen
|
||||
</h2>
|
||||
<div className="space-y-2">
|
||||
{pet.vaccines.map((vac) => {
|
||||
const overdue = vac.nextDueDate && isOverdue(vac.nextDueDate);
|
||||
return (
|
||||
<div key={vac.id} className="flex items-start justify-between gap-2 py-1.5">
|
||||
<div key={vac.id} className="flex items-start justify-between gap-2 py-1.5 border-b last:border-0">
|
||||
<div>
|
||||
<p className="text-sm font-medium">{vac.name}</p>
|
||||
<p className="text-xs text-muted-foreground">Given {formatDate(vac.dateGiven)}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Gegeben: {formatDate(vac.dateGiven)}
|
||||
{vac.notes ? ` · ${vac.notes}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right shrink-0">
|
||||
{vac.nextDueDate && (
|
||||
<Badge variant={overdue ? "destructive" : "secondary"} className="text-xs gap-1">
|
||||
<Badge
|
||||
variant={overdue ? "destructive" : "secondary"}
|
||||
className="text-xs gap-1"
|
||||
>
|
||||
{overdue && <AlertTriangle className="h-3 w-3" />}
|
||||
{overdue ? "Overdue" : `Due ${formatDate(vac.nextDueDate)}`}
|
||||
{overdue
|
||||
? `Überfällig seit ${formatDate(vac.nextDueDate)}`
|
||||
: `Fällig ${formatDate(vac.nextDueDate)}`}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@@ -108,25 +157,43 @@ export default async function HealthCardPage({ params }: PageProps) {
|
||||
{/* Weight history */}
|
||||
{pet.weightLogs.length > 0 && (
|
||||
<div className="bg-card rounded-xl border p-5 space-y-3">
|
||||
<h2 className="text-base font-semibold">Weight History</h2>
|
||||
<div className="space-y-1">
|
||||
{pet.weightLogs.map((log) => (
|
||||
<div key={log.id} className="flex items-center justify-between py-1">
|
||||
<p className="text-sm text-muted-foreground">{formatDate(log.date)}</p>
|
||||
<div className="flex items-center gap-3">
|
||||
{log.notes && <p className="text-xs text-muted-foreground">{log.notes}</p>}
|
||||
<p className="text-sm font-medium tabular-nums">{formatWeight(log.weightGrams)}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<h2 className="text-base font-semibold flex items-center gap-2">
|
||||
<span className="w-1 h-5 rounded-full bg-orange-300 inline-block" />
|
||||
Gewichtsverlauf
|
||||
</h2>
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-xs text-muted-foreground border-b">
|
||||
<th className="text-left pb-2 font-medium">Datum</th>
|
||||
<th className="text-right pb-2 font-medium">Gewicht</th>
|
||||
<th className="text-left pb-2 pl-4 font-medium">Notiz</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pet.weightLogs.map((log) => (
|
||||
<tr key={log.id} className="border-b last:border-0">
|
||||
<td className="py-1.5 text-muted-foreground">{formatDate(log.date)}</td>
|
||||
<td className="py-1.5 text-right font-medium tabular-nums">
|
||||
{formatWeight(log.weightGrams)}
|
||||
</td>
|
||||
<td className="py-1.5 pl-4 text-xs text-muted-foreground">{log.notes ?? ""}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{pet.weightLogs.length >= 2 && (
|
||||
<WeightChart data={pet.weightLogs} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Vet visits */}
|
||||
{pet.vetVisits.length > 0 && (
|
||||
<div className="bg-card rounded-xl border p-5 space-y-3">
|
||||
<h2 className="text-base font-semibold">Vet Visits</h2>
|
||||
<h2 className="text-base font-semibold flex items-center gap-2">
|
||||
<span className="w-1 h-5 rounded-full bg-gray-400 inline-block" />
|
||||
Tierarztbesuche
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{pet.vetVisits.map((visit, i) => (
|
||||
<div key={visit.id}>
|
||||
@@ -134,7 +201,9 @@ export default async function HealthCardPage({ params }: PageProps) {
|
||||
<div className="pt-2 first:pt-0">
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<p className="text-sm font-medium">{visit.reason}</p>
|
||||
<p className="text-xs text-muted-foreground shrink-0">{formatDate(visit.date)}</p>
|
||||
<p className="text-xs text-muted-foreground shrink-0">
|
||||
{formatDate(visit.date)}
|
||||
</p>
|
||||
</div>
|
||||
{visit.vetName && (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">{visit.vetName}</p>
|
||||
@@ -149,16 +218,19 @@ export default async function HealthCardPage({ params }: PageProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{pet.vaccines.length === 0 && pet.weightLogs.length === 0 && pet.vetVisits.length === 0 && (
|
||||
<div className="bg-card rounded-xl border p-8 text-center text-muted-foreground">
|
||||
<p className="text-sm">No health records have been added yet.</p>
|
||||
</div>
|
||||
)}
|
||||
{pet.vaccines.length === 0 &&
|
||||
pet.weightLogs.length === 0 &&
|
||||
pet.vetVisits.length === 0 && (
|
||||
<div className="bg-card rounded-xl border p-8 text-center text-muted-foreground">
|
||||
<p className="text-sm">Noch keine Gesundheitsdaten vorhanden.</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Footer */}
|
||||
<p className="text-xs text-muted-foreground text-center pb-4">
|
||||
Generated via PawFeed · {new Date().toLocaleDateString("de-DE")}
|
||||
</p>
|
||||
<div className="flex items-center justify-between text-xs text-muted-foreground pb-4">
|
||||
<span>Erstellt via PawFeed · {new Date().toLocaleDateString("de-DE")}</span>
|
||||
{card.expiresAt && <span>Gültig bis {formatDate(card.expiresAt)}</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user