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
@@ -10,21 +10,36 @@ interface TopbarProps {
|
||||
}
|
||||
|
||||
const SEARCHABLE_PAGES = [
|
||||
{ label: 'داشبورد (خلاصه وضعیت فروشگاه)', path: '/' },
|
||||
{ label: 'گزارشات کامل فروش و بازدیدها', path: '/reports' },
|
||||
{ label: 'مدیریت سفارشات مشتریان', path: '/orders' },
|
||||
{ label: 'مدیریت محصولات فروشگاه', path: '/products' },
|
||||
{ label: 'دستهبندیهای محصولات (Categories)', path: '/categories' },
|
||||
{ label: 'کدهای تخفیف و کوپنهای خرید', path: '/coupons' },
|
||||
{ label: 'مدیریت کاربران و مشتریان سایت', path: '/users' },
|
||||
{ label: 'مدیریت سگها و گربهها (Pets)', path: '/pets' },
|
||||
{ label: 'مدیریت مقالات وبلاگ', path: '/blogs' },
|
||||
{ label: 'مدیریت دانشنامه و مقالات علمی (Wiki)', path: '/wiki' },
|
||||
{ label: 'تنظیمات کلی سیستم و درگاه پرداخت', path: '/settings' },
|
||||
{ label: 'مدیریت گواهی امنیتی SSL و HTTPS', path: '/settings/ssl' },
|
||||
{ label: 'تنظیمات درگاه پیامک (MeliPayamak)', path: '/settings/sms' },
|
||||
{ label: 'متون رابط کاربری و ترجمهها', path: '/ui-texts' },
|
||||
{ label: 'مدیریت رسانه، عکسها و گالری', path: '/media' },
|
||||
{ label: 'داشبورد (خلاصه وضعیت فروشگاه)', path: '/', keywords: ['dashboard', 'آمار', 'فروش', 'خانه'] },
|
||||
{ label: 'مدیریت نسخههای پزشکی (Prescriptions)', path: '/prescriptions', keywords: ['نسخه', 'نسخهها', 'پزشک', 'دارو', 'تجویز', 'rx', 'prescription', 'بررسی نسخه'] },
|
||||
{ label: 'مدیریت سفارشات مشتریان', path: '/orders', keywords: ['سفارش', 'سفارشات', 'orders', 'خرید', 'فاکتور'] },
|
||||
{ label: 'تراکنشهای مالی و کیف پول', path: '/transactions', keywords: ['تراکنش', 'مالی', 'کیف پول', 'پرداخت', 'واریز', 'transactions'] },
|
||||
{ label: 'مدیریت محصولات فروشگاه', path: '/products', keywords: ['محصول', 'محصولات', 'کالا', 'مکمل', 'products', 'قیمت'] },
|
||||
{ label: 'دستهبندیهای محصولات (Categories)', path: '/categories', keywords: ['دسته', 'دستهبندی', 'categories', 'گروه'] },
|
||||
{ label: 'کدهای تخفیف و کوپنهای خرید', path: '/coupons', keywords: ['تخفیف', 'کوپن', 'کد تخفیف', 'coupons', 'آفر'] },
|
||||
{ label: 'مدیریت کاربران و مشتریان سایت', path: '/users', keywords: ['کاربر', 'کاربران', 'مشتری', 'users', 'پروفایل'] },
|
||||
{ label: 'مدیریت سگها و گربهها (پرونده پتها)', path: '/pets', keywords: ['پت', 'حیوان', 'سگ', 'گربه', 'شناسنامه', 'pets'] },
|
||||
{ label: 'درخواستهای همکاری سازمانی و B2B', path: '/b2b', keywords: ['b2b', 'همکاری', 'همکاران', 'عمده', 'پت شاپ', 'کلینیک'] },
|
||||
{ label: 'مشاور هوشمند تغذیه و درمان', path: '/smart-advisor', keywords: ['مشاور', 'هوشمند', 'تغذیه', 'درمان', 'advisor', 'علائم'] },
|
||||
{ label: 'نظرات و دیدگاههای مشتریان', path: '/reviews', keywords: ['نظرات', 'دیدگاه', 'کامنت', 'امتیاز', 'reviews'] },
|
||||
{ label: 'تیکتها و پشتیبانی', path: '/tickets', keywords: ['تیکت', 'پشتیبانی', 'پیام', 'tickets', 'چت'] },
|
||||
{ label: 'فرمهای تماس با ما', path: '/contact', keywords: ['تماس', 'پیام تماس', 'ارتباط', 'contact'] },
|
||||
{ label: 'مدیریت بنرهای تبلیغاتی و اسلایدر', path: '/banners', keywords: ['بنر', 'اسلایدر', 'تبلیغات', 'banners', 'هیرو'] },
|
||||
{ label: 'مدیریت مقالات وبلاگ', path: '/blogs', keywords: ['وبلاگ', 'مقاله', 'بلاگ', 'آموزش', 'blogs'] },
|
||||
{ label: 'مدیریت دانشنامه و مقالات علمی (Wiki)', path: '/wiki', keywords: ['ویکی', 'دانشنامه', 'علمی', 'پژوهش', 'wiki'] },
|
||||
{ label: 'مدیریت ویدیوها و فیلمهای آموزشی', path: '/videos', keywords: ['ویدیو', 'فیلم', 'کلیپ', 'آپارات', 'videos'] },
|
||||
{ label: 'مدیریت مواد تشکیلدهنده و ترکیبات', path: '/ingredients', keywords: ['مواد', 'ترکیبات', 'گیاهان', 'ingredients'] },
|
||||
{ label: 'مدیریت رضایتنامهها و تجربیات (Testimonials)', path: '/testimonials', keywords: ['رضایت', 'تجربه', 'داستان', 'testimonials'] },
|
||||
{ label: 'صفحات ایستا و CMS', path: '/cms', keywords: ['صفحات', 'قوانین', 'درباره ما', 'cms', 'تماس'] },
|
||||
{ label: 'مدیریت رسانه، عکسها و گالری', path: '/media', keywords: ['رسانه', 'عکس', 'تصویر', 'گالری', 'media', 'آپلود'] },
|
||||
{ label: 'گزارشات کامل فروش و بازدیدها', path: '/reports', keywords: ['گزارش', 'نمودار', 'آمار', 'تحلیل', 'reports'] },
|
||||
{ label: 'تنظیمات کلی سیستم و برند', path: '/settings', keywords: ['تنظیمات', 'لوگو', 'برند', 'settings', 'پیکربندی'] },
|
||||
{ label: 'تنظیمات مالی و ارسال', path: '/settings/financial', keywords: ['تنظیمات مالی', 'هزینه ارسال', 'ارسال رایگان', 'مالیات', 'خیریه'] },
|
||||
{ label: 'تنظیمات سیستمی و حالت تعمیرات', path: '/settings/system', keywords: ['حالت تعمیر', 'تعمیرات', 'سیستم', 'خرید مهمان', 'system'] },
|
||||
{ label: 'تنظیمات سئو (SEO) و متاتگها', path: '/settings/seo', keywords: ['سئو', 'موتور جستجو', 'گوگل', 'seo', 'متاتگ'] },
|
||||
{ label: 'تنظیمات درگاه پیامک (MeliPayamak)', path: '/settings/sms', keywords: ['پیامک', 'اس ام اس', 'سامانه پیامک', 'ملی پیامک', 'sms'] },
|
||||
{ label: 'مدیریت گواهی امنیتی SSL و HTTPS', path: '/settings/ssl', keywords: ['ssl', 'امنیت', 'https', 'گواهی'] },
|
||||
{ label: 'متون رابط کاربری و ترجمهها', path: '/ui-texts', keywords: ['متون', 'ترجمه', 'رابط کاربری', 'ui', 'texts'] },
|
||||
];
|
||||
|
||||
export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
@@ -45,9 +60,14 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
const filteredResults = SEARCHABLE_PAGES.filter(page =>
|
||||
page.label.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
const normalizedQuery = searchQuery.trim().toLowerCase();
|
||||
const filteredResults = normalizedQuery
|
||||
? SEARCHABLE_PAGES.filter(page =>
|
||||
page.label.toLowerCase().includes(normalizedQuery) ||
|
||||
page.path.toLowerCase().includes(normalizedQuery) ||
|
||||
page.keywords.some(k => k.toLowerCase().includes(normalizedQuery))
|
||||
)
|
||||
: [];
|
||||
|
||||
const handleResultClick = (path: string) => {
|
||||
navigate(path);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
|
||||
export type BadgeVariant = 'success' | 'warning' | 'danger' | 'info' | 'purple' | 'gray';
|
||||
|
||||
export interface BadgeProps {
|
||||
variant?: BadgeVariant;
|
||||
children: React.ReactNode;
|
||||
icon?: React.ReactNode;
|
||||
className?: string;
|
||||
size?: 'sm' | 'md';
|
||||
}
|
||||
|
||||
const variantStyles: Record<BadgeVariant, string> = {
|
||||
success: 'bg-emerald-50 text-emerald-700 border-emerald-200',
|
||||
warning: 'bg-amber-50 text-amber-700 border-amber-200',
|
||||
danger: 'bg-red-50 text-red-700 border-red-200',
|
||||
info: 'bg-sky-50 text-sky-700 border-sky-200',
|
||||
purple: 'bg-purple-50 text-purple-700 border-purple-200',
|
||||
gray: 'bg-gray-50 text-gray-700 border-gray-200',
|
||||
};
|
||||
|
||||
export default function Badge({
|
||||
variant = 'gray',
|
||||
children,
|
||||
icon,
|
||||
className = '',
|
||||
size = 'md',
|
||||
}: BadgeProps) {
|
||||
const sizeStyle = size === 'sm' ? 'px-2 py-0.5 text-[10px]' : 'px-2.5 py-1 text-xs';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 font-bold font-vazir rounded-full border shadow-xs ${variantStyles[variant]} ${sizeStyle} ${className}`}
|
||||
>
|
||||
{icon && <span className="shrink-0">{icon}</span>}
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import { HelpCircle } from 'lucide-react';
|
||||
|
||||
export interface FormFieldProps {
|
||||
label?: string;
|
||||
required?: boolean;
|
||||
helpText?: string;
|
||||
description?: string;
|
||||
error?: string;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export default function FormField({
|
||||
label,
|
||||
required,
|
||||
helpText,
|
||||
description,
|
||||
error,
|
||||
children,
|
||||
className = '',
|
||||
id,
|
||||
}: FormFieldProps) {
|
||||
return (
|
||||
<div className={`space-y-1.5 font-vazir ${className}`}>
|
||||
{label && (
|
||||
<div className="flex items-center justify-between">
|
||||
<label
|
||||
htmlFor={id}
|
||||
className="block text-xs font-bold text-gray-700 select-none flex items-center gap-1"
|
||||
>
|
||||
{label}
|
||||
{required && <span className="text-red-500 font-bold">*</span>}
|
||||
</label>
|
||||
{helpText && (
|
||||
<div className="group relative flex items-center">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 cursor-help hover:text-gray-600 transition-colors" />
|
||||
<div className="absolute left-0 bottom-full mb-1 hidden group-hover:block z-20 w-48 p-2 bg-gray-900 text-white text-[10px] rounded-lg shadow-lg">
|
||||
{helpText}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
{description && !error && (
|
||||
<p className="text-[11px] text-gray-500 font-normal leading-relaxed">{description}</p>
|
||||
)}
|
||||
{error && (
|
||||
<p className="text-xs text-red-500 font-medium flex items-center gap-1 animate-in fade-in duration-200">
|
||||
<span>•</span>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { X, ZoomIn, ZoomOut, Download, ExternalLink } from 'lucide-react';
|
||||
|
||||
export interface ImagePreviewModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
imageUrl: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export default function ImagePreviewModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
imageUrl,
|
||||
title,
|
||||
}: ImagePreviewModalProps) {
|
||||
const [zoom, setZoom] = React.useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
setZoom(1);
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||
}
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen || !imageUrl) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/80 backdrop-blur-sm animate-in fade-in duration-200 font-vazir"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="relative max-w-4xl max-h-[90vh] bg-gray-900 border border-gray-800 rounded-3xl overflow-hidden shadow-2xl flex flex-col"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-6 py-3.5 bg-gray-900/90 border-b border-gray-800 text-white">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-bold truncate max-w-xs">{title || 'پیشنمایش تصویر'}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => setZoom((z) => Math.min(z + 0.25, 2.5))}
|
||||
className="p-1.5 text-gray-400 hover:text-white hover:bg-gray-800 rounded-lg transition-colors"
|
||||
title="بزرگنمایی"
|
||||
>
|
||||
<ZoomIn className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setZoom((z) => Math.max(z - 0.25, 0.5))}
|
||||
className="p-1.5 text-gray-400 hover:text-white hover:bg-gray-800 rounded-lg transition-colors"
|
||||
title="کوچکنمایی"
|
||||
>
|
||||
<ZoomOut className="w-4 h-4" />
|
||||
</button>
|
||||
<a
|
||||
href={imageUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="p-1.5 text-gray-400 hover:text-white hover:bg-gray-800 rounded-lg transition-colors"
|
||||
title="مشاهده در تب جدید"
|
||||
>
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</a>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="p-1.5 text-gray-400 hover:text-red-400 hover:bg-gray-800 rounded-lg transition-colors mr-2"
|
||||
title="بستن (Esc)"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Container */}
|
||||
<div className="p-4 flex items-center justify-center overflow-auto max-h-[calc(90vh-60px)] min-h-[300px]">
|
||||
<img
|
||||
src={imageUrl}
|
||||
alt={title || 'Preview'}
|
||||
style={{ transform: `scale(${zoom})`, transition: 'transform 0.2s ease-out' }}
|
||||
className="max-w-full max-h-[70vh] object-contain rounded-xl shadow-lg select-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
error?: string;
|
||||
leftIcon?: React.ReactNode;
|
||||
rightIcon?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className = '', error, leftIcon, rightIcon, disabled, ...props }, ref) => {
|
||||
return (
|
||||
<div className="w-full relative">
|
||||
{rightIcon && (
|
||||
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
|
||||
{rightIcon}
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
ref={ref}
|
||||
disabled={disabled}
|
||||
className={`w-full bg-white border font-vazir text-sm transition-all duration-200 outline-none
|
||||
${error ? 'border-red-400 focus:border-red-500 focus:ring-2 focus:ring-red-500/20' : 'border-gray-200 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20'}
|
||||
${disabled ? 'bg-gray-50 text-gray-400 cursor-not-allowed border-gray-200' : 'text-gray-900 placeholder:text-gray-400 hover:border-gray-300'}
|
||||
${rightIcon ? 'pr-10' : 'pr-4'}
|
||||
${leftIcon ? 'pl-10' : 'pl-4'}
|
||||
py-2.5 rounded-xl shadow-xs ${className}`}
|
||||
{...props}
|
||||
/>
|
||||
{leftIcon && (
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
|
||||
{leftIcon}
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<p className="mt-1 text-xs text-red-500 font-medium font-vazir flex items-center gap-1 animate-in fade-in duration-200">
|
||||
<span>•</span>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Input.displayName = 'Input';
|
||||
export default Input;
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { X, Upload, Image as ImageIcon, Trash2, CheckCircle2, Clipboard } from 'lucide-react';
|
||||
import { X, Upload, Image as ImageIcon, Trash2, CheckCircle2, Clipboard, Eye } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api, { BASE_DOMAIN } from '../../services/api';
|
||||
import Spinner from './Spinner';
|
||||
import Pagination from './Pagination';
|
||||
import ConfirmModal from './ConfirmModal';
|
||||
import ImagePreviewModal from './ImagePreviewModal';
|
||||
|
||||
interface Media {
|
||||
id: string;
|
||||
@@ -31,6 +32,7 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const pasteTimerRef = useRef<ReturnType<typeof setTimeout>>(null);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
|
||||
const fetchMedia = useCallback(async () => {
|
||||
try {
|
||||
@@ -48,6 +50,7 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
let isSubscribed = true;
|
||||
setIsLoading(true);
|
||||
api.get('/admin/media').then(res => {
|
||||
if (!isSubscribed) return;
|
||||
if (res.data?.data) {
|
||||
@@ -116,20 +119,35 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
|
||||
const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (!e.target.files || e.target.files.length === 0) return;
|
||||
const file = e.target.files[0];
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const files = Array.from(e.target.files);
|
||||
|
||||
setIsUploading(true);
|
||||
let successCount = 0;
|
||||
|
||||
try {
|
||||
setIsUploading(true);
|
||||
await api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
const uploadPromises = 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(uploadPromises);
|
||||
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 = '';
|
||||
@@ -141,65 +159,67 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
try {
|
||||
await api.delete(`/admin/media/${deleteTargetId}`);
|
||||
toast.success('تصویر با موفقیت حذف شد');
|
||||
setMediaList(mediaList.filter(m => m.id !== deleteTargetId));
|
||||
setMediaList(prev => prev.filter(item => item.id !== deleteTargetId));
|
||||
} catch (error) {
|
||||
console.error('Delete failed', error);
|
||||
console.error('Failed to delete media:', error);
|
||||
toast.error('خطا در حذف تصویر');
|
||||
} finally {
|
||||
setDeleteTargetId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
|
||||
const handleDragOver = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragOver(true);
|
||||
};
|
||||
|
||||
const handleDragLeave = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragOver(false);
|
||||
};
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
|
||||
const handleDrop = async (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragOver(false);
|
||||
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file.type.startsWith('image/')) {
|
||||
setDragOver(false);
|
||||
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) return;
|
||||
|
||||
setIsUploading(true);
|
||||
let successCount = 0;
|
||||
try {
|
||||
const uploadPromises = files.map(async (file) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
try {
|
||||
setIsUploading(true);
|
||||
await api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
});
|
||||
toast.success('تصویر با موفقیت آپلود شد');
|
||||
fetchMedia();
|
||||
} catch {
|
||||
toast.error('خطا در آپلود تصویر');
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
return api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
});
|
||||
});
|
||||
const results = await Promise.allSettled(uploadPromises);
|
||||
results.forEach(res => {
|
||||
if (res.status === 'fulfilled') successCount++;
|
||||
});
|
||||
|
||||
if (successCount > 0) {
|
||||
toast.success(`${successCount} تصویر با موفقیت آپلود شد`);
|
||||
await fetchMedia();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Drop upload failed', error);
|
||||
toast.error('خطا در آپلود تصاویر رها شده');
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-gray-900/60 backdrop-blur-sm transition-opacity">
|
||||
<div
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
className={`bg-white rounded-2xl shadow-2xl w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden animate-in fade-in zoom-in duration-200 relative transition-all ${isDragOver ? 'ring-4 ring-purple-500 scale-[1.01]' : ''}`}
|
||||
>
|
||||
{isDragOver && (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-xs font-vazir"
|
||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true); }}
|
||||
onDragLeave={() => setDragOver(false)}
|
||||
onDrop={handleDrop}
|
||||
>
|
||||
<div className="bg-white rounded-3xl max-w-5xl w-full max-h-[90vh] flex flex-col shadow-2xl overflow-hidden border border-gray-100 relative animate-in fade-in zoom-in-95 duration-200">
|
||||
|
||||
{/* Drag overlay */}
|
||||
{dragOver && (
|
||||
<div className="absolute inset-0 z-50 bg-purple-600/90 backdrop-blur-xs flex flex-col items-center justify-center text-white pointer-events-none animate-in fade-in">
|
||||
<Upload className="w-16 h-16 mb-2 animate-bounce" />
|
||||
<p className="text-xl font-bold">تصویر را اینجا رها کنید تا آپلود شود</p>
|
||||
<p className="text-xl font-bold">تصاویر را اینجا رها کنید تا آپلود شوند</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -210,8 +230,8 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
<ImageIcon className="w-5 h-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-bold text-gray-900">گالری رسانه</h3>
|
||||
<p className="text-xs text-gray-500 font-medium">تصویر مورد نظر را انتخاب یا آپلود کنید</p>
|
||||
<h3 className="text-lg font-bold text-gray-900">گالری رسانه و تصاویر</h3>
|
||||
<p className="text-xs text-gray-500 font-medium">تصویر مورد نظر را انتخاب یا گروهی آپلود کنید</p>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onClose} className="p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors">
|
||||
@@ -220,11 +240,11 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<div className="p-4 border-b border-gray-100 flex justify-between items-center bg-white">
|
||||
<div className="p-4 border-b border-gray-100 flex justify-between items-center bg-white flex-wrap gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<p className="text-sm font-bold text-gray-600">{mediaList.length} فایل موجود</p>
|
||||
{pasteStatus && (
|
||||
<span className={`text-xs px-2 py-1 rounded-full font-medium ${pasteStatus.includes('موفق') ? 'bg-green-100 text-green-700' : pasteStatus.includes('خطا') ? 'bg-red-100 text-red-700' : 'bg-blue-100 text-blue-700'}`}>
|
||||
<span className={`text-xs px-2.5 py-1 rounded-full font-medium ${pasteStatus.includes('موفق') ? 'bg-green-100 text-green-700' : pasteStatus.includes('خطا') ? 'bg-red-100 text-red-700' : 'bg-blue-100 text-blue-700'}`}>
|
||||
{pasteStatus}
|
||||
</span>
|
||||
)}
|
||||
@@ -239,15 +259,16 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
ref={fileInputRef}
|
||||
onChange={handleFileUpload}
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
/>
|
||||
<button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
disabled={isUploading}
|
||||
className="bg-purple-600 hover:bg-purple-700 disabled:opacity-70 text-white px-4 py-2 rounded-xl flex items-center gap-2 text-sm font-bold transition-colors"
|
||||
className="bg-purple-600 hover:bg-purple-700 disabled:opacity-70 text-white px-4 py-2.5 rounded-xl flex items-center gap-2 text-sm font-bold transition-all shadow-md shadow-purple-200 cursor-pointer"
|
||||
>
|
||||
{isUploading ? <Spinner size="sm" /> : <Upload className="w-4 h-4" />}
|
||||
آپلود تصویر جدید
|
||||
آپلود تصویر جدید (تکی یا گروهی)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -271,7 +292,7 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
|
||||
{paginatedList.map((media) => {
|
||||
const imgUrl = media.url.startsWith('http') ? media.url : `${BASE_DOMAIN}${media.url}`;
|
||||
const isSelected = selectedUrl && imgUrl === selectedUrl;
|
||||
const isSelected = selectedUrl && (imgUrl === selectedUrl || media.url === selectedUrl);
|
||||
return (
|
||||
<div
|
||||
key={media.id}
|
||||
@@ -279,38 +300,55 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
onSelect(imgUrl);
|
||||
if (!multiple) onClose();
|
||||
}}
|
||||
className={`group relative bg-gray-100 rounded-xl overflow-hidden border-2 cursor-pointer transition-all hover:shadow-lg hover:shadow-purple-100 ${isSelected ? 'border-purple-600 ring-2 ring-purple-300' : 'border-transparent hover:border-purple-500'}`}
|
||||
className={`group relative bg-white rounded-2xl overflow-hidden border-2 cursor-pointer transition-all hover:shadow-lg hover:shadow-purple-100 ${
|
||||
isSelected ? 'border-purple-600 ring-2 ring-purple-300' : 'border-gray-200 hover:border-purple-400'
|
||||
}`}
|
||||
>
|
||||
<div className="aspect-square bg-white p-2 flex items-center justify-center border-b border-gray-100">
|
||||
{/* Top Action Icons (Safe Tap Targets) */}
|
||||
<div className="absolute top-2 left-2 right-2 flex items-center justify-between z-10 pointer-events-none">
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setPreviewUrl(imgUrl);
|
||||
}}
|
||||
className="pointer-events-auto p-1.5 rounded-lg bg-black/50 hover:bg-black/80 text-white backdrop-blur-xs transition-colors"
|
||||
title="مشاهده بزرگنمایی"
|
||||
>
|
||||
<Eye className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setDeleteTargetId(media.id);
|
||||
}}
|
||||
className="pointer-events-auto p-1.5 rounded-lg bg-red-600/80 hover:bg-red-600 text-white backdrop-blur-xs transition-colors"
|
||||
title="حذف تصویر"
|
||||
>
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="aspect-square bg-gray-50 p-2 flex items-center justify-center border-b border-gray-100 relative">
|
||||
<img
|
||||
src={imgUrl}
|
||||
alt={media.filename}
|
||||
className="max-w-full max-h-full object-contain object-center"
|
||||
loading="lazy"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-3">
|
||||
<button
|
||||
onClick={(e) => { e.stopPropagation(); setDeleteTargetId(media.id); }}
|
||||
className="w-8 h-8 rounded-full bg-red-500 text-white flex items-center justify-center hover:bg-red-600 transform hover:scale-110 transition-transform"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
className="w-8 h-8 rounded-full bg-purple-500 text-white flex items-center justify-center hover:bg-purple-600 transform hover:scale-110 transition-transform"
|
||||
>
|
||||
<CheckCircle2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="absolute top-2 left-2 bg-purple-600 text-white text-[10px] font-bold px-2 py-0.5 rounded-full shadow-lg">
|
||||
<div className="absolute bottom-2 right-2 bg-purple-600 text-white text-[10px] font-bold px-2 py-0.5 rounded-full shadow-lg flex items-center gap-1">
|
||||
<CheckCircle2 className="w-3 h-3" />
|
||||
انتخاب شده
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="p-2 border-t border-gray-100 bg-white" dir="ltr">
|
||||
<p className="text-[11px] text-gray-500 truncate font-medium" title={media.filename}>
|
||||
<div className="p-2.5 border-t border-gray-100 bg-white" dir="ltr">
|
||||
<p className="text-[11px] text-gray-700 truncate font-medium" title={media.filename}>
|
||||
{media.filename}
|
||||
</p>
|
||||
<p className="text-[10px] text-gray-400 mt-0.5">
|
||||
<p className="text-[10px] text-gray-400 mt-0.5 text-right font-vazir">
|
||||
{new Date(media.createdAt).toLocaleDateString('fa-IR')}
|
||||
</p>
|
||||
</div>
|
||||
@@ -333,7 +371,12 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
/>
|
||||
|
||||
<ImagePreviewModal
|
||||
isOpen={!!previewUrl}
|
||||
imageUrl={previewUrl || ''}
|
||||
onClose={() => setPreviewUrl(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
|
||||
export interface SelectOption {
|
||||
value: string | number;
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
|
||||
options?: SelectOption[];
|
||||
error?: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
({ className = '', error, options, children, disabled, ...props }, ref) => {
|
||||
return (
|
||||
<div className="w-full relative font-vazir">
|
||||
<select
|
||||
ref={ref}
|
||||
disabled={disabled}
|
||||
className={`w-full bg-white border font-vazir text-sm transition-all duration-200 outline-none appearance-none pr-4 pl-10 py-2.5 rounded-xl shadow-xs cursor-pointer
|
||||
${error ? 'border-red-400 focus:border-red-500 focus:ring-2 focus:ring-red-500/20' : 'border-gray-200 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20'}
|
||||
${disabled ? 'bg-gray-50 text-gray-400 cursor-not-allowed border-gray-200' : 'text-gray-900 hover:border-gray-300'}
|
||||
${className}`}
|
||||
{...props}
|
||||
>
|
||||
{options
|
||||
? options.map((opt) => (
|
||||
<option key={opt.value} value={opt.value} disabled={opt.disabled}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))
|
||||
: children}
|
||||
</select>
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
</div>
|
||||
{error && (
|
||||
<p className="mt-1 text-xs text-red-500 font-medium flex items-center gap-1 animate-in fade-in duration-200">
|
||||
<span>•</span>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Select.displayName = 'Select';
|
||||
export default Select;
|
||||
@@ -0,0 +1,33 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
|
||||
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ className = '', error, disabled, rows = 3, ...props }, ref) => {
|
||||
return (
|
||||
<div className="w-full relative font-vazir">
|
||||
<textarea
|
||||
ref={ref}
|
||||
rows={rows}
|
||||
disabled={disabled}
|
||||
className={`w-full bg-white border font-vazir text-sm transition-all duration-200 outline-none p-3.5 rounded-xl shadow-xs resize-y
|
||||
${error ? 'border-red-400 focus:border-red-500 focus:ring-2 focus:ring-red-500/20' : 'border-gray-200 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20'}
|
||||
${disabled ? 'bg-gray-50 text-gray-400 cursor-not-allowed border-gray-200' : 'text-gray-900 placeholder:text-gray-400 hover:border-gray-300'}
|
||||
${className}`}
|
||||
{...props}
|
||||
/>
|
||||
{error && (
|
||||
<p className="mt-1 text-xs text-red-500 font-medium flex items-center gap-1 animate-in fade-in duration-200">
|
||||
<span>•</span>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Textarea.displayName = 'Textarea';
|
||||
export default Textarea;
|
||||
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface ToggleSwitchProps {
|
||||
checked: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
label?: string;
|
||||
description?: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function ToggleSwitch({
|
||||
checked,
|
||||
onChange,
|
||||
label,
|
||||
description,
|
||||
disabled = false,
|
||||
className = '',
|
||||
}: ToggleSwitchProps) {
|
||||
return (
|
||||
<label
|
||||
className={`inline-flex items-center justify-between gap-4 font-vazir cursor-pointer select-none ${
|
||||
disabled ? 'opacity-50 cursor-not-allowed' : ''
|
||||
} ${className}`}
|
||||
>
|
||||
{(label || description) && (
|
||||
<div className="flex-1">
|
||||
{label && <span className="text-sm font-bold text-gray-800 block">{label}</span>}
|
||||
{description && <span className="text-xs text-gray-500 block mt-0.5">{description}</span>}
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={checked}
|
||||
disabled={disabled}
|
||||
onClick={() => !disabled && onChange(!checked)}
|
||||
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 ${
|
||||
checked ? 'bg-purple-600' : 'bg-gray-200'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out ${
|
||||
checked ? '-translate-x-5' : 'translate-x-0'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user