diff --git a/frontend/src/components/AddByRecipeDialog.tsx b/frontend/src/components/AddByRecipeDialog.tsx index 86c9c6f..f0fdf06 100644 --- a/frontend/src/components/AddByRecipeDialog.tsx +++ b/frontend/src/components/AddByRecipeDialog.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Dialog, DialogTitle, @@ -8,23 +8,45 @@ import { Box, } from '@mui/material'; +import { toBuyApi } from '../services/api'; import { recipeApi } from '../services/api'; import CloseIcon from '@mui/icons-material/Close'; -import { StuffNameAndAmount } from '../types/types'; +import { RecipeDetailWithId, StuffNameAndAmount } from '../types/types'; -const AddByRecipeDialog = async ({ +const AddByRecipeDialog = ({ openDialog, setOpenDialog, - recipeId + 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 }) => { - const recipe = await recipeApi.getById(recipeId); + 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]); return ( + recipe ? setOpenDialog(false)} disableScrollLock={true} PaperProps={{ sx: { minWidth: '300px', maxHeight: '80vh' } }}> @@ -42,12 +64,12 @@ const AddByRecipeDialog = async ({ レシピ名: {recipe.recipeName}
- ({recipe.maxservings}) + ({recipe.maxServings}人分在庫あり)
- 材料: + 材料(1人前):
    - {recipe.stuffNameAndAmountList.map((item, index) => ( + {recipe.stuffAndAmountArray.map((item, index) => (
  • {item.stuffName} - {item.amount}個
  • @@ -55,17 +77,47 @@ const AddByRecipeDialog = async ({
- {/* レシピを追加する人数分を入力 */} + {/* 在庫との差分を取るかのチェックボックス */} +
+ +
+ {/* レシピを追加する人数分を入力 */}
- 材料を買うものリストに追加します。 + 人数: + { + setNumOfPeaple(parseInt(e.target.value, 10)); + }} + />
+ + {/* 買うものリストに追加するボタン */} + + + - - -
+ : <> ); } diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index ccf78cb..9cc24dc 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -52,6 +52,8 @@ const RecipeList: React.FC = () => { const [openAddByRecipeDialog, setOpenAddByRecipeDialog] = useState(false); const [addByRecipeId, setAddByRecipeId] = useState(0); + const [numOfPeople, setNumOfPeople] = useState(1); + const [checked, setChecked] = useState(false); const openRecipeById = (recipeId: number) => { navigate('/addRecipe/' + recipeId); @@ -102,7 +104,9 @@ const RecipeList: React.FC = () => { fontSize: '40px' }} onClick = {() => - {setAddByRecipeId(recipe.recipeId) + { + console.log("recipeId: ", recipe.recipeId); + setAddByRecipeId(recipe.recipeId) setOpenAddByRecipeDialog(true)} } > @@ -176,7 +180,9 @@ const RecipeList: React.FC = () => { {/* 買うものリストへ追加ダイアログ */} { + recipeId = {addByRecipeId} numOfPeople={numOfPeople} setNumOfPeaple={setNumOfPeople} + checked = {checked} setChecked={setChecked} + /> } );