feat: complete settings sync, standard UI inputs, prescriptions flow, pet profile and checkout enhancements
Deploy Canina / deploy (push) Failing after 51s
Deploy Canina / deploy (push) Failing after 51s
This commit is contained in:
1 parent
b3c60a1a7d
commit
6df92f03d7
32 files changed
+61750
-59151
No files matched your search
@@ -5,6 +5,7 @@ import api, { BASE_DOMAIN } from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import Pagination from '../components/ui/Pagination';
|
||||
import ConfirmModal from '../components/ui/ConfirmModal';
|
||||
import ImagePreviewModal from '../components/ui/ImagePreviewModal';
|
||||
|
||||
interface Media {
|
||||
id: string;
|
||||
@@ -90,21 +91,35 @@ export default function MediaManager() {
|
||||
}
|
||||
};
|
||||
|
||||
const uploadFile = useCallback(async (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const uploadFiles = useCallback(async (files: File[]) => {
|
||||
if (!files || files.length === 0) return;
|
||||
try {
|
||||
setIsUploading(true);
|
||||
await api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
let successCount = 0;
|
||||
const promises = files.map(async (file) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
});
|
||||
});
|
||||
toast.success('تصویر با موفقیت آپلود شد');
|
||||
fetchMedia();
|
||||
const results = await Promise.allSettled(promises);
|
||||
results.forEach(res => {
|
||||
if (res.status === 'fulfilled') successCount++;
|
||||
});
|
||||
if (successCount > 0) {
|
||||
toast.success(`${successCount} تصویر با موفقیت آپلود شد`);
|
||||
await fetchMedia();
|
||||
}
|
||||
if (successCount < files.length) {
|
||||
toast.error(`خطا در آپلود ${files.length - successCount} تصویر`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Upload failed', error);
|
||||
toast.error('خطا در آپلود فایل');
|
||||
toast.error('خطا در آپلود فایلها');
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
}
|
||||
}, [fetchMedia]);
|
||||
|
||||
@@ -127,19 +142,21 @@ export default function MediaManager() {
|
||||
const handlePaste = (e: ClipboardEvent) => {
|
||||
const items = e.clipboardData?.items;
|
||||
if (!items) return;
|
||||
const files: File[] = [];
|
||||
for (const item of Array.from(items)) {
|
||||
if (item.type.startsWith('image/')) {
|
||||
e.preventDefault();
|
||||
const file = item.getAsFile();
|
||||
if (!file) continue;
|
||||
uploadFile(file);
|
||||
break;
|
||||
if (file) files.push(file);
|
||||
}
|
||||
}
|
||||
if (files.length > 0) {
|
||||
e.preventDefault();
|
||||
uploadFiles(files);
|
||||
}
|
||||
};
|
||||
document.addEventListener('paste', handlePaste);
|
||||
return () => document.removeEventListener('paste', handlePaste);
|
||||
}, [uploadFile]);
|
||||
}, [uploadFiles]);
|
||||
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
const [editingSeoMedia, setEditingSeoMedia] = useState<Media | null>(null);
|
||||
@@ -164,16 +181,16 @@ export default function MediaManager() {
|
||||
|
||||
const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (!e.target.files || e.target.files.length === 0) return;
|
||||
await uploadFile(e.target.files[0]);
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
await uploadFiles(Array.from(e.target.files));
|
||||
};
|
||||
|
||||
const handleDrop = async (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragOver(false);
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file && file.type.startsWith('image/')) {
|
||||
await uploadFile(file);
|
||||
if (!e.dataTransfer.files || e.dataTransfer.files.length === 0) return;
|
||||
const files = Array.from(e.dataTransfer.files).filter(f => f.type.startsWith('image/'));
|
||||
if (files.length > 0) {
|
||||
await uploadFiles(files);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -242,6 +259,7 @@ export default function MediaManager() {
|
||||
ref={fileInputRef}
|
||||
onChange={handleUpload}
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
/>
|
||||
<button
|
||||
@@ -544,6 +562,12 @@ export default function MediaManager() {
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
/>
|
||||
|
||||
<ImagePreviewModal
|
||||
isOpen={!!previewUrl}
|
||||
imageUrl={previewUrl || ''}
|
||||
onClose={() => setPreviewUrl(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Search, Trash2, Heart, Image as ImageIcon } from 'lucide-react';
|
||||
import { Search, Trash2, Heart, Image as ImageIcon, Eye, Clock, Activity, FileText, X, Dog, Cat, ShieldCheck } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api, { BASE_DOMAIN } from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
@@ -18,12 +18,35 @@ export interface Pet {
|
||||
imageUrl?: string;
|
||||
avatarUrl?: string;
|
||||
user?: {
|
||||
firstName: ReactNode;
|
||||
lastName: ReactNode;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
name?: string;
|
||||
mobile?: string;
|
||||
email?: string;
|
||||
};
|
||||
medicalConditions?: Array<{ condition: string }>;
|
||||
reminders?: Array<{
|
||||
id: string;
|
||||
title: string;
|
||||
time: string;
|
||||
frequency: string;
|
||||
}>;
|
||||
healthLogs?: Array<{
|
||||
id: string;
|
||||
appetite: string;
|
||||
energy: string;
|
||||
digestion: string;
|
||||
note?: string;
|
||||
loggedDate: string;
|
||||
createdAt: string;
|
||||
}>;
|
||||
prescriptions?: Array<{
|
||||
id: string;
|
||||
status: string;
|
||||
notes?: string;
|
||||
adminNotes?: string;
|
||||
createdAt: string;
|
||||
}>;
|
||||
ownerName?: string;
|
||||
createdAt?: string;
|
||||
}
|
||||
@@ -36,6 +59,7 @@ export default function Pets() {
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const limit = 10;
|
||||
|
||||
const [selectedPetForView, setSelectedPetForView] = useState<Pet | null>(null);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
|
||||
const fetchPets = useCallback(async () => {
|
||||
@@ -75,74 +99,105 @@ export default function Pets() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-6 font-vazir text-right" dir="rtl">
|
||||
<div className="flex flex-col sm:flex-row justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
|
||||
<Heart className="w-6 h-6 text-purple-600 fill-purple-100" />
|
||||
حیوانات خانگی کاربران (Pets)
|
||||
</h2>
|
||||
<p className="text-gray-500 font-medium mt-1">مشاهده و مدیریت پروفایل حیوانات خانگی ثبت شده توسط کاربران</p>
|
||||
<p className="text-gray-500 font-medium mt-1">مشاهده و پایش آنلاین سلامت، یادآورها، گزارشها و نسخههای پزشکی پتها</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white p-4 rounded-2xl shadow-sm border border-gray-200 flex flex-col sm:flex-row gap-4">
|
||||
<div className="bg-white p-4 rounded-2xl shadow-xs border border-gray-200 flex flex-col sm:flex-row gap-4">
|
||||
<div className="relative flex-1">
|
||||
<Search className="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="جستجو در نام حیوان..."
|
||||
placeholder="جستجو در نام همدم..."
|
||||
value={search}
|
||||
onChange={(e) => { setSearch(e.target.value); setPage(1); }}
|
||||
className="w-full pl-4 pr-12 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none transition-all"
|
||||
className="w-full pl-4 pr-12 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none transition-all text-xs font-bold"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
|
||||
<div className="bg-white rounded-2xl shadow-xs border border-gray-200 overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-right">
|
||||
<thead className="bg-gray-50 border-b border-gray-100">
|
||||
<tr>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">تصویر</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">نام و نژاد</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">صاحب حیوان</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">مشخصات فیزیکی</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500 w-24">عملیات</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">تصویر</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">نام و نژاد</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">صاحب حیوان</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">مشخصات فیزیکی</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">سوابق سلامت</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500 w-28">عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{isLoading ? (
|
||||
<tr><td colSpan={5} className="py-12 text-center"><Spinner size="lg" className="mx-auto text-purple-600" /></td></tr>
|
||||
<tr><td colSpan={6} className="py-12 text-center"><Spinner size="lg" className="mx-auto text-purple-600" /></td></tr>
|
||||
) : pets.length === 0 ? (
|
||||
<tr><td colSpan={5} className="py-12 text-center text-gray-500 font-medium">هیچ حیوانی یافت نشد</td></tr>
|
||||
<tr><td colSpan={6} className="py-12 text-center text-gray-500 font-medium">هیچ حیوانی یافت نشد</td></tr>
|
||||
) : (
|
||||
pets.map((pet) => (
|
||||
<tr key={pet.id} className="hover:bg-gray-50/50 transition-colors">
|
||||
<td className="py-3 px-6">
|
||||
{pet.imageUrl ? (
|
||||
<img src={pet.imageUrl.startsWith('http') ? pet.imageUrl : `${BASE_DOMAIN}${pet.imageUrl}`} alt={pet.name} className="w-12 h-12 rounded-full object-cover border-2 border-purple-100" />
|
||||
<img src={pet.imageUrl.startsWith('http') ? pet.imageUrl : `${BASE_DOMAIN}${pet.imageUrl}`} alt={pet.name} className="w-12 h-12 rounded-2xl object-cover border-2 border-purple-100 shadow-xs" />
|
||||
) : (
|
||||
<div className="w-12 h-12 rounded-full bg-purple-50 flex items-center justify-center text-purple-300 border-2 border-purple-100">
|
||||
<ImageIcon className="w-5 h-5" />
|
||||
<div className="w-12 h-12 rounded-2xl bg-purple-50 flex items-center justify-center text-purple-400 border border-purple-100">
|
||||
{pet.type === 'گربه' ? <Cat className="w-6 h-6" /> : <Dog className="w-6 h-6" />}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<div className="font-bold text-gray-900">{pet.name} <span className="text-xs px-2 py-0.5 bg-gray-100 text-gray-600 rounded-lg">{pet.type}</span></div>
|
||||
<div className="text-gray-500 text-sm">{pet.breed}</div>
|
||||
<div className="font-black text-gray-900 flex items-center gap-1.5">
|
||||
<span>{pet.name}</span>
|
||||
<span className="text-[10px] px-2 py-0.5 bg-purple-50 text-purple-700 rounded-md font-bold">{pet.type || 'سگ'}</span>
|
||||
</div>
|
||||
<div className="text-gray-500 text-xs mt-0.5">{pet.breed || 'نژاد نامشخص'}</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<div className="font-bold text-gray-700">{pet.user?.firstName} {pet.user?.lastName}</div>
|
||||
<div className="text-gray-500 text-xs font-mono">{pet.user?.mobile || pet.user?.email}</div>
|
||||
<div className="font-bold text-gray-800 text-xs">{pet.user?.firstName || ''} {pet.user?.lastName || ''}</div>
|
||||
<div className="text-gray-400 text-[11px] font-mono mt-0.5">{pet.user?.mobile || pet.user?.email || '-'}</div>
|
||||
</td>
|
||||
<td className="py-4 px-6 text-gray-600 text-sm">
|
||||
{pet.age} ساله، {pet.weight} کیلوگرم<br />
|
||||
<span className="text-xs text-gray-400">تحرک: {pet.activityLevel}</span>
|
||||
<td className="py-4 px-6 text-gray-600 text-xs">
|
||||
{pet.age ? `${pet.age} ساله` : 'سن نامشخص'}، {pet.weight ? `${pet.weight} کیلوگرم` : 'وزن نامشخص'}<br />
|
||||
<span className="text-[11px] text-gray-400 font-medium">تحرک: {pet.activityLevel || 'متوسط'}</span>
|
||||
</td>
|
||||
<td className="py-4 px-6 text-xs">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[11px] text-gray-600 font-bold">
|
||||
{pet.reminders?.length || 0} یادآور • {pet.healthLogs?.length || 0} گزارش
|
||||
</span>
|
||||
{pet.prescriptions && pet.prescriptions.length > 0 && (
|
||||
<span className="text-[10px] text-purple-700 font-bold">
|
||||
{pet.prescriptions.length} نسخه پزشکی ثبت شده
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<div className="flex items-center gap-2">
|
||||
<button onClick={() => setDeleteTargetId(pet.id)} className="p-2 text-red-600 hover:bg-red-50 rounded-lg transition-colors"><Trash2 className="w-4 h-4" /></button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPetForView(pet)}
|
||||
className="p-2 text-purple-600 hover:bg-purple-50 rounded-xl transition-colors cursor-pointer"
|
||||
title="مشاهده پرونده کامل سلامت"
|
||||
>
|
||||
<Eye className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDeleteTargetId(pet.id)}
|
||||
className="p-2 text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer"
|
||||
title="حذف پت"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -158,6 +213,135 @@ export default function Pets() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Pet Medical Dossier Details Modal */}
|
||||
{selectedPetForView && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-xs font-vazir" dir="rtl">
|
||||
<div className="bg-white rounded-3xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl border border-gray-100 flex flex-col">
|
||||
<div className="px-6 py-4 border-b border-gray-100 flex items-center justify-between sticky top-0 bg-white z-10">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-purple-100 text-purple-700 flex items-center justify-center font-black">
|
||||
{selectedPetForView.type === 'گربه' ? <Cat className="w-5 h-5" /> : <Dog className="w-5 h-5" />}
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-gray-900">پرونده پزشکی و پایش سلامت: {selectedPetForView.name}</h3>
|
||||
<p className="text-xs text-gray-400 font-mono">شناسه: {selectedPetForView.id}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPetForView(null)}
|
||||
className="p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="p-6 space-y-6">
|
||||
{/* Pet Info Banner */}
|
||||
<div className="p-4 bg-purple-50/60 rounded-2xl border border-purple-100 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 text-xs">
|
||||
<div>
|
||||
<div className="font-black text-gray-900 text-sm">{selectedPetForView.name} ({selectedPetForView.breed || selectedPetForView.type})</div>
|
||||
<div className="text-gray-600 mt-1">
|
||||
سرپرست: {selectedPetForView.user?.firstName} {selectedPetForView.user?.lastName} | همراه: <span className="font-mono">{selectedPetForView.user?.mobile || '-'}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-purple-900 font-bold bg-white px-3 py-1.5 rounded-xl border border-purple-200">
|
||||
{selectedPetForView.age} سال | {selectedPetForView.weight} کیلوگرم | تحرک {selectedPetForView.activityLevel || 'متوسط'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Medical Conditions */}
|
||||
<div>
|
||||
<h4 className="text-xs font-black text-gray-900 flex items-center gap-2 mb-2">
|
||||
<ShieldCheck className="w-4 h-4 text-purple-600" />
|
||||
سوابق و حساسیتهای پزشکی (Medical Conditions)
|
||||
</h4>
|
||||
{selectedPetForView.medicalConditions && selectedPetForView.medicalConditions.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{selectedPetForView.medicalConditions.map((mc, idx) => (
|
||||
<span key={idx} className="px-3 py-1 bg-gray-100 text-gray-800 text-xs font-bold rounded-xl border border-gray-200">
|
||||
{mc.condition}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-400">مورد پزشکی خاصی ثبت نشده است.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Active Reminders */}
|
||||
<div>
|
||||
<h4 className="text-xs font-black text-gray-900 flex items-center gap-2 mb-2">
|
||||
<Clock className="w-4 h-4 text-purple-600" />
|
||||
یادآورهای فعال (Reminders)
|
||||
</h4>
|
||||
{selectedPetForView.reminders && selectedPetForView.reminders.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{selectedPetForView.reminders.map((rem) => (
|
||||
<div key={rem.id} className="p-3 bg-gray-50 rounded-xl border border-gray-200 flex items-center justify-between text-xs">
|
||||
<span className="font-bold text-gray-800">{rem.title}</span>
|
||||
<span className="text-purple-700 font-mono font-bold bg-white px-2 py-0.5 rounded-md border border-purple-100">
|
||||
ساعت {rem.time} ({rem.frequency})
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-400">یادآوری فعالی ثبت نشده است.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Health Logs */}
|
||||
<div>
|
||||
<h4 className="text-xs font-black text-gray-900 flex items-center gap-2 mb-2">
|
||||
<Activity className="w-4 h-4 text-purple-600" />
|
||||
آخرین گزارشات روزانه سلامت (Health Logs)
|
||||
</h4>
|
||||
{selectedPetForView.healthLogs && selectedPetForView.healthLogs.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{selectedPetForView.healthLogs.map((log) => (
|
||||
<div key={log.id} className="p-3 bg-gray-50 rounded-xl border border-gray-200 text-xs space-y-1">
|
||||
<div className="flex items-center justify-between text-gray-500 font-bold">
|
||||
<span>تاریخ: {new Date(log.loggedDate || log.createdAt).toLocaleDateString('fa-IR')}</span>
|
||||
<span className="text-gray-700 font-black">اشتها: {log.appetite} | انرژی: {log.energy} | گوارش: {log.digestion}</span>
|
||||
</div>
|
||||
{log.note && <p className="text-gray-700 font-medium">{log.note}</p>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-400">گزارش سلامتی ثبت نشده است.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Prescriptions */}
|
||||
<div>
|
||||
<h4 className="text-xs font-black text-gray-900 flex items-center gap-2 mb-2">
|
||||
<FileText className="w-4 h-4 text-purple-600" />
|
||||
نسخههای پزشکی این همدم (Prescriptions)
|
||||
</h4>
|
||||
{selectedPetForView.prescriptions && selectedPetForView.prescriptions.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{selectedPetForView.prescriptions.map((rx) => (
|
||||
<div key={rx.id} className="p-3 bg-purple-50/50 rounded-xl border border-purple-100 text-xs space-y-1">
|
||||
<div className="flex items-center justify-between font-bold">
|
||||
<span className="font-mono">نسخه #{rx.id.slice(0, 8)}</span>
|
||||
<span className="text-purple-700 font-black">{rx.status}</span>
|
||||
</div>
|
||||
{rx.notes && <p className="text-gray-600">یادداشت کاربر: {rx.notes}</p>}
|
||||
{rx.adminNotes && <p className="text-purple-900 font-bold">دستور پزشک: {rx.adminNotes}</p>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-400">نسخهای برای این پت ثبت نشده است.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConfirmModal
|
||||
isOpen={!!deleteTargetId}
|
||||
title="حذف حیوان خانگی"
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { FileText, Eye, CheckCircle2, XCircle, Clock, Filter, X, ExternalLink } from 'lucide-react';
|
||||
import { FileText, Eye, CheckCircle2, XCircle, Clock, Filter, X, ExternalLink, Plus, Package, Phone, User, Dog, Cat } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api, { BASE_DOMAIN } from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import ImagePreviewModal from '../components/ui/ImagePreviewModal';
|
||||
import Badge from '../components/ui/Badge';
|
||||
import type { Prescription } from '../types/admin';
|
||||
|
||||
interface ProductItem {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
slug?: string;
|
||||
image?: string;
|
||||
}
|
||||
|
||||
export default function PrescriptionsManager() {
|
||||
const [prescriptions, setPrescriptions] = useState<Prescription[]>([]);
|
||||
const [products, setProducts] = useState<ProductItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [statusFilter, setStatusFilter] = useState<string>('ALL');
|
||||
|
||||
// Review Modal State
|
||||
const [selectedRx, setSelectedRx] = useState<Prescription | null>(null);
|
||||
const [reviewStatus, setReviewStatus] = useState<'APPROVED' | 'REJECTED'>('APPROVED');
|
||||
const [reviewStatus, setReviewStatus] = useState<'APPROVED' | 'REJECTED' | 'PENDING'>('APPROVED');
|
||||
const [adminNotes, setAdminNotes] = useState('');
|
||||
const [selectedProductIds, setSelectedProductIds] = useState<string[]>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [previewImageUrl, setPreviewImageUrl] = useState<string | null>(null);
|
||||
|
||||
const fetchPrescriptions = async () => {
|
||||
try {
|
||||
@@ -31,15 +44,21 @@ export default function PrescriptionsManager() {
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
api.get('/prescriptions')
|
||||
.then(res => {
|
||||
Promise.all([
|
||||
api.get('/prescriptions'),
|
||||
api.get('/products?limit=100').catch(() => ({ data: { data: [] } }))
|
||||
])
|
||||
.then(([rxRes, prodRes]) => {
|
||||
if (!isMounted) return;
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setPrescriptions(data);
|
||||
const rxData = Array.isArray(rxRes.data) ? rxRes.data : (rxRes.data?.data || []);
|
||||
setPrescriptions(rxData);
|
||||
|
||||
const prodData = Array.isArray(prodRes.data) ? prodRes.data : (prodRes.data?.data || []);
|
||||
setProducts(prodData);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Failed to fetch prescriptions:', err);
|
||||
toast.error('خطا در دریافت لیست نسخههای پزشکی');
|
||||
console.error('Failed to load prescriptions or products:', err);
|
||||
toast.error('خطا در بارگذاری اطلاعات');
|
||||
})
|
||||
.finally(() => {
|
||||
if (isMounted) setIsLoading(false);
|
||||
@@ -52,7 +71,21 @@ export default function PrescriptionsManager() {
|
||||
const openReviewModal = (rx: Prescription) => {
|
||||
setSelectedRx(rx);
|
||||
setReviewStatus(rx.status === 'REJECTED' ? 'REJECTED' : 'APPROVED');
|
||||
setAdminNotes(rx.adminNotes || '');
|
||||
|
||||
// Parse existing admin notes and product attachments if stored as JSON or text
|
||||
let existingNotes = rx.adminNotes || '';
|
||||
let existingProductIds: string[] = [];
|
||||
if (existingNotes.includes('__PRESCRIBED_PRODUCTS__:')) {
|
||||
const parts = existingNotes.split('__PRESCRIBED_PRODUCTS__:');
|
||||
existingNotes = parts[0].trim();
|
||||
try {
|
||||
existingProductIds = JSON.parse(parts[1]);
|
||||
} catch {
|
||||
existingProductIds = [];
|
||||
}
|
||||
}
|
||||
setAdminNotes(existingNotes);
|
||||
setSelectedProductIds(existingProductIds);
|
||||
};
|
||||
|
||||
const handleReviewSubmit = async (e: React.FormEvent) => {
|
||||
@@ -61,12 +94,18 @@ export default function PrescriptionsManager() {
|
||||
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
|
||||
let finalAdminNotes = adminNotes.trim();
|
||||
if (selectedProductIds.length > 0) {
|
||||
finalAdminNotes += `\n__PRESCRIBED_PRODUCTS__:${JSON.stringify(selectedProductIds)}`;
|
||||
}
|
||||
|
||||
await api.patch(`/prescriptions/${selectedRx.id}/review`, {
|
||||
status: reviewStatus,
|
||||
adminNotes: adminNotes.trim() || undefined,
|
||||
adminNotes: finalAdminNotes || undefined,
|
||||
});
|
||||
|
||||
toast.success(`نسخه پزشکی با موفقیت ${reviewStatus === 'APPROVED' ? 'تایید' : 'رد'} شد`);
|
||||
toast.success(`نسخه پزشکی با موفقیت ${reviewStatus === 'APPROVED' ? 'تایید و پیامک ارسال' : 'بررسی'} شد`);
|
||||
setSelectedRx(null);
|
||||
fetchPrescriptions();
|
||||
} catch (err) {
|
||||
@@ -89,18 +128,20 @@ export default function PrescriptionsManager() {
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-6 font-vazir text-right" dir="rtl">
|
||||
<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">
|
||||
<FileText className="w-6 h-6 text-purple-600" />
|
||||
داشبورد بررسی نسخههای پزشکی (Prescriptions)
|
||||
</h2>
|
||||
<p className="text-gray-500 font-medium mt-1">بررسی آنلاین نسخههای ارسال شده توسط کاربران و تایید دستور مصرف</p>
|
||||
<p className="text-gray-500 font-medium mt-1">
|
||||
بررسی تخصصی نسخههای ارسال شده، تجویز مکملهای مناسب کنینا و ارسال پیامک خودکار به کاربر
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Status Filters */}
|
||||
<div className="flex items-center gap-2 bg-white p-1.5 rounded-2xl border border-gray-200 shadow-sm">
|
||||
<div className="flex items-center gap-2 bg-white p-1.5 rounded-2xl border border-gray-200 shadow-xs">
|
||||
<Filter className="w-4 h-4 text-gray-400 mr-2" />
|
||||
{[
|
||||
{ id: 'ALL', label: 'همه' },
|
||||
@@ -111,9 +152,9 @@ export default function PrescriptionsManager() {
|
||||
<button
|
||||
key={f.id}
|
||||
onClick={() => setStatusFilter(f.id)}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all ${
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${
|
||||
statusFilter === f.id
|
||||
? 'bg-purple-600 text-white shadow-sm'
|
||||
? 'bg-purple-600 text-white shadow-xs'
|
||||
: 'text-gray-600 hover:bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
@@ -123,17 +164,17 @@ export default function PrescriptionsManager() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
|
||||
<div className="bg-white rounded-2xl shadow-xs border border-gray-200 overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-right">
|
||||
<thead className="bg-gray-50 border-b border-gray-100">
|
||||
<tr>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">شناسه / تاریخ</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">کاربر / حیوان خانگی</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">فایل نسخه</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">یادداشت کاربر</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500">وضعیت</th>
|
||||
<th className="py-4 px-6 text-sm font-bold text-gray-500 w-28">عملیات</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">تاریخ / شناسه</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">مشخصات سرپرست و همدم</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">فایل نسخه</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">توضیحات کاربر</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500">وضعیت</th>
|
||||
<th className="py-4 px-6 text-xs font-black text-gray-500 w-32">عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
@@ -148,62 +189,70 @@ export default function PrescriptionsManager() {
|
||||
<td colSpan={6} className="py-12 text-center text-gray-500 font-medium">هیچ نسخهای با این فیلتر یافت نشد</td>
|
||||
</tr>
|
||||
) : (
|
||||
filteredPrescriptions.map((rx) => (
|
||||
<tr key={rx.id} className="hover:bg-gray-50/50 transition-colors">
|
||||
<td className="py-4 px-6">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-mono text-xs font-bold text-gray-800">{rx.id.slice(0, 8)}...</span>
|
||||
<span className="text-[11px] text-gray-400 mt-0.5">
|
||||
{rx.createdAt ? new Date(rx.createdAt).toLocaleDateString('fa-IR') : '-'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-mono text-xs text-gray-600">User ID: {rx.userId.slice(0, 8)}</span>
|
||||
{rx.petId && <span className="text-xs text-purple-600 font-medium">Pet ID: {rx.petId.slice(0, 8)}</span>}
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<a
|
||||
href={getFileFullUrl(rx.fileUrl)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1 bg-purple-50 text-purple-700 text-xs font-bold rounded-lg border border-purple-100 hover:bg-purple-100 transition-colors"
|
||||
>
|
||||
<Eye className="w-3.5 h-3.5" />
|
||||
مشاهده فایل نسخه
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
</td>
|
||||
<td className="py-4 px-6 text-gray-600 text-xs max-w-xs line-clamp-2">
|
||||
{rx.notes || '-'}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{rx.status === 'APPROVED' ? (
|
||||
<span className="inline-flex items-center gap-1 px-2.5 py-1 bg-green-50 text-green-700 text-xs font-bold rounded-full border border-green-200">
|
||||
<CheckCircle2 className="w-3.5 h-3.5" /> تایید شده
|
||||
</span>
|
||||
) : rx.status === 'REJECTED' ? (
|
||||
<span className="inline-flex items-center gap-1 px-2.5 py-1 bg-red-50 text-red-700 text-xs font-bold rounded-full border border-red-200">
|
||||
<XCircle className="w-3.5 h-3.5" /> رد شده
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1 px-2.5 py-1 bg-amber-50 text-amber-700 text-xs font-bold rounded-full border border-amber-200">
|
||||
<Clock className="w-3.5 h-3.5" /> در انتظار بررسی
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<button
|
||||
onClick={() => openReviewModal(rx)}
|
||||
className="px-3 py-1.5 bg-purple-600 text-white hover:bg-purple-700 rounded-lg text-xs font-bold transition-all shadow-sm"
|
||||
>
|
||||
بررسی / تغییر وضعیت
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
filteredPrescriptions.map((rx: any) => {
|
||||
const fullFile = getFileFullUrl(rx.fileUrl);
|
||||
return (
|
||||
<tr key={rx.id} className="hover:bg-gray-50/50 transition-colors">
|
||||
<td className="py-4 px-6">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-mono text-xs font-bold text-gray-800">{rx.id.slice(0, 8)}...</span>
|
||||
<span className="text-[11px] text-gray-400 mt-0.5">
|
||||
{rx.createdAt ? new Date(rx.createdAt).toLocaleDateString('fa-IR') : '-'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<div className="flex items-center gap-1.5 text-xs font-bold text-gray-900">
|
||||
<User className="w-3.5 h-3.5 text-gray-400" />
|
||||
<span>{rx.user ? `${rx.user.firstName || ''} ${rx.user.lastName || ''}`.trim() || rx.user.mobile : 'کاربر مهمان'}</span>
|
||||
</div>
|
||||
{rx.user?.mobile && (
|
||||
<span className="text-[11px] font-mono text-gray-500">{rx.user.mobile}</span>
|
||||
)}
|
||||
{rx.pet ? (
|
||||
<div className="flex items-center gap-1 text-[11px] text-purple-700 font-bold mt-1">
|
||||
{rx.pet.type === 'گربه' ? <Cat className="w-3 h-3" /> : <Dog className="w-3 h-3" />}
|
||||
<span>{rx.pet.name} ({rx.pet.breed || rx.pet.type})</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-[10px] text-gray-400">بدون نام پت</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPreviewImageUrl(fullFile)}
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-purple-50 text-purple-700 text-xs font-bold rounded-xl border border-purple-100 hover:bg-purple-100 transition-colors cursor-pointer"
|
||||
>
|
||||
<Eye className="w-3.5 h-3.5" />
|
||||
مشاهده تصویر نسخه
|
||||
</button>
|
||||
</td>
|
||||
<td className="py-4 px-6 text-gray-600 text-xs max-w-xs line-clamp-2">
|
||||
{rx.notes || '-'}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{rx.status === 'APPROVED' ? (
|
||||
<Badge variant="success" icon={<CheckCircle2 className="w-3.5 h-3.5" />}>تایید شده</Badge>
|
||||
) : rx.status === 'REJECTED' ? (
|
||||
<Badge variant="danger" icon={<XCircle className="w-3.5 h-3.5" />}>رد شده</Badge>
|
||||
) : (
|
||||
<Badge variant="warning" icon={<Clock className="w-3.5 h-3.5" />}>در انتظار بررسی</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
<button
|
||||
onClick={() => openReviewModal(rx)}
|
||||
className="px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white rounded-xl text-xs font-bold transition-all shadow-xs cursor-pointer"
|
||||
>
|
||||
بررسی و تجویز
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -212,75 +261,122 @@ export default function PrescriptionsManager() {
|
||||
|
||||
{/* Review Modal */}
|
||||
{selectedRx && (
|
||||
<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-lg shadow-2xl overflow-hidden animate-in zoom-in duration-200">
|
||||
<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">
|
||||
بررسی نسخه پزشکی ({selectedRx.id.slice(0, 8)})
|
||||
</h3>
|
||||
<button onClick={() => setSelectedRx(null)} className="text-gray-400 hover:text-red-500 transition-colors">
|
||||
<X className="w-6 h-6" />
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-xs font-vazir" dir="rtl">
|
||||
<div className="bg-white rounded-3xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl border border-gray-100 flex flex-col">
|
||||
<div className="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-gray-50/50 sticky top-0 bg-white z-10">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-purple-100 text-purple-600 flex items-center justify-center">
|
||||
<FileText className="w-5 h-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-bold text-gray-900">بررسی و ثبت نظر تخصصی نسخه</h3>
|
||||
<p className="text-xs text-gray-500">کد نسخه: {selectedRx.id}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setSelectedRx(null)}
|
||||
className="p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleReviewSubmit} className="p-6 space-y-4">
|
||||
<div className="p-4 bg-purple-50/50 rounded-xl border border-purple-100 space-y-2 text-xs">
|
||||
<div className="flex justify-between">
|
||||
<span className="font-bold text-gray-600">فایل نسخه:</span>
|
||||
<a
|
||||
href={getFileFullUrl(selectedRx.fileUrl)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-purple-600 font-bold underline flex items-center gap-1"
|
||||
>
|
||||
باز کردن در پنجره جدید <ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
<form onSubmit={handleReviewSubmit} className="p-6 space-y-5">
|
||||
{/* Pet & User Details Card */}
|
||||
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-200 text-xs space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-bold text-gray-700">سرپرست: {(selectedRx as any).user ? `${(selectedRx as any).user.firstName || ''} ${(selectedRx as any).user.lastName || ''}`.trim() || (selectedRx as any).user.mobile : 'کاربر مهمان'}</span>
|
||||
<span className="font-mono text-gray-600">{(selectedRx as any).user?.mobile || '-'}</span>
|
||||
</div>
|
||||
{(selectedRx as any).pet && (
|
||||
<div className="pt-2 border-t border-gray-200 flex items-center justify-between text-purple-900 font-bold">
|
||||
<span>همدم: {(selectedRx as any).pet.name} ({(selectedRx as any).pet.type} - {(selectedRx as any).pet.breed})</span>
|
||||
<span>وزن: {(selectedRx as any).pet.weight} kg | سن: {(selectedRx as any).pet.age} سال</span>
|
||||
</div>
|
||||
)}
|
||||
{selectedRx.notes && (
|
||||
<div>
|
||||
<span className="font-bold text-gray-600">یادداشت کاربر: </span>
|
||||
<span className="text-gray-800">{selectedRx.notes}</span>
|
||||
<div className="pt-2 border-t border-gray-200 text-gray-700">
|
||||
<strong className="block mb-0.5 text-gray-900">یادداشت کاربر:</strong>
|
||||
{selectedRx.notes}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Status Selector */}
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-2">تغییر وضعیت بررسی *</label>
|
||||
<label className="block text-xs font-black text-gray-700 mb-2">تغییر وضعیت نسخه *</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setReviewStatus('APPROVED')}
|
||||
className={`py-3 px-4 rounded-xl border font-bold text-xs flex items-center justify-center gap-2 transition-all ${
|
||||
className={`py-3 px-4 rounded-xl border font-bold text-xs flex items-center justify-center gap-2 transition-all cursor-pointer ${
|
||||
reviewStatus === 'APPROVED'
|
||||
? 'border-green-500 bg-green-50 text-green-700 shadow-sm'
|
||||
? 'border-green-500 bg-green-50 text-green-700 shadow-xs font-black'
|
||||
: 'border-gray-200 text-gray-600 hover:bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
<CheckCircle2 className="w-4 h-4" /> تایید نسخه (APPROVED)
|
||||
<CheckCircle2 className="w-4 h-4" /> تایید و ثبت تجویز (APPROVED)
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setReviewStatus('REJECTED')}
|
||||
className={`py-3 px-4 rounded-xl border font-bold text-xs flex items-center justify-center gap-2 transition-all ${
|
||||
className={`py-3 px-4 rounded-xl border font-bold text-xs flex items-center justify-center gap-2 transition-all cursor-pointer ${
|
||||
reviewStatus === 'REJECTED'
|
||||
? 'border-red-500 bg-red-50 text-red-700 shadow-sm'
|
||||
? 'border-red-500 bg-red-50 text-red-700 shadow-xs font-black'
|
||||
: 'border-gray-200 text-gray-600 hover:bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
<XCircle className="w-4 h-4" /> عدم تایید / رد (REJECTED)
|
||||
<XCircle className="w-4 h-4" /> عدم تایید / رد نسخه (REJECTED)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Prescribed Products Selector */}
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1">یادداشت کارشناس ادمین (adminNotes)</label>
|
||||
<label className="block text-xs font-black text-gray-700 mb-1 flex items-center justify-between">
|
||||
<span>محصولات و مکملهای تجویزی پزشک (جهت خرید آسان کاربر)</span>
|
||||
<span className="text-[10px] text-gray-400 font-normal">{selectedProductIds.length} محصول انتخاب شده</span>
|
||||
</label>
|
||||
<div className="max-h-40 overflow-y-auto border border-gray-200 rounded-xl p-2 space-y-1 bg-white">
|
||||
{products.map(p => {
|
||||
const isSelected = selectedProductIds.includes(p.id);
|
||||
return (
|
||||
<div
|
||||
key={p.id}
|
||||
onClick={() => {
|
||||
setSelectedProductIds(prev =>
|
||||
isSelected ? prev.filter(id => id !== p.id) : [...prev, p.id]
|
||||
);
|
||||
}}
|
||||
className={`p-2 rounded-lg text-xs font-bold flex items-center justify-between cursor-pointer transition-colors ${
|
||||
isSelected ? 'bg-purple-100 text-purple-900' : 'hover:bg-gray-50 text-gray-700'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-2 truncate">
|
||||
<Package className="w-3.5 h-3.5 shrink-0 text-purple-600" />
|
||||
<span className="truncate">{p.name}</span>
|
||||
</div>
|
||||
<span className="text-[11px] font-mono text-gray-500 shrink-0">
|
||||
{p.price ? `${p.price.toLocaleString('fa-IR')} تومان` : ''}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Doctor / Admin Clinical Note */}
|
||||
<div>
|
||||
<label className="block text-xs font-black text-gray-700 mb-1">
|
||||
توضیحات و دستور مصرف داروها برای بیمار (پیام به کاربر)
|
||||
</label>
|
||||
<textarea
|
||||
rows={4}
|
||||
rows={3}
|
||||
value={adminNotes}
|
||||
onChange={(e) => setAdminNotes(e.target.value)}
|
||||
placeholder="مثال: نسخه تایید شد. دوز مصرفی مطابق دستور پزشک است."
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm"
|
||||
placeholder="مثال: نسخه تایید شد. مکمل کانین ایمون روزانه ۱ قرص به همراه وعده غذایی مصرف شود."
|
||||
className="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs leading-relaxed"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -288,23 +384,31 @@ export default function PrescriptionsManager() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedRx(null)}
|
||||
className="px-5 py-2.5 rounded-xl border border-gray-200 text-gray-600 font-bold hover:bg-gray-50 transition-colors"
|
||||
className="px-5 py-2.5 rounded-xl border border-gray-200 text-gray-600 text-xs font-bold hover:bg-gray-50 transition-colors cursor-pointer"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="px-6 py-2.5 rounded-xl bg-purple-600 text-white font-bold hover:bg-purple-700 transition-colors shadow-md shadow-purple-200 flex items-center gap-2"
|
||||
className="px-6 py-2.5 rounded-xl bg-purple-600 text-white text-xs font-bold hover:bg-purple-700 transition-colors shadow-md shadow-purple-200 flex items-center gap-2 cursor-pointer"
|
||||
>
|
||||
{isSubmitting && <Spinner size="sm" />}
|
||||
ثبت وضعیت بررسی
|
||||
ثبت نهایی و ارسال پیامک
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Fullscreen Lightbox for Prescription Image */}
|
||||
<ImagePreviewModal
|
||||
isOpen={!!previewImageUrl}
|
||||
imageUrl={previewImageUrl || ''}
|
||||
onClose={() => setPreviewImageUrl(null)}
|
||||
title="تصویر نسخه پزشکی بیمار"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { Languages, Save, Search, Loader2, Layout, Sliders, Link as LinkIcon, FileText, Check, Upload, HelpCircle } from 'lucide-react';
|
||||
import { Languages, Save, Search, Loader2, Layout, Sliders, Link as LinkIcon, FileText, Check, Upload, HelpCircle, Eye } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import api, { BASE_DOMAIN } from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
import ToggleSwitch from '../components/ui/ToggleSwitch';
|
||||
import ImagePreviewModal from '../components/ui/ImagePreviewModal';
|
||||
|
||||
const PAGE_TABS = [
|
||||
{ id: 'all', label: 'همه بخشها', icon: Layout },
|
||||
@@ -205,7 +207,41 @@ export default function UITexts() {
|
||||
}
|
||||
};
|
||||
|
||||
const isImageKey = (key: string) => key.includes('image') || key.includes('url') || key.includes('photo');
|
||||
const isBoolKey = (key: string, val: string) => {
|
||||
return val === 'true' || val === 'false' || key.includes('mode') || key.includes('disable') || key.includes('hide') || key.includes('enable');
|
||||
};
|
||||
|
||||
const [previewModalUrl, setPreviewModalUrl] = useState<string | null>(null);
|
||||
const [isSavingAll, setIsSavingAll] = useState(false);
|
||||
|
||||
const handleSaveAll = async () => {
|
||||
const dirtyKeys = Object.keys(edits);
|
||||
if (dirtyKeys.length === 0) {
|
||||
toast.info('هیچ تغییری برای ذخیره وجود ندارد');
|
||||
return;
|
||||
}
|
||||
setIsSavingAll(true);
|
||||
try {
|
||||
await api.put('/settings/ui-texts', edits);
|
||||
setTexts(prev => ({ ...prev, ...edits }));
|
||||
setEdits({});
|
||||
toast.success(`${dirtyKeys.length} تغییر با موفقیت ذخیره شد`);
|
||||
} catch (e) {
|
||||
console.error('Failed to save all UI texts:', e);
|
||||
// Fallback sequential
|
||||
try {
|
||||
const promises = dirtyKeys.map(k => api.put(`/settings/ui-texts/${encodeURIComponent(k)}`, { value: edits[k] }));
|
||||
await Promise.all(promises);
|
||||
setTexts(prev => ({ ...prev, ...edits }));
|
||||
setEdits({});
|
||||
toast.success(`${dirtyKeys.length} تغییر با موفقیت ذخیره شد`);
|
||||
} catch (err) {
|
||||
toast.error('خطا در ذخیرهسازی گروهی تغییرات');
|
||||
}
|
||||
} finally {
|
||||
setIsSavingAll(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -215,6 +251,8 @@ export default function UITexts() {
|
||||
);
|
||||
}
|
||||
|
||||
const hasUnsavedChanges = Object.keys(edits).length > 0;
|
||||
|
||||
return (
|
||||
<div className="space-y-6 font-vazir text-right" dir="rtl">
|
||||
{/* Header */}
|
||||
@@ -228,6 +266,20 @@ export default function UITexts() {
|
||||
ویرایش زنده متون، تصاویر بنر، لینک دکمهها و عناوین تمام صفحات سایت کنینا
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={handleSaveAll}
|
||||
disabled={isSavingAll || !hasUnsavedChanges}
|
||||
className={`px-5 py-2.5 rounded-xl text-sm font-bold flex items-center gap-2 transition-all shadow-sm ${
|
||||
hasUnsavedChanges
|
||||
? 'bg-purple-600 hover:bg-purple-700 text-white shadow-purple-200 cursor-pointer animate-pulse'
|
||||
: 'bg-gray-100 text-gray-400 cursor-not-allowed'
|
||||
}`}
|
||||
>
|
||||
{isSavingAll ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
||||
<span>ذخیره تمامی تغییرات {hasUnsavedChanges ? `(${Object.keys(edits).length})` : ''}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Hidden File Input for Image Upload */}
|
||||
@@ -325,36 +377,58 @@ export default function UITexts() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
{val.length > 60 && !isImg ? (
|
||||
<div className="flex items-center gap-2">
|
||||
{isBoolKey(key, val) ? (
|
||||
<div className="flex-1 bg-white border border-gray-200 rounded-xl px-4 py-2.5 flex items-center justify-between">
|
||||
<span className="text-xs font-bold text-gray-700">
|
||||
وضعیت: {val === 'true' ? <strong className="text-green-600">فعال (روشن)</strong> : <strong className="text-gray-400">غیرفعال (خاموش)</strong>}
|
||||
</span>
|
||||
<ToggleSwitch
|
||||
checked={val === 'true'}
|
||||
onChange={(checked) => setEdits({ ...edits, [key]: String(checked) })}
|
||||
/>
|
||||
</div>
|
||||
) : val.length > 60 && !isImg ? (
|
||||
<textarea
|
||||
value={val}
|
||||
onChange={e => setEdits({ ...edits, [key]: e.target.value })}
|
||||
className="w-full bg-white border border-gray-200 rounded-xl p-3 text-xs font-bold text-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20 h-20"
|
||||
className="w-full bg-white border border-gray-200 rounded-xl p-3 text-xs font-bold text-gray-900 focus:outline-none focus:ring-2 focus:ring-purple-500/20 h-20"
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
type="text"
|
||||
value={val}
|
||||
onChange={e => setEdits({ ...edits, [key]: e.target.value })}
|
||||
className="w-full bg-white border border-gray-200 rounded-xl px-3 py-2.5 text-xs font-bold text-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
className="w-full bg-white border border-gray-200 rounded-xl px-3 py-2.5 text-xs font-bold text-gray-900 focus:outline-none focus:ring-2 focus:ring-purple-500/20"
|
||||
/>
|
||||
)}
|
||||
|
||||
{isImg && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isUploading}
|
||||
onClick={() => {
|
||||
currentKeyForUpload.current = key;
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
className="px-3 py-2.5 bg-purple-50 text-purple-700 border border-purple-200 rounded-xl text-xs font-black hover:bg-purple-100 transition-all shrink-0 flex items-center gap-1"
|
||||
title="آپلود تصویر"
|
||||
>
|
||||
<Upload className="w-3.5 h-3.5" />
|
||||
<span>{isUploading ? '...' : 'عکس'}</span>
|
||||
</button>
|
||||
<>
|
||||
{val && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPreviewModalUrl(val.startsWith('http') ? val : `${BASE_DOMAIN}${val}`)}
|
||||
className="p-2.5 bg-gray-100 text-gray-700 hover:bg-gray-200 rounded-xl text-xs font-bold transition-all shrink-0 flex items-center justify-center"
|
||||
title="پیشنمایش تصویر"
|
||||
>
|
||||
<Eye className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
disabled={isUploading}
|
||||
onClick={() => {
|
||||
currentKeyForUpload.current = key;
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
className="px-3 py-2.5 bg-purple-50 text-purple-700 border border-purple-200 rounded-xl text-xs font-black hover:bg-purple-100 transition-all shrink-0 flex items-center gap-1"
|
||||
title="آپلود تصویر"
|
||||
>
|
||||
<Upload className="w-3.5 h-3.5" />
|
||||
<span>{isUploading ? '...' : 'عکس'}</span>
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
<button
|
||||
@@ -378,6 +452,12 @@ export default function UITexts() {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<ImagePreviewModal
|
||||
isOpen={!!previewModalUrl}
|
||||
imageUrl={previewModalUrl || ''}
|
||||
onClose={() => setPreviewModalUrl(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user