diff --git a/app/[lang]/dashboard/[planId]/page.tsx b/app/[lang]/dashboard/[planId]/page.tsx index 884edcf..6cb2f98 100644 --- a/app/[lang]/dashboard/[planId]/page.tsx +++ b/app/[lang]/dashboard/[planId]/page.tsx @@ -60,7 +60,7 @@ export default async function DashboardPage({ />
-

{dict.home.title}

+

{plan.title}

{plan.startDate.toLocaleDateString(lang)} - {plan.endDate.toLocaleDateString(lang)}

diff --git a/app/api/plan/route.ts b/app/api/plan/route.ts index f604d10..1fd314d 100644 --- a/app/api/plan/route.ts +++ b/app/api/plan/route.ts @@ -4,14 +4,15 @@ import prisma from '@/lib/prisma'; export async function POST(req: Request) { try { const body = await req.json(); - const { startDate, endDate, password, instructions } = body; + const { title, startDate, endDate, password, instructions } = body; - if (!startDate || !endDate || !password) { + if (!title || !startDate || !endDate || !password) { return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); } const plan = await prisma.plan.create({ data: { + title, startDate: new Date(startDate), endDate: new Date(endDate), password, diff --git a/components/create-plan-form.tsx b/components/create-plan-form.tsx index eec0665..5644ee7 100644 --- a/components/create-plan-form.tsx +++ b/components/create-plan-form.tsx @@ -33,6 +33,9 @@ export function CreatePlanForm({ dict, lang }: CreatePlanFormProps) { const router = useRouter() const formSchema = z.object({ + title: z.string().min(2, { + message: dict.titleError, + }), dateRange: z.object({ from: z.date(), to: z.date(), @@ -46,6 +49,7 @@ export function CreatePlanForm({ dict, lang }: CreatePlanFormProps) { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { + title: "", password: "", instructions: "", }, @@ -59,6 +63,7 @@ export function CreatePlanForm({ dict, lang }: CreatePlanFormProps) { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ + title: values.title, startDate: values.dateRange.from, endDate: values.dateRange.to, password: values.password, @@ -81,7 +86,21 @@ export function CreatePlanForm({ dict, lang }: CreatePlanFormProps) { return (
- + + ( + + {dict.title} + + + + + + )} + /> + )} /> - + ) diff --git a/dictionaries/de.json b/dictionaries/de.json index 26ac958..e7e858e 100644 --- a/dictionaries/de.json +++ b/dictionaries/de.json @@ -3,9 +3,12 @@ "title": "Katzen-Sitting-Planer", "description": "Koordiniere die Pflege deiner Vierbeiner, während du weg bist.", "createPlan": "Neuen Plan erstellen", - "createPlanDesc": "Wähle deine Reisedaten und setze ein Gruppen-Passwort." + "createPlanDesc": "Gib deinem Plan einen Namen, wähle deine Reisedaten und setze ein Gruppen-Passwort." }, "createPlanForm": { + "title": "Titel des Plans", + "titlePlaceholder": "Lilly & Diego 🐈 🐈‍⬛", + "titleError": "Der Titel muss mindestens 2 Zeichen lang sein.", "travelDates": "Reisedaten", "pickDateRange": "Zeitraum wählen", "dateRangeDesc": "Wähle die Tage aus, an denen du weg bist.", diff --git a/dictionaries/en.json b/dictionaries/en.json index db916bd..901dddc 100644 --- a/dictionaries/en.json +++ b/dictionaries/en.json @@ -3,9 +3,12 @@ "title": "Cat Sitting Planner", "description": "Coordinate care for your furry friends while you're away.", "createPlan": "Create a New Plan", - "createPlanDesc": "Select your travel dates and set a group password." + "createPlanDesc": "Give your plan a title, select your travel dates and set a group password." }, "createPlanForm": { + "title": "Plan Title", + "titlePlaceholder": "Lilly & Diego 🐈 🐈‍⬛", + "titleError": "Title must be at least 2 characters.", "travelDates": "Travel Dates", "pickDateRange": "Pick a date range", "dateRangeDesc": "Select the days you will be away.", diff --git a/prisma/migrations/20260112213113_add_title_to_plan_with_default/migration.sql b/prisma/migrations/20260112213113_add_title_to_plan_with_default/migration.sql new file mode 100644 index 0000000..f5551bd --- /dev/null +++ b/prisma/migrations/20260112213113_add_title_to_plan_with_default/migration.sql @@ -0,0 +1,19 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Plan" ( + "id" TEXT NOT NULL PRIMARY KEY, + "title" TEXT NOT NULL DEFAULT 'Cat Plan', + "password" TEXT NOT NULL, + "startDate" DATETIME NOT NULL, + "endDate" DATETIME NOT NULL, + "instructions" TEXT, + "webhookUrl" TEXT, + "notifyAll" BOOLEAN NOT NULL DEFAULT true, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); +INSERT INTO "new_Plan" ("createdAt", "endDate", "id", "instructions", "notifyAll", "password", "startDate", "webhookUrl") SELECT "createdAt", "endDate", "id", "instructions", "notifyAll", "password", "startDate", "webhookUrl" FROM "Plan"; +DROP TABLE "Plan"; +ALTER TABLE "new_Plan" RENAME TO "Plan"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20260112213124_remove_title_default/migration.sql b/prisma/migrations/20260112213124_remove_title_default/migration.sql new file mode 100644 index 0000000..4a16e7c --- /dev/null +++ b/prisma/migrations/20260112213124_remove_title_default/migration.sql @@ -0,0 +1,19 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Plan" ( + "id" TEXT NOT NULL PRIMARY KEY, + "title" TEXT NOT NULL, + "password" TEXT NOT NULL, + "startDate" DATETIME NOT NULL, + "endDate" DATETIME NOT NULL, + "instructions" TEXT, + "webhookUrl" TEXT, + "notifyAll" BOOLEAN NOT NULL DEFAULT true, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); +INSERT INTO "new_Plan" ("createdAt", "endDate", "id", "instructions", "notifyAll", "password", "startDate", "title", "webhookUrl") SELECT "createdAt", "endDate", "id", "instructions", "notifyAll", "password", "startDate", "title", "webhookUrl" FROM "Plan"; +DROP TABLE "Plan"; +ALTER TABLE "new_Plan" RENAME TO "Plan"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1abd10f..c5ef726 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -9,6 +9,7 @@ generator client { model Plan { id String @id @default(cuid()) + title String password String startDate DateTime endDate DateTime