diff --git a/frontend/src/components/AddByRecipeDialog.tsx b/frontend/src/components/AddByRecipeDialog.tsx index fcce67d..35ee033 100644 --- a/frontend/src/components/AddByRecipeDialog.tsx +++ b/frontend/src/components/AddByRecipeDialog.tsx @@ -1,11 +1,19 @@ import React, { useEffect, useState } from 'react'; import { - Dialog, - DialogTitle, - DialogContent, - DialogActions, - Button, - Box, + Dialog, + DialogTitle, + DialogContent, + DialogActions, + Button, + Box, + List, + ListItem, + ListItemText, + ListItemSecondaryAction, + Typography, + TextField, + FormControlLabel, + Checkbox, } from '@mui/material'; import { toBuyApi } from '../services/api'; @@ -13,112 +21,138 @@ import { recipeApi } from '../services/api'; import CloseIcon from '@mui/icons-material/Close'; import { RecipeDetailWithId, StuffNameAndAmount } from '../types/types'; +import { GENERAL_ERRORS } from '../constants/errorMessages'; +import { useNavigate } from 'react-router-dom'; +import { useMessage } from './MessageContext'; -const AddByRecipeDialog = ({ - openDialog, - setOpenDialog, - recipeId, - numOfPeople, - setNumOfPeaple, - checked, - setChecked +const AddByRecipeDialog = ({ + openDialog, + setOpenDialog, + recipeId, + numOfPeople, + setNumOfPeaple, + checked, + setChecked }: { - openDialog: boolean, - setOpenDialog: (open: boolean) => void, - recipeId: number, - numOfPeople: number, - setNumOfPeaple: (num: number) => void, - checked: boolean, - setChecked: (checked: boolean) => void + openDialog: boolean, + setOpenDialog: (open: boolean) => void, + recipeId: number, + numOfPeople: number, + setNumOfPeaple: (num: number) => void, + checked: boolean, + setChecked: (checked: boolean) => void }) => { - const [recipe, setRecipe] = useState(); - - - useEffect(() => { - console.log("called AddByRecipeDialog useEffect recipeId: ", recipeId); - if (recipeId) { - const fetchRecipe = async () => { - console.log("Fetching recipe with ID:", recipeId); - setRecipe(await recipeApi.getById(recipeId)); - }; - fetchRecipe(); - } - }, [recipeId]); + const [recipe, setRecipe] = useState(); - return ( - recipe ? - setOpenDialog(false)} disableScrollLock={true} PaperProps={{ sx: { minWidth: '300px', maxHeight: '80vh' } }}> - - 買うものリストへ追加 - setOpenDialog(false)} - sx={{ - cursor: 'pointer', - color: (theme) => theme.palette.grey[500], - }} - /> - - -
- レシピ名: {recipe.recipeName} -
-
- ({recipe.maxServings}人分在庫あり) -
-
- 材料(1人前): -
    - {recipe.stuffAndAmountArray.map((item, index) => ( -
  • - {item.stuffName} - {item.amount}個 -
  • - ))} -
-
- - {/* 在庫との差分を取るかのチェックボックス */} -
- -
+ useEffect(() => { + console.log("called AddByRecipeDialog useEffect recipeId: ", recipeId); + if (recipeId) { + const fetchRecipe = async () => { + console.log("Fetching recipe with ID:", recipeId); + setRecipe(await recipeApi.getById(recipeId)); + }; + fetchRecipe(); + } + }, [recipeId]); - {/* レシピを追加する人数分を入力 */} -
- 人数: - { - setNumOfPeaple(parseInt(e.target.value, 10)); - }} - /> -
+ const navigate = useNavigate(); - {/* 買うものリストに追加するボタン */} - - - -
+ // エラーメッセージ表示 + const { showErrorMessage, showSuccessMessage, showInfoMessage } = useMessage(); -
- : <> - ); + return ( + recipe ? + setOpenDialog(false)} disableScrollLock={true} PaperProps={{ sx: { minWidth: '80vw', maxHeight: '80vh' } }}> + + + 買うものリストへ追加 + setOpenDialog(false)} + sx={{ + cursor: 'pointer', + color: (theme) => theme.palette.grey[500], + }} + /> + + + + {recipe.recipeName} + + + ({recipe.maxServings}人分在庫あり) + +
+ 材料(1人前): + + {recipe.stuffAndAmountArray.map((item, index) => ( + + + + + {`× ${item.amount}`} + + + + ))} + +
+
+ {/* 人数入力フィールド */} + { + setNumOfPeaple(parseInt(e.target.value, 10)); + }} + sx={{ minWidth: "8px", width: "100%" }} + inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可 + + /> +
+ setChecked(e.target.checked)} />} + label={足りない食材のみ登録} + /> + + {/* 買うものリストに追加するボタン */} + + + +
+ +
+ : <> + ); } export default AddByRecipeDialog; \ No newline at end of file diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index c1ca170..906bf5c 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -283,9 +283,9 @@ const AddRecipe: React.FC = () => { ))})}
- + {/* 材料を追加 - + */} setOpenAddDialog(true)}> diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index bd9e225..a44bdf2 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -155,6 +155,16 @@ const RecipeList: React.FC = () => { checked = {checked} setChecked={setChecked} /> } + + {/* 追加ボタン - 画面下部に固定表示 */} + + navigate('/addRecipe/')} className="plusButton"> + + + {/* + レシピの追加 + */} + ); };