'use client' import Link from 'next/link' import { useEffect, useState } from 'react' /* Resend button + status — real /api/auth/resend-verification endpoint. Without SMTP configured the API answers 503 with a clear message. «البريد غير صحيح؟» — collapsed change-email affordance: PATCH /api/users/:id (self-update allowed in Users.ts access) then resend; 400 → duplicate-email copy. Hidden without a session (no id → nothing to patch). */ export default function VerifyActions({ verified, email, userId }: { verified: boolean; email: string | null; userId: number | null }) { const [status, setStatus] = useState('') const [newEmail, setNewEmail] = useState('') const [busy, setBusy] = useState(false) useEffect(() => { if (email) { setNewEmail(email) return } try { const saved = sessionStorage.getItem('anwarpi:signup-email') if (saved) setNewEmail(saved) } catch { /* private mode */ } }, [email]) async function changeEmail() { if (busy || !userId) return setBusy(true) setStatus('جارٍ التحديث…') try { const patchRes = await fetch(`/api/users/${userId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: newEmail.trim() }), }) if (!patchRes.ok) { setStatus(patchRes.status === 400 ? 'هذا البريد مسجَّل لدينا.' : 'تعذّر تحديث البريد، حاول مرة أخرى.') return } const resendRes = await fetch('/api/auth/resend-verification', { method: 'POST' }) const data = await resendRes.json().catch(() => null) as { error?: string; already?: boolean } | null setStatus(resendRes.ok || data?.already ? 'أرسلنا رسالة تأكيد جديدة إلى بريدك المحدَّث.' : data?.error || 'تم تحديث البريد لكن تعذّر الإرسال الآن.') } catch { setStatus('تعذّر الاتصال، حاول مرة أخرى.') } finally { setBusy(false) } } return ( <>
متابعة إعداد الحساب {!verified && ( )}

{status}

{userId && !verified && (
البريد غير صحيح؟
setNewEmail(e.target.value)} aria-label="البريد الإلكتروني الصحيح" />
)} ) }