feat: add property to product
This commit is contained in:
@@ -17,6 +17,11 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
||||
title: '',
|
||||
price: 0,
|
||||
type: 4, // Default to monthly
|
||||
discounted_price: '',
|
||||
daily_price: '',
|
||||
discount: '',
|
||||
is_best_seller: false,
|
||||
sort_order: 0,
|
||||
});
|
||||
|
||||
const [descriptions, setDescriptions] = useState<string[]>([]);
|
||||
@@ -28,16 +33,26 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
||||
title: product.title || '',
|
||||
price: product.price || 0,
|
||||
type: product.type || 4,
|
||||
discounted_price: product.discounted_price || '',
|
||||
daily_price: product.daily_price || '',
|
||||
discount: product.discount || '',
|
||||
is_best_seller: product.is_best_seller || false,
|
||||
sort_order: product.sort_order || 0,
|
||||
});
|
||||
setDescriptions(product.descriptions || []);
|
||||
}
|
||||
}, [product]);
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
||||
const { name, value } = e.target;
|
||||
const { name, value, type } = e.target;
|
||||
if (type === 'checkbox') {
|
||||
const { checked } = e.target as HTMLInputElement;
|
||||
setFormData(prev => ({ ...prev, [name]: checked }));
|
||||
return;
|
||||
}
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: name === 'price' ? parseInt(value) || 0 : value,
|
||||
[name]: name === 'price' || name === 'sort_order' ? parseInt(value) || 0 : value,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -127,6 +142,91 @@ export default function ProductForm({ product, packageName, onSubmit, onCancel,
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Discounted price (display only) */}
|
||||
<div>
|
||||
<label htmlFor="discounted_price" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
قیمت کلی تخفیف خورده <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="discounted_price"
|
||||
name="discounted_price"
|
||||
value={formData.discounted_price || ''}
|
||||
onChange={handleInputChange}
|
||||
dir="rtl"
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||
placeholder="مثال: ۱٬۴۶۰٬۰۰۰"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Daily price (display only) */}
|
||||
<div>
|
||||
<label htmlFor="daily_price" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
قیمت روزانه <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="daily_price"
|
||||
name="daily_price"
|
||||
value={formData.daily_price || ''}
|
||||
onChange={handleInputChange}
|
||||
dir="rtl"
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||
placeholder="مثال: معادل روزانه ۴٬۰۰۰ تومان"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Discount (display only) */}
|
||||
<div>
|
||||
<label htmlFor="discount" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
تخفیف <span className="text-xs text-gray-400">(فقط نمایشی)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="discount"
|
||||
name="discount"
|
||||
value={formData.discount || ''}
|
||||
onChange={handleInputChange}
|
||||
dir="rtl"
|
||||
className="block w-full px-3 py-2 text-slate-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||
placeholder="مثال: ۵۵٪ تخفیف"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Sort order */}
|
||||
<div>
|
||||
<label htmlFor="sort_order" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
ترتیب نمایش <span className="text-xs text-gray-400">(۰ بالاترین)</span>
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="sort_order"
|
||||
name="sort_order"
|
||||
min="0"
|
||||
value={formData.sort_order ?? 0}
|
||||
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 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-800 dark:placeholder-gray-500 transition-colors"
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Best seller */}
|
||||
<div className="md:col-span-2">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_best_seller"
|
||||
checked={!!formData.is_best_seller}
|
||||
onChange={handleInputChange}
|
||||
className="h-4 w-4 text-indigo-600 border-gray-300 dark:border-gray-600 rounded focus:ring-indigo-500 dark:bg-gray-800"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
پرفروشترین اشتراک
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">(فقط برای یک محصول فعال میشود)</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Descriptions */}
|
||||
|
||||
Reference in New Issue
Block a user