feat(admin): standardize Buttons and Modals across CMS, Catalog, Payment, and FAQ managers
This commit is contained in:
1 parent
32f8b8b656
commit
a92cd7fc85
16 files changed
+895
-748
No files matched your search
@@ -4,6 +4,9 @@ import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import ConfirmModal from '../components/ui/ConfirmModal';
|
||||
import Button from '../components/ui/Button';
|
||||
import Modal from '../components/ui/Modal';
|
||||
|
||||
|
||||
interface FAQ {
|
||||
id: string;
|
||||
@@ -129,13 +132,14 @@ export default function FAQManager() {
|
||||
سوالات و پاسخهایی که در صفحه اصلی سایت نمایش داده میشوند — با Schema.org FAQPage برای SEO
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
startIcon={Plus}
|
||||
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>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Info Box */}
|
||||
@@ -147,7 +151,7 @@ export default function FAQManager() {
|
||||
<div className="space-y-3">
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<Spinner size="lg" className="text-orange-500" />
|
||||
<Spinner size="lg" className="text-purple-600" />
|
||||
</div>
|
||||
) : faqs.length === 0 ? (
|
||||
<div className="bg-white rounded-2xl border border-gray-200 py-16 text-center">
|
||||
@@ -155,56 +159,71 @@ export default function FAQManager() {
|
||||
<p className="text-gray-500 font-medium">هیچ سوالی ثبت نشده است</p>
|
||||
<button
|
||||
onClick={() => openModal()}
|
||||
className="mt-4 text-orange-500 font-bold hover:underline text-sm"
|
||||
className="mt-4 text-purple-600 font-bold hover:underline text-sm cursor-pointer"
|
||||
>
|
||||
اولین سوال را اضافه کنید
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
faqs.map((faq, idx) => (
|
||||
faqs.map((faq) => (
|
||||
<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'
|
||||
faq.isActive ? 'border-gray-200 shadow-sm' : 'border-gray-100 opacity-60 bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
<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">
|
||||
غیرفعال
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex items-start gap-3 flex-1">
|
||||
<div className="p-2 bg-orange-50 text-orange-600 rounded-xl mt-0.5 shrink-0">
|
||||
<HelpCircle className="w-5 h-5" />
|
||||
</div>
|
||||
<div className="space-y-2 flex-1">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-xs font-bold px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md">
|
||||
ترتیب: {faq.order}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
className={`text-xs font-bold px-2 py-0.5 rounded-md ${
|
||||
faq.isActive
|
||||
? 'bg-green-100 text-green-700'
|
||||
: 'bg-gray-100 text-gray-500'
|
||||
}`}
|
||||
>
|
||||
{faq.isActive ? 'فعال' : 'غیرفعال'}
|
||||
</span>
|
||||
</div>
|
||||
<h3 className="font-bold text-gray-900 text-base">{faq.question}</h3>
|
||||
<p className="text-gray-600 text-sm leading-relaxed whitespace-pre-line">
|
||||
{faq.answer}
|
||||
</p>
|
||||
</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">
|
||||
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<button
|
||||
onClick={() => toggleActive(faq)}
|
||||
className={`p-2 rounded-lg transition-colors ${
|
||||
title={faq.isActive ? 'غیرفعالسازی' : 'فعالسازی'}
|
||||
className={`p-2 rounded-xl transition-colors cursor-pointer ${
|
||||
faq.isActive
|
||||
? 'text-green-600 hover:bg-green-50'
|
||||
: 'text-gray-400 hover:bg-gray-50'
|
||||
: 'text-gray-400 hover:bg-gray-100'
|
||||
}`}
|
||||
title={faq.isActive ? 'غیرفعال کردن' : 'فعال کردن'}
|
||||
>
|
||||
{faq.isActive ? <ToggleRight className="w-5 h-5" /> : <ToggleLeft className="w-5 h-5" />}
|
||||
{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"
|
||||
className="p-2 text-blue-600 hover:bg-blue-50 rounded-xl transition-colors cursor-pointer"
|
||||
>
|
||||
<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"
|
||||
className="p-2 text-red-600 hover:bg-red-50 rounded-xl transition-colors cursor-pointer"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
@@ -215,31 +234,49 @@ export default function FAQManager() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Form Modal */}
|
||||
{/* 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>
|
||||
<Modal
|
||||
isOpen={isModalOpen}
|
||||
onClose={() => setIsModalOpen(false)}
|
||||
title={editingFaq ? 'ویرایش سوال متداول' : 'افزودن سوال جدید'}
|
||||
icon={HelpCircle}
|
||||
maxWidth="2xl"
|
||||
footer={
|
||||
<div className="flex justify-end gap-2.5 w-full">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
type="button"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
type="submit"
|
||||
form="faqForm"
|
||||
isLoading={isSaving}
|
||||
>
|
||||
ذخیره سوال
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSave} className="p-6 space-y-4">
|
||||
}
|
||||
>
|
||||
<div className="space-y-6 text-right font-vazir">
|
||||
<form id="faqForm" onSubmit={handleSave} className="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
|
||||
type="text"
|
||||
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"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -253,7 +290,7 @@ export default function FAQManager() {
|
||||
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"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -264,44 +301,28 @@ export default function FAQManager() {
|
||||
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"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 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>
|
||||
<label className="flex items-center justify-between p-3 bg-purple-50 rounded-xl border border-purple-200 cursor-pointer w-full">
|
||||
<span className="text-xs font-bold text-purple-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"
|
||||
className="rounded text-purple-600 focus:ring-purple-500"
|
||||
/>
|
||||
</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>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
{deleteTargetId && (
|
||||
<ConfirmModal
|
||||
isOpen={true}
|
||||
|
||||
Reference in new issue
Block a user