diff --git a/frontend/src/components/BuyDialog.tsx b/frontend/src/components/BuyDialog.tsx index 918a285..0d37efb 100644 --- a/frontend/src/components/BuyDialog.tsx +++ b/frontend/src/components/BuyDialog.tsx @@ -9,9 +9,13 @@ import { Box, } from '@mui/material'; import { NewStock } from '../types/types'; -import DatePicker from 'react-datepicker'; +import DatePicker, { registerLocale } from 'react-datepicker'; +import { ja } from 'date-fns/locale/ja'; // date-fnsの日本語ロケールをインポート +// 日本語ロケールを登録 + registerLocale('ja', ja); + const BuyDialog = ({ openDialog, setOpenDialog, @@ -25,7 +29,7 @@ const BuyDialog = ({ setNewStock: (tobuy: NewStock) => void, onSubmit: () => void, }) => { - + return ( diff --git a/frontend/src/pages/StockPage.tsx b/frontend/src/pages/StockPage.tsx index 7e91f1d..3379f18 100644 --- a/frontend/src/pages/StockPage.tsx +++ b/frontend/src/pages/StockPage.tsx @@ -27,21 +27,26 @@ import { MenuItem, } from '@mui/material'; import { STOCK_ERRORS } from '../constants/errorMessages'; +import DatePicker, { registerLocale } from 'react-datepicker'; +import { ja } from 'date-fns/locale/ja'; // date-fnsの日本語ロケールをインポート // 新規在庫の初期状態 const EMPTY_STOCK: Omit & { stuffId: number | null } & { newAddition: boolean } = { stuffId: null, stuffName: '', - amount: 0, + amount: 1, price: 0, lastUpdate: '', - buyDate: '', + buyDate: new Date().toISOString(), expDate: '', category: '', newAddition: false, // 材料を新規作成するか否か // shop '', } +// 日本語ロケールを登録 +registerLocale('ja', ja); + const StockPage: React.FC = () => { const [stocks, setStocks] = useState([]); @@ -86,6 +91,9 @@ const StockPage: React.FC = () => { if (newStock.newAddition) { newStock.stuffId = null; } + if (isNaN(newStock.amount)) return; + if (isNaN(newStock.price)) return; + console.log(newStock) const today = new Date().toISOString().substring(0, 10); @@ -381,7 +389,7 @@ const StockPage: React.FC = () => { 在庫一覧 - + {/* 在庫の食材追加ボタン */}