Template
Schulungs-Vorlage auf neues App-Template umgestellt
This commit is contained in:
1 parent
2dfa403641
commit
46efd2d9d0
17 files changed
+162
-414
No files matched your search
@@ -1,76 +1,17 @@
|
||||
"use client";
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||
import { APP_BESCHREIBUNG, APP_TITEL } from "@/lib/app";
|
||||
|
||||
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.
|
||||
// Startseite im E&P-Layout. Kopf und Fuß kommen aus app/layout.tsx,
|
||||
// Farben und Bausteine (ep-karte, ep-ueberschrift, …) 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>
|
||||
<Card className="ep-karte rounded-none shadow-none ring-0">
|
||||
<CardHeader className="px-0">
|
||||
<h1 className="ep-ueberschrift text-3xl">{APP_TITEL}</h1>
|
||||
</CardHeader>
|
||||
<CardContent className="px-0">
|
||||
<p className="text-ink-muted">{APP_BESCHREIBUNG}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user