画面のレイアウト調整、数値入力のバリデーション強化

feature-frontend-bug-fixes
Masaharu.Kato 4 months ago
parent 2a961fd8c0
commit e86f1bb04a
  1. 19
      frontend/src/components/AddByRecipeDialog.tsx
  2. 5
      frontend/src/components/AddStuffAmountDialog.tsx
  3. 14
      frontend/src/components/DeleteStuffDialog.tsx
  4. 12
      frontend/src/pages/RecipeList.tsx
  5. 24
      frontend/src/pages/StockPage.tsx
  6. 4
      frontend/src/pages/TaskListPage.tsx

@ -76,7 +76,7 @@ const AddByRecipeDialog = ({
/> />
</DialogTitle> </DialogTitle>
<DialogContent dividers sx={{ padding: 2 }}> <DialogContent dividers sx={{ padding: 2 }}>
<Typography sx={{fontSize: '1.5rem'}}> <Typography sx={{fontSize: '1.6rem'}}>
{recipe.recipeName} {recipe.recipeName}
</Typography> </Typography>
<Typography sx={{mt: 2, mb: 2}}> <Typography sx={{mt: 2, mb: 2}}>
@ -108,13 +108,20 @@ const AddByRecipeDialog = ({
type="number" type="number"
margin="dense" margin="dense"
label="何人前" label="何人前"
className="numberField" fullWidth
defaultValue={1} defaultValue={1}
value={numOfPeople} value={numOfPeople}
onChange={(e) => { onChange={(e) => {
// const num = parseInt(e.target.value, 10); const value = e.target.value;
// setNumOfPeaple(!isNaN(num) ? num : ''); const parsedValue = parseInt(value, 10); // 数値に変換
setNumOfPeaple(e.target.value); if (/*!isNaN(parsedValue) && */ isNaN(parsedValue) || parsedValue >= 1) { //負数除外
setNumOfPeaple(value);
}
}}
onKeyDown={(e) => {
if (e.key === '-' || e.key === 'e' || e.key === 'E') {
e.preventDefault();
}
}} }}
inputProps={{ inputMode: "numeric", min: 1, pattern: "[0-9]*" }} // ここで整数のみ許可 inputProps={{ inputMode: "numeric", min: 1, pattern: "[0-9]*" }} // ここで整数のみ許可
@ -132,7 +139,7 @@ const AddByRecipeDialog = ({
color="primary" color="primary"
onClick={async () => { onClick={async () => {
const num = parseInt(numOfPeople, 10); const num = parseInt(numOfPeople, 10);
if (!num || isNaN(num)) { if (!num || isNaN(num) || num <= 0) {
showErrorMessage('人数が正しく入力されていません。'); showErrorMessage('人数が正しく入力されていません。');
return; return;
} }

@ -136,6 +136,11 @@ const AddStuffAmountDialog = ({
setNewItem({ ...newItem, amount: parsedValue }); // number型で保存 setNewItem({ ...newItem, amount: parsedValue }); // number型で保存
} }
}} }}
onKeyDown={(e) => {
if (e.key === '-' || e.key === 'e' || e.key === 'E') {
e.preventDefault();
}
}}
className="numberField" className="numberField"
type="number" type="number"
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可 inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可

@ -4,6 +4,7 @@ import {
DialogContent, DialogContent,
Button, Button,
Typography, Typography,
DialogActions,
} from '@mui/material'; } from '@mui/material';
const DeleteStuffDialog = ({ const DeleteStuffDialog = ({
@ -18,7 +19,7 @@ const DeleteStuffDialog = ({
onSubmit: () => void, onSubmit: () => void,
}) => { }) => {
{/* 削除ダイアログ */} {/* 削除ダイアログ */ }
return <Dialog open={openDialog} onClose={() => setOpenDialog(false)} disableScrollLock={true} return <Dialog open={openDialog} onClose={() => setOpenDialog(false)} disableScrollLock={true}
fullWidth fullWidth
maxWidth="sm" maxWidth="sm"
@ -26,15 +27,16 @@ const DeleteStuffDialog = ({
> >
<DialogTitle></DialogTitle> <DialogTitle></DialogTitle>
<DialogContent> <DialogContent>
<Typography variant="h4">{stuffName}</Typography> <Typography sx={{fontSize: '1.6rem'}}>{stuffName} </Typography>
<Typography variant="body1" color="error"> 注意: 削除すると復元できません</Typography> <Typography variant="body1" color="error"> 注意: 削除すると復元できません</Typography>
<Button onClick={() => setOpenDialog(false)} sx={{ mt: 3, mb: 2, left: '70%' }}></Button> </DialogContent>
<DialogActions>
<Button onClick={() => setOpenDialog(false)} ></Button>
<Button variant="contained" color="error" onClick={() => { <Button variant="contained" color="error" onClick={() => {
onSubmit(); onSubmit();
setOpenDialog(false); // 削除処理後にダイアログを閉じる setOpenDialog(false); // 削除処理後にダイアログを閉じる
}} }}></Button>
style={{ marginTop: "10px" }} sx={{ mt: 3, mb: 2, left: '72%' }}></Button> </DialogActions>
</DialogContent>
</Dialog> </Dialog>
} }

@ -120,20 +120,20 @@ const RecipeList: React.FC = () => {
: <></>} : <></>}
{recipe.maxServings === 0 ? {recipe.maxServings === 0 ?
<Tooltip title="" sx={{ color: "tomato" }}> <Tooltip title="">
<IconButton edge="end" aria-label=""> <IconButton sx={{ mr: 0, ml: 0, color: "tomato" }} edge="end" aria-label="">
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Tooltip> : </Tooltip> :
<Tooltip title="" sx={{ color: "mediumaquamarine" }}> <Tooltip title="">
<IconButton edge="end" aria-label=""> <IconButton sx={{ mr: 0, ml: 0, color: "mediumaquamarine" }} edge="end" aria-label="">
<TaskAltIcon /> <TaskAltIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
} }
<Tooltip title="編集" sx={{ml: 1}}> <Tooltip title="編集" sx={{}}>
<IconButton edge="end" aria-label="編集" <IconButton sx={{ mr: 0, ml: 0 }} edge="end" aria-label="編集"
onClick={() => { onClick={() => {
navigate('/addRecipe/' + recipe.recipeId); navigate('/addRecipe/' + recipe.recipeId);
}} }}

@ -453,6 +453,7 @@ const StockPage: React.FC = () => {
margin="normal" margin="normal"
name="amount" name="amount"
type="number" type="number"
fullWidth
className="numberField" className="numberField"
value={editStock.amount} value={editStock.amount}
onChange={handleChange} onChange={handleChange}
@ -470,7 +471,7 @@ const StockPage: React.FC = () => {
margin="normal" margin="normal"
name="buyAmount" name="buyAmount"
type="number" type="number"
className="numberField" fullWidth
value={editStock.buyAmount} value={editStock.buyAmount}
onChange={handleChange} onChange={handleChange}
inputProps={{ min: 0 }} inputProps={{ min: 0 }}
@ -484,10 +485,10 @@ const StockPage: React.FC = () => {
{/* 購入価格フィールド */} {/* 購入価格フィールド */}
<TextField <TextField
label="購入価格" label="購入価格"
fullWidth
margin="normal" margin="normal"
name="price" name="price"
type="number" type="number"
fullWidth
value={editStock.price} value={editStock.price}
onChange={handleChange} onChange={handleChange}
inputProps={{ min: 0 }} inputProps={{ min: 0 }}
@ -511,19 +512,18 @@ const StockPage: React.FC = () => {
{/* 購入日・賞味期限入力 */} {/* 購入日・賞味期限入力 */}
<BuyExpDateSelect newStock={editStock} setNewStock={({ buyDate, expDate }) => setEditStock({ ...editStock, buyDate, expDate })} /> <BuyExpDateSelect newStock={editStock} setNewStock={({ buyDate, expDate }) => setEditStock({ ...editStock, buyDate, expDate })} />
</>
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 2, mt: 3, mb: 2 }}> )}
</DialogContent>
<DialogActions>
<Button onClick={() => { setOpenEditDialog(false); setSelectedRow(null); }}> <Button onClick={() => { setOpenEditDialog(false); setSelectedRow(null); }}>
</Button> </Button>
<Button variant="contained" color="success" onClick={handleApplyChanges} sx={{ mt: 3, mb: 2 }}> <Button variant="contained" color="success" onClick={handleApplyChanges}>
</Button> </Button>
<Button variant="contained" color="error" onClick={() => setOpenDeleteDialog(true)} sx={{ mt: 3, mb: 2 }}></Button> <Button variant="contained" color="error" onClick={() => setOpenDeleteDialog(true)}></Button>
</Box> </DialogActions>
</>
)}
</DialogContent>
</Dialog> </Dialog>
{/* 削除ダイアログ */} {/* 削除ダイアログ */}
@ -613,10 +613,10 @@ const StockPage: React.FC = () => {
{!openCategory[category] ? <ArrowDownIcon color="primary" /> : <ArrowUpIcon color="primary" />} {!openCategory[category] ? <ArrowDownIcon color="primary" /> : <ArrowUpIcon color="primary" />}
{category} {category}
</Typography> </Typography>
{!stocks {openCategory[category] && (!stocks
? <Typography>...</Typography> ? <Typography>...</Typography>
: StockTable(stocks, [category]) : StockTable(stocks, [category])
} )}
</Box> </Box>
) )
})} })}

