From 9a3692d14725389d48f6222da5ee2e8517b6232b Mon Sep 17 00:00:00 2001
From: Philip
Date: Sun, 13 Apr 2025 09:25:10 +0200
Subject: [PATCH] Refactor DashboardPage to use DashboardContent component and
add API endpoint to fetch all children by user
---
src/app/app/page.tsx | 24 +---
.../dashboard/dashboard-content.tsx | 123 ++++++++++++++++++
src/components/ui/skeleton.tsx | 15 +++
src/server/api/routers/child.ts | 11 ++
4 files changed, 151 insertions(+), 22 deletions(-)
create mode 100644 src/components/dashboard/dashboard-content.tsx
create mode 100644 src/components/ui/skeleton.tsx
diff --git a/src/app/app/page.tsx b/src/app/app/page.tsx
index 12a862e..383f678 100644
--- a/src/app/app/page.tsx
+++ b/src/app/app/page.tsx
@@ -2,9 +2,7 @@ import { getAuthSession } from "@/lib/auth"
import { redirect } from "next/navigation"
import { Header } from "@/components/layout/header"
import { Footer } from "@/components/layout/footer"
-import Link from "next/link"
-import { Button } from "@/components/ui/button"
-import { Plus } from "lucide-react"
+import { DashboardContent } from "@/components/dashboard/dashboard-content"
export default async function DashboardPage() {
const session = await getAuthSession()
@@ -25,25 +23,7 @@ export default async function DashboardPage() {
Wachstum, Impfungen, Zähne & mehr.
-
-
-
-
Kinder
-
-
-
-
-
Du hast noch keine Kinder hinzugefügt.
-
-
-
-
Impfungen
-
Noch keine Einträge vorhanden.
-
-
+
diff --git a/src/components/dashboard/dashboard-content.tsx b/src/components/dashboard/dashboard-content.tsx
new file mode 100644
index 0000000..75658dc
--- /dev/null
+++ b/src/components/dashboard/dashboard-content.tsx
@@ -0,0 +1,123 @@
+"use client";
+
+import { format, differenceInMonths } from "date-fns";
+import { de } from "date-fns/locale";
+import Link from "next/link";
+import { Button } from "@/components/ui/button";
+import { Plus, Baby, Syringe, Calendar, Clock } from "lucide-react";
+import { trpc } from "@/utils/trpc";
+import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
+
+export function DashboardContent() {
+ const { data: children, isLoading } = trpc.child.getAllByUser.useQuery();
+
+ return (
+
+
+
+
+
+ Kinder
+ Verwalte deine Kinder
+
+
+
+
+
+
+ {isLoading ? (
+
+ ) : children && children.length > 0 ? (
+
+ {children.map((child) => {
+ const birthDate = new Date(child.birthDate);
+ const ageInMonths = differenceInMonths(new Date(), birthDate);
+
+ return (
+
+
+
+
{child.name}
+
+
+
+ Geboren: {format(birthDate, "dd.MM.yyyy", { locale: de })}
+
+
+
+ Alter: {ageInMonths} Monate
+
+
+
+
+ );
+ })}
+
+ ) : (
+
+
+
+
+
Du hast noch keine Kinder hinzugefügt.
+
+
+
+
+ )}
+
+
+
+
+
+
+ Impfungen
+ Verfolge Impftermine
+
+
+
+
+
+
+
+
Noch keine Impfungen eingetragen.
+
+
+
+
+
+
+
+
+
+ Entwicklung
+ Verfolge die Entwicklung deines Kindes
+
+
+
+
+
Entwicklungsdaten werden bald verfügbar sein.
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsx
new file mode 100644
index 0000000..f47c316
--- /dev/null
+++ b/src/components/ui/skeleton.tsx
@@ -0,0 +1,15 @@
+import { cn } from "@/lib/utils"
+
+function Skeleton({
+ className,
+ ...props
+}: React.HTMLAttributes) {
+ return (
+
+ )
+}
+
+export { Skeleton }
\ No newline at end of file
diff --git a/src/server/api/routers/child.ts b/src/server/api/routers/child.ts
index 5918dd6..9c9e98e 100644
--- a/src/server/api/routers/child.ts
+++ b/src/server/api/routers/child.ts
@@ -11,6 +11,17 @@ export const childRouter = router({
});
}),
+ getAllByUser: protectedProcedure.query(async ({ ctx }) => {
+ return ctx.prisma.child.findMany({
+ where: {
+ userId: ctx.session.user.id
+ },
+ orderBy: {
+ birthDate: 'asc'
+ }
+ });
+ }),
+
add: protectedProcedure
.input(
z.object({