feat(inventory): 販賣機視覺優化、修復匯入日期缺失與倉庫刪除權限錯誤

This commit is contained in:
2026-02-09 10:19:46 +08:00
parent f22df90e01
commit 5e542752ba
14 changed files with 255 additions and 71 deletions

View File

@@ -69,18 +69,39 @@ export default function SafetyStockPage({
};
const handleEdit = (updatedSetting: SafetyStockSetting) => {
router.put(route('warehouses.safety-stock.update', [warehouse.id, updatedSetting.id]), {
safetyStock: updatedSetting.safetyStock,
}, {
onSuccess: () => {
setEditingSetting(null);
toast.success(`成功更新 ${updatedSetting.productName} 的安全庫存`);
},
onError: (errors) => {
const firstError = Object.values(errors)[0];
toast.error(typeof firstError === 'string' ? firstError : "更新失敗");
}
});
// 如果 ID 包含 temp_表示這是一個「自動帶入但尚未存入資料庫」的建議項
// 這種情況應該呼叫 POST (store) 而非 PUT (update),以避免被後端路由模型綁定報 404
if (updatedSetting.id.includes('temp_')) {
router.post(route('warehouses.safety-stock.store', warehouse.id), {
settings: [{
productId: updatedSetting.productId,
quantity: updatedSetting.safetyStock
}],
}, {
onSuccess: () => {
setEditingSetting(null);
toast.success(`成功設定 ${updatedSetting.productName} 的安全庫存`);
},
onError: (errors) => {
const firstError = Object.values(errors)[0];
toast.error(typeof firstError === 'string' ? firstError : "設定失敗");
}
});
} else {
// 已存在的項目,正常執行 PUT 更新
router.put(route('warehouses.safety-stock.update', [warehouse.id, updatedSetting.id]), {
safetyStock: updatedSetting.safetyStock,
}, {
onSuccess: () => {
setEditingSetting(null);
toast.success(`成功更新 ${updatedSetting.productName} 的安全庫存`);
},
onError: (errors) => {
const firstError = Object.values(errors)[0];
toast.error(typeof firstError === 'string' ? firstError : "更新失敗");
}
});
}
};
const handleDelete = () => {