Archived
WIP 1.51.14: people and messaging 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,7 +3,6 @@
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { MapPin, Plus, ArrowUp, ArrowDown, Archive, ArchiveRestore, Trash2, Pencil } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useDismissingState } from "@/hooks/useDismissingState";
|
||||
import { reloadCampuses, type Campus } from "@/hooks/useCampuses";
|
||||
@@ -41,7 +40,7 @@ function RecipientsField({ value, onChange }: { value: Person[]; onChange: (v: P
|
||||
let cancelled = false;
|
||||
const t = setTimeout(async () => {
|
||||
try {
|
||||
const res = await apiFetch<{ data?: (Person & { role?: string })[] }>(`/api/users?search=${encodeURIComponent(search.trim())}&limit=10`, { authToken: token });
|
||||
const res = await (apiV2Data("get", "/users", { query: { search: search.trim(), limit: "10" }, authToken: token }) as Promise<{ data?: (Person & { role?: string })[] }>);
|
||||
if (!cancelled) setResults((res?.data || []).filter(u => u.role !== "user"));
|
||||
} catch { if (!cancelled) setResults([]); }
|
||||
}, 300);
|
||||
|
||||
@@ -4,10 +4,10 @@ import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { CalendarClock, ArrowRight, Baby, HandHeart, UserCheck, Banknote, Inbox, CheckCircle2 } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useVisiblePolling } from "@/hooks/useVisiblePolling";
|
||||
import { CampusBadge } from "@/components/shared/CampusFilter";
|
||||
import type { Event } from "@/types";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type TodayEvent = {
|
||||
id: string; title: string; location: string | null; campus: Event["campus"]; isHidden: boolean; kidsCheckIn: boolean;
|
||||
@@ -35,7 +35,7 @@ export function TodayPanel({ supervisor }: { supervisor: boolean }) {
|
||||
const [data, setData] = useState<Today | null>(null);
|
||||
const load = useCallback(async () => {
|
||||
if (!token) return;
|
||||
try { setData(await apiFetch<Today>("/api/dashboard/today", { authToken: token })); } catch { /* keep what's shown */ }
|
||||
try { setData(await (apiV2Data("get", "/dashboard/today", { authToken: token }) as Promise<Today>)); } catch { /* keep what's shown */ }
|
||||
}, [token]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
useVisiblePolling(load, 30000, !!token);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch, API_BASE, fetchManagedEvents } from "@/lib/api";
|
||||
import { API_BASE, fetchManagedEvents } from "@/lib/api";
|
||||
import { downloadReportExcel, emailReportPdf, whatsappReportPdf, viewReportPdf, type ReportPdfPayload } from "@/lib/export";
|
||||
import { Printer, Mail, FileSpreadsheet, MessageCircle, ShoppingCart, CreditCard, Gift, Clock, HandHeart, Search, TrendingUp, TicketPercent, ShieldCheck, Star, MessageSquareHeart, Send, Eye, MousePointerClick, BadgeCheck, Users, Ticket as TicketIcon } from "lucide-react";
|
||||
import { REPORTS, type ReportKey } from "./ReportCatalog";
|
||||
@@ -374,7 +374,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
|
||||
if (dateFrom) query.set("from", dateFrom);
|
||||
if (dateTo) query.set("to", dateTo);
|
||||
try {
|
||||
return await apiFetch<FunnelReport>(`/api/analytics/funnel?${query.toString()}`, { authToken: token });
|
||||
return await (apiV2Data("get", "/analytics/funnel", { query: Object.fromEntries(query), authToken: token }) as Promise<FunnelReport>);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type BannerType = "info" | "warning" | "success" | "danger";
|
||||
|
||||
@@ -28,7 +28,7 @@ export function BannerBar() {
|
||||
const [dismissed, setDismissed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<Banner>("/api/banner")
|
||||
(apiV2Data("get", "/banner") as Promise<Banner>)
|
||||
.then(b => {
|
||||
if (!b?.message) return;
|
||||
setBanner(b);
|
||||
|
||||
@@ -4,8 +4,8 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Search, Calendar, User, Banknote, ClipboardList, CornerDownLeft, Zap, FileText, Settings, BarChart2 } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { matchPages, type CommandPage } from "@/lib/commandPages";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type Result = { type: "event" | "payment" | "person" | "registration"; id: string; title: string; subtitle: string; href: string };
|
||||
type Item = { key: string; group: string; title: string; subtitle?: string; href: string; icon: React.ElementType };
|
||||
@@ -59,7 +59,7 @@ export function CommandPalette() {
|
||||
const q = query.trim();
|
||||
if (q.length < 2) { setResults([]); return; }
|
||||
const timer = setTimeout(() => {
|
||||
apiFetch<{ results: Result[] }>(`/api/dashboard/search?q=${encodeURIComponent(q)}`, { authToken: token })
|
||||
(apiV2Data("get", "/dashboard/search", { query: { q: q }, authToken: token }) as Promise<{ results: Result[] }>)
|
||||
.then(r => setResults(r.results || []))
|
||||
.catch(() => setResults([]));
|
||||
}, 200);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Bookmark, Star, Trash2, Check } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
export type FilterValues = Record<string, string | number | boolean | string[]>;
|
||||
type Saved = { id: string; name: string; params: FilterValues; isDefault: boolean };
|
||||
@@ -35,7 +35,7 @@ export function SavedFilters({ page, value, onApply, skipDefault = false, classN
|
||||
const load = useCallback(async () => {
|
||||
if (!token) return;
|
||||
try {
|
||||
const rows = await apiFetch<Saved[]>(`/api/saved-filters?page=${page}`, { authToken: token });
|
||||
const rows = await (apiV2Data("get", "/saved-filters", { query: { page: page }, authToken: token }) as Promise<Saved[]>);
|
||||
setList(rows);
|
||||
// The default, once, when the page opens.
|
||||
if (!defaultDone.current) {
|
||||
@@ -64,14 +64,14 @@ export function SavedFilters({ page, value, onApply, skipDefault = false, classN
|
||||
const save = () => act(async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const row = await apiFetch<Saved>("/api/saved-filters", { method: "POST", authToken: token || undefined, body: { page, name, params: value, isDefault: asDefault } });
|
||||
const row = await (apiV2Data("post", "/saved-filters", { authToken: token, body: { page, name, params: value, isDefault: asDefault } }) as Promise<Saved>);
|
||||
setApplied(row.id); setName(""); setAsDefault(false);
|
||||
} finally { setSaving(false); }
|
||||
});
|
||||
const toggleDefault = (f: Saved) => act(() => apiFetch(`/api/saved-filters/${f.id}`, { method: "PUT", authToken: token || undefined, body: { isDefault: !f.isDefault } }));
|
||||
const toggleDefault = (f: Saved) => act(() => apiV2Data("put", "/saved-filters/{id}", { params: { id: f.id }, authToken: token, body: { isDefault: !f.isDefault } }));
|
||||
const remove = (f: Saved) => act(async () => {
|
||||
if (!confirm(`Delete the saved filter "${f.name}"?`)) return;
|
||||
await apiFetch(`/api/saved-filters/${f.id}`, { method: "DELETE", authToken: token || undefined });
|
||||
await apiV2Data("delete", "/saved-filters/{id}", { params: { id: f.id }, authToken: token });
|
||||
});
|
||||
|
||||
const current = list.find(f => f.id === applied);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { useVisiblePolling } from "@/hooks/useVisiblePolling";
|
||||
import { CheckCircle2, Pencil, Plus, Printer, Trash2, UserPlus, X } from "lucide-react";
|
||||
@@ -82,7 +81,7 @@ export function RosterSheet({ token, eventId, canEdit, kidsRooms = [], onMessage
|
||||
const search = async () => {
|
||||
if (!token || query.trim().length < 2) return;
|
||||
try {
|
||||
const res = await apiFetch<{ data: { id: string; name: string; email: string }[] }>(`/api/users?search=${encodeURIComponent(query.trim())}&limit=8&isActive=true`, { authToken: token });
|
||||
const res = await (apiV2Data("get", "/users", { query: { search: query.trim(), limit: "8", isActive: "true" }, authToken: token }) as Promise<{ data: { id: string; name: string; email: string }[] }>);
|
||||
setFound(res.data);
|
||||
} catch (e) {
|
||||
onMessage({ type: "err", text: errorMessage(e) || "Search failed" });
|
||||
|
||||
Reference in New Issue
Block a user