"use client"; import { useReducer } from "react"; import Link from "next/link"; import { AdminUserRow } from "@/actions/admin/users"; type ProfilePageProps = { currentUser: AdminUserRow; }; type State = { editing: boolean; displayName: string; phoneNumber: string; saving: boolean; error: string | null; emailChangeSent: boolean; changingEmail: boolean; newEmail: string; emailError: string | null; }; type Action = | { type: "START_EDIT" } | { type: "CANCEL_EDIT" } | { type: "SET_DISPLAY_NAME"; value: string } | { type: "SET_PHONE_NUMBER"; value: string } | { type: "SAVE_FAIL"; error: string } | { type: "SENT_EMAIL_CHANGE" } | { type: "SET_NEW_EMAIL"; value: string } | { type: "EMAIL_CHANGE_FAIL"; error: string }; function buildInitialState(currentUser: AdminUserRow): State { return { editing: false, displayName: currentUser.display_name ?? "", phoneNumber: currentUser.phone_number ?? "", saving: false, error: null, emailChangeSent: false, changingEmail: false, newEmail: "", emailError: null, }; } function reducer(state: State, action: Action): State { switch (action.type) { case "START_EDIT": return { ...state, editing: true }; case "CANCEL_EDIT": return { ...state, editing: false, error: null }; case "SET_DISPLAY_NAME": return { ...state, displayName: action.value }; case "SET_PHONE_NUMBER": return { ...state, phoneNumber: action.value }; case "SAVE_FAIL": return { ...state, saving: false, error: action.error }; case "SENT_EMAIL_CHANGE": return { ...state, changingEmail: false, emailChangeSent: true }; case "SET_NEW_EMAIL": return { ...state, newEmail: action.value }; case "EMAIL_CHANGE_FAIL": return { ...state, changingEmail: false, emailError: action.error }; } } export default function AdminMeClient({ currentUser }: ProfilePageProps) { const [state, dispatch] = useReducer(reducer, currentUser, buildInitialState); // Profile / email mutations used to call Supabase directly. With the // platform moved off Supabase entirely, those handlers are stubbed out // — the page remains read-only until a server-action equivalent ships. // See the final YOLO report for the broader Supabase → pg data-fetch // migration that covers the rest of the admin pages. async function handleSaveProfile(e: React.FormEvent) { e.preventDefault(); dispatch({ type: "SAVE_FAIL", error: "Profile editing is temporarily unavailable. Contact a platform admin." }); } async function handleEmailChange(e: React.FormEvent) { e.preventDefault(); dispatch({ type: "EMAIL_CHANGE_FAIL", error: "Email changes are temporarily unavailable. Contact a platform admin." }); } return (
← Back to dashboard

My Profile

Manage your profile information and preferences.

{state.error && (
{state.error}
)} {/* Profile card */}

{currentUser.display_name || currentUser.email}

{currentUser.display_name && (

{currentUser.email}

)}
{currentUser.role.replace("_", " ")} {currentUser.brand_name && ( {currentUser.brand_name} )}
{!state.editing && ( )}
{/* Read-only info when not editing */} {!state.editing && (

Phone

{currentUser.phone_number ?? "—"}

Email

{currentUser.email}

)} {/* Edit form */} {state.editing && (
dispatch({ type: "SET_DISPLAY_NAME", value: e.target.value })} className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1" style={{ borderColor: "var(--admin-border)", color: "var(--admin-text-primary)", backgroundColor: "white" }} placeholder="Your name" />
dispatch({ type: "SET_PHONE_NUMBER", value: e.target.value })} className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1" style={{ borderColor: "var(--admin-border)", color: "var(--admin-text-primary)", backgroundColor: "white" }} placeholder="+1 (555) 000-0000" autoComplete="tel" />
)}
{/* Email change section */}

Email Address

Current: {currentUser.email}

{state.emailChangeSent ? (
A confirmation email has been sent to {state.newEmail}. Click the link in the email to confirm the change.
) : (
dispatch({ type: "SET_NEW_EMAIL", value: e.target.value })} required aria-required="true" className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1" style={{ borderColor: "var(--admin-border)", color: "var(--admin-text-primary)", backgroundColor: "white" }} placeholder="new@example.com" autoComplete="email" />
{state.emailError && (
{state.emailError}
)}
)}
); }