This commit is contained in:
@@ -64,14 +64,29 @@ export default function CreatePurchaseOrder({
|
||||
const isValid = validatePurchaseOrder(String(supplierId), expectedDate, items);
|
||||
|
||||
const handleSave = () => {
|
||||
if (!isValid || !warehouseId) {
|
||||
toast.error("請填寫完整的表單資訊");
|
||||
if (!warehouseId) {
|
||||
toast.error("請選擇入庫倉庫");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!supplierId) {
|
||||
toast.error("請選擇供應商");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!expectedDate) {
|
||||
toast.error("請選擇預計到貨日期");
|
||||
return;
|
||||
}
|
||||
|
||||
if (items.length === 0) {
|
||||
toast.error("請至少新增一項採購商品");
|
||||
return;
|
||||
}
|
||||
|
||||
const validItems = filterValidItems(items);
|
||||
if (validItems.length === 0) {
|
||||
toast.error("請至少新增一項採購商品");
|
||||
toast.error("請填寫有效的採購數量(必須大於 0)");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,13 +104,24 @@ export default function CreatePurchaseOrder({
|
||||
};
|
||||
|
||||
if (order) {
|
||||
// Edit not implemented yet but structure is ready
|
||||
router.put(`/purchase-orders/${order.id}`, data, {
|
||||
onSuccess: () => toast.success("採購單已更新")
|
||||
onSuccess: () => toast.success("採購單已更新"),
|
||||
onError: (errors) => {
|
||||
toast.error("更新失敗,請檢查輸入內容");
|
||||
console.error(errors);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
router.post("/purchase-orders", data, {
|
||||
onSuccess: () => toast.success("採購單已成功建立")
|
||||
onSuccess: () => toast.success("採購單已成功建立"),
|
||||
onError: (errors) => {
|
||||
if (errors.error) {
|
||||
toast.error(errors.error);
|
||||
} else {
|
||||
toast.error("建立失敗,請檢查輸入內容");
|
||||
}
|
||||
console.error(errors);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -284,7 +310,6 @@ export default function CreatePurchaseOrder({
|
||||
size="lg"
|
||||
className="bg-primary hover:bg-primary/90 text-white px-12 h-14 rounded-xl shadow-lg shadow-primary/20 text-lg font-bold transition-all hover:scale-[1.02] active:scale-[0.98]"
|
||||
onClick={handleSave}
|
||||
disabled={!canSave}
|
||||
>
|
||||
{order ? "更新採購單" : "確認發布採購單"}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user