Budget Manager App
that helps users manage their budgets
and expenses
. The app consists of two main components, BudgetForm
and ExpenseForm
, which are used to add budgets
and expenses
, respectively.
Let's go through the functionality of each component in detail.
BudgetForm
Component:
- The BudgetForm component is responsible for
adding budgets
to the app. It has two input fields, one for thebudget name
and another for thebudget amount
. - When the form is
submitted
, a handleSubmit function should be called, whichprevents the default form submission behavior
, extracts thename
andamount
from the input fields usinguseState
hooks, and then add thename
andamount of the budget
tobudgets
array. - After submitting the form, the input fields should
reset to empty values
.
ExpenseForm
Component:
- The ExpenseForm component is responsible for
adding expenses
to the app. It has three input fields, one for theexpense name
, another for theexpense amount
, and aselect field for selecting the budget category
. - The
categories
are populated in the select field using the budgets array received as props from the parent App component. - When the form is
submitted
, an onSubmit function should be called, whichprevents the default form submission behavior
, extracts thename
,amount
, andcategoryId (selected budget category)
from the input fields usinguseState
hooks, and then add thename
,amount
, andcategoryID
toexpenses
array. - After submitting the form, the input fields should
reset to empty values
.
App
Component:
- The App component is the main component that renders the
BudgetForm
andExpenseForm
components. - It also maintains the state for
budgets
andexpenses
using useState hooks. - The budgets state is an array that holds the list of budgets added by the user, and the expenses state is an array that holds the list of expenses added by the user.
- The
getCategoryName
function is a utility function defined in the parent App component. It takes acategoryId as an argument
andfinds the corresponding budget category from the budgets array
.
Note:
Do not remove the given boilerplate.
Do not remove the classes and Ids from the boilerplate.
Use Date.now() as categoryId.