feat: add validate new item from admin panel
This commit is contained in:
@@ -26,6 +26,26 @@ function ItemFormModal({ item, onClose, onSaved }) {
|
||||
setForm({ ...form, [field]: e.target.value });
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!form.name.trim()) {
|
||||
alert("Введите название товара");
|
||||
return;
|
||||
}
|
||||
if (!form.category.trim()) {
|
||||
alert("Введите категорию");
|
||||
return;
|
||||
}
|
||||
if (!form.price || Number(form.price) <= 0) {
|
||||
alert("Введите корректную цену");
|
||||
return;
|
||||
}
|
||||
if (form.stock === "" || Number(form.stock) < 0) {
|
||||
alert("Введите остаток (0 или больше)");
|
||||
return;
|
||||
}
|
||||
if (!isEdit && !file) {
|
||||
alert("Добавьте картинку товара");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
// числовые поля привести к числам
|
||||
|
||||
Reference in New Issue
Block a user