Initial commit: spreewaldzeit + Dockerfile for Coolify (Next.js + Prisma/SQLite)
This commit is contained in:
99
app/admin/anfragen/page.tsx
Normal file
99
app/admin/anfragen/page.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import { prisma } from "@/lib/db";
|
||||
import { InquiryRow, type InquiryRowData } from "@/components/admin/InquiryRow";
|
||||
import type { InquiryStatus } from "@/types";
|
||||
import { INQUIRY_STATUS_LABELS } from "@/types";
|
||||
import Link from "next/link";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
interface PageProps {
|
||||
searchParams: { status?: string };
|
||||
}
|
||||
|
||||
const FILTERS: Array<{ key: InquiryStatus | "all"; label: string }> = [
|
||||
{ key: "all", label: "Alle" },
|
||||
{ key: "new", label: "Neu" },
|
||||
{ key: "read", label: "Gelesen" },
|
||||
{ key: "confirmed", label: "Bestätigt" },
|
||||
{ key: "declined", label: "Abgelehnt" },
|
||||
{ key: "archived", label: "Archiviert" },
|
||||
];
|
||||
|
||||
export default async function AdminInquiriesPage({ searchParams }: PageProps) {
|
||||
const filter = (searchParams.status ?? "all") as InquiryStatus | "all";
|
||||
|
||||
const inquiries = await prisma.inquiry.findMany({
|
||||
where: filter === "all" ? {} : { status: filter },
|
||||
include: { apartment: { select: { name: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
const newCount = await prisma.inquiry.count({ where: { status: "new" } });
|
||||
|
||||
const rows: InquiryRowData[] = inquiries.map((i) => ({
|
||||
id: i.id,
|
||||
apartmentName: i.apartment.name,
|
||||
arrival: i.arrival.toISOString(),
|
||||
departure: i.departure.toISOString(),
|
||||
guests: i.guests,
|
||||
name: i.name,
|
||||
email: i.email,
|
||||
phone: i.phone,
|
||||
message: i.message,
|
||||
status: i.status as InquiryStatus,
|
||||
createdAt: i.createdAt.toISOString(),
|
||||
}));
|
||||
|
||||
return (
|
||||
<div className="container py-10 md:py-14">
|
||||
<div className="flex items-end justify-between gap-6 mb-8">
|
||||
<div>
|
||||
<div className="eyebrow mb-2">Admin</div>
|
||||
<h1 className="font-display text-3xl md:text-4xl leading-tight">
|
||||
Anfragen
|
||||
</h1>
|
||||
<p className="text-ink/60 text-sm mt-2">
|
||||
{newCount > 0
|
||||
? `${newCount} neue Anfrage${newCount === 1 ? "" : "n"} wartet auf Ihre Rückmeldung.`
|
||||
: "Alle Anfragen sind bearbeitet."}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filter */}
|
||||
<div className="flex flex-wrap gap-2 mb-6">
|
||||
{FILTERS.map((f) => {
|
||||
const active = filter === f.key;
|
||||
const href = f.key === "all" ? "/admin/anfragen" : `/admin/anfragen?status=${f.key}`;
|
||||
return (
|
||||
<Link
|
||||
key={f.key}
|
||||
href={href}
|
||||
className={cn(
|
||||
"px-3.5 py-1.5 rounded-full text-xs uppercase tracking-wider transition",
|
||||
active
|
||||
? "bg-ink text-parchment"
|
||||
: "bg-cream border border-ink/15 text-ink/70 hover:border-ink/30"
|
||||
)}
|
||||
>
|
||||
{f.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="bg-cream border border-ink/10 rounded-sm p-12 text-center text-ink/55">
|
||||
Keine Anfragen in dieser Ansicht.
|
||||
</div>
|
||||
) : (
|
||||
<ul className="space-y-3">
|
||||
{rows.map((row) => (
|
||||
<InquiryRow key={row.id} inquiry={row} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
41
app/admin/kalender/page.tsx
Normal file
41
app/admin/kalender/page.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/lib/db";
|
||||
import { CalendarManager, type BlockRow } from "@/components/admin/CalendarManager";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminKalenderPage() {
|
||||
const apartments = await prisma.apartment.findMany({
|
||||
orderBy: { createdAt: "asc" },
|
||||
select: { id: true, slug: true, name: true },
|
||||
});
|
||||
|
||||
const blocks = await prisma.block.findMany({
|
||||
include: { apartment: { select: { name: true } } },
|
||||
orderBy: { startDate: "asc" },
|
||||
});
|
||||
|
||||
const rows: BlockRow[] = blocks.map((b) => ({
|
||||
id: b.id,
|
||||
apartmentId: b.apartmentId,
|
||||
apartmentName: b.apartment.name,
|
||||
startDate: b.startDate.toISOString(),
|
||||
endDate: b.endDate.toISOString(),
|
||||
reason: b.reason,
|
||||
source: b.source,
|
||||
note: b.note,
|
||||
}));
|
||||
|
||||
return (
|
||||
<div className="container py-10 md:py-14">
|
||||
<div className="mb-10">
|
||||
<div className="eyebrow mb-2">Admin</div>
|
||||
<h1 className="font-display text-3xl md:text-4xl leading-tight">Kalender</h1>
|
||||
<p className="text-ink/60 text-sm mt-2">
|
||||
Zeiträume sperren oder freigeben. Für jede Wohnung getrennt.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<CalendarManager apartments={apartments} blocks={rows} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
app/admin/layout.tsx
Normal file
22
app/admin/layout.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { AdminNav } from "@/components/admin/AdminNav";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
// Die Middleware (middleware.ts) schützt alle /admin-Routen außer /admin/login.
|
||||
// Hier holen wir nur die Session, um bei eingeloggten Admins die Nav anzuzeigen.
|
||||
// Auf der Login-Seite gibt es (noch) keine Session → Nav wird nicht gerendert.
|
||||
const session = await getSession();
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-parchment flex flex-col">
|
||||
{session && <AdminNav email={session.email} />}
|
||||
<div className="flex-1">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
82
app/admin/login/page.tsx
Normal file
82
app/admin/login/page.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Input, Label, FieldError } from "@/components/ui/Input";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const next = searchParams.get("next") ?? "/admin/anfragen";
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch("/api/admin/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error ?? "Login fehlgeschlagen.");
|
||||
}
|
||||
router.push(next);
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Unbekannter Fehler.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-6 bg-parchment">
|
||||
<div className="w-full max-w-sm bg-cream border border-ink/10 rounded-sm p-8 shadow-card">
|
||||
<div className="eyebrow mb-3">Admin</div>
|
||||
<h1 className="font-display text-3xl mb-8 leading-tight">
|
||||
Willkommen zurück.
|
||||
</h1>
|
||||
|
||||
<form onSubmit={onSubmit} className="space-y-6">
|
||||
<div>
|
||||
<Label htmlFor="email">E-Mail</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
autoComplete="email"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="password">Passwort</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
autoComplete="current-password"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FieldError message={error ?? undefined} />
|
||||
|
||||
<Button type="submit" size="lg" className="w-full" disabled={loading}>
|
||||
{loading ? "Anmelden…" : "Anmelden"}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
5
app/admin/page.tsx
Normal file
5
app/admin/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function AdminIndex() {
|
||||
redirect("/admin/anfragen");
|
||||
}
|
||||
50
app/admin/wohnungen/page.tsx
Normal file
50
app/admin/wohnungen/page.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { prisma } from "@/lib/db";
|
||||
import { parseJsonArray } from "@/lib/utils";
|
||||
import {
|
||||
ApartmentEditor,
|
||||
type EditorApartment,
|
||||
} from "@/components/admin/ApartmentEditor";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminApartmentsPage() {
|
||||
const rows = await prisma.apartment.findMany({
|
||||
orderBy: { createdAt: "asc" },
|
||||
});
|
||||
|
||||
const apartments: EditorApartment[] = rows.map((r) => ({
|
||||
id: r.id,
|
||||
slug: r.slug,
|
||||
name: r.name,
|
||||
tagline: r.tagline,
|
||||
shortDescription: r.shortDescription,
|
||||
description: r.description,
|
||||
priceFrom: r.priceFrom,
|
||||
maxGuests: r.maxGuests,
|
||||
bedrooms: r.bedrooms,
|
||||
sizeSqm: r.sizeSqm,
|
||||
features: parseJsonArray<string>(r.features),
|
||||
images: parseJsonArray<string>(r.images),
|
||||
airbnbUrl: r.airbnbUrl ?? null,
|
||||
bookingUrl: r.bookingUrl ?? null,
|
||||
published: r.published,
|
||||
}));
|
||||
|
||||
return (
|
||||
<div className="container py-10 md:py-14">
|
||||
<div className="mb-10">
|
||||
<div className="eyebrow mb-2">Admin</div>
|
||||
<h1 className="font-display text-3xl md:text-4xl leading-tight">Wohnungen</h1>
|
||||
<p className="text-ink/60 text-sm mt-2">
|
||||
Basisdaten, Ausstattung und Bilder pflegen.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-8">
|
||||
{apartments.map((apt) => (
|
||||
<ApartmentEditor key={apt.id} apartment={apt} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user