From 758247f649ef46664c1043425502d544369cae5f Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Wed, 21 Feb 2024 15:09:35 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C0?= =?UTF-8?q?=E4=BB=B6=E3=81=AE=E5=87=A6=E7=90=86=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/next-project/src/pages/budgets/index.tsx | 191 +++++++++--------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/view/next-project/src/pages/budgets/index.tsx b/view/next-project/src/pages/budgets/index.tsx index 9478a31f0..8fa4ae6e2 100644 --- a/view/next-project/src/pages/budgets/index.tsx +++ b/view/next-project/src/pages/budgets/index.tsx @@ -94,11 +94,8 @@ export default function BudgetList(props: Props) { const getBudgets = async () => { const getBudgtesByYearsURL = process.env.CSR_API_URI + '/budgets/details/' + selectedYear; - const getExpensesByYearsURL = process.env.CSR_API_URI + '/expenses/details/' + selectedYear; const getBudgetsByYears = await get(getBudgtesByYearsURL); - const getExpensesByYears = await get(getExpensesByYearsURL); setBudgetViews(getBudgetsByYears); - setExpenseViews(getExpensesByYears); }; const getExpenses = async () => { @@ -117,13 +114,17 @@ export default function BudgetList(props: Props) { }, [selectedExpenseYear]); // 合計金額用の変数 - const budgetsTotalFee = budgetViews.reduce((prev, current) => { - return prev + current.budget.price; - }, 0); + const budgetsTotalFee = + budgetViews && + budgetViews.reduce((prev, current) => { + return prev + current.budget.price; + }, 0); - const expensesTotalFee = expenseViews.reduce((prev, current) => { - return prev + current.expense.totalPrice; - }, 0); + const expensesTotalFee = + expenseViews && + expenseViews.reduce((prev, current) => { + return prev + current.expense.totalPrice; + }, 0); const formatDate = (date: string) => { const datetime = date.replace('T', ' '); @@ -188,42 +189,43 @@ export default function BudgetList(props: Props) { - {budgetViews.map((budgetView, index) => ( - - {budgetView.source.name} - {budgetView.year.year} - {budgetView.budget.price} - - {formatDate( - budgetView.budget.createdAt ? budgetView.budget.createdAt : '', + {budgetViews && + budgetViews.map((budgetView, index) => ( + - - {formatDate( - budgetView.budget.updatedAt ? budgetView.budget.updatedAt : '', - )} - - - - - - - ))} - {!budgetViews.length && ( + > + {budgetView.source.name} + {budgetView.year.year} + {budgetView.budget.price} + + {formatDate( + budgetView.budget.createdAt ? budgetView.budget.createdAt : '', + )} + + + {formatDate( + budgetView.budget.updatedAt ? budgetView.budget.updatedAt : '', + )} + + + + + + + ))} + {!budgetViews && ( データがありません @@ -231,7 +233,7 @@ export default function BudgetList(props: Props) { )} - {budgetViews.length > 0 && ( + {budgetViews && budgetViews.length > 0 && ( - {expenseViews.map((expenseView, index) => ( - - onOpen(expenseView.expense.id || 0, expenseView)} - > - {expenseView.expense.name} - - onOpen(expenseView.expense.id || 0, expenseView)} - className='py-3 text-center' - > - {expenseView.expense.totalPrice} - - onOpen(expenseView.expense.id || 0, expenseView)} - className='py-3 text-center' - > - {formatDate( - expenseView.expense.createdAt ? expenseView.expense.createdAt : '', + {expenseViews && + expenseViews.map((expenseView, index) => ( + - onOpen(expenseView.expense.id || 0, expenseView)} - className='py-3 text-center' > - {formatDate( - expenseView.expense.updatedAt ? expenseView.expense.updatedAt : '', - )} - - - - - - - ))} - {!expenseViews.length && ( + onOpen(expenseView.expense.id || 0, expenseView)} + > + {expenseView.expense.name} + + onOpen(expenseView.expense.id || 0, expenseView)} + className='py-3 text-center' + > + {expenseView.expense.totalPrice} + + onOpen(expenseView.expense.id || 0, expenseView)} + className='py-3 text-center' + > + {formatDate( + expenseView.expense.createdAt ? expenseView.expense.createdAt : '', + )} + + onOpen(expenseView.expense.id || 0, expenseView)} + className='py-3 text-center' + > + {formatDate( + expenseView.expense.updatedAt ? expenseView.expense.updatedAt : '', + )} + + + + + + + ))} + {!expenseViews && ( データがありません @@ -355,7 +358,7 @@ export default function BudgetList(props: Props) { )} - {expenseViews.length > 0 && ( + {expenseViews && expenseViews.length > 0 && (