diff --git a/openspec/changes/polish-e2e-followups/tasks.md b/openspec/changes/polish-e2e-followups/tasks.md
index 18acb3b..01c597a 100644
--- a/openspec/changes/polish-e2e-followups/tasks.md
+++ b/openspec/changes/polish-e2e-followups/tasks.md
@@ -24,7 +24,7 @@ Verify commands:
- Depends on: 2
- Scope: `solvway-services-system/**`, `solvway-mobile-api/**`, `solvway-api-gateway/**` (security: controller reads the whole diff)
- Verify: `mvn -T 1C -q -pl solvway-services-system,solvway-mobile-api,solvway-api-gateway verify`
-- [ ] 4. Portal behaviour:
+- [x] 4. Portal behaviour:
- the login hint when the company is empty;
- `PasswordRulesHint`, built from the rules, on the four password screens, with the named refusal message;
- interest Delete and Deactivate confirmations;
diff --git a/solvway-admin-portal/app/api/interests/[id]/route.delete.test.ts b/solvway-admin-portal/app/api/interests/[id]/route.delete.test.ts
new file mode 100644
index 0000000..c0cdde6
--- /dev/null
+++ b/solvway-admin-portal/app/api/interests/[id]/route.delete.test.ts
@@ -0,0 +1,31 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+
+const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
+vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
+vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
+
+import { DELETE } from "./route";
+
+const call = () => DELETE(new Request("http://localhost/api/interests/7", { method: "DELETE" }) as never, { params: Promise.resolve({ id: "7" }) });
+
+beforeEach(() => {
+ mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: undefined });
+ mocks.getToken.mockReset().mockResolvedValue("tok");
+});
+
+describe("DELETE /api/interests/[id]", () => {
+ it("is 401 without a session", async () => {
+ mocks.getToken.mockResolvedValue(null);
+ expect((await call()).status).toBe(401);
+ });
+
+ it("deletes upstream and answers ok", async () => {
+ expect((await call()).status).toBe(200);
+ expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/interests/7", { method: "DELETE", token: "tok" });
+ });
+
+ it("passes the upstream refusal through", async () => {
+ mocks.callMobileApi.mockResolvedValue({ ok: false, error: "x", status: 404 });
+ expect((await call()).status).toBe(404);
+ });
+});
diff --git a/solvway-admin-portal/app/api/interests/[id]/route.ts b/solvway-admin-portal/app/api/interests/[id]/route.ts
index b06b8d7..5dd07ca 100644
--- a/solvway-admin-portal/app/api/interests/[id]/route.ts
+++ b/solvway-admin-portal/app/api/interests/[id]/route.ts
@@ -33,3 +33,12 @@ export async function PUT(req: NextRequest, { params }: Ctx) {
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}
+
+export async function DELETE(_req: NextRequest, { params }: Ctx) {
+ const token = await getToken();
+ if (!token) return unauthorized();
+ const { id } = await params;
+ const result = await callMobileApi(`/api/admin/interests/${encodeURIComponent(id)}`, { method: "DELETE", token });
+ if (!result.ok) return errorResponse(result);
+ return NextResponse.json({ ok: true });
+}
diff --git a/solvway-admin-portal/app/api/password-rules/route.test.ts b/solvway-admin-portal/app/api/password-rules/route.test.ts
new file mode 100644
index 0000000..e60a865
--- /dev/null
+++ b/solvway-admin-portal/app/api/password-rules/route.test.ts
@@ -0,0 +1,26 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+
+const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
+vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
+vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
+
+import { GET } from "./route";
+
+beforeEach(() => {
+ mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: [{ param: "NO_OTHER_LANGUAGE", value: null }] });
+ mocks.getToken.mockReset().mockResolvedValue("tok");
+});
+
+describe("GET /api/password-rules", () => {
+ it("is 401 without a session", async () => {
+ mocks.getToken.mockResolvedValue(null);
+ expect((await GET()).status).toBe(401);
+ expect(mocks.callMobileApi).not.toHaveBeenCalled();
+ });
+
+ it("returns the active rules from the admin endpoint", async () => {
+ const res = await GET();
+ expect(await res.json()).toEqual([{ param: "NO_OTHER_LANGUAGE", value: null }]);
+ expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/password-rules/active", { token: "tok" });
+ });
+});
diff --git a/solvway-admin-portal/app/api/password-rules/route.ts b/solvway-admin-portal/app/api/password-rules/route.ts
new file mode 100644
index 0000000..01bdca4
--- /dev/null
+++ b/solvway-admin-portal/app/api/password-rules/route.ts
@@ -0,0 +1,12 @@
+import { NextResponse } from "next/server";
+import { callMobileApi } from "@/app/lib/server/mobileApi";
+import { getToken } from "@/app/lib/server/session";
+import { errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
+
+export async function GET() {
+ const token = await getToken();
+ if (!token) return unauthorized();
+ const result = await callMobileApi("/api/admin/password-rules/active", { token });
+ if (!result.ok) return errorResponse(result);
+ return NextResponse.json(result.data);
+}
diff --git a/solvway-admin-portal/app/api/public/password-rules/route.test.ts b/solvway-admin-portal/app/api/public/password-rules/route.test.ts
new file mode 100644
index 0000000..25824fb
--- /dev/null
+++ b/solvway-admin-portal/app/api/public/password-rules/route.test.ts
@@ -0,0 +1,25 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+
+const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn() }));
+vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
+
+import { GET } from "./route";
+
+type Req = Parameters[0];
+const req = (init: RequestInit = {}) => new Request("http://localhost/api/public/password-rules", init) as unknown as Req;
+
+beforeEach(() => mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: [{ param: "INPUT_LENGTH_MIN", value: 8 }] }));
+
+describe("/api/public/password-rules", () => {
+ it("forwards without a session, with only the last-hop visitor IP, and returns the rules", async () => {
+ const res = await GET(req({ headers: { "x-forwarded-for": "6.6.6.6, 203.0.113.7" } }));
+ expect(res.status).toBe(200);
+ expect(await res.json()).toEqual([{ param: "INPUT_LENGTH_MIN", value: 8 }]);
+ expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/public/password-rules", { headers: { "X-Forwarded-For": "203.0.113.7" } });
+ });
+
+ it("passes upstream failures with their status", async () => {
+ mocks.callMobileApi.mockResolvedValue({ ok: false, error: "Too many requests", status: 429 });
+ expect((await GET(req())).status).toBe(429);
+ });
+});
diff --git a/solvway-admin-portal/app/api/public/password-rules/route.ts b/solvway-admin-portal/app/api/public/password-rules/route.ts
new file mode 100644
index 0000000..704fa1b
--- /dev/null
+++ b/solvway-admin-portal/app/api/public/password-rules/route.ts
@@ -0,0 +1,4 @@
+import type { NextRequest } from "next/server";
+import { forwardPublic } from "@/app/lib/server/publicProxy";
+
+export const GET = (req: NextRequest) => forwardPublic(req, "/api/public/password-rules", "GET");
diff --git a/solvway-admin-portal/app/api/roles/[id]/route.delete.test.ts b/solvway-admin-portal/app/api/roles/[id]/route.delete.test.ts
new file mode 100644
index 0000000..ac95889
--- /dev/null
+++ b/solvway-admin-portal/app/api/roles/[id]/route.delete.test.ts
@@ -0,0 +1,31 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+
+const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
+vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
+vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
+
+import { DELETE } from "./route";
+
+const call = () => DELETE(new Request("http://localhost/api/roles/7", { method: "DELETE" }) as never, { params: Promise.resolve({ id: "7" }) });
+
+beforeEach(() => {
+ mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: undefined });
+ mocks.getToken.mockReset().mockResolvedValue("tok");
+});
+
+describe("DELETE /api/roles/[id]", () => {
+ it("is 401 without a session", async () => {
+ mocks.getToken.mockResolvedValue(null);
+ expect((await call()).status).toBe(401);
+ });
+
+ it("deletes upstream and answers ok", async () => {
+ expect((await call()).status).toBe(200);
+ expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/roles/7", { method: "DELETE", token: "tok" });
+ });
+
+ it("passes the upstream refusal through", async () => {
+ mocks.callMobileApi.mockResolvedValue({ ok: false, error: "x", status: 404 });
+ expect((await call()).status).toBe(404);
+ });
+});
diff --git a/solvway-admin-portal/app/api/roles/[id]/route.ts b/solvway-admin-portal/app/api/roles/[id]/route.ts
index 2a413d6..f239daf 100644
--- a/solvway-admin-portal/app/api/roles/[id]/route.ts
+++ b/solvway-admin-portal/app/api/roles/[id]/route.ts
@@ -33,3 +33,12 @@ export async function PUT(req: NextRequest, { params }: Ctx) {
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}
+
+export async function DELETE(_req: NextRequest, { params }: Ctx) {
+ const token = await getToken();
+ if (!token) return unauthorized();
+ const { id } = await params;
+ const result = await callMobileApi(`/api/admin/roles/${encodeURIComponent(id)}`, { method: "DELETE", token });
+ if (!result.ok) return errorResponse(result);
+ return NextResponse.json({ ok: true });
+}
diff --git a/solvway-admin-portal/app/companies/page.cancel.test.tsx b/solvway-admin-portal/app/companies/page.cancel.test.tsx
new file mode 100644
index 0000000..25b28f3
--- /dev/null
+++ b/solvway-admin-portal/app/companies/page.cancel.test.tsx
@@ -0,0 +1,37 @@
+import { render, screen, within } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, it, expect, vi, beforeEach } from "vitest";
+
+const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), getPrivacyNotice: vi.fn(), savePrivacyNotice: vi.fn() }));
+vi.mock("@/app/lib/clientApi", async (importOriginal) => ({
+ ApiError: (await importOriginal()).ApiError,
+ apiGet: mocks.apiGet,
+ apiPost: mocks.apiPost,
+}));
+vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: () => ({ loading: false, isSuper: true }) }));
+vi.mock("@/app/lib/services/adminRegistration", () => ({
+ getPrivacyNotice: mocks.getPrivacyNotice,
+ savePrivacyNotice: mocks.savePrivacyNotice,
+}));
+
+import CompaniesPage from "./page";
+
+beforeEach(() => {
+ mocks.apiGet.mockReset().mockResolvedValue([{ id: 1, name: "Insight", code: "ins", status: "A" }]);
+ mocks.apiPost.mockReset();
+ mocks.getPrivacyNotice.mockReset().mockResolvedValue(null);
+ mocks.savePrivacyNotice.mockReset();
+});
+
+describe.each(["Edit", "Change code", "Privacy notice"])("Companies %s dialog", (action) => {
+ it("Cancel closes it without saving", async () => {
+ render();
+ const row = (await screen.findByText("Insight")).closest("tr")!;
+ await userEvent.click(within(row).getByRole("button", { name: action }));
+ const dialog = await screen.findByRole("dialog");
+ await userEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect(mocks.apiPost).not.toHaveBeenCalled();
+ expect(mocks.savePrivacyNotice).not.toHaveBeenCalled();
+ });
+});
diff --git a/solvway-admin-portal/app/companies/page.tsx b/solvway-admin-portal/app/companies/page.tsx
index 1cd3340..1daa15b 100644
--- a/solvway-admin-portal/app/companies/page.tsx
+++ b/solvway-admin-portal/app/companies/page.tsx
@@ -103,6 +103,9 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos
>
)}
+
@@ -170,6 +173,9 @@ function PrivacyNoticeDialog({ company, onClose }: { company: AdminCompany; onCl
)}
+
diff --git a/solvway-admin-portal/app/components/app/ChangePasswordDialog.tsx b/solvway-admin-portal/app/components/app/ChangePasswordDialog.tsx
index ac8e5e6..845e3f3 100644
--- a/solvway-admin-portal/app/components/app/ChangePasswordDialog.tsx
+++ b/solvway-admin-portal/app/components/app/ChangePasswordDialog.tsx
@@ -6,6 +6,7 @@ import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "
import { Input } from "@/app/components/ui/input";
import { Label } from "@/app/components/ui/label";
import { PasswordFields } from "@/app/components/users/PasswordFields";
+import { passwordRuleError } from "@/app/components/users/PasswordRulesHint";
import { changeOwnPassword } from "@/app/lib/services/adminUsers";
import { useT } from "@/app/lib/i18n/MessagesProvider";
@@ -17,6 +18,7 @@ export default function ChangePasswordDialog({ onClose, onDone }: { onClose: ()
const [confirmPassword, setConfirmPassword] = useState("");
const [error, setError] = useState(null);
const [saving, setSaving] = useState(false);
+ const [ruleError, setRuleError] = useState();
async function submit(event: FormEvent) {
event.preventDefault();
@@ -24,12 +26,15 @@ export default function ChangePasswordDialog({ onClose, onDone }: { onClose: ()
if (password !== confirmPassword) return setError("UsrPasswordMismatch");
setSaving(true);
setError(null);
+ setRuleError(undefined);
try {
await changeOwnPassword(current, password, confirmPassword);
onClose();
onDone();
} catch (err) {
- setError(err instanceof Error ? err.message : "PwdChangeRequired");
+ const rule = passwordRuleError(err, t);
+ if (rule) setRuleError(rule);
+ else setError(err instanceof Error ? err.message : "PwdChangeRequired");
setSaving(false);
}
}
@@ -59,6 +64,7 @@ export default function ChangePasswordDialog({ onClose, onDone }: { onClose: ()
onPassword={setPassword}
onConfirmPassword={setConfirmPassword}
disabled={saving}
+ passwordError={ruleError}
/>
{error && (
diff --git a/solvway-admin-portal/app/components/dashboard/LeadDashboard.tsx b/solvway-admin-portal/app/components/dashboard/LeadDashboard.tsx
index 0765bb2..3a94395 100644
--- a/solvway-admin-portal/app/components/dashboard/LeadDashboard.tsx
+++ b/solvway-admin-portal/app/components/dashboard/LeadDashboard.tsx
@@ -38,11 +38,12 @@ function bucketLabel(bucket: string, kind: "DAY" | "MONTH"): string {
return new Date(Date.UTC(Number(y), Number(m) - 1, 1)).toLocaleString("en-GB", { month: "short", year: "numeric", timeZone: "UTC" });
}
-function Tile({ label, value }: { label: string; value: string }) {
+function Tile({ label, value, note }: { label: string; value: string; note?: string }) {
return (
{label}
{value}
+ {note &&
{note}
}
);
}
@@ -138,7 +139,7 @@ export function LeadDashboard() {
-
+
@@ -146,7 +147,10 @@ export function LeadDashboard() {
- {t("DashFunnel")}
+
+ {t("DashFunnel")}
+ {t("DashFunnelNote")}
+
{funnelRows.map(([key, label]) => {
diff --git a/solvway-admin-portal/app/components/ui/confirm-dialog.tsx b/solvway-admin-portal/app/components/ui/confirm-dialog.tsx
new file mode 100644
index 0000000..fa353d8
--- /dev/null
+++ b/solvway-admin-portal/app/components/ui/confirm-dialog.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { Button } from "@/app/components/ui/button";
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/app/components/ui/dialog";
+import { useT } from "@/app/lib/i18n/MessagesProvider";
+
+/** Cancel / confirm prompt; `onConfirm` is the caller's job to close it (it decides what stays open on failure). */
+export function ConfirmDialog(props: {
+ title: string;
+ message: string;
+ confirmLabel: string;
+ destructive?: boolean;
+ busy?: boolean;
+ onConfirm: () => void;
+ onCancel: () => void;
+}) {
+ const t = useT();
+ return (
+
+ );
+}
diff --git a/solvway-admin-portal/app/components/ui/states.tsx b/solvway-admin-portal/app/components/ui/states.tsx
index 77de151..95c2546 100644
--- a/solvway-admin-portal/app/components/ui/states.tsx
+++ b/solvway-admin-portal/app/components/ui/states.tsx
@@ -37,10 +37,13 @@ export function EmptyState({
export function ErrorState({
message,
+ hint,
onRetry,
className,
}: {
message: string
+ /** A second, muted line under the message. */
+ hint?: string
onRetry?: () => void
className?: string
}) {
@@ -61,7 +64,10 @@ export function ErrorState({
>
-
{message}
+
+
{message}
+ {hint &&
{hint}
}
+
{onRetry && (
- {error ?
: elsewhere &&
}
+ {error ?
: elsewhere &&
}
),
}]),
],
- [parentLabel, t, readOnly],
+ [parentLabel, t, readOnly, isSuper],
);
+ async function runDelete() {
+ if (!confirmDelete) return;
+ const role = confirmDelete;
+ setConfirmDelete(null);
+ try {
+ await deleteAdminRole(role.id!);
+ refetch();
+ } catch (err) {
+ const data = (err as { data?: { code?: string; details?: { users?: number } } }).data;
+ if (data?.code === "ROLE_IN_USE") setError(t("RolInUse", { n: data.details?.users ?? 0 }));
+ else if (data?.code === "ROLE_PROTECTED") setError("RolProtected");
+ else setError("RolDeleteFailed");
+ }
+ }
+
return (
<>
}
/>
+ {confirmDelete && (
+
setConfirmDelete(null)}
+ />
+ )}
+
{dialog && (
setDialog(null)} onSaved={refetch} />
)}