// Auteur : Simon-Pierre Boucher — contact@spboucher.ai "use client"; import { useRef, useState } from "react"; export default function AvatarEditor({ hasAvatar }: { hasAvatar: boolean }) { const fileRef = useRef(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function upload(f: File | undefined) { if (!f) return; setBusy(true); setError(null); const fd = new FormData(); fd.append("photo", f); const res = await fetch("/api/profile/avatar", { method: "POST", body: fd }); const data = await res.json().catch(() => ({})); if (res.ok) { window.location.reload(); } else { setError(data.error ?? "Téléversement impossible — réessayez."); setBusy(false); } } async function remove() { setBusy(true); setError(null); await fetch("/api/profile/avatar", { method: "DELETE" }); window.location.reload(); } return (
{hasAvatar && ( )}

JPG, PNG ou WebP (8 Mo max) — recadrée en carré 512 px. Visible sur votre carte, votre carte Wallet et toutes les plateformes ·Ka.

{error && (

{error}

)} upload(e.target.files?.[0] ?? undefined)} />
); }