From bd9536947901333da702b29fc3b1583e7593c25b Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Mon, 16 Jun 2025 14:57:36 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BD=95=E4=BA=BA=E5=88=86=E3=81=8B?= =?UTF-8?q?=E3=82=92=E5=85=A5=E5=8A=9B=E3=81=99=E3=82=8B=E3=83=80=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=AD=E3=82=B0=E3=82=92=E8=A1=A8=E7=A4=BA(?= =?UTF-8?q?=E8=87=AA=E5=88=86=E3=81=AE=E7=94=BB=E9=9D=A2=E3=81=A7=E3=81=AF?= =?UTF-8?q?=E5=8B=95=E3=81=8B=E3=81=AA=E3=81=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 97 ++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 2618fda..00337cb 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -21,6 +21,7 @@ import { TextField, Button, Box, + FormGroup, MenuItem, Select, FormControl, @@ -43,6 +44,9 @@ const AddRecipe: React.FC = () => { const navigate = useNavigate(); + // 何人分かを格納する + const [numOfPeaple, setNumOfPeaple] = useState(1); + const [openNumOfPeapleDialog, setOpenNumOfPeapleDialog] = useState(false); // 料理名,説明 const [recipeName, setRecipeName] = useState(''); const [recipeSummary, setRecipeSummary] = useState(''); @@ -71,17 +75,20 @@ const AddRecipe: React.FC = () => { const handleSaveRecipe = async () => { - if (!recipeName) { - alert('レシピ名が入力されていません!') - return false; - } + // if (!recipeName) { + // alert('レシピ名が入力されていません!') + // console.log("yes1"); + // return false; + // } - if (!items.length) { - alert('材料が追加されていません!') - return false; - } + // if (!items.length) { + // alert('材料が追加されていません!') + // console.log("yes2"); + // return false; + // } if (!recipeId) { + console.log("yes3"); // 新規追加 const response = await recipeApi.addRecipe({ recipeName, @@ -97,10 +104,25 @@ const AddRecipe: React.FC = () => { summary: recipeSummary, stuffAndAmountArray: items, }) - + console.log("yes4"); return recipeId; } + const checkRecipeAndItems = async () => { + + if (!recipeName) { + alert('レシピ名が入力されていません!') + console.log("yes1"); + return false; + } + + if (!items.length) { + alert('材料が追加されていません!') + console.log("yes2"); + return false; + } + } + const handleSubmit = async () => { const recipeId = await handleSaveRecipe(); // alert('レシピが保存されました!'); @@ -109,13 +131,27 @@ const AddRecipe: React.FC = () => { } const handleSubmitAndAddToBuy = async () => { + console.log(recipeName); const recipeId = await handleSaveRecipe(); + console.log("before"); if (!recipeId) return false; + console.log("ds"); await toBuyApi.addByRecipe(recipeId); // alert('レシピが保存されて買うものリストに追加されました!'); navigate('/tasks'); } + const openNumOfPeopleDialog = async () => { + await checkRecipeAndItems(); + setOpenNumOfPeapleDialog(true); + } + + const cancelNumOfPeopleDialog = async () => { + const recipeId = await handleSaveRecipe(); + if (!recipeId) return false; + setOpenNumOfPeapleDialog(false); + } + // コンポーネントマウント時にタスク一覧を取得 useEffect(() => { loadRecipe(); @@ -138,7 +174,7 @@ const AddRecipe: React.FC = () => { value={recipeSummary} onChange={(e) => setRecipeSummary(e.target.value)} /> -

+

材料リスト

{/* すべての材料情報を表示 */} @@ -190,6 +226,7 @@ const AddRecipe: React.FC = () => { ))})} +
@@ -205,7 +242,7 @@ const AddRecipe: React.FC = () => { レシピを保存 - @@ -228,6 +265,44 @@ const AddRecipe: React.FC = () => { setOpenAmountDialog(false); }} /> + setOpenNumOfPeapleDialog(false)} disableScrollLock={true} + style={{ width : '100%', position : 'fixed', left: '50%', transform: 'translateX(-50%)' }} + > + + 何人前かを入力 + + +
+ {/* 人数入力フィールド */} + { + const value = e.target.value; + const parsedValue = parseInt(value, 10); // 数値に変換 + if (/*!isNaN(parsedValue) && */ isNaN(parsedValue) || parsedValue >= 1) { //負数除外 + setNumOfPeaple(parsedValue); // number型で保存 + } + }} + sx={{ minWidth: "8px", width: "100%" }} + type="number" + inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可 + + /> +
+
+ + + + +
); }; From 5e1aac49221943588209f51c2871405a27739aea Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Mon, 16 Jun 2025 15:01:34 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=BD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=AD=E3=82=B0=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 00337cb..0256240 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -131,6 +131,7 @@ const AddRecipe: React.FC = () => { } const handleSubmitAndAddToBuy = async () => { + console.log("too"); console.log(recipeName); const recipeId = await handleSaveRecipe(); console.log("before"); From 164ae67ed7bcf8c0943b25d23a638fac93fffecf Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Mon, 16 Jun 2025 16:41:17 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=99=E7=90=86=E5=90=8D=E3=82=84?= =?UTF-8?q?=E9=A3=9F=E6=9D=90=E3=83=AA=E3=82=B9=E3=83=88=E3=81=AB=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E3=81=8C=E3=81=AA=E3=81=8F=E3=81=A6=E3=82=82=E3=83=80?= =?UTF-8?q?=E3=82=A4=E3=82=A2=E3=83=AD=E3=82=B0=E3=81=8C=E5=87=BA=E3=82=8B?= =?UTF-8?q?=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 0256240..ac5aa14 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -121,6 +121,7 @@ const AddRecipe: React.FC = () => { console.log("yes2"); return false; } + return true; } const handleSubmit = async () => { @@ -143,7 +144,8 @@ const AddRecipe: React.FC = () => { } const openNumOfPeopleDialog = async () => { - await checkRecipeAndItems(); + const check = await checkRecipeAndItems(); + if (!check) return false; setOpenNumOfPeapleDialog(true); } From 2c59dc9484e8e1781782c74181f9574f11b5375f Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Tue, 17 Jun 2025 09:42:41 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E3=83=AC=E3=82=B7=E3=83=94=E3=81=8B?= =?UTF-8?q?=E3=82=89=E8=BF=BD=E5=8A=A0=E3=81=AEAPI=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/services/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index 7a31c9e..f076e74 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -132,11 +132,11 @@ export const toBuyApi = { }, - addByRecipe: async (recipeId: number): Promise => { + addByRecipe: async (recipeId: number, servings: number): Promise => { const response = await fetch(`${API_BASE_URL}/api/tobuy/addByRecipe`, { method: 'POST', headers: getHeaders(), - body: JSON.stringify({ recipeId }), + body: JSON.stringify({ recipeId, servings }), }) if (!response.ok) { throw new Error(TOBUY_ERRORS.CREATE_FAILED); From 8fceebb5a902e8d8d4229cd30a5c1453cea88109 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Tue, 17 Jun 2025 10:22:42 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BA=BA=E6=95=B0=E5=88=86=E3=81=AE?= =?UTF-8?q?=E9=A3=9F=E6=9D=90=E3=82=92=E8=B2=B7=E3=81=84=E7=89=A9=E3=83=AA?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AB=E7=99=BB=E9=8C=B2=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E5=AE=9F=E8=A3=85=E3=80=81?= =?UTF-8?q?UI=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 37 ++++++++++++++++---------------- frontend/src/pages/StockPage.tsx | 7 ------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 2bb15fc..a4f52ab 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -86,17 +86,17 @@ const AddRecipe: React.FC = () => { const handleSaveRecipe = async () => { - // if (!recipeName) { - // showErrorMessage('レシピ名が入力されていません!') - // console.log("yes1"); - // return false; - // } - - // if (!items.length) { - // showErrorMessage('材料が追加されていません!') - // console.log("yes2"); - // return false; - // } + if (!recipeName) { + showErrorMessage('レシピ名が入力されていません!') + console.log("yes1"); + return false; + } + + if (!items.length) { + showErrorMessage('材料が追加されていません!') + console.log("yes2"); + return false; + } try { if (!recipeId) { @@ -127,13 +127,13 @@ const AddRecipe: React.FC = () => { const checkRecipeAndItems = async () => { if (!recipeName) { - alert('レシピ名が入力されていません!') + showErrorMessage('レシピ名が入力されていません!') console.log("yes1"); return false; } if (!items.length) { - alert('材料が追加されていません!') + showErrorMessage('材料が追加されていません!') console.log("yes2"); return false; } @@ -154,7 +154,7 @@ const AddRecipe: React.FC = () => { console.log("before"); if (!recipeId) return false; console.log("ds"); - await toBuyApi.addByRecipe(recipeId); + await toBuyApi.addByRecipe(recipeId, numOfPeaple); showSuccessMessage('レシピが保存されて買うものリストに追加されました!'); navigate('/tasks'); } @@ -312,12 +312,13 @@ const AddRecipe: React.FC = () => { setOpenAmountDialog(false); }} /> + {/* 人数入力ダイアログ */} setOpenNumOfPeapleDialog(false)} disableScrollLock={true} style={{ width : '100%', position : 'fixed', left: '50%', transform: 'translateX(-50%)' }} > - 何人前かを入力 + 買うものリストへ追加
@@ -343,10 +344,10 @@ const AddRecipe: React.FC = () => { -
diff --git a/frontend/src/pages/StockPage.tsx b/frontend/src/pages/StockPage.tsx index b359f94..981464f 100644 --- a/frontend/src/pages/StockPage.tsx +++ b/frontend/src/pages/StockPage.tsx @@ -39,13 +39,6 @@ const formatDateLocal = (date: Date) => { return `${year}-${month}-${day}`; }; -// 日付をyyyy-MM-dd形式で返す関数 -const formatDateLocal = (date: Date) => { - const year = date.getFullYear(); - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const day = date.getDate().toString().padStart(2, '0'); - return `${year}-${month}-${day}`; -}; // 新規在庫の初期状態 const EMPTY_STOCK: Omit & { stuffId: number | null } & { newAddition: boolean } = { From 82b83f50440fa3e8caef3a9c70183b7f8e84f703 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Tue, 17 Jun 2025 10:31:35 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BA=BA=E6=95=B0=E3=81=8C=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E3=81=AB=E3=82=82=E8=B2=B7=E3=81=86=E3=82=82?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=82=B9=E3=83=88=E3=81=AB=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index a4f52ab..6a2e230 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -154,6 +154,11 @@ const AddRecipe: React.FC = () => { console.log("before"); if (!recipeId) return false; console.log("ds"); + if (!numOfPeaple) { + showErrorMessage('人数が入力されていません!') + console.log("yes2"); + return false; + } await toBuyApi.addByRecipe(recipeId, numOfPeaple); showSuccessMessage('レシピが保存されて買うものリストに追加されました!'); navigate('/tasks'); From 80f163418a172884e5da330dcc473eb3a3a16f90 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Tue, 17 Jun 2025 11:29:22 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E5=88=A9=E7=94=A8=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=82=A4=E3=83=B3=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddRecipe.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 6a2e230..75678cf 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -4,7 +4,6 @@ */ import React, { useState, useEffect } from 'react'; import { - Container, Typography, Tooltip, List, @@ -12,7 +11,6 @@ import { ListItemText, ListItemSecondaryAction, IconButton, - Checkbox, Fab, Dialog, DialogTitle, @@ -21,13 +19,6 @@ import { TextField, Button, Box, - FormGroup, - MenuItem, - Select, - FormControl, - InputLabel, - ListItemIcon, - AlertColor } from '@mui/material'; import { Add as AddIcon, Delete as DeleteIcon, ShoppingBasket as ShoppingBasketIcon,