'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { X, Building2, Globe, CheckCircle2, Loader2 } from 'lucide-react'; interface AddMerchantModalProps { isOpen: boolean; onClose: () => void; } export default function AddMerchantModal({ isOpen, onClose }: AddMerchantModalProps) { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [name, setName] = useState(''); const [webhookUrl, setWebhookUrl] = useState(''); const [success, setSuccess] = useState(false); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { const response = await fetch('/api/merchants', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, webhook_url: webhookUrl }), }); if (!response.ok) { const data = await response.json(); throw new Error(data.error || 'Firma eklenemedi.'); } setSuccess(true); setTimeout(() => { onClose(); setSuccess(false); setName(''); setWebhookUrl(''); router.refresh(); }, 2000); } catch (err: any) { console.error('Error adding merchant:', err); alert(err.message || 'Firma eklenirken bir hata oluştu.'); } finally { setIsLoading(false); } }; return (
{/* Backdrop */}
{/* Modal Content */}

Yeni Firma Ekle

{success ? (

Firma Eklendi!

Firma başarıyla kaydedildi, yönlendiriliyorsunuz...

) : (
setName(e.target.value)} className="w-full px-6 py-4 bg-gray-50 border-none rounded-2xl text-sm font-bold focus:ring-2 focus:ring-blue-500 outline-none placeholder:text-gray-300" />
setWebhookUrl(e.target.value)} className="w-full pl-14 pr-6 py-4 bg-gray-50 border-none rounded-2xl text-sm font-bold focus:ring-2 focus:ring-blue-500 outline-none placeholder:text-gray-300" />

Ödeme başarılı olduğunda sistemin bu adrese veri göndermesini istiyorsanız girin.

)}
); }