"use client"; import { useEffect, useState } from "react"; import { AppShell } from "../../components/app-shell"; type ApiResponse = { data: T; meta: { timestamp: string; version: "v1" }; error: null | { message: string; code?: string }; }; type ProfileData = { user: { id: string; email: string; fullName: string; phone?: string | null; companyName?: string | null; addressLine1i: string | null; addressLine2i: string | null; city?: string | null; state?: string | null; postalCode?: string | null; country?: string | null; }; }; export default function ProfilePage() { const [token, setToken] = useState(""); const [status, setStatus] = useState(""); const [fullName, setFullName] = useState(""); const [phone, setPhone] = useState(""); const [companyName, setCompanyName] = useState(""); const [addressLine1, setAddressLine1] = useState(""); const [addressLine2, setAddressLine2] = useState(""); const [city, setCity] = useState(""); const [state, setState] = useState(""); const [postalCode, setPostalCode] = useState(""); const [country, setCountry] = useState(""); useEffect(() => { const stored = localStorage.getItem("ledgerone_token") ?? ""; setToken(stored); }, []); const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!token) { setStatus("Please sign in to update your profile."); return; } setStatus("Saving profile..."); try { const res = await fetch("/api/auth/profile", { method: "PATCH", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, body: JSON.stringify({ fullName, phone: phone || undefined, companyName: companyName || undefined, addressLine1: addressLine1 || undefined, addressLine2: addressLine2 || undefined, city: city || undefined, state: state || undefined, postalCode: postalCode || undefined, country: country || undefined }) }); const payload = (await res.json()) as ApiResponse; if (!res.ok || payload.error) { setStatus(payload.error?.message ?? "Profile update failed."); return; } setStatus("Profile updated."); } catch { setStatus("Profile update failed."); } }; return (

LedgerOne

Complete your profile

Add the details we need to personalize your ledger workspace.

setFullName(event.target.value)} required />
setPhone(event.target.value)} />
setCompanyName(event.target.value)} />
setAddressLine1(event.target.value)} />
setAddressLine2(event.target.value)} />
setCity(event.target.value)} />
setState(event.target.value)} />
setPostalCode(event.target.value)} />
setCountry(event.target.value)} />
{status ?

{status}

: null}
); }