import { useRef, useState } from "react"; import { updateAccountProfile } from "../api"; import { getAccessToken, saveStoredAccount } from "../auth"; const MAX_AVATAR_BYTES = 512 * 1024; const ALLOWED_TYPES = new Set(["image/jpeg", "image/png", "image/webp"]); function accountInitials(account) { return `${account?.first_name?.[0] || ""}${account?.last_name?.[0] || ""}`.toUpperCase() || "AG"; } function displayPhone(phone) { if (!phone) return "Not set"; return phone.replace(/^\+/, ""); } export default function AccountProfile({ account, onUpdated }) { const token = getAccessToken(); const inputRef = useRef(null); const [status, setStatus] = useState({ loading: false, error: "", notice: "" }); const fullName = `${account?.first_name || ""} ${account?.last_name || ""}`.trim(); const isCompany = account?.account_type === "company"; const hasPhoto = Boolean(account?.profile_picture_url); async function handleFileChange(event) { const file = event.target.files?.[0]; event.target.value = ""; if (!file) return; if (!ALLOWED_TYPES.has(file.type)) { setStatus({ loading: false, error: "Use a JPG, PNG, or WebP image.", notice: "" }); return; } if (file.size > MAX_AVATAR_BYTES) { setStatus({ loading: false, error: "Profile picture must be 512 KB or smaller.", notice: "" }); return; } setStatus({ loading: true, error: "", notice: "" }); try { const dataUrl = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(String(reader.result || "")); reader.onerror = () => reject(new Error("Could not read that image.")); reader.readAsDataURL(file); }); const updated = await updateAccountProfile({ profile_picture_url: dataUrl }, token); saveStoredAccount(updated); onUpdated?.(updated); setStatus({ loading: false, error: "", notice: "Saved" }); } catch (error) { setStatus({ loading: false, error: error.message, notice: "" }); } } async function removePhoto() { setStatus({ loading: true, error: "", notice: "" }); try { const updated = await updateAccountProfile({ profile_picture_url: null }, token); saveStoredAccount(updated); onUpdated?.(updated); setStatus({ loading: false, error: "", notice: "Saved" }); } catch (error) { setStatus({ loading: false, error: error.message, notice: "" }); } } return (

{isCompany ? "Company workspace" : "Personal workspace"}

Profile

Manage your personal information and how you appear across Gentic.

{isCompany ? "Company account" : "Personal account"} · {isCompany ? "Company" : "Individual"}

{hasPhoto ? ( ) : ( {accountInitials(account)} )}
{fullName}
{hasPhoto && ( <> )}
{status.error &&

{status.error}

} {status.notice && !status.error && (

{status.notice}

)} {status.loading && !status.notice && (

Saving…

)}
); }