Ignore local storage; admin users NIP-05, media, events, footer updates
- Add /storage/ and /backend/storage/ to .gitignore - Track meetup time helper, logo asset, and assorted frontend/backend fixes
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
Check,
|
||||
} from "lucide-react";
|
||||
import { MediaPickerModal } from "@/components/admin/MediaPickerModal";
|
||||
import { getMeetupStartUtc } from "@/lib/meetupEventTime";
|
||||
|
||||
interface Meetup {
|
||||
id: string;
|
||||
@@ -73,12 +74,14 @@ type EditableStatus = (typeof EDITABLE_STATUS_OPTIONS)[number];
|
||||
// Display statuses (includes computed Upcoming/Past from PUBLISHED + date)
|
||||
type DisplayStatus = "DRAFT" | "UPCOMING" | "PAST" | "CANCELLED";
|
||||
|
||||
function getDisplayStatus(meetup: { status: string; date: string }): DisplayStatus {
|
||||
function getDisplayStatus(meetup: { status: string; date: string; time: string }): DisplayStatus {
|
||||
if (meetup.status === "CANCELLED") return "CANCELLED";
|
||||
if (meetup.status === "DRAFT") return "DRAFT";
|
||||
// PUBLISHED (or legacy UPCOMING/PAST values) → derive from date
|
||||
if (!meetup.date) return "DRAFT";
|
||||
return new Date(meetup.date) > new Date() ? "UPCOMING" : "PAST";
|
||||
// PUBLISHED (or legacy UPCOMING/PAST values) → derive from Brussels-local start (date + time)
|
||||
if (!meetup.date?.trim()) return "DRAFT";
|
||||
const start = getMeetupStartUtc(meetup.date, meetup.time || "00:00");
|
||||
if (Number.isNaN(start.getTime())) return "DRAFT";
|
||||
return start > new Date() ? "UPCOMING" : "PAST";
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
@@ -158,7 +161,7 @@ function StatusDropdown({
|
||||
meetup,
|
||||
onChange,
|
||||
}: {
|
||||
meetup: { status: string; date: string };
|
||||
meetup: { status: string; date: string; time: string };
|
||||
onChange: (v: string) => void;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { api } from "@/lib/api";
|
||||
import { getMeetupStartUtc } from "@/lib/meetupEventTime";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { Calendar, FileText, Tag, User, Plus, Download, FolderOpen } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
@@ -54,9 +55,11 @@ export default function OverviewPage() {
|
||||
|
||||
const shortPubkey = `${user.pubkey.slice(0, 8)}...${user.pubkey.slice(-8)}`;
|
||||
|
||||
const upcomingMeetup = meetups.find(
|
||||
(m) => new Date(m.date) > new Date()
|
||||
);
|
||||
const upcomingMeetup = meetups.find((m) => {
|
||||
const start = getMeetupStartUtc(m.date, m.time || "00:00");
|
||||
if (Number.isNaN(start.getTime())) return false;
|
||||
return start > new Date();
|
||||
});
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
||||
@@ -1,22 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { api } from "@/lib/api";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { cn, formatDate } from "@/lib/utils";
|
||||
import { fetchNostrProfile, type NostrProfile } from "@/lib/nostr";
|
||||
import { ShieldCheck, ShieldOff, UserPlus } from "lucide-react";
|
||||
|
||||
function hexToNpub(hex: string): string {
|
||||
try {
|
||||
return nip19.npubEncode(hex);
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function shortenNpub(npub: string): string {
|
||||
if (npub.length <= 26) return npub;
|
||||
return `${npub.slice(0, 14)}...${npub.slice(-10)}`;
|
||||
}
|
||||
|
||||
function profileInitials(profile: NostrProfile | undefined, npub: string): string {
|
||||
const n = profile?.name || profile?.displayName;
|
||||
if (n?.trim()) return n.trim().slice(0, 2).toUpperCase();
|
||||
if (npub.length >= 8) return npub.slice(5, 7).toUpperCase();
|
||||
return "?";
|
||||
}
|
||||
|
||||
export default function UsersPage() {
|
||||
const [users, setUsers] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [promotePubkey, setPromotePubkey] = useState("");
|
||||
const [promoting, setPromoting] = useState(false);
|
||||
const [hostname, setHostname] = useState("");
|
||||
const [usernameDrafts, setUsernameDrafts] = useState<Record<string, string>>({});
|
||||
const [savingPubkey, setSavingPubkey] = useState<string | null>(null);
|
||||
const [nostrByPubkey, setNostrByPubkey] = useState<Record<string, NostrProfile>>({});
|
||||
const [nostrLoading, setNostrLoading] = useState(false);
|
||||
const [copiedPubkey, setCopiedPubkey] = useState<string | null>(null);
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
const data = await api.getUsers();
|
||||
setUsers(data);
|
||||
setUsernameDrafts(
|
||||
Object.fromEntries(
|
||||
data.map((u: { pubkey: string; username?: string | null }) => [u.pubkey, u.username ?? ""])
|
||||
)
|
||||
);
|
||||
} catch (err: any) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
@@ -28,6 +61,48 @@ export default function UsersPage() {
|
||||
loadUsers();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setHostname(typeof window !== "undefined" ? window.location.hostname : "");
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (users.length === 0) {
|
||||
setNostrByPubkey({});
|
||||
setNostrLoading(false);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
setNostrLoading(true);
|
||||
setNostrByPubkey({});
|
||||
(async () => {
|
||||
const entries = await Promise.all(
|
||||
users.map(async (u: { pubkey: string }) => {
|
||||
const profile = await fetchNostrProfile(u.pubkey);
|
||||
return [u.pubkey, profile] as const;
|
||||
})
|
||||
);
|
||||
if (!cancelled) {
|
||||
setNostrByPubkey(Object.fromEntries(entries));
|
||||
setNostrLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [users]);
|
||||
|
||||
const handleCopyNpub = async (pubkey: string) => {
|
||||
const full = hexToNpub(pubkey);
|
||||
if (!full) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(full);
|
||||
setCopiedPubkey(pubkey);
|
||||
window.setTimeout(() => setCopiedPubkey((p) => (p === pubkey ? null : p)), 2000);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
const handlePromote = async () => {
|
||||
if (!promotePubkey.trim()) return;
|
||||
setPromoting(true);
|
||||
@@ -64,6 +139,26 @@ export default function UsersPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveUsername = async (pubkey: string, currentUsername: string | null | undefined) => {
|
||||
const trimmed = (usernameDrafts[pubkey] ?? "").trim().toLowerCase();
|
||||
if (!trimmed) return;
|
||||
setSavingPubkey(pubkey);
|
||||
setError("");
|
||||
try {
|
||||
await api.updateUserUsername(pubkey, trimmed);
|
||||
await loadUsers();
|
||||
} catch (err: any) {
|
||||
setError(err.message);
|
||||
setUsernameDrafts((prev) => ({ ...prev, [pubkey]: currentUsername ?? "" }));
|
||||
} finally {
|
||||
setSavingPubkey(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelUsername = (pubkey: string, stored: string | null | undefined) => {
|
||||
setUsernameDrafts((prev) => ({ ...prev, [pubkey]: stored ?? "" }));
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[60vh]">
|
||||
@@ -102,16 +197,109 @@ export default function UsersPage() {
|
||||
{users.length === 0 ? (
|
||||
<p className="text-on-surface/50 text-sm">No users found.</p>
|
||||
) : (
|
||||
users.map((user) => (
|
||||
users.map((user) => {
|
||||
const draft = usernameDrafts[user.pubkey] ?? "";
|
||||
const stored = user.username ?? "";
|
||||
const usernameDirty = draft.trim().toLowerCase() !== stored.toLowerCase();
|
||||
const profile = nostrByPubkey[user.pubkey];
|
||||
const fullNpub = hexToNpub(user.pubkey);
|
||||
const nostrDisplay = profile?.name || profile?.displayName;
|
||||
return (
|
||||
<div
|
||||
key={user.pubkey || user.id}
|
||||
className="bg-surface-container-low rounded-xl p-6 flex items-center justify-between"
|
||||
className="bg-surface-container-low rounded-xl p-6 flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"
|
||||
>
|
||||
<div>
|
||||
<p className="text-on-surface font-mono text-sm">
|
||||
{user.pubkey?.slice(0, 12)}...{user.pubkey?.slice(-8)}
|
||||
</p>
|
||||
<div className="flex items-center gap-3 mt-2">
|
||||
<div className="flex-1 min-w-0 flex gap-4 items-start">
|
||||
<div className="shrink-0 w-14 h-14 rounded-full bg-surface-container-high flex items-center justify-center overflow-hidden text-on-surface">
|
||||
{nostrLoading ? (
|
||||
<span className="text-on-surface/40 text-xs">…</span>
|
||||
) : profile?.picture ? (
|
||||
<Image
|
||||
src={profile.picture}
|
||||
alt={nostrDisplay ? `Avatar: ${nostrDisplay}` : "Nostr profile picture"}
|
||||
width={56}
|
||||
height={56}
|
||||
className="object-cover w-full h-full"
|
||||
unoptimized
|
||||
/>
|
||||
) : (
|
||||
<span className="font-semibold text-sm" aria-hidden>
|
||||
{profileInitials(profile, fullNpub)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0 space-y-3">
|
||||
<div>
|
||||
<p className="text-on-surface font-semibold text-base truncate">
|
||||
{nostrLoading ? (
|
||||
<span className="text-on-surface/40 font-normal">…</span>
|
||||
) : nostrDisplay ? (
|
||||
nostrDisplay
|
||||
) : (
|
||||
<span className="text-on-surface/50 font-normal">No Nostr name</span>
|
||||
)}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCopyNpub(user.pubkey)}
|
||||
className="mt-1 text-left font-mono text-sm text-on-surface/80 hover:text-primary transition-colors cursor-pointer break-all w-full"
|
||||
title={fullNpub || "Copy npub"}
|
||||
>
|
||||
{copiedPubkey === user.pubkey
|
||||
? "Copied!"
|
||||
: fullNpub
|
||||
? shortenNpub(fullNpub)
|
||||
: `${user.pubkey?.slice(0, 12)}...${user.pubkey?.slice(-8)}`}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-on-surface/50 mb-1 uppercase tracking-wide">
|
||||
NIP-05 username
|
||||
</p>
|
||||
<p className="text-on-surface-variant text-xs mb-2">
|
||||
Reserved names from the site blocklist can be assigned here (users cannot claim them on the dashboard).
|
||||
</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
value={draft}
|
||||
onChange={(e) =>
|
||||
setUsernameDrafts((prev) => ({ ...prev, [user.pubkey]: e.target.value }))
|
||||
}
|
||||
disabled={savingPubkey === user.pubkey}
|
||||
placeholder="local-part"
|
||||
className="bg-surface-container-highest text-on-surface rounded-lg px-3 py-2 text-sm font-mono min-w-[8rem] max-w-full flex-1 focus:outline-none focus:ring-1 focus:ring-primary/40 disabled:opacity-50"
|
||||
/>
|
||||
<span className="text-on-surface/50 text-sm font-mono shrink-0">
|
||||
@{hostname || "…"}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleSaveUsername(user.pubkey, user.username)}
|
||||
disabled={
|
||||
savingPubkey === user.pubkey ||
|
||||
!draft.trim() ||
|
||||
!usernameDirty
|
||||
}
|
||||
className="px-3 py-2 rounded-lg bg-gradient-to-r from-primary to-primary-container text-on-primary font-semibold text-sm hover:opacity-90 transition-opacity disabled:opacity-50 whitespace-nowrap"
|
||||
>
|
||||
{savingPubkey === user.pubkey ? "Saving…" : "Save"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCancelUsername(user.pubkey, user.username)}
|
||||
disabled={savingPubkey === user.pubkey || !usernameDirty}
|
||||
className="px-3 py-2 rounded-lg bg-surface-container-highest text-on-surface/70 text-sm hover:text-on-surface transition-colors disabled:opacity-50 whitespace-nowrap"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
{draft.trim() && (
|
||||
<p className="text-on-surface-variant text-xs font-mono mt-2">
|
||||
{draft.trim().toLowerCase()}@{hostname || "…"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-3 flex-wrap">
|
||||
<span
|
||||
className={cn(
|
||||
"rounded-full px-3 py-1 text-xs font-bold",
|
||||
@@ -131,6 +319,7 @@ export default function UsersPage() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{user.role !== "ADMIN" && (
|
||||
<div className="flex items-center gap-2">
|
||||
{user.role !== "MODERATOR" && (
|
||||
@@ -154,7 +343,8 @@ export default function UsersPage() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user