добавлена форма заявки тестовая, тестовая сттраница crm база данных
Some checks failed
Auto Deploy / deploy (push) Failing after 45s
Some checks failed
Auto Deploy / deploy (push) Failing after 45s
This commit is contained in:
56
app/admin/leads/page.tsx
Normal file
56
app/admin/leads/page.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminLeadsPage() {
|
||||
const leads = await prisma.lead.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-neutral-950 text-white">
|
||||
<div className="max-w-6xl mx-auto px-4 sm:px-6 py-10">
|
||||
<h1 className="text-3xl font-bold mb-8">Заявки</h1>
|
||||
|
||||
<div className="overflow-x-auto rounded-2xl border border-white/10 bg-neutral-900">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="border-b border-white/10 text-neutral-400">
|
||||
<tr>
|
||||
<th className="text-left px-4 py-3">Дата</th>
|
||||
<th className="text-left px-4 py-3">Компания</th>
|
||||
<th className="text-left px-4 py-3">Телефон</th>
|
||||
<th className="text-left px-4 py-3">Сообщение</th>
|
||||
<th className="text-left px-4 py-3">Статус</th>
|
||||
<th className="text-left px-4 py-3">Источник</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{leads.map((lead) => (
|
||||
<tr key={lead.id} className="border-b border-white/5 align-top">
|
||||
<td className="px-4 py-3 whitespace-nowrap">
|
||||
{new Date(lead.createdAt).toLocaleString("ru-RU")}
|
||||
</td>
|
||||
<td className="px-4 py-3">{lead.company}</td>
|
||||
<td className="px-4 py-3">{lead.phone}</td>
|
||||
<td className="px-4 py-3 text-neutral-300">
|
||||
{lead.message || "—"}
|
||||
</td>
|
||||
<td className="px-4 py-3">{lead.status}</td>
|
||||
<td className="px-4 py-3">{lead.source}</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
{leads.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="px-4 py-8 text-center text-neutral-400">
|
||||
Пока заявок нет
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
58
app/api/leads/route.ts
Normal file
58
app/api/leads/route.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
type LeadPayload = {
|
||||
company?: string;
|
||||
phone?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = (await request.json()) as LeadPayload;
|
||||
|
||||
const company = body.company?.trim();
|
||||
const phone = body.phone?.trim();
|
||||
const message = body.message?.trim() || "";
|
||||
|
||||
if (!company || !phone) {
|
||||
return NextResponse.json(
|
||||
{ error: "Компания и телефон обязательны" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const lead = await prisma.lead.create({
|
||||
data: {
|
||||
company,
|
||||
phone,
|
||||
message,
|
||||
source: "website",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, leadId: lead.id }, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error("POST /api/leads error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Не удалось сохранить заявку" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const leads = await prisma.lead.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return NextResponse.json(leads);
|
||||
} catch (error) {
|
||||
console.error("GET /api/leads error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Не удалось получить заявки" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
10
app/api/test/route.ts
Normal file
10
app/api/test/route.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET() {
|
||||
const leads = await prisma.lead.findMany();
|
||||
|
||||
return Response.json({
|
||||
ok: true,
|
||||
count: leads.length,
|
||||
});
|
||||
}
|
||||
25
app/page.tsx
25
app/page.tsx
@@ -1,5 +1,6 @@
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import LeadForm from "@/components/lead-form";
|
||||
import {
|
||||
ArrowRight,
|
||||
Camera,
|
||||
@@ -305,28 +306,8 @@ export default function Home() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form className="mt-8 grid gap-4 sm:gap-5">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Название ЖК, ТСЖ или УК"
|
||||
className="w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
|
||||
/>
|
||||
<input
|
||||
type="tel"
|
||||
placeholder="+7 (___) ___-__-__"
|
||||
className="w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
|
||||
/>
|
||||
<textarea
|
||||
placeholder="Опишите текущий шлагбаум и что хотите добавить: номерной доступ, приложение, история, аналитика"
|
||||
className="min-h-32 w-full rounded-2xl border border-white/10 bg-black/30 px-5 py-4 outline-none placeholder:text-neutral-500 focus:border-emerald-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="inline-flex items-center justify-center rounded-2xl bg-emerald-600 px-6 py-4 text-base font-semibold hover:bg-emerald-500 transition-colors"
|
||||
>
|
||||
Отправить заявку
|
||||
</button>
|
||||
</form>
|
||||
<LeadForm />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user