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

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)
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); // ダイアログを閉じる
setNewStock(EMPTY_STOCK); // 入力内容をリセット
fetchStocks(); // 作成後のタスク一覧を再取得
@ -249,8 +255,8 @@ const StockPage: React.FC = () => {
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
</TableRow>
</TableHead>
<TableBody>
@ -269,12 +275,12 @@ const StockPage: React.FC = () => {
<TableCell>{stock.stuffName}</TableCell>
<TableCell>{stock.amount}</TableCell>
<TableCell>{stock.price}</TableCell>
<TableCell>{formatDate(stock.buyDate)}</TableCell>
<TableCell
style={daysLeft <= 3 ? { color: "red", fontWeight: "bold" } : {}}
>
{formatDate(stock.expDate)}
</TableCell>
<TableCell>{formatDate(stock.buyDate)}</TableCell>
</TableRow>
);
})}
@ -309,19 +315,19 @@ const StockPage: React.FC = () => {
onChange={handleChange}
/>
<TextField
label="賞味・消費期限 (yyyy-MM-dd)"
label="購入日 (yyyy-MM-dd)"
fullWidth
margin="normal"
name="expDate"
value={editStock.expDate}
name="buyDate"
value={editStock.buyDate}
onChange={handleChange}
/>
<TextField
label="購入日 (yyyy-MM-dd)"
label="消費・賞味期限 (yyyy-MM-dd)"
fullWidth
margin="normal"
name="buyDate"
value={editStock.buyDate}
name="expDate"
value={editStock.expDate}
onChange={handleChange}
/>
@ -364,8 +370,6 @@ const StockPage: React.FC = () => {
)}
</DialogContent>
</Dialog>
</>
);
};
@ -474,22 +478,22 @@ const StockPage: React.FC = () => {
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可
/>
{/* 賞味・消費期限入力フィールド */}
{/* 購入日入力フィールド */}
<TextField
margin="dense"
label="消費・賞味期限(yyyy/MM/dd)"
label="購入日(yyyy/MM/dd)"
fullWidth
value={newStock.expDate}
onChange={(e) => setNewStock({ ...newStock, expDate: e.target.value })}
value={newStock.buyDate}
onChange={(e) => setNewStock({ ...newStock, buyDate: e.target.value })}
/>
{/* 購入日入力フィールド */}
{/* 賞味・消費期限入力フィールド */}
<TextField
margin="dense"
label="購入日(yyyy/MM/dd)"
label="消費・賞味期限(yyyy/MM/dd)"
fullWidth
value={newStock.buyDate}
onChange={(e) => setNewStock({ ...newStock, buyDate: e.target.value })}
value={newStock.expDate}
onChange={(e) => setNewStock({ ...newStock, expDate: e.target.value })}
/>
</Box>
</DialogContent>

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

Loading…
Cancel
Save