fix(admin): persist data directory and pass env vars
This commit is contained in:
parent
99e8201745
commit
1d7e7c41c9
39 changed files with 1297 additions and 32 deletions
|
|
@ -5,3 +5,6 @@ node_modules
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
.git
|
.git
|
||||||
README.md
|
README.md
|
||||||
|
data/*.json
|
||||||
|
public/uploads/images/*
|
||||||
|
!public/uploads/images/.gitkeep
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
NEXT_PUBLIC_SITE_URL=http://localhost:3010
|
NEXT_PUBLIC_SITE_URL=http://localhost:3010
|
||||||
|
|
||||||
|
# Admin Foundation
|
||||||
|
ADMIN_EMAIL=admin@funktechnik-schubert.local
|
||||||
|
ADMIN_PASSWORD=change-me
|
||||||
|
ADMIN_SESSION_SECRET=change-me-with-a-long-random-secret
|
||||||
|
AUTH_COOKIE_SECURE=false
|
||||||
|
|
||||||
# Optional spaetere Integration. Nicht im Browser verwenden.
|
# Optional spaetere Integration. Nicht im Browser verwenden.
|
||||||
OLYMPUS_INTAKE_API_URL=
|
OLYMPUS_INTAKE_API_URL=
|
||||||
OLYMPUS_INTAKE_API_TOKEN=
|
OLYMPUS_INTAKE_API_TOKEN=
|
||||||
|
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -5,3 +5,9 @@ dist
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
data/*.json
|
||||||
|
public/uploads/images/*
|
||||||
|
!public/uploads/.gitkeep
|
||||||
|
!public/uploads/images/.gitkeep
|
||||||
|
data/
|
||||||
|
.DS_Store
|
||||||
|
|
|
||||||
45
README.md
45
README.md
|
|
@ -7,6 +7,8 @@ Eigenständige öffentliche Firmenwebsite für Funktechnik Schubert. Dieses Proj
|
||||||
- Next.js 16 App Router
|
- Next.js 16 App Router
|
||||||
- TypeScript strict
|
- TypeScript strict
|
||||||
- Serverseitige API-Routen für Kontakt und Reparaturannahme
|
- Serverseitige API-Routen für Kontakt und Reparaturannahme
|
||||||
|
- Geschützter Admin-Bereich unter `/admin`
|
||||||
|
- Lokale Foundation-Datenablage für Anfragen und Einstellungen
|
||||||
- Docker
|
- Docker
|
||||||
- Nginx/Reverse-Proxy-fähig
|
- Nginx/Reverse-Proxy-fähig
|
||||||
- SEO Metadata, Sitemap und robots.txt
|
- SEO Metadata, Sitemap und robots.txt
|
||||||
|
|
@ -21,6 +23,16 @@ Eigenständige öffentliche Firmenwebsite für Funktechnik Schubert. Dieses Proj
|
||||||
- `/kontakt`
|
- `/kontakt`
|
||||||
- `/impressum`
|
- `/impressum`
|
||||||
- `/datenschutz`
|
- `/datenschutz`
|
||||||
|
- `/admin/login`
|
||||||
|
- `/admin`
|
||||||
|
- `/admin/kontaktanfragen`
|
||||||
|
- `/admin/reparaturanfragen`
|
||||||
|
- `/admin/website`
|
||||||
|
- `/admin/medien`
|
||||||
|
- `/admin/einstellungen`
|
||||||
|
- `/admin/smtp`
|
||||||
|
- `/admin/seo`
|
||||||
|
- `/admin/system`
|
||||||
|
|
||||||
## Lokale Entwicklung
|
## Lokale Entwicklung
|
||||||
|
|
||||||
|
|
@ -72,17 +84,48 @@ cp .env.example .env
|
||||||
Variablen:
|
Variablen:
|
||||||
|
|
||||||
- `NEXT_PUBLIC_SITE_URL`
|
- `NEXT_PUBLIC_SITE_URL`
|
||||||
|
- `ADMIN_EMAIL`
|
||||||
|
- `ADMIN_PASSWORD`
|
||||||
|
- `ADMIN_SESSION_SECRET`
|
||||||
|
- `AUTH_COOKIE_SECURE`
|
||||||
- `OLYMPUS_INTAKE_API_URL`
|
- `OLYMPUS_INTAKE_API_URL`
|
||||||
- `OLYMPUS_INTAKE_API_TOKEN`
|
- `OLYMPUS_INTAKE_API_TOKEN`
|
||||||
|
|
||||||
Die Olympus-Variablen sind nur für eine spätere serverseitige Integration vorbereitet. Sie werden nicht im Browser verwendet.
|
Die Olympus-Variablen sind nur für eine spätere serverseitige Integration vorbereitet. Sie werden nicht im Browser verwendet.
|
||||||
|
|
||||||
|
Für lokale Entwicklung kann `AUTH_COOKIE_SECURE=false` bleiben. Produktiv muss HTTPS verwendet und `AUTH_COOKIE_SECURE=true` gesetzt werden. `ADMIN_SESSION_SECRET` muss produktiv ein langer zufälliger Wert sein.
|
||||||
|
|
||||||
## API-Routen
|
## API-Routen
|
||||||
|
|
||||||
- `POST /api/repair`
|
- `POST /api/repair`
|
||||||
- `POST /api/contact`
|
- `POST /api/contact`
|
||||||
|
- `POST /api/admin/login`
|
||||||
|
- `POST /api/admin/logout`
|
||||||
|
- `PATCH /api/admin/contact/[id]`
|
||||||
|
- `PATCH /api/admin/repair/[id]`
|
||||||
|
- `POST /api/admin/settings`
|
||||||
|
- `POST /api/admin/smtp`
|
||||||
|
- `GET/POST /api/admin/media`
|
||||||
|
|
||||||
Aktuell validieren die Routen serverseitig, geben klare JSON-Antworten zurück und schreiben nur technische Metadaten in Server-Logs. Es werden keine Nachrichteninhalte oder Tokens geloggt.
|
Aktuell validieren die Routen serverseitig, geben klare JSON-Antworten zurück und schreiben nur technische Metadaten in Server-Logs. Es werden keine Nachrichteninhalte oder Tokens geloggt. Kontakt- und Reparaturanfragen werden lokal unter `data/*.json` gespeichert und nicht versioniert.
|
||||||
|
|
||||||
|
## Admin-Bereich
|
||||||
|
|
||||||
|
Der geschützte Admin-Bereich ist unter `/admin/login` erreichbar. Er verwendet ein signiertes HttpOnly-Cookie und ist für Desktop und Tablet ausgelegt.
|
||||||
|
|
||||||
|
Funktionen:
|
||||||
|
|
||||||
|
- Dashboard mit Kennzahlen
|
||||||
|
- Kontaktanfragen verwalten
|
||||||
|
- Reparaturanfragen verwalten
|
||||||
|
- Website-Inhaltsverwaltung vorbereitet
|
||||||
|
- Firmendaten pflegen
|
||||||
|
- SMTP-Konfiguration vorbereiten
|
||||||
|
- Medien hochladen
|
||||||
|
- SEO-Übersicht
|
||||||
|
- Systemübersicht
|
||||||
|
|
||||||
|
SMTP-Versand, Publishing von Website-Inhalten und Olympus-Übernahme sind bewusst noch nicht aktiv gekoppelt.
|
||||||
|
|
||||||
## Nginx
|
## Nginx
|
||||||
|
|
||||||
|
|
|
||||||
28
app/admin/einstellungen/page.tsx
Normal file
28
app/admin/einstellungen/page.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { getSiteSettings } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export default async function AdminSettingsPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const settings = await getSiteSettings();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Konfiguration</p>
|
||||||
|
<h1>Firmeneinstellungen</h1>
|
||||||
|
</div>
|
||||||
|
<form className="admin-card admin-form" action="/api/admin/settings" method="post">
|
||||||
|
<label>Firmenname<input name="companyName" defaultValue={settings.companyName} /></label>
|
||||||
|
<label>Telefon<input name="phone" defaultValue={settings.phone} /></label>
|
||||||
|
<label>E-Mail<input name="email" type="email" defaultValue={settings.email} /></label>
|
||||||
|
<label>Adresse<input name="address" defaultValue={settings.address} /></label>
|
||||||
|
<label>Öffnungszeiten<input name="openingHours" defaultValue={settings.openingHours} /></label>
|
||||||
|
<label>Google Maps Embed URL<input name="googleMapsEmbedUrl" defaultValue={settings.googleMapsEmbedUrl} /></label>
|
||||||
|
<label>Social Links<textarea name="socialLinks" defaultValue={settings.socialLinks} /></label>
|
||||||
|
<button className="button" type="submit">Speichern</button>
|
||||||
|
</form>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
48
app/admin/kontaktanfragen/page.tsx
Normal file
48
app/admin/kontaktanfragen/page.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import StatusSelect from "@/components/admin/StatusSelect";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { getContactInquiries } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export default async function AdminContactsPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const inquiries = await getContactInquiries();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Anfragen</p>
|
||||||
|
<h1>Kontaktanfragen</h1>
|
||||||
|
</div>
|
||||||
|
<section className="admin-card">
|
||||||
|
<table className="admin-table">
|
||||||
|
<thead><tr><th>Name</th><th>E-Mail</th><th>Betreff</th><th>Datum</th><th>Status</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{inquiries.map((item) => (
|
||||||
|
<tr key={item.id}>
|
||||||
|
<td>{item.name}</td>
|
||||||
|
<td><a href={`mailto:${item.email}`}>{item.email}</a></td>
|
||||||
|
<td>{item.subject}</td>
|
||||||
|
<td>{new Date(item.createdAt).toLocaleString("de-DE")}</td>
|
||||||
|
<td><StatusSelect id={item.id} type="contact" status={item.status} /></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{inquiries.length === 0 && <tr><td colSpan={5}>Noch keine Kontaktanfragen vorhanden.</td></tr>}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Detailansicht</h2>
|
||||||
|
<div className="admin-detail-grid">
|
||||||
|
{inquiries.slice(0, 6).map((item) => (
|
||||||
|
<article key={item.id} className="admin-detail">
|
||||||
|
<h3>{item.name}</h3>
|
||||||
|
<p><strong>{item.subject}</strong></p>
|
||||||
|
<p>{item.message}</p>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
5
app/admin/layout.tsx
Normal file
5
app/admin/layout.tsx
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
export default function AdminRootLayout({ children }: { children: ReactNode }) {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
13
app/admin/login/page.tsx
Normal file
13
app/admin/login/page.tsx
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import AdminLoginForm from "@/components/admin/AdminLoginForm";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Admin Login | Funktechnik Schubert",
|
||||||
|
robots: { index: false, follow: false },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function AdminLoginPage({ searchParams }: { searchParams: Promise<{ next?: string }> }) {
|
||||||
|
const params = await searchParams;
|
||||||
|
const nextPath = params.next?.startsWith("/admin") ? params.next : "/admin";
|
||||||
|
return <AdminLoginForm nextPath={nextPath} />;
|
||||||
|
}
|
||||||
47
app/admin/medien/page.tsx
Normal file
47
app/admin/medien/page.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { mkdir, readdir } from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
const uploadDir = path.join(process.cwd(), "public", "uploads", "images");
|
||||||
|
|
||||||
|
async function getFiles() {
|
||||||
|
await mkdir(uploadDir, { recursive: true });
|
||||||
|
return readdir(uploadDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function AdminMediaPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const files = await getFiles();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Assets</p>
|
||||||
|
<h1>Medienverwaltung</h1>
|
||||||
|
</div>
|
||||||
|
<form className="admin-card admin-upload" action="/api/admin/media" method="post" encType="multipart/form-data">
|
||||||
|
<label>Datei hochladen<input name="file" type="file" accept="image/jpeg,image/png,image/webp,application/pdf" /></label>
|
||||||
|
<button className="button" type="submit">Datei hochladen</button>
|
||||||
|
</form>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Uploads</h2>
|
||||||
|
<div className="media-grid">
|
||||||
|
{files.map((file) => {
|
||||||
|
const url = `/uploads/images/${file}`;
|
||||||
|
return (
|
||||||
|
<a key={file} className="media-item" href={url} target="_blank" rel="noreferrer">
|
||||||
|
{/\.(png|jpe?g|webp)$/i.test(file)
|
||||||
|
? <Image src={url} alt={file} width={320} height={220} />
|
||||||
|
: <span>{file}</span>}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{files.length === 0 && <p className="admin-muted">Noch keine Uploads vorhanden.</p>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
46
app/admin/page.tsx
Normal file
46
app/admin/page.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { getContactInquiries, getRepairInquiries } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
function countNew<T extends { status: string }>(items: T[]) {
|
||||||
|
return items.filter((item) => item.status === "new").length;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function AdminDashboardPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const [contacts, repairs] = await Promise.all([getContactInquiries(), getRepairInquiries()]);
|
||||||
|
const latest = [...contacts, ...repairs].sort((a, b) => b.createdAt.localeCompare(a.createdAt)).slice(0, 6);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Administration</p>
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
</div>
|
||||||
|
<div className="admin-kpis">
|
||||||
|
<div className="admin-kpi"><span>Kontaktanfragen</span><strong>{countNew(contacts)}</strong><small>neu</small></div>
|
||||||
|
<div className="admin-kpi"><span>Reparaturanfragen</span><strong>{countNew(repairs)}</strong><small>neu</small></div>
|
||||||
|
<div className="admin-kpi"><span>Website</span><strong>Online</strong><small>OK</small></div>
|
||||||
|
<div className="admin-kpi"><span>SMTP</span><strong>Vorbereitet</strong><small>nicht aktiv</small></div>
|
||||||
|
</div>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Letzte Anfragen</h2>
|
||||||
|
<table className="admin-table">
|
||||||
|
<thead><tr><th>Datum</th><th>Name</th><th>Typ</th><th>Status</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{latest.map((item) => (
|
||||||
|
<tr key={item.id}>
|
||||||
|
<td>{new Date(item.createdAt).toLocaleDateString("de-DE")}</td>
|
||||||
|
<td>{item.name}</td>
|
||||||
|
<td>{"manufacturer" in item ? "Reparatur" : "Kontakt"}</td>
|
||||||
|
<td><span className={`status ${item.status}`}>{item.status}</span></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{latest.length === 0 && <tr><td colSpan={4}>Noch keine Anfragen vorhanden.</td></tr>}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
51
app/admin/reparaturanfragen/page.tsx
Normal file
51
app/admin/reparaturanfragen/page.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import StatusSelect from "@/components/admin/StatusSelect";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { getRepairInquiries } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export default async function AdminRepairsPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const inquiries = await getRepairInquiries();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Anfragen</p>
|
||||||
|
<h1>Reparaturanfragen</h1>
|
||||||
|
</div>
|
||||||
|
<section className="admin-card">
|
||||||
|
<table className="admin-table">
|
||||||
|
<thead><tr><th>Datum</th><th>Name</th><th>Gerät</th><th>Hersteller</th><th>Modell</th><th>Status</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{inquiries.map((item) => (
|
||||||
|
<tr key={item.id}>
|
||||||
|
<td>{new Date(item.createdAt).toLocaleDateString("de-DE")}</td>
|
||||||
|
<td>{item.name}</td>
|
||||||
|
<td>{item.deviceType}</td>
|
||||||
|
<td>{item.manufacturer}</td>
|
||||||
|
<td>{item.model}</td>
|
||||||
|
<td><StatusSelect id={item.id} type="repair" status={item.status} /></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{inquiries.length === 0 && <tr><td colSpan={6}>Noch keine Reparaturanfragen vorhanden.</td></tr>}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Technische Details</h2>
|
||||||
|
<div className="admin-detail-grid">
|
||||||
|
{inquiries.slice(0, 6).map((item) => (
|
||||||
|
<article key={item.id} className="admin-detail">
|
||||||
|
<h3>{item.manufacturer} {item.model}</h3>
|
||||||
|
<p><strong>Fehler:</strong> {item.description}</p>
|
||||||
|
<p><strong>Zubehör:</strong> {item.accessories || "nicht angegeben"}</p>
|
||||||
|
<p><strong>Vorarbeiten:</strong> {item.previousWork || "nicht angegeben"}</p>
|
||||||
|
<button className="button light" type="button" disabled>In Olympus übernehmen</button>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
24
app/admin/seo/page.tsx
Normal file
24
app/admin/seo/page.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { defaultTitle, siteName, siteUrl } from "@/app/seo";
|
||||||
|
|
||||||
|
export default async function AdminSeoPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Sichtbarkeit</p>
|
||||||
|
<h1>SEO Verwaltung</h1>
|
||||||
|
</div>
|
||||||
|
<section className="admin-card admin-form">
|
||||||
|
<label>Seitentitel<input readOnly value={defaultTitle} /></label>
|
||||||
|
<label>Site Name<input readOnly value={siteName} /></label>
|
||||||
|
<label>Basis-URL<input readOnly value={siteUrl} /></label>
|
||||||
|
<label>Meta Description<textarea readOnly value="Service, Reparatur, Diagnose und Abgleich von Funktechnik, CB-Funk, Amateurfunk und Kommunikationstechnik." /></label>
|
||||||
|
<p className="admin-muted">Live-Bearbeitung pro Seite ist vorbereitet und wird in einer späteren Publishing-Ausbaustufe aktiviert.</p>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
28
app/admin/smtp/page.tsx
Normal file
28
app/admin/smtp/page.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { getSmtpSettings } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export default async function AdminSmtpPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
const settings = await getSmtpSettings();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">E-Mail</p>
|
||||||
|
<h1>SMTP Einstellungen</h1>
|
||||||
|
</div>
|
||||||
|
<form className="admin-card admin-form" action="/api/admin/smtp" method="post">
|
||||||
|
<label>SMTP Server<input name="host" defaultValue={settings.host} /></label>
|
||||||
|
<label>Port<input name="port" defaultValue={settings.port} inputMode="numeric" /></label>
|
||||||
|
<label>Benutzername<input name="username" defaultValue={settings.username} /></label>
|
||||||
|
<label>Passwort<input name="password" type="password" placeholder="wird in dieser Foundation noch nicht gespeichert" disabled /></label>
|
||||||
|
<label>Absenderadresse<input name="fromAddress" type="email" defaultValue={settings.fromAddress} /></label>
|
||||||
|
<label>Antwortadresse<input name="replyToAddress" type="email" defaultValue={settings.replyToAddress} /></label>
|
||||||
|
<label className="admin-checkbox"><input name="tls" type="checkbox" defaultChecked={settings.tls} /> TLS aktivieren</label>
|
||||||
|
<button className="button" type="submit">Speichern</button>
|
||||||
|
</form>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
36
app/admin/system/page.tsx
Normal file
36
app/admin/system/page.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
export default async function AdminSystemPage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Betrieb</p>
|
||||||
|
<h1>System</h1>
|
||||||
|
</div>
|
||||||
|
<div className="admin-detail-grid">
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Technik</h2>
|
||||||
|
<ul className="list">
|
||||||
|
<li>Next.js 16 App Router</li>
|
||||||
|
<li>TypeScript strict</li>
|
||||||
|
<li>HttpOnly Admin-Session</li>
|
||||||
|
<li>Lokale Foundation-Datenablage in JSON-Dateien</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Vorbereitet</h2>
|
||||||
|
<ul className="list">
|
||||||
|
<li>Olympus-Integration bleibt deaktiviert</li>
|
||||||
|
<li>SMTP-Konfiguration ohne Versandlogik</li>
|
||||||
|
<li>Medien-Upload mit Dateityp- und Größenprüfung</li>
|
||||||
|
<li>SEO- und Inhaltsverwaltung als Admin-Grundlage</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
38
app/admin/website/page.tsx
Normal file
38
app/admin/website/page.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import AdminShell from "@/components/admin/AdminShell";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
const editablePages = [
|
||||||
|
["Startseite", "Hero, Vorteile, Textblöcke"],
|
||||||
|
["Leistungen", "Funktechnik, Messtechnik, Servicebereiche"],
|
||||||
|
["Funkgeräte-Service", "Diagnose, Abgleich, Fehlerbilder"],
|
||||||
|
["Reparatur", "Reparaturannahme und Hinweise"],
|
||||||
|
["Über uns", "Profil und Werkstattbeschreibung"],
|
||||||
|
["Kontakt", "Kontakttext und Hinweise"],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export default async function AdminWebsitePage() {
|
||||||
|
if (!await requireAdminSession()) redirect("/admin/login");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell>
|
||||||
|
<div className="admin-page-head">
|
||||||
|
<p className="eyebrow">Website</p>
|
||||||
|
<h1>Website-Inhalte</h1>
|
||||||
|
</div>
|
||||||
|
<section className="admin-card">
|
||||||
|
<h2>Editierbare Inhalte</h2>
|
||||||
|
<p className="admin-muted">Diese Foundation bereitet die Inhaltsverwaltung vor. Die öffentliche Website bleibt bis zur finalen Publishing-Funktion weiterhin quellcodebasiert.</p>
|
||||||
|
<div className="admin-detail-grid">
|
||||||
|
{editablePages.map(([title, description]) => (
|
||||||
|
<article key={title} className="admin-detail">
|
||||||
|
<h3>{title}</h3>
|
||||||
|
<p>{description}</p>
|
||||||
|
<button className="button light" type="button" disabled>Bearbeiten vorbereitet</button>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
19
app/api/admin/contact/[id]/route.ts
Normal file
19
app/api/admin/contact/[id]/route.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { updateContactStatus } from "@/lib/admin/store";
|
||||||
|
import type { InquiryStatus } from "@/lib/admin/types";
|
||||||
|
|
||||||
|
const statuses: InquiryStatus[] = ["new", "in_progress", "done"];
|
||||||
|
|
||||||
|
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
|
||||||
|
const body = await request.json() as { status?: InquiryStatus };
|
||||||
|
if (!body.status || !statuses.includes(body.status)) {
|
||||||
|
return NextResponse.json({ message: "Ungültiger Status." }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = await params;
|
||||||
|
await updateContactStatus(id, body.status);
|
||||||
|
return NextResponse.json({ message: "Status aktualisiert." });
|
||||||
|
}
|
||||||
16
app/api/admin/login/route.ts
Normal file
16
app/api/admin/login/route.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { adminCookieOptions, adminSessionCookie, createAdminSession, validateAdminCredentials } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const form = await request.formData();
|
||||||
|
const email = String(form.get("email") ?? "");
|
||||||
|
const password = String(form.get("password") ?? "");
|
||||||
|
|
||||||
|
if (!validateAdminCredentials(email, password)) {
|
||||||
|
return NextResponse.json({ message: "Ungültige Zugangsdaten." }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = NextResponse.json({ message: "Anmeldung erfolgreich." });
|
||||||
|
response.cookies.set(adminSessionCookie, createAdminSession(), adminCookieOptions());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
8
app/api/admin/logout/route.ts
Normal file
8
app/api/admin/logout/route.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { adminSessionCookie } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
export async function POST() {
|
||||||
|
const response = NextResponse.json({ message: "Abgemeldet." });
|
||||||
|
response.cookies.set(adminSessionCookie, "", { path: "/", maxAge: 0 });
|
||||||
|
return response;
|
||||||
|
}
|
||||||
38
app/api/admin/media/route.ts
Normal file
38
app/api/admin/media/route.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { mkdir, readdir, writeFile } from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
|
||||||
|
const uploadDir = path.join(process.cwd(), "public", "uploads", "images");
|
||||||
|
const allowedTypes = new Set(["image/jpeg", "image/png", "image/webp", "application/pdf"]);
|
||||||
|
|
||||||
|
async function ensureUploadDir() {
|
||||||
|
await mkdir(uploadDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
await ensureUploadDir();
|
||||||
|
const files = await readdir(uploadDir);
|
||||||
|
return NextResponse.json({
|
||||||
|
files: files.map((file) => ({ name: file, url: `/uploads/images/${file}` })),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
await ensureUploadDir();
|
||||||
|
const form = await request.formData();
|
||||||
|
const file = form.get("file");
|
||||||
|
|
||||||
|
if (!(file instanceof File) || !allowedTypes.has(file.type) || file.size > 5 * 1024 * 1024) {
|
||||||
|
return NextResponse.json({ message: "Bitte eine JPG-, PNG-, WebP- oder PDF-Datei bis 5 MB hochladen." }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = path.extname(file.name).toLowerCase();
|
||||||
|
const safeName = `${Date.now()}-${file.name.toLowerCase().replace(/[^a-z0-9.-]/g, "-")}`;
|
||||||
|
const target = safeName.endsWith(extension) ? safeName : `${safeName}${extension}`;
|
||||||
|
await writeFile(path.join(uploadDir, target), Buffer.from(await file.arrayBuffer()));
|
||||||
|
|
||||||
|
return NextResponse.redirect(new URL("/admin/medien?uploaded=1", request.url));
|
||||||
|
}
|
||||||
19
app/api/admin/repair/[id]/route.ts
Normal file
19
app/api/admin/repair/[id]/route.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { updateRepairStatus } from "@/lib/admin/store";
|
||||||
|
import type { InquiryStatus } from "@/lib/admin/types";
|
||||||
|
|
||||||
|
const statuses: InquiryStatus[] = ["new", "in_progress", "done"];
|
||||||
|
|
||||||
|
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
|
||||||
|
const body = await request.json() as { status?: InquiryStatus };
|
||||||
|
if (!body.status || !statuses.includes(body.status)) {
|
||||||
|
return NextResponse.json({ message: "Ungültiger Status." }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = await params;
|
||||||
|
await updateRepairStatus(id, body.status);
|
||||||
|
return NextResponse.json({ message: "Status aktualisiert." });
|
||||||
|
}
|
||||||
9
app/api/admin/settings/route.ts
Normal file
9
app/api/admin/settings/route.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { saveSiteSettings } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
await saveSiteSettings(await request.formData());
|
||||||
|
return NextResponse.redirect(new URL("/admin/einstellungen?saved=1", request.url));
|
||||||
|
}
|
||||||
9
app/api/admin/smtp/route.ts
Normal file
9
app/api/admin/smtp/route.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireAdminSession } from "@/lib/admin/auth";
|
||||||
|
import { saveSmtpSettings } from "@/lib/admin/store";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||||
|
await saveSmtpSettings(await request.formData());
|
||||||
|
return NextResponse.redirect(new URL("/admin/smtp?saved=1", request.url));
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { addContactInquiry } from "@/lib/admin/store";
|
||||||
|
|
||||||
function text(value: FormDataEntryValue | null) {
|
function text(value: FormDataEntryValue | null) {
|
||||||
return typeof value === "string" ? value.trim() : "";
|
return typeof value === "string" ? value.trim() : "";
|
||||||
|
|
@ -8,16 +9,14 @@ export async function POST(request: Request) {
|
||||||
const form = await request.formData();
|
const form = await request.formData();
|
||||||
const name = text(form.get("name"));
|
const name = text(form.get("name"));
|
||||||
const email = text(form.get("email"));
|
const email = text(form.get("email"));
|
||||||
|
const subject = text(form.get("subject"));
|
||||||
const message = text(form.get("message"));
|
const message = text(form.get("message"));
|
||||||
|
|
||||||
if (!name || !email.includes("@") || message.length < 10 || form.get("privacy") !== "on") {
|
if (!name || !email.includes("@") || !subject || message.length < 10 || form.get("privacy") !== "on") {
|
||||||
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("contact_request.received", {
|
await addContactInquiry(form);
|
||||||
messageLength: message.length,
|
|
||||||
hasEmail: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
message: "Ihre Nachricht wurde erfasst. Sie erhalten eine Rückmeldung.",
|
message: "Ihre Nachricht wurde erfasst. Sie erhalten eine Rückmeldung.",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { addRepairInquiry } from "@/lib/admin/store";
|
||||||
|
|
||||||
function required(value: FormDataEntryValue | null) {
|
function required(value: FormDataEntryValue | null) {
|
||||||
return typeof value === "string" && value.trim().length > 0;
|
return typeof value === "string" && value.trim().length > 0;
|
||||||
|
|
@ -18,18 +19,7 @@ export async function POST(request: Request) {
|
||||||
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const intakeUrl = process.env.OLYMPUS_INTAKE_API_URL;
|
await addRepairInquiry(form);
|
||||||
const hasIntegrationToken = Boolean(process.env.OLYMPUS_INTAKE_API_TOKEN);
|
|
||||||
|
|
||||||
console.info("repair_intake.received", {
|
|
||||||
hasIntakeIntegration: Boolean(intakeUrl && hasIntegrationToken),
|
|
||||||
manufacturer: String(manufacturer),
|
|
||||||
model: String(model),
|
|
||||||
deviceType: String(deviceType),
|
|
||||||
hasPhone: required(form.get("phone")),
|
|
||||||
hasSerialNumber: required(form.get("serialNumber")),
|
|
||||||
hasAccessories: required(form.get("accessories")),
|
|
||||||
});
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
message: "Ihre Reparaturanfrage wurde erfasst. Sie erhalten nach Prüfung eine Rückmeldung.",
|
message: "Ihre Reparaturanfrage wurde erfasst. Sie erhalten nach Prüfung eine Rückmeldung.",
|
||||||
|
|
|
||||||
296
app/globals.css
296
app/globals.css
|
|
@ -461,6 +461,283 @@ h3 {
|
||||||
font-size: 26px;
|
font-size: 26px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin-login-page {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
background:
|
||||||
|
linear-gradient(90deg, rgba(6, 24, 52, 0.94), rgba(8, 42, 96, 0.76)),
|
||||||
|
url("/admin-workbench-bg.png"),
|
||||||
|
#07172d;
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login-card {
|
||||||
|
display: grid;
|
||||||
|
gap: 14px;
|
||||||
|
width: min(420px, calc(100% - 32px));
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.16);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
padding: 28px;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login-card img {
|
||||||
|
width: 230px;
|
||||||
|
height: 64px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login-card h1 {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: var(--ink);
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login-card label,
|
||||||
|
.admin-form label,
|
||||||
|
.admin-upload label {
|
||||||
|
display: grid;
|
||||||
|
gap: 7px;
|
||||||
|
color: var(--ink);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login-card input,
|
||||||
|
.admin-form input,
|
||||||
|
.admin-form textarea,
|
||||||
|
.admin-upload input {
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #cfd8e5;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fff;
|
||||||
|
padding: 11px 12px;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-shell {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 248px minmax(0, 1fr);
|
||||||
|
background: #eef2f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-sidebar {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
border-right: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
background: #071c3d;
|
||||||
|
color: #fff;
|
||||||
|
padding: 18px 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-logo {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-logo img {
|
||||||
|
width: 190px;
|
||||||
|
height: 54px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-nav {
|
||||||
|
display: grid;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-nav a,
|
||||||
|
.admin-logout {
|
||||||
|
border: 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: transparent;
|
||||||
|
color: rgba(255, 255, 255, 0.78);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 800;
|
||||||
|
padding: 10px 12px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-nav a:hover,
|
||||||
|
.admin-nav a[aria-current="page"],
|
||||||
|
.admin-logout:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-logout {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 18px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-main {
|
||||||
|
min-width: 0;
|
||||||
|
padding: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-page-head {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-page-head h1 {
|
||||||
|
margin-bottom: 0;
|
||||||
|
color: var(--ink);
|
||||||
|
font-size: 34px;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-kpis {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
gap: 14px;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-kpi,
|
||||||
|
.admin-card,
|
||||||
|
.admin-detail {
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 0 10px 28px rgba(8, 42, 96, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-kpi {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-kpi span,
|
||||||
|
.admin-kpi small,
|
||||||
|
.admin-muted {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-kpi strong {
|
||||||
|
color: var(--navy);
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-card {
|
||||||
|
margin-bottom: 18px;
|
||||||
|
padding: 20px;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-card h2 {
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
min-width: 760px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-table th,
|
||||||
|
.admin-table td {
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
padding: 12px 10px;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-table th {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status,
|
||||||
|
.status-select {
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #f8fafc;
|
||||||
|
color: var(--navy);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 800;
|
||||||
|
padding: 6px 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.new {
|
||||||
|
color: #b45309;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.in_progress {
|
||||||
|
color: #0b63a7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.done {
|
||||||
|
color: #157347;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-detail-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-detail {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-detail p {
|
||||||
|
color: var(--muted);
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-form {
|
||||||
|
display: grid;
|
||||||
|
gap: 14px;
|
||||||
|
max-width: 880px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-checkbox {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-checkbox input {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-upload {
|
||||||
|
display: flex;
|
||||||
|
align-items: end;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item {
|
||||||
|
display: grid;
|
||||||
|
min-height: 130px;
|
||||||
|
place-items: center;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f8fafc;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item img {
|
||||||
|
width: 100%;
|
||||||
|
height: 150px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 1080px) and (min-width: 861px) {
|
@media (max-width: 1080px) and (min-width: 861px) {
|
||||||
.brand-logo {
|
.brand-logo {
|
||||||
width: 236px;
|
width: 236px;
|
||||||
|
|
@ -540,7 +817,24 @@ h3 {
|
||||||
.grid.two,
|
.grid.two,
|
||||||
.service-grid,
|
.service-grid,
|
||||||
.split,
|
.split,
|
||||||
.footer-grid {
|
.footer-grid,
|
||||||
|
.admin-shell,
|
||||||
|
.admin-kpis,
|
||||||
|
.admin-detail-grid,
|
||||||
|
.media-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin-sidebar {
|
||||||
|
position: static;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-main {
|
||||||
|
padding: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-upload {
|
||||||
|
display: grid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import Header from "@/components/Header";
|
import SiteFrame from "@/components/SiteFrame";
|
||||||
import Footer from "@/components/Footer";
|
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import { createMetadata } from "./seo";
|
import { createMetadata } from "./seo";
|
||||||
|
|
||||||
|
|
@ -13,9 +12,7 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
|
||||||
return (
|
return (
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<body>
|
<body>
|
||||||
<Header />
|
<SiteFrame>{children}</SiteFrame>
|
||||||
<main>{children}</main>
|
|
||||||
<Footer />
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,10 @@ export default function ContactForm() {
|
||||||
const form = new FormData(event.currentTarget);
|
const form = new FormData(event.currentTarget);
|
||||||
const name = String(form.get("name") ?? "").trim();
|
const name = String(form.get("name") ?? "").trim();
|
||||||
const email = String(form.get("email") ?? "").trim();
|
const email = String(form.get("email") ?? "").trim();
|
||||||
|
const subject = String(form.get("subject") ?? "").trim();
|
||||||
const text = String(form.get("message") ?? "").trim();
|
const text = String(form.get("message") ?? "").trim();
|
||||||
|
|
||||||
if (!name || !email.includes("@") || text.length < 10 || form.get("privacy") !== "on") {
|
if (!name || !email.includes("@") || !subject || text.length < 10 || form.get("privacy") !== "on") {
|
||||||
setError("Bitte füllen Sie alle Pflichtfelder aus und bestätigen Sie die Datenschutz-Hinweise.");
|
setError("Bitte füllen Sie alle Pflichtfelder aus und bestätigen Sie die Datenschutz-Hinweise.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +46,14 @@ export default function ContactForm() {
|
||||||
<label htmlFor="email">E-Mail</label>
|
<label htmlFor="email">E-Mail</label>
|
||||||
<input id="email" name="email" type="email" />
|
<input id="email" name="email" type="email" />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="field">
|
||||||
|
<label htmlFor="phone">Telefon</label>
|
||||||
|
<input id="phone" name="phone" />
|
||||||
|
</div>
|
||||||
|
<div className="field">
|
||||||
|
<label htmlFor="subject">Betreff</label>
|
||||||
|
<input id="subject" name="subject" />
|
||||||
|
</div>
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label htmlFor="message">Nachricht</label>
|
<label htmlFor="message">Nachricht</label>
|
||||||
<textarea id="message" name="message" />
|
<textarea id="message" name="message" />
|
||||||
|
|
|
||||||
21
components/SiteFrame.tsx
Normal file
21
components/SiteFrame.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import Header from "@/components/Header";
|
||||||
|
import Footer from "@/components/Footer";
|
||||||
|
|
||||||
|
export default function SiteFrame({ children }: { children: ReactNode }) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const isAdmin = pathname.startsWith("/admin");
|
||||||
|
|
||||||
|
if (isAdmin) return <>{children}</>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header />
|
||||||
|
<main>{children}</main>
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
50
components/admin/AdminLoginForm.tsx
Normal file
50
components/admin/AdminLoginForm.tsx
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import Image from "next/image";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState, type FormEvent } from "react";
|
||||||
|
|
||||||
|
export default function AdminLoginForm({ nextPath = "/admin" }: { nextPath?: string }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [pending, setPending] = useState(false);
|
||||||
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
setError("");
|
||||||
|
setPending(true);
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/admin/login", {
|
||||||
|
method: "POST",
|
||||||
|
body: new FormData(event.currentTarget),
|
||||||
|
});
|
||||||
|
const result = await response.json() as { message?: string };
|
||||||
|
if (!response.ok) throw new Error(result.message ?? "Anmeldung fehlgeschlagen.");
|
||||||
|
router.push(nextPath);
|
||||||
|
router.refresh();
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Anmeldung fehlgeschlagen.");
|
||||||
|
} finally {
|
||||||
|
setPending(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="admin-login-page">
|
||||||
|
<form className="admin-login-card" onSubmit={submit}>
|
||||||
|
<Image src="/funktechnik_schubert_logo.jpg" alt="Funktechnik Schubert" width={1672} height={941} priority />
|
||||||
|
<h1>Administration Login</h1>
|
||||||
|
<label>
|
||||||
|
E-Mail
|
||||||
|
<input name="email" type="email" autoComplete="username" required />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Passwort
|
||||||
|
<input name="password" type="password" autoComplete="current-password" required />
|
||||||
|
</label>
|
||||||
|
{error && <p className="error">{error}</p>}
|
||||||
|
<button className="button" type="submit" disabled={pending}>{pending ? "Anmeldung..." : "Anmelden"}</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
48
components/admin/AdminShell.tsx
Normal file
48
components/admin/AdminShell.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import Image from "next/image";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
const navItems = [
|
||||||
|
["Dashboard", "/admin"],
|
||||||
|
["Kontaktanfragen", "/admin/kontaktanfragen"],
|
||||||
|
["Reparaturanfragen", "/admin/reparaturanfragen"],
|
||||||
|
["Website-Inhalte", "/admin/website"],
|
||||||
|
["Medien", "/admin/medien"],
|
||||||
|
["Einstellungen", "/admin/einstellungen"],
|
||||||
|
["SMTP", "/admin/smtp"],
|
||||||
|
["SEO", "/admin/seo"],
|
||||||
|
["System", "/admin/system"],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export default function AdminShell({ children }: { children: ReactNode }) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
async function logout() {
|
||||||
|
await fetch("/api/admin/logout", { method: "POST" });
|
||||||
|
router.push("/admin/login");
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="admin-shell">
|
||||||
|
<aside className="admin-sidebar">
|
||||||
|
<Link className="admin-logo" href="/admin">
|
||||||
|
<Image src="/funktechnik_schubert_logo.jpg" alt="Funktechnik Schubert" width={1672} height={941} />
|
||||||
|
</Link>
|
||||||
|
<nav className="admin-nav" aria-label="Administration">
|
||||||
|
{navItems.map(([label, href]) => (
|
||||||
|
<Link key={href} href={href} aria-current={pathname === href ? "page" : undefined}>
|
||||||
|
{label}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
<button className="admin-logout" type="button" onClick={logout}>Abmelden</button>
|
||||||
|
</aside>
|
||||||
|
<div className="admin-main">{children}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
34
components/admin/StatusSelect.tsx
Normal file
34
components/admin/StatusSelect.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
import type { InquiryStatus } from "@/lib/admin/types";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
id: string;
|
||||||
|
type: "contact" | "repair";
|
||||||
|
status: InquiryStatus;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StatusSelect({ id, type, status }: Props) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [value, setValue] = useState(status);
|
||||||
|
|
||||||
|
async function update(nextStatus: InquiryStatus) {
|
||||||
|
setValue(nextStatus);
|
||||||
|
const response = await fetch(`/api/admin/${type}/${id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ status: nextStatus }),
|
||||||
|
});
|
||||||
|
if (response.ok) router.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select className="status-select" value={value} onChange={(event) => update(event.target.value as InquiryStatus)}>
|
||||||
|
<option value="new">Neu</option>
|
||||||
|
<option value="in_progress">In Prüfung</option>
|
||||||
|
<option value="done">Erledigt</option>
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
services:
|
services:
|
||||||
funktechnik-website:
|
funktechnik-website:
|
||||||
|
container_name: funktechnik-website
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: funktechnik-website
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
NODE_ENV: production
|
|
||||||
NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-http://localhost:3010}
|
|
||||||
OLYMPUS_INTAKE_API_URL: ${OLYMPUS_INTAKE_API_URL:-}
|
|
||||||
OLYMPUS_INTAKE_API_TOKEN: ${OLYMPUS_INTAKE_API_TOKEN:-}
|
|
||||||
ports:
|
ports:
|
||||||
- "3010:3010"
|
- "3010:3010"
|
||||||
|
environment:
|
||||||
|
NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL}
|
||||||
|
ADMIN_EMAIL: ${ADMIN_EMAIL}
|
||||||
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
||||||
|
ADMIN_SESSION_SECRET: ${ADMIN_SESSION_SECRET}
|
||||||
|
AUTH_COOKIE_SECURE: ${AUTH_COOKIE_SECURE}
|
||||||
|
OLYMPUS_INTAKE_API_URL: ${OLYMPUS_INTAKE_API_URL}
|
||||||
|
OLYMPUS_INTAKE_API_TOKEN: ${OLYMPUS_INTAKE_API_TOKEN}
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
|
||||||
69
lib/admin/auth.ts
Normal file
69
lib/admin/auth.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
import { createHmac, timingSafeEqual } from "crypto";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
|
export const adminSessionCookie = "fs_admin_session";
|
||||||
|
|
||||||
|
const sessionMaxAgeSeconds = 60 * 60 * 8;
|
||||||
|
|
||||||
|
function secret() {
|
||||||
|
return process.env.ADMIN_SESSION_SECRET ?? "dev-admin-session-secret-change-me";
|
||||||
|
}
|
||||||
|
|
||||||
|
function adminEmail() {
|
||||||
|
return process.env.ADMIN_EMAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adminPassword() {
|
||||||
|
return process.env.ADMIN_PASSWORD;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sign(value: string) {
|
||||||
|
return createHmac("sha256", secret()).update(value).digest("base64url");
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeEqual(left: string, right: string) {
|
||||||
|
const leftBuffer = Buffer.from(left);
|
||||||
|
const rightBuffer = Buffer.from(right);
|
||||||
|
return leftBuffer.length === rightBuffer.length && timingSafeEqual(leftBuffer, rightBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateAdminCredentials(email: string, password: string) {
|
||||||
|
const configuredEmail = adminEmail();
|
||||||
|
const configuredPassword = adminPassword();
|
||||||
|
if (!configuredEmail || !configuredPassword) return false;
|
||||||
|
return safeEqual(email.trim().toLowerCase(), configuredEmail.toLowerCase()) && safeEqual(password, configuredPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createAdminSession() {
|
||||||
|
const expiresAt = Date.now() + sessionMaxAgeSeconds * 1000;
|
||||||
|
const payload = Buffer.from(JSON.stringify({ sub: adminEmail() ?? "admin", exp: expiresAt })).toString("base64url");
|
||||||
|
return `${payload}.${sign(payload)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verifyAdminSession(token?: string) {
|
||||||
|
if (!token) return false;
|
||||||
|
const [payload, signature] = token.split(".");
|
||||||
|
if (!payload || !signature || !safeEqual(signature, sign(payload))) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const session = JSON.parse(Buffer.from(payload, "base64url").toString("utf8")) as { exp?: number };
|
||||||
|
return typeof session.exp === "number" && session.exp > Date.now();
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function requireAdminSession() {
|
||||||
|
const cookieStore = await cookies();
|
||||||
|
return verifyAdminSession(cookieStore.get(adminSessionCookie)?.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function adminCookieOptions() {
|
||||||
|
return {
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: "lax" as const,
|
||||||
|
secure: process.env.AUTH_COOKIE_SECURE === "true",
|
||||||
|
path: "/",
|
||||||
|
maxAge: sessionMaxAgeSeconds,
|
||||||
|
};
|
||||||
|
}
|
||||||
139
lib/admin/store.ts
Normal file
139
lib/admin/store.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import type { ContactInquiry, InquiryStatus, RepairInquiry, SiteSettings, SmtpSettings } from "./types";
|
||||||
|
|
||||||
|
const dataDir = path.join(process.cwd(), "data");
|
||||||
|
|
||||||
|
async function ensureDataDir() {
|
||||||
|
await mkdir(dataDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readJson<T>(fileName: string, fallback: T): Promise<T> {
|
||||||
|
await ensureDataDir();
|
||||||
|
try {
|
||||||
|
const file = await readFile(path.join(dataDir, fileName), "utf8");
|
||||||
|
return JSON.parse(file) as T;
|
||||||
|
} catch {
|
||||||
|
await writeJson(fileName, fallback);
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeJson<T>(fileName: string, value: T) {
|
||||||
|
await ensureDataDir();
|
||||||
|
await writeFile(path.join(dataDir, fileName), `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
function id(prefix: string) {
|
||||||
|
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function text(value: FormDataEntryValue | null) {
|
||||||
|
return typeof value === "string" ? value.trim() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getContactInquiries() {
|
||||||
|
return readJson<ContactInquiry[]>("contact-inquiries.json", []);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRepairInquiries() {
|
||||||
|
return readJson<RepairInquiry[]>("repair-inquiries.json", []);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addContactInquiry(form: FormData) {
|
||||||
|
const inquiries = await getContactInquiries();
|
||||||
|
const inquiry: ContactInquiry = {
|
||||||
|
id: id("contact"),
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
status: "new",
|
||||||
|
name: text(form.get("name")),
|
||||||
|
email: text(form.get("email")),
|
||||||
|
phone: text(form.get("phone")),
|
||||||
|
subject: text(form.get("subject")) || "Kontaktanfrage",
|
||||||
|
message: text(form.get("message")),
|
||||||
|
};
|
||||||
|
await writeJson("contact-inquiries.json", [inquiry, ...inquiries]);
|
||||||
|
return inquiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addRepairInquiry(form: FormData) {
|
||||||
|
const inquiries = await getRepairInquiries();
|
||||||
|
const inquiry: RepairInquiry = {
|
||||||
|
id: id("repair"),
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
status: "new",
|
||||||
|
name: text(form.get("name")),
|
||||||
|
email: text(form.get("email")),
|
||||||
|
phone: text(form.get("phone")),
|
||||||
|
manufacturer: text(form.get("manufacturer")),
|
||||||
|
model: text(form.get("model")),
|
||||||
|
serialNumber: text(form.get("serialNumber")),
|
||||||
|
deviceType: text(form.get("deviceType")),
|
||||||
|
accessories: text(form.get("accessories")),
|
||||||
|
opened: text(form.get("opened")),
|
||||||
|
previousWork: text(form.get("previousWork")),
|
||||||
|
description: text(form.get("description")),
|
||||||
|
};
|
||||||
|
await writeJson("repair-inquiries.json", [inquiry, ...inquiries]);
|
||||||
|
return inquiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateContactStatus(id: string, status: InquiryStatus) {
|
||||||
|
const inquiries = await getContactInquiries();
|
||||||
|
await writeJson("contact-inquiries.json", inquiries.map((item) => item.id === id ? { ...item, status } : item));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateRepairStatus(id: string, status: InquiryStatus) {
|
||||||
|
const inquiries = await getRepairInquiries();
|
||||||
|
await writeJson("repair-inquiries.json", inquiries.map((item) => item.id === id ? { ...item, status } : item));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSiteSettings() {
|
||||||
|
return readJson<SiteSettings>("site-settings.json", {
|
||||||
|
companyName: "Funktechnik Schubert",
|
||||||
|
phone: "",
|
||||||
|
email: "info@funktechnik-schubert.de",
|
||||||
|
address: "",
|
||||||
|
openingHours: "",
|
||||||
|
googleMapsEmbedUrl: "",
|
||||||
|
socialLinks: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveSiteSettings(form: FormData) {
|
||||||
|
const settings: SiteSettings = {
|
||||||
|
companyName: text(form.get("companyName")),
|
||||||
|
phone: text(form.get("phone")),
|
||||||
|
email: text(form.get("email")),
|
||||||
|
address: text(form.get("address")),
|
||||||
|
openingHours: text(form.get("openingHours")),
|
||||||
|
googleMapsEmbedUrl: text(form.get("googleMapsEmbedUrl")),
|
||||||
|
socialLinks: text(form.get("socialLinks")),
|
||||||
|
};
|
||||||
|
await writeJson("site-settings.json", settings);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSmtpSettings() {
|
||||||
|
return readJson<SmtpSettings>("smtp-settings.json", {
|
||||||
|
host: "",
|
||||||
|
port: "587",
|
||||||
|
username: "",
|
||||||
|
fromAddress: "",
|
||||||
|
replyToAddress: "",
|
||||||
|
tls: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveSmtpSettings(form: FormData) {
|
||||||
|
const settings: SmtpSettings = {
|
||||||
|
host: text(form.get("host")),
|
||||||
|
port: text(form.get("port")),
|
||||||
|
username: text(form.get("username")),
|
||||||
|
fromAddress: text(form.get("fromAddress")),
|
||||||
|
replyToAddress: text(form.get("replyToAddress")),
|
||||||
|
tls: form.get("tls") === "on",
|
||||||
|
};
|
||||||
|
await writeJson("smtp-settings.json", settings);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
48
lib/admin/types.ts
Normal file
48
lib/admin/types.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
export type InquiryStatus = "new" | "in_progress" | "done";
|
||||||
|
|
||||||
|
export type ContactInquiry = {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
status: InquiryStatus;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
phone?: string;
|
||||||
|
subject?: string;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RepairInquiry = {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
status: InquiryStatus;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
phone?: string;
|
||||||
|
manufacturer: string;
|
||||||
|
model: string;
|
||||||
|
serialNumber?: string;
|
||||||
|
deviceType: string;
|
||||||
|
accessories?: string;
|
||||||
|
opened?: string;
|
||||||
|
previousWork?: string;
|
||||||
|
description: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SiteSettings = {
|
||||||
|
companyName: string;
|
||||||
|
phone: string;
|
||||||
|
email: string;
|
||||||
|
address: string;
|
||||||
|
openingHours: string;
|
||||||
|
googleMapsEmbedUrl: string;
|
||||||
|
socialLinks: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SmtpSettings = {
|
||||||
|
host: string;
|
||||||
|
port: string;
|
||||||
|
username: string;
|
||||||
|
fromAddress: string;
|
||||||
|
replyToAddress: string;
|
||||||
|
tls: boolean;
|
||||||
|
};
|
||||||
20
proxy.ts
Normal file
20
proxy.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { NextResponse, type NextRequest } from "next/server";
|
||||||
|
|
||||||
|
const adminSessionCookie = "fs_admin_session";
|
||||||
|
|
||||||
|
export function proxy(request: NextRequest) {
|
||||||
|
const { pathname } = request.nextUrl;
|
||||||
|
if (!pathname.startsWith("/admin") || pathname === "/admin/login") return NextResponse.next();
|
||||||
|
|
||||||
|
if (!request.cookies.get(adminSessionCookie)?.value) {
|
||||||
|
const loginUrl = new URL("/admin/login", request.url);
|
||||||
|
loginUrl.searchParams.set("next", pathname);
|
||||||
|
return NextResponse.redirect(loginUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ["/admin/:path*"],
|
||||||
|
};
|
||||||
BIN
public/admin-workbench-bg.png
Normal file
BIN
public/admin-workbench-bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
1
public/uploads/.gitkeep
Normal file
1
public/uploads/.gitkeep
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
public/uploads/images/.gitkeep
Normal file
1
public/uploads/images/.gitkeep
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue