feat: resolve doctors query error, add FAQ, testimonials, blog preview, and full menu management
Deploy Canina / deploy (push) Successful in 1m41s
Deploy Canina / deploy (push) Successful in 1m41s
This commit is contained in:
1 parent
70d58e7086
commit
2c452215c3
31 files changed
+1987
-76
No files matched your search
@@ -32,6 +32,8 @@ import {
|
||||
ChevronDown,
|
||||
Star,
|
||||
Layers,
|
||||
HelpCircle,
|
||||
Menu,
|
||||
} from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
|
||||
@@ -146,6 +148,8 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
{ icon: UserCheck, label: 'پزشکان و کادر علمی', path: '/doctors' },
|
||||
{ icon: MessageSquareQuote, label: 'نظرات و گواهی متخصصان', path: '/testimonials' },
|
||||
{ icon: Video, label: 'ویدئوها و آموزشها', path: '/videos' },
|
||||
{ icon: HelpCircle, label: 'سوالات متداول (FAQ)', path: '/faq' },
|
||||
{ icon: Menu, label: 'مدیریت منو و فوتر', path: '/menu' },
|
||||
{ icon: Image, label: 'کتابخانه رسانه', path: '/media' },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { HelpCircle, Plus, Edit2, Trash2, X, GripVertical, ToggleLeft, ToggleRight } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import ConfirmModal from '../components/ui/ConfirmModal';
|
||||
|
||||
interface FAQ {
|
||||
id: string;
|
||||
question: string;
|
||||
answer: string;
|
||||
order: number;
|
||||
isActive: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export default function FAQManager() {
|
||||
const [faqs, setFaqs] = useState<FAQ[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [editingFaq, setEditingFaq] = useState<FAQ | null>(null);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
question: '',
|
||||
answer: '',
|
||||
order: 0,
|
||||
isActive: true,
|
||||
});
|
||||
|
||||
const fetchFaqs = useCallback(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await api.get('/faq/admin');
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setFaqs(data);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch FAQs:', err);
|
||||
toast.error('خطا در دریافت سوالات متداول');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchFaqs();
|
||||
}, [fetchFaqs]);
|
||||
|
||||
const openModal = (item: FAQ | null = null) => {
|
||||
if (item) {
|
||||
setEditingFaq(item);
|
||||
setFormData({
|
||||
question: item.question,
|
||||
answer: item.answer,
|
||||
order: item.order,
|
||||
isActive: item.isActive,
|
||||
});
|
||||
} else {
|
||||
setEditingFaq(null);
|
||||
setFormData({
|
||||
question: '',
|
||||
answer: '',
|
||||
order: faqs.length,
|
||||
isActive: true,
|
||||
});
|
||||
}
|
||||
setIsModalOpen(true);
|
||||
};
|
||||
|
||||
const handleSave = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!formData.question.trim() || !formData.answer.trim()) {
|
||||
toast.error('سوال و جواب اجباری هستند');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setIsSaving(true);
|
||||
if (editingFaq) {
|
||||
await api.put(`/faq/${editingFaq.id}`, formData);
|
||||
toast.success('سوال با موفقیت بروزرسانی شد');
|
||||
} else {
|
||||
await api.post('/faq', formData);
|
||||
toast.success('سوال جدید اضافه شد');
|
||||
}
|
||||
setIsModalOpen(false);
|
||||
fetchFaqs();
|
||||
} catch (err) {
|
||||
console.error('Failed to save FAQ:', err);
|
||||
toast.error('خطا در ذخیره سوال');
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleActive = async (item: FAQ) => {
|
||||
try {
|
||||
await api.put(`/faq/${item.id}`, { isActive: !item.isActive });
|
||||
toast.success(item.isActive ? 'غیرفعال شد' : 'فعال شد');
|
||||
fetchFaqs();
|
||||
} catch {
|
||||
toast.error('خطا در تغییر وضعیت');
|
||||
}
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (!deleteTargetId) return;
|
||||
try {
|
||||
await api.delete(`/faq/${deleteTargetId}`);
|
||||
toast.success('سوال حذف شد');
|
||||
fetchFaqs();
|
||||
} catch {
|
||||
toast.error('خطا در حذف');
|
||||
} finally {
|
||||
setDeleteTargetId(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
|
||||
<HelpCircle className="w-6 h-6 text-orange-500" />
|
||||
سوالات متداول (FAQ)
|
||||
</h2>
|
||||
<p className="text-gray-500 font-medium mt-1">
|
||||
سوالات و پاسخهایی که در صفحه اصلی سایت نمایش داده میشوند — با Schema.org FAQPage برای SEO
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => openModal()}
|
||||
className="bg-orange-500 hover:bg-orange-600 text-white px-5 py-2.5 rounded-xl flex items-center gap-2 font-bold transition-all shadow-md shadow-orange-200"
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
افزودن سوال جدید
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Info Box */}
|
||||
<div className="bg-orange-50 border border-orange-200 rounded-xl p-4 text-sm text-orange-800">
|
||||
<strong>💡 نکته SEO:</strong> سوالات فعال به صورت خودکار با markup <code className="bg-orange-100 px-1 rounded">FAQPage</code> در صفحه اصلی نمایش داده میشوند و در نتایج گوگل به عنوان Rich Snippet ظاهر میشوند.
|
||||
</div>
|
||||
|
||||
{/* List */}
|
||||
<div className="space-y-3">
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<Spinner size="lg" className="text-orange-500" />
|
||||
</div>
|
||||
) : faqs.length === 0 ? (
|
||||
<div className="bg-white rounded-2xl border border-gray-200 py-16 text-center">
|
||||
<HelpCircle className="w-12 h-12 text-gray-300 mx-auto mb-3" />
|
||||
<p className="text-gray-500 font-medium">هیچ سوالی ثبت نشده است</p>
|
||||
<button
|
||||
onClick={() => openModal()}
|
||||
className="mt-4 text-orange-500 font-bold hover:underline text-sm"
|
||||
>
|
||||
اولین سوال را اضافه کنید
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
faqs.map((faq, idx) => (
|
||||
<div
|
||||
key={faq.id}
|
||||
className={`bg-white rounded-2xl border p-5 transition-all ${
|
||||
faq.isActive ? 'border-gray-200' : 'border-dashed border-gray-300 opacity-60'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="flex items-center gap-2 shrink-0 mt-1">
|
||||
<GripVertical className="w-4 h-4 text-gray-300" />
|
||||
<span className="text-xs font-black text-gray-400 w-5 text-center">{idx + 1}</span>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span className="font-black text-gray-900 text-sm">{faq.question}</span>
|
||||
{!faq.isActive && (
|
||||
<span className="px-2 py-0.5 bg-gray-100 text-gray-500 text-[10px] font-bold rounded">
|
||||
غیرفعال
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-gray-600 text-sm leading-relaxed line-clamp-2">{faq.answer}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button
|
||||
onClick={() => toggleActive(faq)}
|
||||
className={`p-2 rounded-lg transition-colors ${
|
||||
faq.isActive
|
||||
? 'text-green-600 hover:bg-green-50'
|
||||
: 'text-gray-400 hover:bg-gray-50'
|
||||
}`}
|
||||
title={faq.isActive ? 'غیرفعال کردن' : 'فعال کردن'}
|
||||
>
|
||||
{faq.isActive ? <ToggleRight className="w-5 h-5" /> : <ToggleLeft className="w-5 h-5" />}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => openModal(faq)}
|
||||
className="p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setDeleteTargetId(faq.id)}
|
||||
className="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Form Modal */}
|
||||
{isModalOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-gray-900/60 backdrop-blur-sm">
|
||||
<div className="bg-white rounded-2xl w-full max-w-2xl shadow-2xl overflow-hidden">
|
||||
<div className="px-6 py-4 border-b border-gray-100 flex justify-between items-center bg-gray-50/50">
|
||||
<h3 className="text-lg font-bold text-gray-900">
|
||||
{editingFaq ? 'ویرایش سوال متداول' : 'افزودن سوال جدید'}
|
||||
</h3>
|
||||
<button onClick={() => setIsModalOpen(false)} className="p-2 hover:bg-gray-100 rounded-lg">
|
||||
<X className="w-5 h-5 text-gray-500" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSave} className="p-6 space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">
|
||||
سوال <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
value={formData.question}
|
||||
onChange={(e) => setFormData({ ...formData, question: e.target.value })}
|
||||
placeholder="مثال: آیا محصولات کنینا برای سگهای حساس مناسب است؟"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-orange-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">
|
||||
پاسخ <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<textarea
|
||||
required
|
||||
rows={5}
|
||||
value={formData.answer}
|
||||
onChange={(e) => setFormData({ ...formData, answer: e.target.value })}
|
||||
placeholder="پاسخ کامل، واضح و مفید..."
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-orange-400 outline-none text-sm resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">ترتیب نمایش</label>
|
||||
<input
|
||||
type="number"
|
||||
value={formData.order}
|
||||
onChange={(e) => setFormData({ ...formData, order: Number(e.target.value) })}
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-orange-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-end">
|
||||
<label className="flex items-center justify-between p-3 bg-orange-50 rounded-xl border border-orange-200 cursor-pointer w-full">
|
||||
<span className="text-xs font-bold text-orange-700">✅ فعال و قابل نمایش</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.isActive}
|
||||
onChange={(e) => setFormData({ ...formData, isActive: e.target.checked })}
|
||||
className="rounded text-orange-500 focus:ring-orange-400"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 flex justify-end gap-3 border-t border-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
className="px-5 py-2.5 rounded-xl border border-gray-200 text-gray-600 font-bold hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSaving}
|
||||
className="px-6 py-2.5 rounded-xl bg-orange-500 text-white font-bold hover:bg-orange-600 transition-colors shadow-md shadow-orange-200 flex items-center gap-2"
|
||||
>
|
||||
{isSaving && <Spinner size="sm" />}
|
||||
ذخیره
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{deleteTargetId && (
|
||||
<ConfirmModal
|
||||
isOpen={true}
|
||||
title="حذف سوال"
|
||||
message="آیا از حذف این سوال متداول اطمینان دارید؟"
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Menu, Plus, Edit2, Trash2, X, ExternalLink,
|
||||
Eye, EyeOff, ChevronDown, ChevronRight
|
||||
} from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import ConfirmModal from '../components/ui/ConfirmModal';
|
||||
|
||||
interface MenuItem {
|
||||
id: string;
|
||||
menuType: string;
|
||||
label: string;
|
||||
href: string;
|
||||
parentId: string | null;
|
||||
order: number;
|
||||
isActive: boolean;
|
||||
isExternal: boolean;
|
||||
icon: string | null;
|
||||
badge: string | null;
|
||||
children?: MenuItem[];
|
||||
}
|
||||
|
||||
type MenuType = 'HEADER' | 'FOOTER_COL1' | 'FOOTER_COL2' | 'FOOTER_COL3';
|
||||
|
||||
const MENU_TABS: { key: MenuType; label: string; color: string }[] = [
|
||||
{ key: 'HEADER', label: '📌 منوی هدر', color: 'blue' },
|
||||
{ key: 'FOOTER_COL1', label: '🔗 فوتر — ستون ۱', color: 'purple' },
|
||||
{ key: 'FOOTER_COL2', label: '🔗 فوتر — ستون ۲', color: 'indigo' },
|
||||
{ key: 'FOOTER_COL3', label: '🔗 فوتر — ستون ۳', color: 'violet' },
|
||||
];
|
||||
|
||||
export default function MenuManager() {
|
||||
const [activeTab, setActiveTab] = useState<MenuType>('HEADER');
|
||||
const [allItems, setAllItems] = useState<MenuItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [editingItem, setEditingItem] = useState<MenuItem | null>(null);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
menuType: 'HEADER' as MenuType,
|
||||
label: '',
|
||||
href: '',
|
||||
parentId: null as string | null,
|
||||
order: 0,
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
icon: '',
|
||||
badge: '',
|
||||
});
|
||||
|
||||
const fetchAll = useCallback(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await api.get('/menu/admin');
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setAllItems(data);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch menu items:', err);
|
||||
toast.error('خطا در دریافت آیتمهای منو');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAll();
|
||||
}, [fetchAll]);
|
||||
|
||||
const currentItems = allItems.filter(
|
||||
(item) => item.menuType === activeTab && item.parentId === null
|
||||
);
|
||||
|
||||
const openModal = (item: MenuItem | null = null, parentId?: string) => {
|
||||
if (item) {
|
||||
setEditingItem(item);
|
||||
setFormData({
|
||||
menuType: item.menuType as MenuType,
|
||||
label: item.label,
|
||||
href: item.href,
|
||||
parentId: item.parentId,
|
||||
order: item.order,
|
||||
isActive: item.isActive,
|
||||
isExternal: item.isExternal,
|
||||
icon: item.icon || '',
|
||||
badge: item.badge || '',
|
||||
});
|
||||
} else {
|
||||
setEditingItem(null);
|
||||
setFormData({
|
||||
menuType: activeTab,
|
||||
label: '',
|
||||
href: '',
|
||||
parentId: parentId || null,
|
||||
order: currentItems.length,
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
icon: '',
|
||||
badge: '',
|
||||
});
|
||||
}
|
||||
setIsModalOpen(true);
|
||||
};
|
||||
|
||||
const handleSave = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!formData.label.trim() || !formData.href.trim()) {
|
||||
toast.error('عنوان و لینک اجباری هستند');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setIsSaving(true);
|
||||
const payload = {
|
||||
...formData,
|
||||
icon: formData.icon || null,
|
||||
badge: formData.badge || null,
|
||||
};
|
||||
if (editingItem) {
|
||||
await api.put(`/menu/${editingItem.id}`, payload);
|
||||
toast.success('آیتم منو بروزرسانی شد');
|
||||
} else {
|
||||
await api.post('/menu', payload);
|
||||
toast.success('آیتم جدید اضافه شد');
|
||||
}
|
||||
setIsModalOpen(false);
|
||||
fetchAll();
|
||||
} catch (err) {
|
||||
console.error('Failed to save menu item:', err);
|
||||
toast.error('خطا در ذخیره');
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleActive = async (item: MenuItem) => {
|
||||
try {
|
||||
await api.put(`/menu/${item.id}`, { isActive: !item.isActive });
|
||||
toast.success(item.isActive ? 'مخفی شد' : 'فعال شد');
|
||||
fetchAll();
|
||||
} catch {
|
||||
toast.error('خطا در تغییر وضعیت');
|
||||
}
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (!deleteTargetId) return;
|
||||
try {
|
||||
await api.delete(`/menu/${deleteTargetId}`);
|
||||
toast.success('آیتم حذف شد');
|
||||
fetchAll();
|
||||
} catch {
|
||||
toast.error('خطا در حذف');
|
||||
} finally {
|
||||
setDeleteTargetId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const parentItems = allItems.filter(
|
||||
(item) => item.menuType === formData.menuType && item.parentId === null && item.id !== editingItem?.id
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
|
||||
<Menu className="w-6 h-6 text-blue-600" />
|
||||
مدیریت منو
|
||||
</h2>
|
||||
<p className="text-gray-500 font-medium mt-1">
|
||||
مدیریت آیتمهای هدر و فوتر سایت — تغییرات بلادرنگ اعمال میشوند
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => openModal()}
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2.5 rounded-xl flex items-center gap-2 font-bold transition-all shadow-md shadow-blue-200"
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
آیتم جدید
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{MENU_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
onClick={() => setActiveTab(tab.key)}
|
||||
className={`px-4 py-2 rounded-xl text-sm font-bold transition-all ${
|
||||
activeTab === tab.key
|
||||
? 'bg-blue-600 text-white shadow-md shadow-blue-200'
|
||||
: 'bg-white border border-gray-200 text-gray-600 hover:border-blue-300'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Menu Items List */}
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<Spinner size="lg" className="text-blue-600" />
|
||||
</div>
|
||||
) : currentItems.length === 0 ? (
|
||||
<div className="bg-white rounded-2xl border border-dashed border-gray-300 py-16 text-center">
|
||||
<Menu className="w-12 h-12 text-gray-300 mx-auto mb-3" />
|
||||
<p className="text-gray-500 font-medium">هیچ آیتمی در این منو وجود ندارد</p>
|
||||
<button
|
||||
onClick={() => openModal()}
|
||||
className="mt-4 text-blue-600 font-bold hover:underline text-sm"
|
||||
>
|
||||
اولین آیتم را اضافه کنید
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{currentItems.map((item) => (
|
||||
<div key={item.id} className="bg-white rounded-2xl border border-gray-200 overflow-hidden">
|
||||
{/* Parent Item */}
|
||||
<div className={`flex items-center gap-3 p-4 ${!item.isActive ? 'opacity-50' : ''}`}>
|
||||
<div className="flex items-center gap-2 text-gray-400 shrink-0">
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
<span className="text-xs font-mono text-gray-300">#{item.order}</span>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
{item.icon && <span className="text-base">{item.icon}</span>}
|
||||
<span className="font-bold text-gray-900">{item.label}</span>
|
||||
{item.badge && (
|
||||
<span className="px-1.5 py-0.5 bg-blue-100 text-blue-700 text-[10px] font-bold rounded">
|
||||
{item.badge}
|
||||
</span>
|
||||
)}
|
||||
{item.isExternal && <ExternalLink className="w-3 h-3 text-gray-400" />}
|
||||
</div>
|
||||
<span className="text-xs text-gray-400 font-mono mt-0.5 block">{item.href}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button
|
||||
onClick={() => toggleActive(item)}
|
||||
className={`p-2 rounded-lg transition-colors ${item.isActive ? 'text-green-600 hover:bg-green-50' : 'text-gray-400 hover:bg-gray-50'}`}
|
||||
title={item.isActive ? 'مخفی کردن' : 'نمایش'}
|
||||
>
|
||||
{item.isActive ? <Eye className="w-4 h-4" /> : <EyeOff className="w-4 h-4" />}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => openModal(item)}
|
||||
className="p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setDeleteTargetId(item.id)}
|
||||
className="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Children */}
|
||||
{item.children && item.children.length > 0 && (
|
||||
<div className="border-t border-gray-100 bg-gray-50/50">
|
||||
{item.children.map((child) => (
|
||||
<div key={child.id} className={`flex items-center gap-3 px-6 py-3 border-b border-gray-100 last:border-0 ${!child.isActive ? 'opacity-50' : ''}`}>
|
||||
<ChevronDown className="w-3.5 h-3.5 text-gray-300 shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-bold text-gray-700">{child.label}</span>
|
||||
{child.isExternal && <ExternalLink className="w-3 h-3 text-gray-400" />}
|
||||
</div>
|
||||
<span className="text-xs text-gray-400 font-mono">{child.href}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<button onClick={() => openModal(child)} className="p-1.5 text-blue-600 hover:bg-blue-50 rounded-lg">
|
||||
<Edit2 className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button onClick={() => setDeleteTargetId(child.id)} className="p-1.5 text-red-500 hover:bg-red-50 rounded-lg">
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Form Modal */}
|
||||
{isModalOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-gray-900/60 backdrop-blur-sm">
|
||||
<div className="bg-white rounded-2xl w-full max-w-xl shadow-2xl overflow-hidden">
|
||||
<div className="px-6 py-4 border-b border-gray-100 flex justify-between items-center bg-gray-50/50">
|
||||
<h3 className="text-lg font-bold text-gray-900">
|
||||
{editingItem ? 'ویرایش آیتم منو' : 'افزودن آیتم جدید'}
|
||||
</h3>
|
||||
<button onClick={() => setIsModalOpen(false)} className="p-2 hover:bg-gray-100 rounded-lg">
|
||||
<X className="w-5 h-5 text-gray-500" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSave} className="p-6 space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">موقعیت در منو</label>
|
||||
<select
|
||||
value={formData.menuType}
|
||||
onChange={(e) => setFormData({ ...formData, menuType: e.target.value as MenuType, parentId: null })}
|
||||
className="w-full px-3 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm bg-white"
|
||||
>
|
||||
{MENU_TABS.map((tab) => (
|
||||
<option key={tab.key} value={tab.key}>{tab.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">زیر آیتم از</label>
|
||||
<select
|
||||
value={formData.parentId || ''}
|
||||
onChange={(e) => setFormData({ ...formData, parentId: e.target.value || null })}
|
||||
className="w-full px-3 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm bg-white"
|
||||
>
|
||||
<option value="">— آیتم اصلی —</option>
|
||||
{parentItems.map((p) => (
|
||||
<option key={p.id} value={p.id}>{p.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">عنوان <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
required
|
||||
type="text"
|
||||
value={formData.label}
|
||||
onChange={(e) => setFormData({ ...formData, label: e.target.value })}
|
||||
placeholder="مثال: فروشگاه تخصصی"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">لینک (href) <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
required
|
||||
type="text"
|
||||
value={formData.href}
|
||||
onChange={(e) => setFormData({ ...formData, href: e.target.value })}
|
||||
placeholder="مثال: /shop یا https://..."
|
||||
dir="ltr"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm font-mono"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">آیکون (اختیاری)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.icon}
|
||||
onChange={(e) => setFormData({ ...formData, icon: e.target.value })}
|
||||
placeholder="🐕 یا نام آیکون"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">Badge (اختیاری)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.badge}
|
||||
onChange={(e) => setFormData({ ...formData, badge: e.target.value })}
|
||||
placeholder="مثال: جدید"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">ترتیب</label>
|
||||
<input
|
||||
type="number"
|
||||
value={formData.order}
|
||||
onChange={(e) => setFormData({ ...formData, order: Number(e.target.value) })}
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-blue-400 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
<label className="flex items-center justify-between p-3 bg-green-50 rounded-xl border border-green-200 cursor-pointer col-span-1 mt-auto">
|
||||
<span className="text-xs font-bold text-green-700">✅ فعال</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.isActive}
|
||||
onChange={(e) => setFormData({ ...formData, isActive: e.target.checked })}
|
||||
className="rounded text-green-600"
|
||||
/>
|
||||
</label>
|
||||
<label className="flex items-center justify-between p-3 bg-gray-50 rounded-xl border border-gray-200 cursor-pointer col-span-1 mt-auto">
|
||||
<span className="text-xs font-bold text-gray-700">🔗 لینک خارجی</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.isExternal}
|
||||
onChange={(e) => setFormData({ ...formData, isExternal: e.target.checked })}
|
||||
className="rounded"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 flex justify-end gap-3 border-t border-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
className="px-5 py-2.5 rounded-xl border border-gray-200 text-gray-600 font-bold hover:bg-gray-50"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSaving}
|
||||
className="px-6 py-2.5 rounded-xl bg-blue-600 text-white font-bold hover:bg-blue-700 shadow-md shadow-blue-200 flex items-center gap-2"
|
||||
>
|
||||
{isSaving && <Spinner size="sm" />}
|
||||
ذخیره
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{deleteTargetId && (
|
||||
<ConfirmModal
|
||||
isOpen={true}
|
||||
title="حذف آیتم منو"
|
||||
message="آیا از حذف این آیتم اطمینان دارید؟ آیتمهای زیرمجموعه نیز حذف خواهند شد."
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ export default function TestimonialsManager() {
|
||||
rating: 5,
|
||||
isFeatured: true,
|
||||
isActive: true,
|
||||
showOnHome: false,
|
||||
order: 0,
|
||||
});
|
||||
|
||||
@@ -71,6 +72,7 @@ export default function TestimonialsManager() {
|
||||
rating: item.rating || 5,
|
||||
isFeatured: item.isFeatured ?? true,
|
||||
isActive: item.isActive ?? true,
|
||||
showOnHome: (item as any).showOnHome ?? false,
|
||||
order: item.order || 0,
|
||||
});
|
||||
} else {
|
||||
@@ -83,6 +85,7 @@ export default function TestimonialsManager() {
|
||||
rating: 5,
|
||||
isFeatured: true,
|
||||
isActive: true,
|
||||
showOnHome: false,
|
||||
order: testimonials.length,
|
||||
});
|
||||
}
|
||||
@@ -213,6 +216,11 @@ export default function TestimonialsManager() {
|
||||
ویژه (Featured)
|
||||
</span>
|
||||
)}
|
||||
{(item as any).showOnHome && (
|
||||
<span className="px-2 py-0.5 bg-blue-50 text-blue-700 text-[11px] font-bold rounded border border-blue-200">
|
||||
🏠 صفحه اصلی
|
||||
</span>
|
||||
)}
|
||||
{item.isActive ? (
|
||||
<span className="inline-flex items-center gap-0.5 text-green-600 text-xs font-bold">
|
||||
<CheckCircle2 className="w-3.5 h-3.5" /> فعال
|
||||
@@ -337,7 +345,7 @@ export default function TestimonialsManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2 grid grid-cols-2 gap-4">
|
||||
<div className="pt-2 grid grid-cols-3 gap-3">
|
||||
<label className="flex items-center justify-between p-3 bg-gray-50 rounded-xl border border-gray-200 cursor-pointer">
|
||||
<span className="text-xs font-bold text-gray-700">نمایش ویژه (Featured)</span>
|
||||
<input
|
||||
@@ -357,6 +365,16 @@ export default function TestimonialsManager() {
|
||||
className="rounded text-purple-600 focus:ring-purple-500"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between p-3 bg-blue-50 rounded-xl border border-blue-200 cursor-pointer">
|
||||
<span className="text-xs font-bold text-blue-700">🏠 صفحه اصلی</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.showOnHome}
|
||||
onChange={(e) => setFormData({ ...formData, showOnHome: e.target.checked })}
|
||||
className="rounded text-blue-600 focus:ring-blue-500"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 flex justify-end gap-3 border-t border-gray-100">
|
||||
|
||||
@@ -41,6 +41,8 @@ const Transactions = lazyWithRetry(() => import('../pages/Transactions'));
|
||||
const Tickets = lazyWithRetry(() => import('../pages/Tickets'));
|
||||
const Reviews = lazyWithRetry(() => import('../pages/Reviews'));
|
||||
const DoctorsManager = lazyWithRetry(() => import('../pages/DoctorsManager'));
|
||||
const FAQManager = lazyWithRetry(() => import('../pages/FAQManager'));
|
||||
const MenuManager = lazyWithRetry(() => import('../pages/MenuManager'));
|
||||
|
||||
export interface AdminRouteConfig {
|
||||
path: string;
|
||||
@@ -97,6 +99,8 @@ export const router = createBrowserRouter([
|
||||
{ path: 'contact/*', element: <ContactSubmissions /> },
|
||||
{ path: 'tickets/*', element: <Tickets /> },
|
||||
{ path: 'reviews/*', element: <Reviews /> },
|
||||
{ path: 'faq/*', element: <FAQManager /> },
|
||||
{ path: 'menu/*', element: <MenuManager /> },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user