const { useState, useEffect, useCallback } = React; // ─── Durum Renkleri ───────────────────────────────────────────────────────── const STATUS_MAP = { pending: { label: 'Bekliyor', color: '#f59e0b', bg: 'rgba(245,158,11,0.1)' }, confirmed: { label: 'Onaylandi', color: '#3b82f6', bg: 'rgba(59,130,246,0.1)' }, calling: { label: 'Araniyor', color: '#8b5cf6', bg: 'rgba(139,92,246,0.1)' }, completed: { label: 'Tamamlandi', color: '#22c55e', bg: 'rgba(34,197,94,0.1)' }, cancelled: { label: 'Iptal', color: '#94a3b8', bg: 'rgba(148,163,184,0.1)' }, missed: { label: 'Kacirildi', color: '#ef4444', bg: 'rgba(239,68,68,0.1)' }, }; function StatusBadge({ status }) { const s = STATUS_MAP[status] || STATUS_MAP.pending; return ( {s.label} ); } // ─── Tarih formatlama ───────────────────────────────────────────────────────── // Backend datetime'ları parseUTC ile yorumlanır (Z suffix yoksa UTC kabul edilir). function fmtDate(iso) { const d = parseUTC(iso); if (!d) return '-'; const pad = n =>String(n).padStart(2, '0'); return `${pad(d.getDate())}.${pad(d.getMonth() + 1)}.${d.getFullYear()} ${pad(d.getHours())}:${pad(d.getMinutes())}`; } function timeUntil(iso) { const target = parseUTC(iso); if (!target) return ''; const diff = target.getTime() - Date.now(); if (diff < 0) return 'Gecmis'; const h = Math.floor(diff / 3600000); const m = Math.floor((diff % 3600000) / 60000); if (h > 24) return `${Math.floor(h / 24)} gun`; if (h > 0) return `${h}sa ${m}dk`; return `${m}dk`; } // ─── Yeni Randevu Modal ───────────────────────────────────────────────────── function NewAppointmentModal({ onClose, onSave }) { const [form, setForm] = useState({ phone: '', customer_name: '', subject: '', notes: '', appointment_date: '', auto_callback: true, max_retries: 2 }); const set = (k, v) =>setForm(f => ({ ...f, [k]: v })); async function save() { if (!form.phone || !form.appointment_date) return; const body = { ...form, appointment_date: new Date(form.appointment_date).toISOString(), }; const r = await authFetch('/api/appointments', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); if (r.ok) onSave(); } return (
e.stopPropagation()} style={{ maxWidth: 500 }}>
Yeni Randevu
set('phone', e.target.value)} placeholder="05XX XXX XX XX" />
set('customer_name', e.target.value)} />
set('appointment_date', e.target.value)} />
set('subject', e.target.value)} placeholder="Randevu nedeni" />