diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index a8fccef..798d39b 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -117,8 +117,8 @@ const AddRecipe: React.FC = () => { const handleSubmit = async () => { const recipeId = await handleSaveRecipe(); - showSuccessMessage('レシピが保存されました!'); if (!recipeId) return; + showSuccessMessage('レシピが保存されました!'); navigate('/recipeList'); } diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index 42826db..ac93704 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -31,11 +31,14 @@ import { SoupKitchen as SoupKitchenIcon } from '@mui/icons-material'; import { ToBuy, Stuff, RecipeWithId, RecipeDetail } from '../types/types'; +import { useMessage } from '../components/MessageContext'; const RecipeList: React.FC = () => { const navigate = useNavigate(); // 料理リストの料理名を格納する配列 + const { showErrorMessage } = useMessage(); + // すべての料理リスト const [allRecipes, setAllRecipes] = useState(); @@ -48,7 +51,7 @@ const RecipeList: React.FC = () => { const recipes = await recipeApi.getAllRecipes(); setAllRecipes(recipes); } catch (error) { - alert("レシピの取得に失敗しました."); + showErrorMessage("レシピの取得に失敗しました。"); // console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); } }; diff --git a/frontend/src/pages/StockPage.tsx b/frontend/src/pages/StockPage.tsx index 2aa95ba..7688049 100644 --- a/frontend/src/pages/StockPage.tsx +++ b/frontend/src/pages/StockPage.tsx @@ -29,6 +29,7 @@ import { import { STOCK_ERRORS } from '../constants/errorMessages'; import DatePicker, { registerLocale } from 'react-datepicker'; import { ja } from 'date-fns/locale/ja'; // date-fnsの日本語ロケールをインポート +import { useMessage } from '../components/MessageContext'; // 日付をyyyy-MM-dd形式で返す関数 const formatDateLocal = (date: Date) => { @@ -72,6 +73,8 @@ const StockPage: React.FC = () => { // 在庫の編集状態 const [editStock, setEditStock] = useState(null); + const { showWarningMessage } = useMessage(); + // コンポーネントマウント時にタスク一覧を取得 useEffect(() => { fetchStocks(); @@ -196,7 +199,7 @@ const StockPage: React.FC = () => { setEditStock({ ...selectedRow }); setIsEditOpen(true); } else { - alert("編集する食材を選択してください。"); + showWarningMessage("編集する食材を選択してください。"); } }; // 変更を適用 @@ -248,7 +251,7 @@ const StockPage: React.FC = () => { if (selectedRow) { setIsDeleteOpen(true); } else { - alert("削除する食材を選択してください。"); + showWarningMessage("削除する食材を選択してください。"); } }; /** 削除ダイアログを閉じる */ diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 74b756d..0a20838 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -31,6 +31,7 @@ import AddStuffAmountDialog from '../components/AddStuffAmountDialog'; import BuyDialog from '../components/BuyDialog'; import { useNavigate } from 'react-router-dom'; import DatePicker from 'react-datepicker'; +import { useMessage } from '../components/MessageContext'; //import { FaCarrot } from "react-icons/fa6"; //エラー起きる いったん保留 @@ -91,7 +92,7 @@ const TaskListPage: React.FC = () => { shop: undefined, }); - + const { showErrorMessage } = useMessage(); // コンポーネントマウント時にタスク一覧を取得 useEffect(() => { @@ -149,7 +150,7 @@ const TaskListPage: React.FC = () => { const handleAddNewToBuy = async () => { try { if (isNaN(newToBuy.amount)) { - console.log('数量が正しくありません.'); + showErrorMessage('数量が正しくありません.'); return; } @@ -171,7 +172,7 @@ const TaskListPage: React.FC = () => { const handleUpdateNewToBuy = async () => { try { if (isNaN(editingItem.amount)) { - console.log('数量が正しくありません.'); + showErrorMessage('数量が正しくありません.'); return; } @@ -195,7 +196,7 @@ const TaskListPage: React.FC = () => { console.log("newPrice:", newStock.price) console.log("parsedPrice: ", parsedPrice) if (isNaN(parsedPrice)) { - alert('入力が無効です') + showErrorMessage('価格が正しく入力されていません。') return //setNewStock({ ...newStock, price: parsedPrice }); }