Удалить локальную CRM и Prisma, обновить Docker Compose и автодеплой Gitea
All checks were successful
Auto Deploy / deploy (push) Successful in 47s

This commit is contained in:
deonisii
2026-04-19 00:03:26 +03:00
parent e37b503187
commit 71ec905860
25 changed files with 92 additions and 2254 deletions

View File

@@ -1,141 +0,0 @@
import { prisma } from "@/lib/prisma";
import LeadStatusSelect from "@/components/lead-status-select";
import { LeadStatus } from "@prisma/client";
export const dynamic = "force-dynamic";
type SearchParams = Promise<{
q?: string;
status?: string;
}>;
const leadStatuses = Object.values(LeadStatus);
function formatLeadNumber(id: string, createdAt: Date) {
const date = new Date(createdAt);
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");
const d = String(date.getDate()).padStart(2, "0");
return `WP-${y}${m}${d}-${id.slice(-6).toUpperCase()}`;
}
export default async function AdminLeadsPage({
searchParams,
}: {
searchParams: SearchParams;
}) {
const params = await searchParams;
const q = params.q?.trim() || "";
const statusParam = params.status?.trim() || "";
const status = leadStatuses.includes(statusParam as LeadStatus)
? (statusParam as LeadStatus)
: undefined;
const leads = await prisma.lead.findMany({
where: {
AND: [
q
? {
OR: [
{ company: { contains: q, mode: "insensitive" } },
{ phone: { contains: q, mode: "insensitive" } },
{ email: { contains: q, mode: "insensitive" } },
{ message: { contains: q, mode: "insensitive" } },
],
}
: {},
status ? { status } : {},
],
},
orderBy: { createdAt: "desc" },
});
return (
<main className="min-h-screen bg-neutral-950 text-white">
<div className="max-w-7xl mx-auto px-4 sm:px-6 py-10">
<div className="flex items-center justify-between gap-4 mb-8">
<h1 className="text-3xl font-bold">Заявки</h1>
<form action="/api/admin/logout" method="POST">
<button className="rounded-2xl border border-white/10 px-4 py-2 hover:bg-white/5">
Выйти
</button>
</form>
</div>
<form className="grid md:grid-cols-[1fr_220px_auto] gap-4 mb-6">
<input
type="text"
name="q"
defaultValue={q}
placeholder="Поиск: компания, телефон, email, сообщение"
className="rounded-2xl border border-white/10 bg-neutral-900 px-4 py-3 outline-none"
/>
<select
name="status"
defaultValue={status}
className="rounded-2xl border border-white/10 bg-neutral-900 px-4 py-3 outline-none"
>
<option value="">Все статусы</option>
<option value="NEW">Новая</option>
<option value="IN_PROGRESS">В работе</option>
<option value="CALL_SCHEDULED">Назначен звонок</option>
<option value="WON">Успешно</option>
<option value="LOST">Закрыта</option>
</select>
<button className="rounded-2xl bg-emerald-600 px-5 py-3 font-semibold hover:bg-emerald-500">
Найти
</button>
</form>
<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">Email</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 whitespace-nowrap">
{formatLeadNumber(lead.id, lead.createdAt)}
</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">{lead.email || "—"}</td>
<td className="px-4 py-3 text-neutral-300">{lead.message || "—"}</td>
<td className="px-4 py-3">
<LeadStatusSelect leadId={lead.id} value={lead.status} />
</td>
<td className="px-4 py-3">{lead.source}</td>
</tr>
))}
{leads.length === 0 && (
<tr>
<td colSpan={8} className="px-4 py-8 text-center text-neutral-400">
Пока заявок нет
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</main>
);
}

View File

