diff --git a/frontend/src/components/AddByRecipeDialog.tsx b/frontend/src/components/AddByRecipeDialog.tsx index a9ec83b..fcce67d 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' } }}> @@ -41,31 +63,61 @@ const AddByRecipeDialog = async ({
レシピ名: {recipe.recipeName}
- {/*
- ({recipe.maxservings}) +
+ ({recipe.maxServings}人分在庫あり)
- 材料: + 材料(1人前):
    - {recipe.stuffNameAndAmountList.map((item, index) => ( + {recipe.stuffAndAmountArray.map((item, index) => (
  • {item.stuffName} - {item.amount}個
  • ))}
-
*/} +
- {/* レシピを追加する人数分を入力 */} + {/* 在庫との差分を取るかのチェックボックス */} +
+ +
+ {/* レシピを追加する人数分を入力 */}
- 材料を買うものリストに追加します。 + 人数: + { + setNumOfPeaple(parseInt(e.target.value, 10)); + }} + />
+ + {/* 買うものリストに追加するボタン */} + + + - - -
+ : <> ); } diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index 74c5c9f..bd9e225 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -54,6 +54,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); @@ -147,10 +149,12 @@ const RecipeList: React.FC = () => { {/* 買うものリストへ追加ダイアログ */} - {/* + { - */} + recipeId = {addByRecipeId} numOfPeople={numOfPeople} setNumOfPeaple={setNumOfPeople} + checked = {checked} setChecked={setChecked} + /> + } ); };