在庫の新規追加機能を実装しました

feature-frontend-dishedit-kato
Yuna.Suzuki 4 months ago
parent 44c8660939
commit 9a3b22d2e7
  1. 42
      frontend/src/pages/StockPage.tsx
  2. 2
      frontend/src/services/api.ts

@ -88,7 +88,13 @@ const StockPage: React.FC = () => {
} }
console.log(newStock) console.log(newStock)
const today = new Date().toISOString().substring(0, 10); const today = new Date().toISOString().substring(0, 10);
await stockApi.addStock(newStock);
const updatedStock = { ...newStock, lastUpdate: today }; // lastUpdate に today を設定
console.log("送信するデータ:", updatedStock); // 送信前のデータを確認
await stockApi.addStock(updatedStock); // 修正したオブジェクトを API に送信
// await stockApi.addStock(newStock);
setIsAddOpen(false); // ダイアログを閉じる setIsAddOpen(false); // ダイアログを閉じる
setNewStock(EMPTY_STOCK); // 入力内容をリセット setNewStock(EMPTY_STOCK); // 入力内容をリセット
fetchStocks(); // 作成後のタスク一覧を再取得 fetchStocks(); // 作成後のタスク一覧を再取得
@ -249,8 +255,8 @@ const StockPage: React.FC = () => {
<TableCell></TableCell> <TableCell></TableCell>
<TableCell></TableCell> <TableCell></TableCell>
<TableCell></TableCell> <TableCell></TableCell>
<TableCell></TableCell>
<TableCell></TableCell> <TableCell></TableCell>
<TableCell></TableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -269,12 +275,12 @@ const StockPage: React.FC = () => {
<TableCell>{stock.stuffName}</TableCell> <TableCell>{stock.stuffName}</TableCell>
<TableCell>{stock.amount}</TableCell> <TableCell>{stock.amount}</TableCell>
<TableCell>{stock.price}</TableCell> <TableCell>{stock.price}</TableCell>
<TableCell>{formatDate(stock.buyDate)}</TableCell>
<TableCell <TableCell
style={daysLeft <= 3 ? { color: "red", fontWeight: "bold" } : {}} style={daysLeft <= 3 ? { color: "red", fontWeight: "bold" } : {}}
> >
{formatDate(stock.expDate)} {formatDate(stock.expDate)}
</TableCell> </TableCell>
<TableCell>{formatDate(stock.buyDate)}</TableCell>
</TableRow> </TableRow>
); );
})} })}
@ -309,19 +315,19 @@ const StockPage: React.FC = () => {
onChange={handleChange} onChange={handleChange}
/> />
<TextField <TextField
label="賞味・消費期限 (yyyy-MM-dd)" label="購入日 (yyyy-MM-dd)"
fullWidth fullWidth
margin="normal" margin="normal"
name="expDate" name="buyDate"
value={editStock.expDate} value={editStock.buyDate}
onChange={handleChange} onChange={handleChange}
/> />
<TextField <TextField
label="購入日 (yyyy-MM-dd)" label="消費・賞味期限 (yyyy-MM-dd)"
fullWidth fullWidth
margin="normal" margin="normal"
name="buyDate" name="expDate"
value={editStock.buyDate} value={editStock.expDate}
onChange={handleChange} onChange={handleChange}
/> />
@ -364,8 +370,6 @@ const StockPage: React.FC = () => {
)} )}
</DialogContent> </DialogContent>
</Dialog> </Dialog>
</> </>
); );
}; };
@ -474,22 +478,22 @@ const StockPage: React.FC = () => {
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可 inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可
/> />
{/* 賞味・消費期限入力フィールド */} {/* 購入日入力フィールド */}
<TextField <TextField
margin="dense" margin="dense"
label="消費・賞味期限(yyyy/MM/dd)" label="購入日(yyyy/MM/dd)"
fullWidth fullWidth
value={newStock.expDate} value={newStock.buyDate}
onChange={(e) => setNewStock({ ...newStock, expDate: e.target.value })} onChange={(e) => setNewStock({ ...newStock, buyDate: e.target.value })}
/> />
{/* 購入日入力フィールド */} {/* 賞味・消費期限入力フィールド */}
<TextField <TextField
margin="dense" margin="dense"
label="購入日(yyyy/MM/dd)" label="消費・賞味期限(yyyy/MM/dd)"
fullWidth fullWidth
value={newStock.buyDate} value={newStock.expDate}
onChange={(e) => setNewStock({ ...newStock, buyDate: e.target.value })} onChange={(e) => setNewStock({ ...newStock, expDate: e.target.value })}
/> />
</Box> </Box>
</DialogContent> </DialogContent>

@ -268,7 +268,7 @@ export const stockApi = {
console.log("レスポンスステータス:", response.status); console.log("レスポンスステータス:", response.status);
console.log("レスポンスヘッダー:", response.headers); console.log("レスポンスヘッダー:", response.headers);
console.log("レスポンス内容:", await response.text()); // console.log("レスポンス内容:", await response.text());
if (!response.ok) { if (!response.ok) {

Loading…
Cancel
Save