ehsan-dashboards/dashboards/crm/components/NewLeadModal.tsx

271 lines
No EOL
10 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// components/NewLeadModal.tsx
'use client';
import React, { useState } from 'react';
import {
X,
Building2,
Phone,
User,
MapPin,
Plus,
Save,
DollarSign
} from 'lucide-react';
import { PIPELINE_STAGES } from '@/lib/automation';
interface NewLeadModalProps {
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
}
export function NewLeadModal({ isOpen, onClose, onSuccess }: NewLeadModalProps) {
if (!isOpen) return null;
const [name, setName] = useState('');
const [city, setCity] = useState('تهران');
const [district, setDistrict] = useState('');
const [managerName, setManagerName] = useState('');
const [phone, setPhone] = useState('');
const [instagram, setInstagram] = useState('');
const [website, setWebsite] = useState('');
const [stage, setStage] = useState('ارتباط اولیه');
const [dealValue, setDealValue] = useState(15000000);
const [roomName, setRoomName] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name.trim() || !phone.trim() || !city.trim()) {
setError('نام مجموعه، شهر و شماره تماس الزامی هستند.');
return;
}
setLoading(true);
setError('');
try {
const res = await fetch('/api/leads', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: name.trim(),
city: city.trim(),
district: district.trim() || null,
ownerName: managerName.trim() || 'مدیر مجموعه',
ownerPhone: phone.trim(),
managerName: managerName.trim() || null,
phone: phone.trim(),
stage,
rooms: roomName.trim()
? [{ title: roomName.trim(), minPlayers: 4, maxPlayers: 8, ticketPrice: 250000 }]
: []
})
});
if (!res.ok) {
const d = await res.json();
throw new Error(d.error || 'خطا در ثبت لید');
}
onSuccess();
onClose();
} catch (err: any) {
setError(err.message || 'خطا در برقراری ارتباط');
} finally {
setLoading(false);
}
};
return (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto">
<div className="bg-white rounded-3xl shadow-2xl border border-slate-200 w-full max-w-xl overflow-hidden animate-in fade-in zoom-in-95 duration-150">
<div className="p-6 border-b border-slate-100 flex items-center justify-between bg-slate-50">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-teal-600 text-white flex items-center justify-center">
<Building2 className="w-5 h-5" />
</div>
<div>
<h2 className="text-base font-bold text-slate-900">افزودن مجموعه اتاق فرار جدید</h2>
<p className="text-xs text-slate-500">ثبت لید جدید در پایپ‌لاین فروش اکیپا</p>
</div>
</div>
<button
onClick={onClose}
className="p-2 text-slate-400 hover:text-slate-700 hover:bg-slate-200/50 rounded-xl transition-colors"
>
<X className="w-5 h-5" />
</button>
</div>
<form onSubmit={handleSubmit} className="p-6 space-y-4">
{error && (
<div className="p-3 rounded-xl bg-rose-50 border border-rose-200 text-rose-700 text-xs font-semibold">
{error}
</div>
)}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="md:col-span-2">
<label className="text-xs font-semibold text-slate-700 block mb-1">
نام مجموعه / اتاق فرار <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="مثال: اتاق فرار طاعون سیاه"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
شهر <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
value={city}
onChange={(e) => setCity(e.target.value)}
placeholder="تهران / کرج / اصفهان ..."
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
منطقه / محله
</label>
<input
type="text"
value={district}
onChange={(e) => setDistrict(e.target.value)}
placeholder="مثال: سعادت‌آباد، فردیس"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
نام مدیر یا مسئول
</label>
<input
type="text"
value={managerName}
onChange={(e) => setManagerName(e.target.value)}
placeholder="مثال: احسان رضایی"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
شماره تماس <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
dir="ltr"
value={phone}
onChange={(e) => setPhone(e.target.value)}
placeholder="09123456789"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
آیدی اینستاگرام
</label>
<input
type="text"
dir="ltr"
value={instagram}
onChange={(e) => setInstagram(e.target.value)}
placeholder="@escaperoom_ir"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
وب‌سایت / پلتفرم رزرو
</label>
<input
type="text"
dir="ltr"
value={website}
onChange={(e) => setWebsite(e.target.value)}
placeholder="https://t4f.ir/..."
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
مرحله ورود به پایپ‌لاین
</label>
<select
value={stage}
onChange={(e) => setStage(e.target.value)}
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 font-semibold"
>
{PIPELINE_STAGES.map((s, idx) => (
<option key={idx} value={s.stage}>
{s.stage}
</option>
))}
</select>
</div>
<div>
<label className="text-xs font-semibold text-slate-700 block mb-1">
ارزش بالقوه قرارداد (تومان)
</label>
<input
type="number"
value={dealValue}
onChange={(e) => setDealValue(Number(e.target.value))}
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
<div className="md:col-span-2">
<label className="text-xs font-semibold text-slate-700 block mb-1">
نام اولین اتاق فعال مجموعه (اختیاری)
</label>
<input
type="text"
value={roomName}
onChange={(e) => setRoomName(e.target.value)}
placeholder="مثال: اتاق جن‌گیر (۶ نفره - ۲۵۰,۰۰۰ تومان)"
className="w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"
/>
</div>
</div>
<div className="pt-4 border-t border-slate-100 flex items-center justify-end gap-3">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-xs font-semibold text-slate-600 hover:bg-slate-100 rounded-xl transition-colors"
>
انصراف
</button>
<button
type="submit"
disabled={loading}
className="flex items-center gap-1.5 px-6 py-2.5 bg-teal-600 hover:bg-teal-700 text-white text-xs font-bold rounded-xl shadow transition-all active:scale-95"
>
<Plus className="w-4 h-4" />
<span>{loading ? 'در حال ثبت...' : 'ثبت مجموعه در CRM'}</span>
</button>
</div>
</form>
</div>
</div>
);
}