|
|
|
@ -18,6 +18,8 @@ import { |
|
|
|
|
DialogActions, |
|
|
|
|
TextField, |
|
|
|
|
Button, |
|
|
|
|
Checkbox, |
|
|
|
|
FormControlLabel, |
|
|
|
|
Box, |
|
|
|
|
} from '@mui/material'; |
|
|
|
|
import { |
|
|
|
@ -27,7 +29,7 @@ import { |
|
|
|
|
import AddStuffAmountDialog from '../components/AddStuffAmountDialog'; |
|
|
|
|
import { StuffAndCategoryAndAmount } from '../types/types'; |
|
|
|
|
import EditAmountDialog from '../components/EditAmountDialog'; |
|
|
|
|
import { recipeApi, toBuyApi } from '../services/api'; |
|
|
|
|
import { recipeApi, toBuyApi, stockApi } from '../services/api'; |
|
|
|
|
import { useNavigate, useParams } from 'react-router-dom'; |
|
|
|
|
import MessageAlert from '../components/MessageAlert'; |
|
|
|
|
import { useMessage } from '../components/MessageContext'; |
|
|
|
@ -60,6 +62,8 @@ const AddRecipe: React.FC = () => { |
|
|
|
|
const [editingItemIdx, setEditingItemIdx] = useState(0); |
|
|
|
|
//削除確認ダイアログの表示状態
|
|
|
|
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false); |
|
|
|
|
// チェックボックスが押されたかどうか
|
|
|
|
|
const [checked, setChecked] = useState(false); |
|
|
|
|
|
|
|
|
|
// エラーメッセージ表示
|
|
|
|
|
const { showErrorMessage, showSuccessMessage } = useMessage(); |
|
|
|
@ -150,8 +154,32 @@ const AddRecipe: React.FC = () => { |
|
|
|
|
console.log("yes2"); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
await toBuyApi.addByRecipe(recipeId, numOfPeaple); |
|
|
|
|
const finalAddResult = await toBuyApi.addByRecipe(recipeId, numOfPeaple, checked); |
|
|
|
|
console.log(finalAddResult) |
|
|
|
|
// const recipeStuffInfo = (await recipeApi.getById(recipeId)).stuffAndAmountArray;
|
|
|
|
|
// const recipeStuffId = recipeStuffInfo.map(item => item.stuffId);
|
|
|
|
|
// console.log(recipeStuffId);
|
|
|
|
|
// const stockStuff = await stockApi.getStocks();
|
|
|
|
|
// const stockedStuffId = stockStuff.filter(stock => recipeStuff.stuffAndAmountArray).map(item => item.id);
|
|
|
|
|
// const stockedStuffAmountRecipe = recipeStuff.filter(recipe => (stockStuff.some(stuff => recipe.stuffId === stuff.stuffId)));
|
|
|
|
|
// console.log(stockedStuffAmountRecipe)
|
|
|
|
|
// const stockedStuffAmountStock = stockStuff.filter(stock => (stockedStuffAmountRecipe.some(stocked => stock.stuffId === stocked.stuffId)));
|
|
|
|
|
|
|
|
|
|
// recipeStuff.map(item => {
|
|
|
|
|
// await Promise.all(stockStuff.map(async stock => {
|
|
|
|
|
// if (item.stuffId == stock.stuffId)
|
|
|
|
|
// await toBuyApi.updateToBuy({stuffName: item.stuffName,
|
|
|
|
|
// amount: item.amount - stock.amount,
|
|
|
|
|
// tobuyId: item.tobuyId,
|
|
|
|
|
// stuffId: item.stuffId});
|
|
|
|
|
// }))
|
|
|
|
|
// });
|
|
|
|
|
if (finalAddResult.data.length === 0) { |
|
|
|
|
showSuccessMessage('必要な食材が在庫にあったのでリストには追加されませんでした!'); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
showSuccessMessage('レシピが保存されて買うものリストに追加されました!'); |
|
|
|
|
} |
|
|
|
|
navigate('/tasks'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -337,6 +365,10 @@ const AddRecipe: React.FC = () => { |
|
|
|
|
|
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<FormControlLabel |
|
|
|
|
control={<Checkbox checked={checked} onChange={(e) => setChecked(e.target.checked)} />} |
|
|
|
|
label={<Typography fontSize="clamp(8px, 1.5vw, 14px)">足りない食材のみ登録</Typography>} |
|
|
|
|
/> |
|
|
|
|
</DialogContent> |
|
|
|
|
<DialogActions> |
|
|
|
|
<Button onClick={() => setOpenNumOfPeapleDialog(false)}>前の画面に戻る</Button> |
|
|
|
|