Keep cabinet data private per patient, email new accounts after a request, and store gallery photos as files.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alexey Novikov
2026-09-17 01:46:27 +03:00
co-authored by Cursor
parent 2ab7c29576
commit 1550bccb83
33 changed files with 715 additions and 82 deletions
@@ -1,3 +1,5 @@
import { getMyDocuments } from "@/lib/api";
import { formatDate } from "@/lib/utils";
import { getTranslations, setRequestLocale } from "next-intl/server";
export default async function CabinetDocumentsPage({
@@ -8,11 +10,27 @@ export default async function CabinetDocumentsPage({
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations("cabinet");
const documents = await getMyDocuments();
return (
<div>
<h2 className="mb-4 text-xl font-semibold">{t("documents")}</h2>
<p className="text-[var(--text-muted)]">{t("emptyDocuments")}</p>
{documents.length === 0 ? (
<p className="text-[var(--text-muted)]">{t("emptyDocuments")}</p>
) : (
<ul className="space-y-3">
{documents.map((doc) => (
<li key={doc.id} className="rounded-[12px] border border-[var(--border)] bg-white px-4 py-3">
<a href={doc.href} className="font-semibold text-[var(--brand-700)]" target="_blank" rel="noreferrer">
{doc.title}
</a>
{doc.issuedAt ? (
<p className="mt-1 text-sm text-[var(--text-muted)]">{formatDate(doc.issuedAt, locale)}</p>
) : null}
</li>
))}
</ul>
)}
</div>
);
}
@@ -1,6 +1,6 @@
import { Card } from "@/components/ui/Card";
import { getMyBookings } from "@/lib/api";
import { formatPrice } from "@/lib/utils";
import { getMyInvoices } from "@/lib/api";
import { formatDate, formatPrice } from "@/lib/utils";
import { getTranslations, setRequestLocale } from "next-intl/server";
export default async function CabinetInvoicesPage({
@@ -11,24 +11,27 @@ export default async function CabinetInvoicesPage({
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations("cabinet");
const bookings = await getMyBookings();
const invoices = await getMyInvoices();
return (
<div>
<h2 className="mb-4 text-xl font-semibold">{t("invoices")}</h2>
{bookings.length === 0 ? (
{invoices.length === 0 ? (
<p className="text-[var(--text-muted)]">{t("emptyInvoices")}</p>
) : (
<div className="space-y-3">
{bookings.map((b) => (
<Card key={b.id} className="flex items-center justify-between gap-4">
{invoices.map((invoice) => (
<Card key={invoice.id} className="flex items-center justify-between gap-4">
<div>
<p className="font-semibold">{b.serviceTitle}</p>
<p className="text-sm text-[var(--text-muted)]">{b.datetime}</p>
<p className="font-semibold">{invoice.title}</p>
<p className="text-sm text-[var(--text-muted)]">
{invoice.number}
{invoice.datetime ? ` · ${formatDate(invoice.datetime, locale)}` : ""}
</p>
</div>
<div className="text-right">
<p className="font-bold text-[var(--brand-700)]">{formatPrice(b.price, locale)}</p>
<p className="text-xs text-[var(--neutral-500)]">{b.paid ? t("paid") : t("unpaid")}</p>
<p className="font-bold text-[var(--brand-700)]">{formatPrice(invoice.amount, locale)}</p>
<p className="text-xs text-[var(--neutral-500)]">{invoice.paid ? t("paid") : t("unpaid")}</p>
</div>
</Card>
))}
@@ -1,5 +1,7 @@
import { CabinetNav } from "@/components/cabinet/CabinetNav";
import { namedPageMetadata } from "@/lib/page-metadata";
import { me } from "@/lib/api";
import { Link } from "@/i18n/routing";
import { getTranslations, setRequestLocale } from "next-intl/server";
import type { ReactNode } from "react";
@@ -22,6 +24,20 @@ export default async function CabinetLayout({
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations("cabinet");
const auth = await getTranslations("auth");
const user = await me();
if (!user) {
return (
<div className="mx-auto max-w-xl px-4 py-12 sm:px-6">
<h1 className="text-3xl font-bold text-[var(--neutral-900)]">{t("title")}</h1>
<p className="mt-4 text-[var(--text-muted)]">{t("loginHint")}</p>
<Link href="/login" className="mt-4 inline-block font-semibold text-[var(--brand-700)]">
{auth("login")}
</Link>
</div>
);
}
return (
<div className="mx-auto max-w-6xl px-4 py-12 sm:px-6">
+1 -1
View File
@@ -35,7 +35,7 @@ export default async function GalleryPage({
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={item.image} alt={item.title} className="mx-auto block w-full object-cover object-center" />
<figcaption className="bg-white px-3 py-2 text-sm text-[var(--neutral-600)]">
{item.title} · {item.category}
{item.title}
</figcaption>
</figure>
))}
-13
View File
@@ -24,19 +24,6 @@ export async function POST(request: Request) {
});
return response;
} catch {
// Demo login fallback when CMS is down
if (body.email && body.password) {
const response = NextResponse.json({
user: { id: "demo", email: body.email, name: "Пациент" },
});
response.cookies.set(AUTH_COOKIE, "demo-token", {
httpOnly: true,
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 7,
});
return response;
}
return NextResponse.json({ message: "Login failed" }, { status: 500 });
}
}
+10 -16
View File
@@ -5,13 +5,7 @@ import { NextResponse } from "next/server";
export async function GET() {
const store = await cookies();
const token = store.get(AUTH_COOKIE)?.value;
if (!token) return NextResponse.json({ user: null }, { status: 401 });
if (token === "demo-token") {
return NextResponse.json({
user: { id: "demo", email: "patient@example.com", name: "Пациент", phone: "+7" },
});
}
if (!token || token === "demo-token") return NextResponse.json({ user: null }, { status: 401 });
try {
const res = await fetch(`${CMS_URL}/api/users/me`, {
@@ -21,21 +15,21 @@ export async function GET() {
const data = await res.json();
return NextResponse.json(data, { status: res.status });
} catch {
return NextResponse.json({
user: { id: "demo", email: "patient@example.com", name: "Пациент" },
});
return NextResponse.json({ user: null }, { status: 401 });
}
}
export async function PATCH(request: Request) {
const store = await cookies();
const token = store.get(AUTH_COOKIE)?.value;
if (!token) return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
if (!token || token === "demo-token") return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
const body = await request.json();
if (token === "demo-token") {
return NextResponse.json({ user: { id: "demo", ...body } });
}
const payload = {
...body,
fullName: body.fullName || body.name,
};
delete payload.name;
try {
const res = await fetch(`${CMS_URL}/api/users/me`, {
@@ -44,11 +38,11 @@ export async function PATCH(request: Request) {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
body: JSON.stringify(payload),
});
const data = await res.json();
return NextResponse.json(data, { status: res.status });
} catch {
return NextResponse.json({ user: { id: "demo", ...body } });
return NextResponse.json({ message: "Update failed" }, { status: 500 });
}
}
+13 -13
View File
@@ -4,24 +4,33 @@ import { NextResponse } from "next/server";
export async function POST(request: Request) {
const body = await request.json();
try {
const payload = {
email: body.email,
password: body.password,
fullName: body.fullName || body.name,
phone: body.phone,
role: "patient",
};
const res = await fetch(`${CMS_URL}/api/users`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
body: JSON.stringify(payload),
});
const data = await res.json();
if (!res.ok) {
return NextResponse.json(data, { status: res.status });
}
// Auto-login after register
const loginRes = await fetch(`${CMS_URL}/api/users/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: body.email, password: body.password }),
});
const loginData = await loginRes.json().catch(() => ({}));
const token = loginData.token || data.token || "demo-token";
const token = loginData.token || data.token;
if (!token) {
return NextResponse.json({ message: "Register succeeded but login failed" }, { status: 500 });
}
const response = NextResponse.json({ user: data.doc || data.user || { email: body.email } });
response.cookies.set(AUTH_COOKIE, token, {
@@ -33,15 +42,6 @@ export async function POST(request: Request) {
});
return response;
} catch {
const response = NextResponse.json({
user: { id: "demo", email: body.email, name: body.name },
});
response.cookies.set(AUTH_COOKIE, "demo-token", {
httpOnly: true,
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 7,
});
return response;
return NextResponse.json({ message: "Register failed" }, { status: 500 });
}
}