import React, { useEffect, useState } from 'react'; import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Box, } from '@mui/material'; import { toBuyApi } from '../services/api'; import { recipeApi } from '../services/api'; import CloseIcon from '@mui/icons-material/Close'; import { RecipeDetailWithId, StuffNameAndAmount } from '../types/types'; 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 }) => { 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' } }}> 買うものリストへ追加 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}個
  • ))}
{/* 在庫との差分を取るかのチェックボックス */}
{/* レシピを追加する人数分を入力 */}
人数: { setNumOfPeaple(parseInt(e.target.value, 10)); }} />
{/* 買うものリストに追加するボタン */}
: <> ); } export default AddByRecipeDialog;