fix: redesign
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Promotion, CreatePromotionData, UpdatePromotionData, PROMOTION_TYPES } from '@/types/promotion';
|
||||
import { PhotoIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
||||
import Image from 'next/image';
|
||||
|
||||
interface PromotionFormProps {
|
||||
promotion?: Promotion | null;
|
||||
@@ -33,10 +32,8 @@ export default function PromotionForm({ promotion, onSubmit, onCancel, isLoading
|
||||
|
||||
useEffect(() => {
|
||||
if (promotion) {
|
||||
// Format dates for input fields
|
||||
const startAt = promotion.start_at ? promotion.start_at.slice(0, 16) : '';
|
||||
const endAt = promotion.end_at ? promotion.end_at.slice(0, 16) : '';
|
||||
|
||||
setFormData({
|
||||
type: promotion.type || 'slider',
|
||||
title: promotion.title || '',
|
||||
@@ -50,32 +47,21 @@ export default function PromotionForm({ promotion, onSubmit, onCancel, isLoading
|
||||
start_at: startAt,
|
||||
end_at: endAt,
|
||||
});
|
||||
|
||||
setIsActive(promotion.is_active);
|
||||
|
||||
if (promotion.image_url) {
|
||||
setImagePreview(promotion.image_url);
|
||||
}
|
||||
if (promotion.image_url) setImagePreview(promotion.image_url);
|
||||
} else {
|
||||
// Set default priority
|
||||
setFormData(prev => ({ ...prev, priority: 0 }));
|
||||
}
|
||||
}, [promotion]);
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: value === '' ? null : value,
|
||||
}));
|
||||
setFormData(prev => ({ ...prev, [name]: value === '' ? null : value }));
|
||||
};
|
||||
|
||||
const handleNumberChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: value === '' ? null : parseInt(value, 10),
|
||||
}));
|
||||
setFormData(prev => ({ ...prev, [name]: value === '' ? null : parseInt(value, 10) }));
|
||||
};
|
||||
|
||||
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -83,12 +69,8 @@ export default function PromotionForm({ promotion, onSubmit, onCancel, isLoading
|
||||
if (file) {
|
||||
setImageFile(file);
|
||||
setFormData(prev => ({ ...prev, image: file }));
|
||||
|
||||
// Create preview
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
setImagePreview(reader.result as string);
|
||||
};
|
||||
reader.onloadend = () => setImagePreview(reader.result as string);
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
};
|
||||
@@ -101,295 +83,120 @@ export default function PromotionForm({ promotion, onSubmit, onCancel, isLoading
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Format dates properly
|
||||
let submitData: any = { ...formData };
|
||||
|
||||
if (submitData.start_at) {
|
||||
submitData.start_at = submitData.start_at.replace('T', ' ') + ':00';
|
||||
}
|
||||
|
||||
if (submitData.end_at) {
|
||||
submitData.end_at = submitData.end_at.replace('T', ' ') + ':00';
|
||||
}
|
||||
|
||||
// Add is_active for updates
|
||||
if (promotion) {
|
||||
submitData.is_active = isActive;
|
||||
}
|
||||
|
||||
if (submitData.start_at) submitData.start_at = submitData.start_at.replace('T', ' ') + ':00';
|
||||
if (submitData.end_at) submitData.end_at = submitData.end_at.replace('T', ' ') + ':00';
|
||||
if (promotion) submitData.is_active = isActive;
|
||||
await onSubmit(submitData);
|
||||
};
|
||||
|
||||
const inputClass = 'block w-full px-4 py-2.5 text-sm text-gray-900 dark:text-gray-100 border border-gray-200 dark:border-gray-700 rounded-xl bg-gray-50 dark:bg-gray-800/60 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 dark:focus:border-indigo-400 transition-colors';
|
||||
const labelClass = 'block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5';
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-6 bg-white dark:bg-gray-900 p-6 rounded-lg shadow">
|
||||
<div>
|
||||
<h3 className="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">
|
||||
<form onSubmit={handleSubmit} className="space-y-6 bg-white dark:bg-gray-900 p-6 rounded-2xl ring-1 ring-gray-200 dark:ring-gray-800 shadow-sm">
|
||||
<div className="pb-4 border-b border-gray-100 dark:border-gray-800">
|
||||
<h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100">
|
||||
{promotion ? 'ویرایش تبلیغ' : 'ایجاد تبلیغ جدید'}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{/* Type */}
|
||||
<div className="grid grid-cols-1 gap-5 md:grid-cols-2">
|
||||
<div>
|
||||
<label htmlFor="type" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
نوع <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
id="type"
|
||||
name="type"
|
||||
required
|
||||
value={formData.type || 'slider'}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
>
|
||||
<label htmlFor="type" className={labelClass}>نوع <span className="text-red-500">*</span></label>
|
||||
<select id="type" name="type" required value={formData.type || 'slider'} onChange={handleInputChange} className={inputClass}>
|
||||
{Object.entries(PROMOTION_TYPES).map(([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>
|
||||
<option key={value} value={value}>{label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Title */}
|
||||
<div>
|
||||
<label htmlFor="title" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
عنوان
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
name="title"
|
||||
value={formData.title || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="عنوان تبلیغ"
|
||||
/>
|
||||
<label htmlFor="title" className={labelClass}>عنوان</label>
|
||||
<input type="text" id="title" name="title" value={formData.title || ''} onChange={handleInputChange} className={inputClass} placeholder="عنوان تبلیغ" />
|
||||
</div>
|
||||
|
||||
{/* Subtitle */}
|
||||
<div className="md:col-span-2">
|
||||
<label htmlFor="subtitle" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
زیرعنوان
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="subtitle"
|
||||
name="subtitle"
|
||||
value={formData.subtitle || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="زیرعنوان تبلیغ"
|
||||
/>
|
||||
<label htmlFor="subtitle" className={labelClass}>زیرعنوان</label>
|
||||
<input type="text" id="subtitle" name="subtitle" value={formData.subtitle || ''} onChange={handleInputChange} className={inputClass} placeholder="زیرعنوان تبلیغ" />
|
||||
</div>
|
||||
|
||||
{/* Action Text */}
|
||||
<div>
|
||||
<label htmlFor="action_text" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
متن دکمه
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="action_text"
|
||||
name="action_text"
|
||||
value={formData.action_text || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="مثال: همین حالا نصب کن"
|
||||
/>
|
||||
<label htmlFor="action_text" className={labelClass}>متن دکمه</label>
|
||||
<input type="text" id="action_text" name="action_text" value={formData.action_text || ''} onChange={handleInputChange} className={inputClass} placeholder="مثال: همین حالا نصب کن" />
|
||||
</div>
|
||||
|
||||
{/* Priority */}
|
||||
<div>
|
||||
<label htmlFor="priority" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
اولویت
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="priority"
|
||||
name="priority"
|
||||
min="0"
|
||||
value={formData.priority || 0}
|
||||
onChange={handleNumberChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="عدد بالاتر = اولویت بیشتر"
|
||||
/>
|
||||
<label htmlFor="priority" className={labelClass}>اولویت</label>
|
||||
<input type="number" id="priority" name="priority" min="0" value={formData.priority || 0} onChange={handleNumberChange} className={inputClass} placeholder="عدد بالاتر = اولویت بیشتر" />
|
||||
</div>
|
||||
|
||||
{/* Start Date */}
|
||||
<div>
|
||||
<label htmlFor="start_at" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
تاریخ شروع
|
||||
</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
id="start_at"
|
||||
name="start_at"
|
||||
value={formData.start_at || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
/>
|
||||
<label htmlFor="start_at" className={labelClass}>تاریخ شروع</label>
|
||||
<input type="datetime-local" id="start_at" name="start_at" value={formData.start_at || ''} onChange={handleInputChange} className={inputClass} />
|
||||
</div>
|
||||
|
||||
{/* End Date */}
|
||||
<div>
|
||||
<label htmlFor="end_at" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
تاریخ پایان
|
||||
</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
id="end_at"
|
||||
name="end_at"
|
||||
value={formData.end_at || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
/>
|
||||
<label htmlFor="end_at" className={labelClass}>تاریخ پایان</label>
|
||||
<input type="datetime-local" id="end_at" name="end_at" value={formData.end_at || ''} onChange={handleInputChange} className={inputClass} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* URLs Section */}
|
||||
<div className="border-t border-gray-200 dark:border-gray-800 pt-4">
|
||||
<h4 className="text-md font-medium text-gray-900 dark:text-gray-100 mb-3">لینکها</h4>
|
||||
<div className="pt-4 border-t border-gray-100 dark:border-gray-800">
|
||||
<h4 className="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3">لینکها</h4>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
{/* Myket URL */}
|
||||
<div>
|
||||
<label htmlFor="url_myket" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
لینک مایکت
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
id="url_myket"
|
||||
name="url_myket"
|
||||
value={formData.url_myket || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="https://myket.ir/app/..."
|
||||
/>
|
||||
<label htmlFor="url_myket" className={labelClass}>لینک مایکت</label>
|
||||
<input type="url" id="url_myket" name="url_myket" value={formData.url_myket || ''} onChange={handleInputChange} className={inputClass} placeholder="https://myket.ir/app/..." dir="ltr" />
|
||||
</div>
|
||||
|
||||
{/* Bazaar URL */}
|
||||
<div>
|
||||
<label htmlFor="url_bazzar" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
لینک بازار
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
id="url_bazzar"
|
||||
name="url_bazzar"
|
||||
value={formData.url_bazzar || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="https://cafebazaar.ir/app/..."
|
||||
/>
|
||||
<label htmlFor="url_bazzar" className={labelClass}>لینک بازار</label>
|
||||
<input type="url" id="url_bazzar" name="url_bazzar" value={formData.url_bazzar || ''} onChange={handleInputChange} className={inputClass} placeholder="https://cafebazaar.ir/app/..." dir="ltr" />
|
||||
</div>
|
||||
|
||||
{/* Google Play URL */}
|
||||
<div>
|
||||
<label htmlFor="url_google_play" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
لینک گوگلپلی
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
id="url_google_play"
|
||||
name="url_google_play"
|
||||
value={formData.url_google_play || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="https://play.google.com/store/apps/..."
|
||||
/>
|
||||
<label htmlFor="url_google_play" className={labelClass}>لینک گوگلپلی</label>
|
||||
<input type="url" id="url_google_play" name="url_google_play" value={formData.url_google_play || ''} onChange={handleInputChange} className={inputClass} placeholder="https://play.google.com/store/apps/..." dir="ltr" />
|
||||
</div>
|
||||
|
||||
{/* Site URL */}
|
||||
<div>
|
||||
<label htmlFor="url_site" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
لینک وبسایت
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
id="url_site"
|
||||
name="url_site"
|
||||
value={formData.url_site || ''}
|
||||
onChange={handleInputChange}
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:placeholder-gray-500 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm transition-colors"
|
||||
placeholder="https://example.com"
|
||||
/>
|
||||
<label htmlFor="url_site" className={labelClass}>لینک وبسایت</label>
|
||||
<input type="url" id="url_site" name="url_site" value={formData.url_site || ''} onChange={handleInputChange} className={inputClass} placeholder="https://example.com" dir="ltr" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
تصویر
|
||||
</label>
|
||||
<div className="flex items-center space-x-3 space-x-reverse">
|
||||
<label className="cursor-pointer flex items-center px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
|
||||
<PhotoIcon className="h-5 w-5 ml-2 text-gray-400 dark:text-gray-500" />
|
||||
<div className="pt-2 border-t border-gray-100 dark:border-gray-800">
|
||||
<label className={labelClass}>تصویر</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<label className="cursor-pointer inline-flex items-center gap-2 px-4 py-2.5 rounded-xl border border-gray-200 dark:border-gray-700 text-sm font-medium text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-gray-800/60 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">
|
||||
<PhotoIcon className="h-4 w-4 text-gray-400" />
|
||||
انتخاب تصویر
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleImageChange}
|
||||
className="hidden"
|
||||
/>
|
||||
<input type="file" accept="image/*" onChange={handleImageChange} className="hidden" />
|
||||
</label>
|
||||
{imagePreview && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={removeImage}
|
||||
className="text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300 transition-colors"
|
||||
>
|
||||
<button type="button" onClick={removeImage} className="text-red-500 hover:text-red-700 transition-colors">
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{imagePreview && (
|
||||
<div className="mt-2 relative h-32 w-32 rounded-lg overflow-hidden border border-gray-200 dark:border-gray-800">
|
||||
<img
|
||||
src={imagePreview}
|
||||
alt="Preview"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
<div className="mt-3 relative h-32 w-32 rounded-xl overflow-hidden ring-1 ring-gray-200 dark:ring-gray-800">
|
||||
<img src={imagePreview} alt="Preview" className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
حداکثر حجم: ۲ مگابایت
|
||||
</p>
|
||||
<p className="mt-1.5 text-xs text-gray-400 dark:text-gray-500">حداکثر حجم: ۲ مگابایت</p>
|
||||
</div>
|
||||
|
||||
{/* Active Status (only for edit) */}
|
||||
{promotion && (
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="is_active"
|
||||
checked={isActive}
|
||||
onChange={(e) => setIsActive(e.target.checked)}
|
||||
className="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 dark:border-gray-600 dark:bg-gray-800 rounded"
|
||||
/>
|
||||
<label htmlFor="is_active" className="mr-2 block text-sm text-gray-900 dark:text-gray-100">
|
||||
فعال
|
||||
<div className="pt-2 border-t border-gray-100 dark:border-gray-800">
|
||||
<label className="flex items-center gap-3 p-3 rounded-xl bg-gray-50 dark:bg-gray-800/60 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
||||
<input type="checkbox" id="is_active" checked={isActive} onChange={(e) => setIsActive(e.target.checked)} className="h-4 w-4 text-indigo-600 border-gray-300 dark:border-gray-600 dark:bg-gray-800 rounded-lg focus:ring-indigo-500" />
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">فعال</span>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Form Actions */}
|
||||
<div className="flex justify-end space-x-3 space-x-reverse pt-4 border-t dark:border-gray-800">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
className="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-900 focus:ring-indigo-500 transition-colors"
|
||||
>
|
||||
<div className="flex justify-end gap-3 pt-4 border-t border-gray-100 dark:border-gray-800">
|
||||
<button type="button" onClick={onCancel} className="px-5 py-2.5 rounded-xl border border-gray-200 dark:border-gray-700 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-900 focus:ring-indigo-500 disabled:opacity-50 transition-colors"
|
||||
>
|
||||
<button type="submit" disabled={isLoading} className="px-5 py-2.5 rounded-xl bg-indigo-600 text-white text-sm font-medium hover:bg-indigo-700 focus:ring-2 focus:ring-indigo-500/30 disabled:opacity-50 transition-colors shadow-sm shadow-indigo-500/20">
|
||||
{isLoading ? 'در حال ذخیره...' : promotion ? 'بهروزرسانی' : 'ایجاد'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,25 +20,27 @@ export default function PromotionList({ promotions, onEdit, onDelete, onToggleAc
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center py-12">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600"></div>
|
||||
<div className="flex justify-center items-center py-16">
|
||||
<div className="h-10 w-10 border-4 border-indigo-200 dark:border-indigo-800 border-t-indigo-600 rounded-full animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!promotions || promotions.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-12 bg-white dark:bg-gray-900 rounded-lg shadow">
|
||||
<p className="text-gray-500 dark:text-gray-400">هیچ تبلیغاتی یافت نشد</p>
|
||||
<div className="text-center py-16 bg-white dark:bg-gray-900 rounded-2xl ring-1 ring-gray-200 dark:ring-gray-800 shadow-sm">
|
||||
<div className="mx-auto h-12 w-12 rounded-xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center mb-3">
|
||||
<svg className="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M10.34 15.84c-.688-.06-1.386-.09-2.09-.09H7.5a4.5 4.5 0 1 1 0-9h.75c.704 0 1.402-.03 2.09-.09m0 9.18c.253.962.584 1.892.985 2.783.247.55.06 1.21-.463 1.511l-.657.38c-.551.318-1.26.117-1.527-.461a20.845 20.845 0 0 1-1.44-4.282m3.102.069a18.03 18.03 0 0 1-.59-4.59c0-1.586.205-3.124.59-4.59m0 9.18a23.848 23.848 0 0 1-8.635 2.517m0 0a23.848 23.848 0 0 1-8.635-2.517m8.635 2.517a23.848 23.848 0 0 0 8.635 2.517m0 0a23.848 23.848 0 0 0 8.635-2.517M12 13.5a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Z" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-gray-500 dark:text-gray-400 text-sm">هیچ تبلیغاتی یافت نشد</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Sort promotions by priority (higher priority first) and then by creation date
|
||||
const sortedPromotions = [...promotions].sort((a, b) => {
|
||||
if (a.priority && b.priority) {
|
||||
return b.priority - a.priority;
|
||||
}
|
||||
if (a.priority && b.priority) return b.priority - a.priority;
|
||||
if (a.priority) return -1;
|
||||
if (b.priority) return 1;
|
||||
return new Date(b.created_at).getTime() - new Date(a.created_at).getTime();
|
||||
@@ -49,145 +51,106 @@ export default function PromotionList({ promotions, onEdit, onDelete, onToggleAc
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-white dark:bg-gray-900 shadow overflow-hidden sm:rounded-lg">
|
||||
<div className="px-4 py-5 sm:px-6">
|
||||
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">
|
||||
<div className="bg-white dark:bg-gray-900 ring-1 ring-gray-200 dark:ring-gray-800 rounded-2xl overflow-hidden shadow-sm">
|
||||
<div className="px-5 py-4 border-b border-gray-200 dark:border-gray-800">
|
||||
<h3 className="text-base font-semibold text-gray-900 dark:text-gray-100">
|
||||
لیست تبلیغات
|
||||
</h3>
|
||||
</div>
|
||||
<ul className="divide-y divide-gray-200 dark:divide-gray-800">
|
||||
{sortedPromotions.map((promotion) => (
|
||||
<li key={promotion.id} className="px-6 py-4 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start space-x-4 space-x-reverse">
|
||||
{/* Promotion Image - Using unoptimized Image component */}
|
||||
{promotion.image_url && !imageErrors[promotion.id] && (
|
||||
<div className="flex-shrink-0">
|
||||
<div className="relative h-20 w-20 rounded-lg overflow-hidden border border-gray-200 dark:border-gray-800">
|
||||
<Image
|
||||
src={promotion.image_url}
|
||||
alt={promotion.title || 'Promotion'}
|
||||
fill
|
||||
className="object-cover"
|
||||
onError={() => handleImageError(promotion.id)}
|
||||
unoptimized={true} // This disables image optimization
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Promotion Details */}
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2 space-x-reverse">
|
||||
<p className="text-sm font-medium text-indigo-600 dark:text-indigo-400">
|
||||
{promotion.title || 'بدون عنوان'}
|
||||
</p>
|
||||
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
|
||||
{getPromotionTypeLabel(promotion.type)}
|
||||
</span>
|
||||
{promotion.is_active ? (
|
||||
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300">
|
||||
فعال
|
||||
</span>
|
||||
) : (
|
||||
<span className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300">
|
||||
غیرفعال
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{promotion.subtitle && (
|
||||
<p className="mt-1 text-sm text-gray-600 dark:text-gray-400">
|
||||
{promotion.subtitle}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{promotion.action_text && (
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
متن دکمه: {promotion.action_text}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{promotion.priority && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400">
|
||||
<span className="font-medium">اولویت:</span> {promotion.priority}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{promotion.start_at && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400">
|
||||
<span className="font-medium">شروع:</span> {formatDate(promotion.start_at)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{promotion.end_at && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400">
|
||||
<span className="font-medium">پایان:</span> {formatDate(promotion.end_at)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* URLs */}
|
||||
<div className="mt-2 space-y-1">
|
||||
{promotion.url_site && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||||
<span className="font-medium">وبسایت:</span> {promotion.url_site}
|
||||
</div>
|
||||
)}
|
||||
{promotion.url_myket && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||||
<span className="font-medium">مایکت:</span> {promotion.url_myket}
|
||||
</div>
|
||||
)}
|
||||
{promotion.url_bazzar && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||||
<span className="font-medium">بازار:</span> {promotion.url_bazzar}
|
||||
</div>
|
||||
)}
|
||||
{promotion.url_google_play && (
|
||||
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||||
<span className="font-medium">گوگلپلی:</span> {promotion.url_google_play}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-2 text-xs text-gray-400 dark:text-gray-500">
|
||||
آخرین بهروزرسانی: {formatDate(promotion.updated_at)}
|
||||
</div>
|
||||
<li key={promotion.id} className="px-5 py-4 hover:bg-gray-50 dark:hover:bg-gray-800/40 transition-colors">
|
||||
<div className="flex items-start gap-4">
|
||||
{promotion.image_url && !imageErrors[promotion.id] && (
|
||||
<div className="flex-shrink-0">
|
||||
<div className="relative h-16 w-16 rounded-xl overflow-hidden ring-1 ring-gray-200 dark:ring-gray-800">
|
||||
<Image
|
||||
src={promotion.image_url}
|
||||
alt={promotion.title || 'Promotion'}
|
||||
fill
|
||||
className="object-cover"
|
||||
onError={() => handleImageError(promotion.id)}
|
||||
unoptimized
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<p className="text-sm font-semibold text-indigo-600 dark:text-indigo-400">
|
||||
{promotion.title || 'بدون عنوان'}
|
||||
</p>
|
||||
<span className="px-2 py-0.5 text-xs font-semibold rounded-lg bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
|
||||
{getPromotionTypeLabel(promotion.type)}
|
||||
</span>
|
||||
{promotion.is_active ? (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-semibold rounded-lg bg-green-50 text-green-700 dark:bg-green-500/10 dark:text-green-400">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-green-500" />
|
||||
فعال
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-semibold rounded-lg bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-gray-400" />
|
||||
غیرفعال
|
||||
</span>
|
||||
)}
|
||||
{promotion.priority && (
|
||||
<span className="px-2 py-0.5 text-xs font-medium rounded-lg bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300">
|
||||
اولویت: {promotion.priority}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{promotion.subtitle && (
|
||||
<p className="mt-1 text-sm text-gray-600 dark:text-gray-400">{promotion.subtitle}</p>
|
||||
)}
|
||||
|
||||
<div className="mt-2 flex flex-wrap gap-x-5 gap-y-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{promotion.action_text && <span>دکمه: {promotion.action_text}</span>}
|
||||
{promotion.start_at && <span>شروع: {formatDate(promotion.start_at)}</span>}
|
||||
{promotion.end_at && <span>پایان: {formatDate(promotion.end_at)}</span>}
|
||||
</div>
|
||||
|
||||
<div className="mt-1.5 flex flex-wrap gap-1.5">
|
||||
{promotion.url_site && (
|
||||
<span className="px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-md">وبسایت</span>
|
||||
)}
|
||||
{promotion.url_myket && (
|
||||
<span className="px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-md">مایکت</span>
|
||||
)}
|
||||
{promotion.url_bazzar && (
|
||||
<span className="px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-md">بازار</span>
|
||||
)}
|
||||
{promotion.url_google_play && (
|
||||
<span className="px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-md">گوگلپلی</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="mr-4 flex-shrink-0 flex flex-col space-y-2">
|
||||
<div className="flex items-center gap-1 flex-shrink-0">
|
||||
<button
|
||||
onClick={() => onToggleActive(promotion)}
|
||||
className={`p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors ${
|
||||
promotion.is_active ? 'text-green-600 dark:text-green-400' : 'text-gray-400 dark:text-gray-500'
|
||||
className={`p-2 rounded-lg transition-colors ${
|
||||
promotion.is_active
|
||||
? 'text-green-600 dark:text-green-400 hover:bg-green-50 dark:hover:bg-green-500/10'
|
||||
: 'text-gray-400 dark:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800'
|
||||
}`}
|
||||
title={promotion.is_active ? 'غیرفعال کردن' : 'فعال کردن'}
|
||||
>
|
||||
{promotion.is_active ? (
|
||||
<EyeIcon className="h-5 w-5" />
|
||||
) : (
|
||||
<EyeSlashIcon className="h-5 w-5" />
|
||||
)}
|
||||
{promotion.is_active ? <EyeIcon className="h-4 w-4" /> : <EyeSlashIcon className="h-4 w-4" />}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onEdit(promotion)}
|
||||
className="text-indigo-600 dark:text-indigo-400 hover:text-indigo-900 dark:hover:text-indigo-300 p-2 rounded-full hover:bg-indigo-50 dark:hover:bg-indigo-900/40 transition-colors"
|
||||
className="p-2 rounded-lg text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-500/10 transition-colors"
|
||||
>
|
||||
<PencilIcon className="h-5 w-5" />
|
||||
<PencilIcon className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onDelete(promotion)}
|
||||
className="text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300 p-2 rounded-full hover:bg-red-50 dark:hover:bg-red-900/40 transition-colors"
|
||||
className="p-2 rounded-lg text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors"
|
||||
>
|
||||
<TrashIcon className="h-5 w-5" />
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -196,4 +159,4 @@ export default function PromotionList({ promotions, onEdit, onDelete, onToggleAc
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user