@@ -1,78 +0,0 @@
"use client";
import { useState } from "react";
export default function AdminLoginPage() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [errorText, setErrorText] = useState("");
const [isLoading, setIsLoading] = useState(false);
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setErrorText("");
setIsLoading(true);
try {
const response = await fetch("/api/admin/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email, password }),
});
const data = await response.json();
if (!response.ok) {
setErrorText(data.error || "Ошибка входа");
return;
}
window.location.href = "/admin/leads";
} catch {
setErrorText("Ошибка сети");
} finally {
setIsLoading(false);
}
}
return (
<main className="min-h-screen bg-neutral-950 text-white flex items-center justify-center px-4">
<div className="w-full max-w-md rounded-3xl border border-white/10 bg-neutral-900 p-8">
<h1 className="text-3xl font-bold mb-2">Вход в CRM</h1>
<p className="text-neutral-400 mb-6">WorkParking CRM</p>
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full rounded-2xl border border-white/10 bg-black/30 px-4 py-3 outline-none focus:border-emerald-500"
required
/>
<input
type="password"
placeholder="Пароль"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full rounded-2xl border border-white/10 bg-black/30 px-4 py-3 outline-none focus:border-emerald-500"
required
/>
<button
type="submit"
disabled={isLoading}
className="w-full rounded-2xl bg-emerald-600 px-4 py-3 font-semibold hover:bg-emerald-500 disabled:opacity-60"
>
{isLoading ? "Входим..." : "Войти"}
</button>
{errorText && <p className="text-sm text-red-400">{errorText}</p>}
</form>
</div>
</main>
);
}

View File

@@ -1,38 +0,0 @@
import { NextResponse } from "next/server";
import { createSessionToken, getAdminCredentials, getSessionCookieName } from "@/lib/auth";
type LoginPayload = {
email?: string;
password?: string;
};
export async function POST(request: Request) {
try {
const body = (await request.json()) as LoginPayload;
const email = body.email?.trim().toLowerCase() || "";
const password = body.password?.trim() || "";
const admin = getAdminCredentials();
if (email !== admin.email.toLowerCase() || password !== admin.password) {
return NextResponse.json({ error: "Неверный email или пароль" }, { status: 401 });
}
const token = await createSessionToken(email);
const response = NextResponse.json({ success: true });
response.cookies.set({
name: getSessionCookieName(),
value: token,
httpOnly: true,
secure: true,
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 7,
});
return response;
} catch {
return NextResponse.json({ error: "Ошибка авторизации" }, { status: 500 });
}
}

View File

@@ -1,18 +0,0 @@
import { NextResponse } from "next/server";
import { getSessionCookieName } from "@/lib/auth";
export async function POST() {
const response = NextResponse.json({ success: true });
response.cookies.set({
name: getSessionCookieName(),
value: "",
httpOnly: true,
secure: true,
sameSite: "lax",
path: "/",
maxAge: 0,
});
return response;
}

View File

@@ -1,43 +0,0 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
const allowedStatuses = [
"NEW",
"IN_PROGRESS",
"CALL_SCHEDULED",
"WON",
"LOST",
] as const;
type LeadStatus = (typeof allowedStatuses)[number];
type PatchPayload = {
status?: LeadStatus;
};
export async function PATCH(
request: Request,
context: { params: Promise<{ id: string }> }
) {
try {
const { id } = await context.params;
const body = (await request.json()) as PatchPayload;
if (!body.status || !allowedStatuses.includes(body.status)) {
return NextResponse.json({ error: "Некорректный статус" }, { status: 400 });
}
const lead = await prisma.lead.update({
where: { id },
data: { status: body.status },
});
return NextResponse.json({ success: true, lead });
} catch (error) {
console.error("PATCH /api/leads/[id] error:", error);
return NextResponse.json(
{ error: "Не удалось обновить статус" },
{ status: 500 }
);
}
}

View File

@@ -1,45 +0,0 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
type LeadPayload = {
company?: string;
phone?: string;
email?: 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 email = body.email?.trim().toLowerCase();
const message = body.message?.trim() || "";
if (!company || !phone || !email) {
return NextResponse.json(
{ error: "Компания, телефон и email обязательны" },
{ status: 400 }
);
}
const lead = await prisma.lead.create({
data: {
company,
phone,
email,
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 }
);
}
}

View File

@@ -1,10 +0,0 @@
import { prisma } from "@/lib/prisma";
export async function GET() {
const leads = await prisma.lead.findMany();
return Response.json({
ok: true,
count: leads.length,
});
}

View File

