|
|
@ -25,7 +25,8 @@ import { |
|
|
|
SoupKitchen as SoupKitchenIcon, Edit as EditIcon |
|
|
|
SoupKitchen as SoupKitchenIcon, Edit as EditIcon |
|
|
|
} from '@mui/icons-material'; |
|
|
|
} from '@mui/icons-material'; |
|
|
|
import { ToBuy, Stuff, NewToBuy, NewStock, StuffAndCategoryAndAmount, StuffNameAndAmount, StockHistory, /*Stock*/ } from '../types/types'; |
|
|
|
import { ToBuy, Stuff, NewToBuy, NewStock, StuffAndCategoryAndAmount, StuffNameAndAmount, StockHistory, /*Stock*/ } from '../types/types'; |
|
|
|
import { GENERAL_ERRORS, TOBUY_ERRORS } from '../constants/errorMessages'; |
|
|
|
import { GENERAL_ERRORS, TOBUY_ERRORS, STUFF_HISTORY_ERRORS } from '../constants/errorMessages'; |
|
|
|
|
|
|
|
import { TOBUY_MESSAGES } from '../constants/normalMessages'; |
|
|
|
import EditAmountDialog from '../components/EditAmountDialog'; |
|
|
|
import EditAmountDialog from '../components/EditAmountDialog'; |
|
|
|
import AddStuffAmountDialog from '../components/AddStuffAmountDialog'; |
|
|
|
import AddStuffAmountDialog from '../components/AddStuffAmountDialog'; |
|
|
|
import BuyDialog from '../components/BuyDialog'; |
|
|
|
import BuyDialog from '../components/BuyDialog'; |
|
|
@ -96,7 +97,7 @@ const TaskListPage: React.FC = () => { |
|
|
|
shop: undefined, |
|
|
|
shop: undefined, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const { showErrorMessage } = useMessage(); |
|
|
|
const { showErrorMessage, showSuccessMessage } = useMessage(); |
|
|
|
|
|
|
|
|
|
|
|
// コンポーネントマウント時にタスク一覧を取得
|
|
|
|
// コンポーネントマウント時にタスク一覧を取得
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
@ -158,11 +159,20 @@ const TaskListPage: React.FC = () => { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newToBuy.stuffName = newToBuy.stuffName.trim(); // 材料名の前後の空白を削除
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!newToBuy.stuffName) { |
|
|
|
|
|
|
|
showErrorMessage(GENERAL_ERRORS.INVALID_STUFF_NAME); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(newToBuy) |
|
|
|
console.log(newToBuy) |
|
|
|
await toBuyApi.addToBuy(newToBuy); |
|
|
|
await toBuyApi.addToBuy(newToBuy); |
|
|
|
setOpenAddToBuyDialog(false); // ダイアログを閉じる
|
|
|
|
setOpenAddToBuyDialog(false); // ダイアログを閉じる
|
|
|
|
|
|
|
|
showSuccessMessage(TOBUY_MESSAGES.CREATE_OK); |
|
|
|
setNewToBuy(EMPTY_TOBUY); // 入力内容をリセット
|
|
|
|
setNewToBuy(EMPTY_TOBUY); // 入力内容をリセット
|
|
|
|
fetchTasks(); // 作成後のタスク一覧を再取得
|
|
|
|
fetchTasks(); // 作成後のタスク一覧を再取得
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
console.error(`${TOBUY_ERRORS.CREATE_FAILED}:`, error); |
|
|
|
console.error(`${TOBUY_ERRORS.CREATE_FAILED}:`, error); |
|
|
|
} |
|
|
|
} |
|
|
@ -197,17 +207,17 @@ const TaskListPage: React.FC = () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const today = new Date().toISOString().substring(0, 10); |
|
|
|
const today = new Date().toISOString().substring(0, 10); |
|
|
|
const parsedPrice = parseInt(newStock.price, 10); |
|
|
|
const parsedPrice = parseInt(newStock.price, 10); |
|
|
|
console.log("newPrice:", newStock.price) |
|
|
|
console.log("newPrice:", newStock.price); |
|
|
|
console.log("parsedPrice: ", parsedPrice) |
|
|
|
console.log("parsedPrice: ", parsedPrice); |
|
|
|
if (isNaN(parsedPrice)) { |
|
|
|
if (isNaN(parsedPrice)) { |
|
|
|
showErrorMessage(GENERAL_ERRORS.INVALID_PRICE) |
|
|
|
showErrorMessage(GENERAL_ERRORS.INVALID_PRICE); |
|
|
|
return |
|
|
|
return; |
|
|
|
//setNewStock({ ...newStock, price: parsedPrice });
|
|
|
|
//setNewStock({ ...newStock, price: parsedPrice });
|
|
|
|
} |
|
|
|
} |
|
|
|
const amount = parseInt(newStock.amount, 10); |
|
|
|
const amount = parseInt(newStock.amount, 10); |
|
|
|
if (isNaN(amount)) { |
|
|
|
if (isNaN(amount)) { |
|
|
|
showErrorMessage('購入数量が正しく入力されていません。') |
|
|
|
showErrorMessage(TOBUY_ERRORS.INVALID_BUYAMOUNT); |
|
|
|
return |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
await toBuyApi.buy({ |
|
|
|
await toBuyApi.buy({ |
|
|
|
tobuyId: selectedToBuyId, |
|
|
|
tobuyId: selectedToBuyId, |
|
|
@ -236,7 +246,7 @@ const TaskListPage: React.FC = () => { |
|
|
|
setStockHistories(await stockApi.getHistories(tobuy.stuffId)); |
|
|
|
setStockHistories(await stockApi.getHistories(tobuy.stuffId)); |
|
|
|
setOpenHistoryDialog(true); |
|
|
|
setOpenHistoryDialog(true); |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
showErrorMessage("履歴の読み込みに失敗しました。"); |
|
|
|
showErrorMessage(STUFF_HISTORY_ERRORS.FETCH_FAILED); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|