add crm auth, email, status update and search
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s
This commit is contained in:
@@ -1,16 +1,80 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import LeadStatusSelect from "@/components/lead-status-select";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminLeadsPage() {
|
||||
type SearchParams = Promise<{
|
||||
q?: string;
|
||||
status?: string;
|
||||
}>;
|
||||
|
||||
export default async function AdminLeadsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: SearchParams;
|
||||
}) {
|
||||
const params = await searchParams;
|
||||
const q = params.q?.trim() || "";
|
||||
const status = params.status?.trim() || "";
|
||||
|
||||
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: status as any } : {},
|
||||
],
|
||||
},
|
||||
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="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">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>
|
||||
</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">
|
||||
@@ -19,6 +83,7 @@ export default async function AdminLeadsPage() {
|
||||
<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>
|
||||
@@ -32,17 +97,18 @@ export default async function AdminLeadsPage() {
|
||||
</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 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.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 colSpan={7} className="px-4 py-8 text-center text-neutral-400">
|
||||
Пока заявок нет
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
78
app/admin/login/page.tsx
Normal file
78
app/admin/login/page.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
"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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user