статусы на русском языке
All checks were successful
Auto Deploy / deploy (push) Successful in 22s

This commit is contained in:
deonisii
2026-04-17 23:49:12 +03:00
parent 4f67bca4be
commit 9b86175929
3 changed files with 103 additions and 51 deletions

View File

@@ -8,6 +8,15 @@ type SearchParams = Promise<{
status?: string;
}>;
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,
}: {
@@ -64,11 +73,11 @@ export default async function AdminLeadsPage({
className="rounded-2xl border border-white/10 bg-neutral-900 px-4 py-3 outline-none"
>
<option value="">Все статусы</option>
<option value="NEW">NEW</option>
<option value="IN_PROGRESS">IN_PROGRESS</option>
<option value="CALL_SCHEDULED">CALL_SCHEDULED</option>
<option value="WON">WON</option>
<option value="LOST">LOST</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">
@@ -81,6 +90,7 @@ export default async function AdminLeadsPage({
<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>
@@ -95,6 +105,9 @@ export default async function AdminLeadsPage({
<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>
@@ -108,7 +121,7 @@ export default async function AdminLeadsPage({
{leads.length === 0 && (
<tr>
<td colSpan={7} className="px-4 py-8 text-center text-neutral-400">
<td colSpan={8} className="px-4 py-8 text-center text-neutral-400">
Пока заявок нет
</td>
</tr>

View File

@@ -3,13 +3,30 @@
import { useState } from "react";
const statuses = [
{ value: "NEW", label: "NEW" },
{ value: "IN_PROGRESS", label: "IN_PROGRESS" },
{ value: "CALL_SCHEDULED", label: "CALL_SCHEDULED" },
{ value: "WON", label: "WON" },
{ value: "LOST", label: "LOST" },
{ value: "NEW", label: "Новая" },
{ value: "IN_PROGRESS", label: "В работе" },
{ value: "CALL_SCHEDULED", label: "Назначен звонок" },
{ value: "WON", label: "Успешно" },
{ value: "LOST", label: "Закрыта" },
] as const;
function getStatusDot(value: string) {
switch (value) {
case "NEW":
return "bg-sky-400";
case "IN_PROGRESS":
return "bg-amber-400";
case "CALL_SCHEDULED":
return "bg-violet-400";
case "WON":
return "bg-emerald-400";
case "LOST":
return "bg-rose-400";
default:
return "bg-neutral-400";
}
}
export default function LeadStatusSelect({
leadId,
value,
@@ -21,6 +38,7 @@ export default function LeadStatusSelect({
const [isSaving, setIsSaving] = useState(false);
async function updateStatus(nextStatus: string) {
const prev = status;
setStatus(nextStatus);
setIsSaving(true);
@@ -34,11 +52,11 @@ export default function LeadStatusSelect({
});
if (!response.ok) {
setStatus(value);
setStatus(prev);
alert("Не удалось обновить статус");
}
} catch {
setStatus(value);
setStatus(prev);
alert("Ошибка сети");
} finally {
setIsSaving(false);
@@ -46,6 +64,8 @@ export default function LeadStatusSelect({
}
return (
<div className="flex items-center gap-2">
<span className={`inline-block h-2.5 w-2.5 rounded-full ${getStatusDot(status)}`} />
<select
value={status}
disabled={isSaving}
@@ -58,5 +78,6 @@ export default function LeadStatusSelect({
</option>
))}
</select>
</div>
);
}

View File

@@ -1,41 +1,59 @@
import { NextRequest, NextResponse } from "next/server";
import { getSessionCookieName, verifySessionToken } from "@/lib/auth";
function normalizeHost(host: string) {
return host.split(":")[0].toLowerCase();
}
export async function middleware(request: NextRequest) {
const { pathname, search } = request.nextUrl;
const host = request.headers.get("host") || "";
const crmHost = process.env.CRM_HOST || "crm.workparking.ru";
if (!pathname.startsWith("/admin")) {
return NextResponse.next();
}
if (host !== crmHost) {
const redirectUrl = new URL(request.url);
redirectUrl.host = crmHost;
redirectUrl.protocol = "https:";
return NextResponse.redirect(redirectUrl);
}
const cookieName = getSessionCookieName();
const token = request.cookies.get(cookieName)?.value;
const isAuthed = await verifySessionToken(token);
const pathname = request.nextUrl.pathname;
const search = request.nextUrl.search;
const host = normalizeHost(request.headers.get("host") || "");
const crmHost = (process.env.CRM_HOST || "crm.workparking.ru").toLowerCase();
const isCrmHost = host === crmHost;
const isAdminPath = pathname.startsWith("/admin");
const isLoginPage = pathname === "/admin/login";
const token = request.cookies.get(getSessionCookieName())?.value;
const isAuthed = await verifySessionToken(token);
// Если открыли crm.workparking.ru/ — сразу ведём в CRM
if (isCrmHost && pathname === "/") {
const url = request.nextUrl.clone();
url.pathname = isAuthed ? "/admin/leads" : "/admin/login";
url.search = "";
return NextResponse.redirect(url);
}
// Если admin открыли не на CRM-домене — уводим на CRM без порта
if (isAdminPath && !isCrmHost) {
const url = request.nextUrl.clone();
url.protocol = "https";
url.hostname = crmHost;
url.port = "";
return NextResponse.redirect(url);
}
if (isAdminPath) {
if (!isAuthed && !isLoginPage) {
const loginUrl = new URL("/admin/login", request.url);
loginUrl.searchParams.set("next", `${pathname}${search}`);
const loginUrl = request.nextUrl.clone();
loginUrl.pathname = "/admin/login";
loginUrl.search = `?next=${encodeURIComponent(`${pathname}${search}`)}`;
return NextResponse.redirect(loginUrl);
}
if (isAuthed && isLoginPage) {
return NextResponse.redirect(new URL("/admin/leads", request.url));
const url = request.nextUrl.clone();
url.pathname = "/admin/leads";
url.search = "";
return NextResponse.redirect(url);
}
}
return NextResponse.next();
}
export const config = {
matcher: ["/admin/:path*"],
matcher: ["/", "/admin/:path*"],
};