| Дата |
+ Заявка |
Компания |
Телефон |
Email |
@@ -95,6 +105,9 @@ export default async function AdminLeadsPage({
{new Date(lead.createdAt).toLocaleString("ru-RU")}
|
+
+ {formatLeadNumber(lead.id, lead.createdAt)}
+ |
{lead.company} |
{lead.phone} |
{lead.email || "—"} |
@@ -108,7 +121,7 @@ export default async function AdminLeadsPage({
{leads.length === 0 && (
- |
+ |
Пока заявок нет
|
@@ -119,4 +132,4 @@ export default async function AdminLeadsPage({
);
-}
\ No newline at end of file
+}
diff --git a/components/lead-status-select.tsx b/components/lead-status-select.tsx
index a50f50f..0022eed 100644
--- a/components/lead-status-select.tsx
+++ b/components/lead-status-select.tsx
@@ -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,17 +64,20 @@ export default function LeadStatusSelect({
}
return (
-
+
+
+
+
);
}
\ No newline at end of file
diff --git a/middleware.ts b/middleware.ts
index 8e8d002..b8f2ccc 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -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";
- if (!isAuthed && !isLoginPage) {
- const loginUrl = new URL("/admin/login", request.url);
- loginUrl.searchParams.set("next", `${pathname}${search}`);
- return NextResponse.redirect(loginUrl);
+ 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);
}
- if (isAuthed && isLoginPage) {
- return NextResponse.redirect(new URL("/admin/leads", request.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 = request.nextUrl.clone();
+ loginUrl.pathname = "/admin/login";
+ loginUrl.search = `?next=${encodeURIComponent(`${pathname}${search}`)}`;
+ return NextResponse.redirect(loginUrl);
+ }
+
+ if (isAuthed && isLoginPage) {
+ 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*"],
};
\ No newline at end of file