feat: add plan title field with data migration
This commit is contained in:
@@ -60,7 +60,7 @@ export default async function DashboardPage({
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{dict.home.title}</h1>
|
||||
<h1 className="text-2xl font-bold">{plan.title}</h1>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{plan.startDate.toLocaleDateString(lang)} - {plan.endDate.toLocaleDateString(lang)}
|
||||
</p>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<z.infer<typeof formSchema>>({
|
||||
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 (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="title"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{dict.title}</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder={dict.titlePlaceholder} {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="dateRange"
|
||||
@@ -150,7 +169,7 @@ export function CreatePlanForm({ dict, lang }: CreatePlanFormProps) {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button type="submit">{dict.submit}</Button>
|
||||
<Button type="submit" className="w-full">{dict.submit}</Button>
|
||||
</form>
|
||||
</Form>
|
||||
)
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -9,6 +9,7 @@ generator client {
|
||||
|
||||
model Plan {
|
||||
id String @id @default(cuid())
|
||||
title String
|
||||
password String
|
||||
startDate DateTime
|
||||
endDate DateTime
|
||||
|
||||
Reference in New Issue
Block a user