@ -290,7 +290,7 @@ const TaskListPage: React.FC = () => {
</Typography> </Typography>
{/* 買い物リスト:数量変更ボタン */} {/* 買い物リスト:数量変更ボタン */}
<Tooltip title="数量変更"> <Tooltip title="数量変更">
<IconButton sx={{ marginRight: 0, marginLeft: 0 }} edge="end" aria-label="数量変更" <IconButton sx={{ mr: 0, ml: 0 }} edge="end" aria-label="数量変更"
onClick={() => { onClick={() => {
setOpenAmountDialog(true) setOpenAmountDialog(true)
setEditingItem(tobuy) setEditingItem(tobuy)
@ -301,7 +301,7 @@ const TaskListPage: React.FC = () => {
</Tooltip> </Tooltip>
{/* 買い物リスト:食材情報記入ボタン */} {/* 買い物リスト:食材情報記入ボタン */}
<Tooltip title="購入情報を記入"> <Tooltip title="購入情報を記入">
<IconButton color="primary" sx={{ marginRight: 0, marginLeft: 0 }} edge="end" aria-label="購入情報を記入" <IconButton color="primary" sx={{ mr: 0, ml: 0 }} edge="end" aria-label="購入情報を記入"
onClick={() => { onClick={() => {
setOpenInfoDialog(true) setOpenInfoDialog(true)
setEditingItem(tobuy) setEditingItem(tobuy)

Loading…
Cancel
Save