Archived
WIP 1.51.15: privacy and admin on v2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { ShieldAlert, KeyRound, ArrowUpCircle, BellOff } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import type { HubStatus } from "@/components/admin/LicenceTab";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
/**
|
||||
* Licence and update notices for **site admins only** (never supervisors, staff, users or the
|
||||
@@ -20,7 +20,7 @@ export function LicenceBanner() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAdmin || !token) return;
|
||||
apiFetch<HubStatus>("/api/hub/status", { authToken: token }).then(setStatus).catch(() => {});
|
||||
(apiV2Data("get", "/hub/status", { authToken: token }) as Promise<HubStatus>).then(setStatus).catch(() => {});
|
||||
}, [isAdmin, token]);
|
||||
|
||||
if (!isAdmin || !status) return null;
|
||||
@@ -69,7 +69,7 @@ export function LicenceBanner() {
|
||||
if (status.updateAvailable && !awaiting && !status.updateSnoozed) {
|
||||
const notNow = async () => {
|
||||
setBusy(true);
|
||||
try { setStatus(await apiFetch<HubStatus>("/api/hub/update-snooze", { method: "POST", authToken: token, body: { snooze: true } })); } catch { /* the Licence page shows why */ }
|
||||
try { setStatus(await (apiV2Data("post", "/hub/update-snooze", { authToken: token, body: { snooze: true } }) as Promise<HubStatus>)); } catch { /* the Licence page shows why */ }
|
||||
setBusy(false);
|
||||
};
|
||||
return (
|
||||
|
||||
@@ -4,8 +4,8 @@ import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Megaphone } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type News = { email: boolean; whatsapp: boolean };
|
||||
|
||||
@@ -26,7 +26,7 @@ export function NewsPrompt() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!pending || !token || news) return;
|
||||
apiFetch<{ news: News; canWhatsApp: boolean }>("/api/privacy/me", { authToken: token })
|
||||
(apiV2Data("get", "/me/privacy", { authToken: token }) as Promise<{ news: News; canWhatsApp: boolean }>)
|
||||
.then(res => { setNews(res.news); setCanWhatsApp(res.canWhatsApp); })
|
||||
.catch(() => setDone(true)); // never block the dashboard over this
|
||||
}, [pending, token, news]);
|
||||
@@ -38,7 +38,7 @@ export function NewsPrompt() {
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
await apiFetch("/api/privacy/me/news", { method: "PUT", authToken: token, body: { ...choice, source: "prompt" } });
|
||||
await apiV2Data("put", "/me/privacy/news", { authToken: token, body: { ...choice, source: "prompt" } });
|
||||
setDone(true);
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Could not save your choice.");
|
||||
|
||||
@@ -4,9 +4,9 @@ import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { ScrollText } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { PublicNotice } from "@/components/shared/PrivacyNoticeSection";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
/**
|
||||
* POPIA: asked once after login when this person never accepted the privacy notice (an account
|
||||
@@ -21,7 +21,7 @@ export function NoticePrompt({ reason = "updated", onDone }: { reason?: "first"
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<PublicNotice>("/api/privacy/notice").then(setNotice).catch(() => onDone());
|
||||
(apiV2Data("get", "/privacy/notice") as Promise<PublicNotice>).then(setNotice).catch(() => onDone());
|
||||
}, [onDone]);
|
||||
|
||||
if (!notice) return null;
|
||||
@@ -31,7 +31,7 @@ export function NoticePrompt({ reason = "updated", onDone }: { reason?: "first"
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
await apiFetch("/api/privacy/me/notice/accept", { method: "POST", authToken: token });
|
||||
await apiV2Data("post", "/me/privacy/notice/accept", { authToken: token, body: {} });
|
||||
onDone();
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Could not save. Please try again.");
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Info, Wrench, AlertTriangle, X } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import type { HubNotice } from "@/components/admin/LicenceTab";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
const DISMISSED_KEY = "cross_events_dismissed_notices";
|
||||
|
||||
@@ -35,7 +35,7 @@ export function ProviderNotices() {
|
||||
useEffect(() => {
|
||||
if (!canSee || !token) return;
|
||||
setDismissed(readDismissed());
|
||||
apiFetch<HubNotice[]>("/api/hub/notices", { authToken: token }).then(setNotices).catch(() => {});
|
||||
(apiV2Data("get", "/hub/notices", { authToken: token }) as Promise<HubNotice[]>).then(setNotices).catch(() => {});
|
||||
}, [canSee, token]);
|
||||
|
||||
if (!canSee) return null;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useRouter, usePathname } from "next/navigation";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
// Checks once per browser session whether first-time setup is needed.
|
||||
// If the backend says yes and we're not already on /setup, redirect there.
|
||||
@@ -16,7 +16,7 @@ export function SetupGuard() {
|
||||
if (pathname?.startsWith("/setup")) return;
|
||||
checked.current = true;
|
||||
|
||||
apiFetch<{ needsSetup: boolean }>("/api/settings/needs-setup")
|
||||
(apiV2Data("get", "/setup/needed") as Promise<{ needsSetup: boolean }>)
|
||||
.then((data) => {
|
||||
if (data?.needsSetup) {
|
||||
router.replace("/setup");
|
||||
|
||||
Reference in New Issue
Block a user