@@ -1,5 +1,3 @@
import LeadForm from "@/components/lead-form";
export default function ContactsPage() {
return (
<main className="bg-neutral-950">
@@ -87,14 +85,49 @@ export default function ContactsPage() {
</div>
</section>
<section className="pb-16 sm:pb-20">
<section id="contact-request" className="pb-16 sm:pb-20">
<div className="max-w-5xl mx-auto px-4 sm:px-6">
<div className="rounded-[32px] border border-white/10 bg-neutral-900 p-6 sm:p-10">
<LeadForm
id="lead-form"
title="Оставить заявку"
description="Заполните короткую форму. Мы свяжемся с вами, уточним задачу и предложим подходящий сценарий для объекта."
/>
<div className="max-w-3xl">
<h2 className="text-3xl font-bold tracking-[-0.04em] sm:text-4xl">
Обсудим ваш объект
</h2>
<p className="mt-4 text-base leading-relaxed text-neutral-400 sm:text-lg">
Мы убрали локальную CRM, базу заявок и админку из сайта. Дальше
сюда можно спокойно подключить внешнюю форму из EspoCRM или
любой другой системы, а пока используйте прямые контакты.
</p>
</div>
<div className="mt-8 grid gap-4 md:grid-cols-2">
<a
href="tel:+79999698149"
className="rounded-3xl border border-emerald-500/30 bg-emerald-500/10 px-5 py-5 transition-colors hover:bg-emerald-500/15"
>
<div className="text-sm uppercase tracking-[0.18em] text-emerald-300">
Телефон
</div>
<div className="mt-3 text-2xl font-semibold">
+7 (999) 969-81-49
</div>
<p className="mt-2 text-neutral-400">
Для обсуждения объекта, внедрения и тарифов
</p>
</a>
<a
href="mailto:sale@parkflow.ru"
className="rounded-3xl border border-white/10 bg-black/25 px-5 py-5 transition-colors hover:border-white/20 hover:bg-white/[0.03]"
>
<div className="text-sm uppercase tracking-[0.18em] text-neutral-400">
Email
</div>
<div className="mt-3 text-2xl font-semibold">sale@parkflow.ru</div>
<p className="mt-2 text-neutral-400">
Можно сразу прислать адрес объекта и краткое описание задачи
</p>
</a>
</div>
</div>
</div>
</section>

View File

@@ -1,6 +1,5 @@
import Link from "next/link";
import Image from "next/image";
import LeadForm from "@/components/lead-form";
import BarrierIcon from "@/components/barrier-icon";
import {
ArrowRight,
@@ -135,7 +134,7 @@ export default function Home() {
<div className="mt-7 flex flex-col gap-3 sm:mt-8 sm:flex-row sm:gap-4">
<Link
href="/contacts#lead-form"
href="/contacts#contact-request"
className="inline-flex items-center justify-center gap-2 rounded-2xl bg-emerald-600 px-5 py-3.5 text-sm font-semibold text-white transition-colors hover:bg-emerald-500 sm:px-6 sm:py-4 sm:text-base"
>
Получить консультацию
@@ -411,11 +410,35 @@ export default function Home() {
</div>
<div className="rounded-[28px] border border-white/10 bg-black/25 p-5 shadow-[inset_0_1px_0_rgba(255,255,255,0.05)] sm:p-6">
<LeadForm
title="Оставить заявку"
description="Ответим, уточним сценарий подключения и предложим вариант под ваш объект."
compact
/>
<h3 className="text-3xl font-bold tracking-[-0.05em]">
Свяжитесь с нами
</h3>
<p className="mt-4 text-base leading-relaxed text-neutral-400 sm:text-lg">
Дальше вы сможете подключить сюда форму из EspoCRM или другой
внешней CRM. Пока сайт остаётся чистым фронтом без своей базы
заявок и админки.
</p>
<div className="mt-8 grid gap-3">
<a
href="tel:+79999698149"
className="inline-flex items-center justify-center rounded-2xl bg-emerald-600 px-5 py-4 text-base font-semibold text-white transition-colors hover:bg-emerald-500"
>
Позвонить: +7 (999) 969-81-49
</a>
<a
href="mailto:sale@parkflow.ru"
className="inline-flex items-center justify-center rounded-2xl border border-white/15 bg-white/[0.02] px-5 py-4 text-base font-semibold transition-colors hover:border-white/30 hover:bg-white/5"
>
Написать: sale@parkflow.ru
</a>
<Link
href="/contacts#contact-request"
className="inline-flex items-center justify-center rounded-2xl border border-white/15 bg-white/[0.02] px-5 py-4 text-base font-semibold transition-colors hover:border-white/30 hover:bg-white/5"
>
Открыть страницу контактов
</Link>
</div>
</div>
</div>
</div>