Template
Starterpacket von FSC & Shadcn eingebunden
This commit is contained in:
1 parent
6cf7985a44
commit
872bce2cfe
25 files changed
+5407
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { streamText, convertToModelMessages, type UIMessage } from "ai";
|
||||
import { getModel } from "@/lib/ai/model";
|
||||
|
||||
// Streaming-Chat-Endpoint (Muster C). Wird von useChat (Default /api/chat) aufgerufen.
|
||||
//
|
||||
// ACHTUNG: Dieser Endpoint hat KEINEN Login. Wer die Adresse der App kennt, kann hier
|
||||
// auf Kosten des hinterlegten ANTHROPIC_API_KEY chatten (offener KI-Proxy).
|
||||
// Deshalb ist er standardmäßig AUS und läuft nur mit CHAT_ENABLED=true.
|
||||
// Nie mit echtem Key öffentlich veröffentlichen, solange die App keinen Schutz hat
|
||||
// (Login, Zugangscode). Die Grenzen unten dämpfen Missbrauch nur, sie verhindern ihn nicht.
|
||||
|
||||
const MAX_MESSAGES = 40;
|
||||
const MAX_REQUEST_CHARS = 60000;
|
||||
const MAX_OUTPUT_TOKENS = 1024;
|
||||
|
||||
function parseJson(text: string): unknown {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
if (process.env.CHAT_ENABLED !== "true") {
|
||||
return new Response(
|
||||
"KI-Chat ist deaktiviert. Zum Einschalten CHAT_ENABLED=true setzen (nur mit Schutz öffentlich betreiben).",
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
|
||||
const raw = await req.text();
|
||||
if (raw.length > MAX_REQUEST_CHARS) {
|
||||
return new Response("Anfrage zu groß.", { status: 413 });
|
||||
}
|
||||
|
||||
const body = parseJson(raw) as { messages?: unknown } | null;
|
||||
const messages = body?.messages;
|
||||
if (!Array.isArray(messages) || messages.length === 0) {
|
||||
return new Response("Ungültige Anfrage.", { status: 400 });
|
||||
}
|
||||
if (messages.length > MAX_MESSAGES) {
|
||||
return new Response("Der Chat ist zu lang. Bitte die Seite neu laden.", { status: 413 });
|
||||
}
|
||||
|
||||
const result = streamText({
|
||||
model: getModel(),
|
||||
messages: await convertToModelMessages(messages as UIMessage[]),
|
||||
maxOutputTokens: MAX_OUTPUT_TOKENS,
|
||||
});
|
||||
return result.toUIMessageStreamResponse();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useChat } from "@ai-sdk/react";
|
||||
|
||||
// Muster C: KI-Chat mit Token-Streaming. Ruft POST /api/chat auf.
|
||||
// Achtung: /api/chat hat keinen Login und ist nur mit CHAT_ENABLED=true aktiv (siehe route.ts).
|
||||
// In der Schulung bleibt der Chat aus. KI läuft über einen n8n-Workflow.
|
||||
export default function ChatPage() {
|
||||
const { messages, sendMessage, status, error } = useChat();
|
||||
const [input, setInput] = useState("");
|
||||
const busy = status === "submitted" || status === "streaming";
|
||||
|
||||
function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!input.trim() || busy) return;
|
||||
sendMessage({ text: input });
|
||||
setInput("");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1 className="ep-ueberschrift text-3xl">KI-Chat (Muster C)</h1>
|
||||
<p className="text-sm text-ink-muted">
|
||||
Streamt Antworten von Claude. Braucht <code>ANTHROPIC_API_KEY</code> und <code>CHAT_ENABLED=true</code>. Ohne
|
||||
Login nie mit echtem Key öffentlich veröffentlichen.
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
{messages.map((message) => (
|
||||
<div
|
||||
key={message.id}
|
||||
className={
|
||||
message.role === "user"
|
||||
? "self-end bg-accent px-3 py-2 text-on-accent"
|
||||
: "self-start border border-hairline bg-surface px-3 py-2"
|
||||
}
|
||||
>
|
||||
{message.parts.map((part, i) => (part.type === "text" ? <span key={i}>{part.text}</span> : null))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{error && <div className="ep-fehler">{error.message}</div>}
|
||||
|
||||
<form onSubmit={onSubmit} className="flex gap-2">
|
||||
<input
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
placeholder="Frag mich etwas …"
|
||||
className="ep-feld flex-1"
|
||||
/>
|
||||
<button type="submit" disabled={busy} className="ep-knopf">
|
||||
Senden
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,363 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "shadcn/tailwind.css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* E&P-Layout wie auf ep-reisen.de und im EP-Budget-Tool:
|
||||
* Lato, Tiefblau #18527b als Akzent, Magenta-Verlauf nur für die
|
||||
* Hauptaktion (.ep-cta), eckige Formen, hellblauer Seitenhintergrund.
|
||||
* Jede Oberfläche der Schulung nutzt genau diese Werte und Bausteine.
|
||||
* Keine weiteren Farben, keine anderen Schriften, keine runden Ecken.
|
||||
* ------------------------------------------------------------------ */
|
||||
@theme inline {
|
||||
--color-ground: var(--ground);
|
||||
--color-surface: var(--surface);
|
||||
--color-hairline: var(--hairline);
|
||||
--color-ink: var(--ink);
|
||||
--color-ink-muted: var(--ink-muted);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-press: var(--accent-press);
|
||||
--color-accent-soft: var(--accent-soft);
|
||||
--color-on-accent: var(--on-accent);
|
||||
--color-strich: var(--strich);
|
||||
--color-fehler: var(--fehler);
|
||||
/* alter Name aus früheren Versionen des Starters, zeigt jetzt auf das Tiefblau */
|
||||
--color-brand: var(--accent);
|
||||
|
||||
--font-heading: var(--font-sans);
|
||||
--font-body: var(--body-font);
|
||||
--font-sans: var(--font-sans);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-background: var(--background);
|
||||
--radius-sm: calc(var(--radius) * 0.6);
|
||||
--radius-md: calc(var(--radius) * 0.8);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) * 1.4);
|
||||
--radius-2xl: calc(var(--radius) * 1.8);
|
||||
--radius-3xl: calc(var(--radius) * 2.2);
|
||||
--radius-4xl: calc(var(--radius) * 2.6);
|
||||
}
|
||||
|
||||
/* Eckig wie ep-reisen.de: alle Tailwind-Radien auf 0 */
|
||||
@theme {
|
||||
--radius-xs: 0px;
|
||||
--radius-sm: 0px;
|
||||
--radius-md: 0px;
|
||||
--radius-lg: 0px;
|
||||
--radius-xl: 0px;
|
||||
--radius-2xl: 0px;
|
||||
--radius-3xl: 0px;
|
||||
}
|
||||
|
||||
:root {
|
||||
--ground: #ebf3fa; /* Seitenhintergrund */
|
||||
--surface: #ffffff; /* Flächen, Karten, Kopfleiste */
|
||||
--hairline: #d8e3ed; /* Linien */
|
||||
--ink: #27272a; /* Text */
|
||||
--ink-muted: #52525b; /* gedämpfter Text */
|
||||
--accent: oklch(0.97 0 0); /* E&P-Tiefblau */
|
||||
--accent-press: #103c5b;
|
||||
--accent-soft: #e3eef8;
|
||||
--on-accent: #ffffff;
|
||||
--strich: #009fff; /* nur Zierstrich unter Überschriften, nie für Text */
|
||||
--fehler: #c0261b; /* Fehlermeldungen */
|
||||
/* --font-lato setzt next/font auf <html>, siehe app/layout.tsx */
|
||||
--heading-font: var(--font-lato), "Lato", ui-sans-serif, system-ui, sans-serif;
|
||||
--body-font: var(--font-lato), "Lato", ui-sans-serif, system-ui, sans-serif;
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--radius: 0.625rem;
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
html {
|
||||
color-scheme: light;
|
||||
background: var(--ground);
|
||||
@apply font-sans;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--ground);
|
||||
color: var(--ink);
|
||||
font-family: var(--body-font);
|
||||
line-height: 1.6;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4 {
|
||||
font-family: var(--heading-font);
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.01em;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--accent);
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 3px;
|
||||
}
|
||||
|
||||
code {
|
||||
background: var(--accent-soft);
|
||||
padding: 0 0.3em;
|
||||
font-size: 0.92em;
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
}
|
||||
|
||||
/* Bausteine für alle Oberflächen. Neue Seiten setzen sich daraus zusammen. */
|
||||
@layer components {
|
||||
/* Skip-Link (erstes Element im Body) */
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
background: var(--accent);
|
||||
color: var(--on-accent);
|
||||
padding: 0.75rem 1.25rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.skip-link:focus {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* Überschrift mit kurzem Zierstrich darunter */
|
||||
.ep-ueberschrift {
|
||||
color: var(--ink);
|
||||
font-weight: 900;
|
||||
}
|
||||
.ep-ueberschrift::after {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 3rem;
|
||||
height: 3px;
|
||||
margin-top: 0.6rem;
|
||||
background: var(--strich);
|
||||
}
|
||||
|
||||
/* Weiße Fläche mit feiner Linie, für Formulare und Ergebnisse */
|
||||
.ep-karte {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--hairline);
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.ep-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 700;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
/* Eingabefelder, Auswahllisten und Textfelder */
|
||||
.ep-feld {
|
||||
width: 100%;
|
||||
background: var(--surface);
|
||||
border: 1px solid #b9c9d8;
|
||||
color: var(--ink);
|
||||
padding: 0.6rem 0.75rem;
|
||||
}
|
||||
.ep-feld:focus {
|
||||
border-color: var(--accent);
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 0;
|
||||
}
|
||||
|
||||
/* Knopf in Tiefblau. Für die eine Hauptaktion zusätzlich .ep-cta */
|
||||
.ep-knopf {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
background-color: var(--accent);
|
||||
color: var(--on-accent);
|
||||
font-weight: 700;
|
||||
padding: 0.7rem 1.4rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ep-knopf:hover {
|
||||
background-color: var(--accent-press);
|
||||
}
|
||||
.ep-knopf:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Hauptaktion: Magenta-Verlauf wie „Alle Reisen anzeigen“ auf ep-reisen.de. Nur einmal je Seite. */
|
||||
.ep-cta {
|
||||
background-image: linear-gradient(120deg, #960167, #9e036a 40%, #fa1a8c);
|
||||
color: #ffffff;
|
||||
}
|
||||
.ep-cta:hover {
|
||||
background-image: linear-gradient(120deg, #7d0156, #8a035d 40%, #e3107c);
|
||||
}
|
||||
|
||||
/* Hellblauer Kasten für Ergebnisse und Hinweise */
|
||||
.ep-hinweis {
|
||||
background: var(--accent-soft);
|
||||
border-left: 4px solid var(--accent);
|
||||
padding: 0.9rem 1.1rem;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
/* Fehlermeldung */
|
||||
.ep-fehler {
|
||||
background: #fdf1f0;
|
||||
border-left: 4px solid var(--fehler);
|
||||
padding: 0.9rem 1.1rem;
|
||||
color: var(--fehler);
|
||||
font-size: 0.925rem;
|
||||
}
|
||||
|
||||
/* Tabelle für Ergebnisse */
|
||||
.ep-tabelle {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--surface);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.ep-tabelle th {
|
||||
background: var(--accent);
|
||||
color: var(--on-accent);
|
||||
text-align: left;
|
||||
font-weight: 700;
|
||||
padding: 0.55rem 0.75rem;
|
||||
}
|
||||
.ep-tabelle td {
|
||||
border-bottom: 1px solid var(--hairline);
|
||||
padding: 0.55rem 0.75rem;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
/* Pfeil-Aufzählung */
|
||||
.arrow-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
.arrow-list > li {
|
||||
position: relative;
|
||||
padding-left: 1.4rem;
|
||||
}
|
||||
.arrow-list > li::before {
|
||||
content: "→";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--secondary: oklch(0.269 0 0);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.269 0 0);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.269 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import localFont from "next/font/local";
|
||||
import "./globals.css";
|
||||
import { EpKopf } from "@/components/EpKopf";
|
||||
import { EpFuss } from "@/components/EpFuss";
|
||||
import { APP_BESCHREIBUNG, APP_TITEL } from "@/lib/app";
|
||||
import { Inter } from "next/font/google";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const inter = Inter({subsets:['latin'],variable:'--font-sans'});
|
||||
|
||||
|
||||
// Hausschrift von ep-reisen.de (Lato, freie Lizenz OFL). Die Dateien liegen im Projekt,
|
||||
// damit der Build ohne Internet klappt. Lato hat keine Stärke 600, font-semibold erscheint fett.
|
||||
const lato = localFont({
|
||||
src: [
|
||||
{ path: "./fonts/lato-400.woff2", weight: "400", style: "normal" },
|
||||
{ path: "./fonts/lato-700.woff2", weight: "700", style: "normal" },
|
||||
{ path: "./fonts/lato-900.woff2", weight: "900", style: "normal" },
|
||||
],
|
||||
variable: "--font-lato",
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `${APP_TITEL} · E&P Reisen`,
|
||||
description: APP_BESCHREIBUNG,
|
||||
robots: { index: false, follow: false },
|
||||
icons: { icon: "/favicon.svg" },
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
themeColor: "#ffffff",
|
||||
colorScheme: "light",
|
||||
};
|
||||
|
||||
// E&P-Layout für jede Seite: Kopf mit Logo, Inhalt, Fuß. Seiten liefern nur ihren Inhalt, kein eigenes <main>.
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="de" className={cn("font-sans", inter.variable)}>
|
||||
<body className="flex min-h-screen flex-col bg-ground text-ink">
|
||||
<a href="#inhalt" className="skip-link">
|
||||
Zum Inhalt springen
|
||||
</a>
|
||||
<EpKopf />
|
||||
<main id="inhalt" className="mx-auto w-full max-w-3xl flex-1 px-4 py-8 sm:px-6 sm:py-12">
|
||||
{children}
|
||||
</main>
|
||||
<EpFuss />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { postWebhook } from "@/lib/n8n";
|
||||
|
||||
type HelloResponse = { message?: string };
|
||||
|
||||
// Pfad des eigenen Webhooks mit Kürzel, zum Beispiel "anna-hello" (ohne /webhook/).
|
||||
// In der E&P-n8n gehört jeder Pfad genau einem Workflow. Ohne Angabe ruft die Seite nichts auf.
|
||||
const HELLO_PATH = (process.env.NEXT_PUBLIC_HELLO_PATH || "").trim();
|
||||
|
||||
// Beispielseite im E&P-Layout. Kopf und Fuß kommen aus app/layout.tsx,
|
||||
// Farben und Bausteine (ep-karte, ep-feld, ep-knopf, ep-cta, ep-hinweis, ep-fehler) aus app/globals.css.
|
||||
export default function Home() {
|
||||
const [name, setName] = useState("");
|
||||
const [answer, setAnswer] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
setAnswer(null);
|
||||
if (!HELLO_PATH) {
|
||||
setError(
|
||||
"NEXT_PUBLIC_HELLO_PATH fehlt. Beim ersten Veröffentlichen den eigenen Pfad mitgeben, zum Beispiel anna-hello.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await postWebhook<HelloResponse>(HELLO_PATH, { name });
|
||||
setAnswer(res.message ?? JSON.stringify(res));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div>
|
||||
<h1 className="ep-ueberschrift text-3xl">Hallo aus n8n</h1>
|
||||
<p className="mt-4 text-ink-muted">
|
||||
Das Formular ruft einen n8n-Webhook deines eigenen Workflows auf (Vorlage <code>hello-webhook.json</code>,
|
||||
Pfad <code>/webhook/{HELLO_PATH || "anna-hello"}</code>).
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={onSubmit} className="ep-karte flex flex-col gap-3">
|
||||
<label htmlFor="name" className="ep-label">
|
||||
Dein Name
|
||||
</label>
|
||||
<input
|
||||
id="name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="Max"
|
||||
className="ep-feld"
|
||||
required
|
||||
/>
|
||||
<button type="submit" disabled={loading} className="ep-knopf ep-cta self-start">
|
||||
{loading ? "Sende …" : "An n8n senden"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{answer && <div className="ep-hinweis">{answer}</div>}
|
||||
{error && (
|
||||
<div role="alert" className="ep-fehler">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user