feat(admin): add Info Tooltips and flexible discount rule settings to Coupons manager [TASK-23.1, TASK-24.1]

This commit is contained in:
parsa aghaei 2026-08-03 11:52:32 +03:30
parent c3ca9ccaa2
commit 9cc1b74d72

View File

@ -1,5 +1,5 @@
import { useState, useEffect, useCallback } from 'react';
import { Tag, Plus, Edit2, Trash2, Search, XCircle, CheckCircle2, User, Heart, ShoppingBag, FolderTree, Shield } from 'lucide-react';
import { Tag, Plus, Edit2, Trash2, Search, XCircle, CheckCircle2, User, Heart, ShoppingBag, FolderTree, Shield, HelpCircle } from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
@ -301,36 +301,92 @@ function CouponModal({ formData, setFormData, onSave, onClose, isEditing }: Coup
<h4 className="font-bold text-gray-800 border-b border-gray-100 pb-2">تنظیمات پایه</h4>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="space-y-2">
<label className="text-sm font-bold text-gray-700">کد تخفیف *</label>
<label className="text-sm font-bold text-gray-700 flex items-center gap-1.5">
<span>کد تخفیف *</span>
<div className="group relative inline-block">
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-56 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
عبارت یکتا جهت وارد کردن توسط کاربر (مثال: CANINA20). حروف به طور خودکار بزرگ میشوند.
</div>
</div>
</label>
<input required type="text" value={formData.code} onChange={e => setFormData({...formData, code: e.target.value.toUpperCase()})} dir="ltr" className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none font-mono text-center uppercase font-bold" />
</div>
<div className="space-y-2">
<label className="text-sm font-bold text-gray-700">نوع *</label>
<label className="text-sm font-bold text-gray-700 flex items-center gap-1.5">
<span>نوع محاسبه *</span>
<div className="group relative inline-block">
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-56 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
درصدی (کسر درصد از کل مبلغ) یا مبلغ ثابت (کسر مقدار ریالی مشخص).
</div>
</div>
</label>
<select required value={formData.type} onChange={e => setFormData({...formData, type: e.target.value})} className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 bg-white">
<option value="percent">درصدی (٪)</option>
<option value="fixed">مبلغ ثابت (تومان)</option>
</select>
</div>
<div className="space-y-2">
<label className="text-sm font-bold text-gray-700">مقدار *</label>
<label className="text-sm font-bold text-gray-700 flex items-center gap-1.5">
<span>مقدار پایه *</span>
<div className="group relative inline-block">
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-56 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
عدد درصد یا مبلغ ثابت تخفیف به تومان.
</div>
</div>
</label>
<input required type="number" min="0" value={formData.value} onChange={e => setFormData({...formData, value: e.target.value})} dir="ltr" className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500" />
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<div className="space-y-2">
<label className="text-xs font-bold text-gray-700">حداقل خرید</label>
<label className="text-xs font-bold text-gray-700 flex items-center gap-1">
<span>حداقل خرید (تومان)</span>
<div className="group relative inline-block">
<HelpCircle className="w-3 h-3 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-48 p-2 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
حداقل مبلغ سبد خرید برای فعال شدن این کد.
</div>
</div>
</label>
<input type="number" min="0" value={formData.minCartValue} onChange={e => setFormData({...formData, minCartValue: e.target.value})} dir="ltr" className="w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-purple-500 text-sm" />
</div>
<div className="space-y-2">
<label className="text-xs font-bold text-gray-700">حداکثر تخفیف</label>
<label className="text-xs font-bold text-gray-700 flex items-center gap-1">
<span>سقف تخفیف (تومان)</span>
<div className="group relative inline-block">
<HelpCircle className="w-3 h-3 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-48 p-2 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
حداکثر سقف ریالی کسر شده در تخفیفهای درصدی.
</div>
</div>
</label>
<input type="number" min="0" value={formData.maxCartValue} onChange={e => setFormData({...formData, maxCartValue: e.target.value})} dir="ltr" className="w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-purple-500 text-sm" />
</div>
<div className="space-y-2">
<label className="text-xs font-bold text-gray-700">دفعات مجاز</label>
<label className="text-xs font-bold text-gray-700 flex items-center gap-1">
<span>دفعات مجاز استفاده</span>
<div className="group relative inline-block">
<HelpCircle className="w-3 h-3 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-48 p-2 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
تعداد کل دفات قابل استفاده توسط کلیه کاربران.
</div>
</div>
</label>
<input type="number" min="1" value={formData.maxUses} onChange={e => setFormData({...formData, maxUses: e.target.value})} dir="ltr" className="w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-purple-500 text-sm" />
</div>
<div className="space-y-2">
<label className="text-xs font-bold text-gray-700">انقضا</label>
<label className="text-xs font-bold text-gray-700 flex items-center gap-1">
<span>تاریخ انقضا</span>
<div className="group relative inline-block">
<HelpCircle className="w-3 h-3 text-gray-400 hover:text-purple-600 cursor-help" />
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-48 p-2 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
آخرین مهلت اعتبار کد تخفیف.
</div>
</div>
</label>
<input type="date" value={formData.expiresAt} onChange={e => setFormData({...formData, expiresAt: e.target.value})} className="w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-purple-500 text-sm" />
</div>
</div>