diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 51493a9..d8ac976 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -44,7 +44,7 @@ import { TOBUY_ERRORS } from '../constants/errorMessages'; const EMPTY_TOBUY: Omit & { stuffId: number | null, category: string } & { newAddition: boolean } = { stuffId: null, stuffName: '', - amount: 0, + amount: 1, shop: '', category: '', newAddition: false, @@ -174,6 +174,11 @@ const TaskListPage: React.FC = () => { if (newToBuy.newAddition) { newToBuy.stuffId = null; } + if (isNaN(newToBuy.amount)) { + console.log('数量が正しくありません.'); + return; + } + console.log(newToBuy) await toBuyApi.addToBuy(newToBuy); setOpenDialog(false); // ダイアログを閉じる @@ -191,6 +196,11 @@ const TaskListPage: React.FC = () => { */ const handleUpdateTask = async () => { try { + if (isNaN(selectedEditingTask.amount)) { + console.log('数量が正しくありません.'); + return; + } + console.log(selectedEditingTask) await toBuyApi.updateToBuy(selectedEditingTask); setOpenAmountDialog(false); // ダイアログを閉じる @@ -299,7 +309,7 @@ const TaskListPage: React.FC = () => { handleDeleteTask(tobuy.tobuyId)} > @@ -411,7 +421,7 @@ const TaskListPage: React.FC = () => { onChange={(e) => { const value = e.target.value; const parsedValue = parseInt(value, 10); // 数値に変換 - if (!isNaN(parsedValue) && parsedValue >= 0) { //負数除外 + if (/*!isNaN(parsedValue) && */ isNaN(parsedValue) || parsedValue >= 1) { //負数除外 setNewToBuy({ ...newToBuy, amount: parsedValue }); // number型で保存 } }} @@ -517,7 +527,7 @@ const TaskListPage: React.FC = () => { onChange={(e) => { const value = e.target.value; const parsedValue = parseInt(value, 10); // 数値に変換 - if (!isNaN(parsedValue) && parsedValue >= 0) { //負数除外 + if (/*!isNaN(parsedValue) && */ isNaN(parsedValue) || parsedValue >= 1) { //負数除外 setSelectedEditingTask({ ...selectedEditingTask, amount: parsedValue }); // number型で保存 } }}