diff --git a/src/App.js b/src/App.js
index 610e47d694..2ad445f2b9 100644
--- a/src/App.js
+++ b/src/App.js
@@ -2,8 +2,12 @@ import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
-//Code to import Budget.js
import Budget from './components/Budget';
+import Remaining from './components/Remaining'
+import ExpenseTotal from './components/ExpenseTotal';
+import ExpenseList from './components/ExpenseList';
+import ExpenseItem from './components/ExpenseItem';
+import AllocationForm from './components/AllocationForm';
// Add code to import the other components here under
@@ -16,27 +20,45 @@ const App = () => {
Company's Budget Allocation
{
- /* Add Budget component here */
+ /* Budget component here */
+
+
+
}
{
- /* Add Remaining component here*/
+ /* Remaining component here*/
+
+
+
}
{
- /* Add ExpenseTotal component here */
+ /* ExpenseTotal component here */
+
+
+
}
{
- /* Add ExpenseList component here */
+ /* ExpenseList component here */
+
+
+
}
{
- /* Add ExpenseItem component here */
+ /* ExpenseItem component here */
+
+
+
}
{
- /* Add AllocationForm component here under */
+ /* AllocationForm component here under */
+
}
diff --git a/src/components/AllocationForm.js b/src/components/AllocationForm.js
index 8b13789179..e84e8a3f87 100644
--- a/src/components/AllocationForm.js
+++ b/src/components/AllocationForm.js
@@ -1 +1,81 @@
+import React, { useContext, useState } from 'react';
+import { AppContext } from '../context/AppContext';
+const AllocationForm = (props) => {
+ const { dispatch,remaining } = useContext(AppContext);
+
+ const [name, setName] = useState('');
+ const [cost, setCost] = useState('');
+ const [action, setAction] = useState('');
+
+ const submitEvent = () => {
+
+ if(cost > remaining) {
+ alert("The value cannot exceed remaining funds £"+remaining);
+ setCost("");
+ return;
+ }
+
+ const expense = {
+ name: name,
+ cost: parseInt(cost),
+ };
+ if(action === "Reduce") {
+ dispatch({
+ type: 'RED_EXPENSE',
+ payload: expense,
+ });
+ } else {
+ dispatch({
+ type: 'ADD_EXPENSE',
+ payload: expense,
+ });
+ }
+ };
+
+ return (
+
+
+
+
+
+ Department
+
+
setName(event.target.value)}>
+ Choose...
+ Marketing
+ Sales
+ Finance
+ HR
+ IT
+ Admin
+
+
+
+ Allocation
+
+
setAction(event.target.value)}>
+ Add
+ Reduce
+
+
+
setCost(event.target.value)}>
+
+
+
+ Save
+
+
+
+
+
+ );
+};
+
+export default AllocationForm;
\ No newline at end of file
diff --git a/src/components/Budget.js b/src/components/Budget.js
index 8b13789179..a0aa8e1d0f 100644
--- a/src/components/Budget.js
+++ b/src/components/Budget.js
@@ -1 +1,17 @@
+import React, { useContext, useState } from 'react';
+import { AppContext } from '../context/AppContext';
+const Budget = () => {
+ const { budget } = useContext(AppContext);
+ const [newBudget, setNewBudget] = useState(budget);
+ const handleBudgetChange = (event) => {
+ setNewBudget(event.target.value);
+ }
+ return (
+
+ Budget: £{budget}
+
+
+ );
+};
+export default Budget;
\ No newline at end of file
diff --git a/src/components/ExpenseItem.js b/src/components/ExpenseItem.js
index 8b13789179..d6d77f2226 100644
--- a/src/components/ExpenseItem.js
+++ b/src/components/ExpenseItem.js
@@ -1 +1,38 @@
+import React, { useContext } from 'react';
+import { TiDelete } from 'react-icons/ti';
+import { AppContext } from '../context/AppContext';
+const ExpenseItem = (props) => {
+ const { dispatch } = useContext(AppContext);
+
+ const handleDeleteExpense = () => {
+ dispatch({
+ type: 'DELETE_EXPENSE',
+ payload: props.id,
+ });
+ };
+
+ const increaseAllocation = (name) => {
+ const expense = {
+ name: name,
+ cost: 10,
+ };
+
+ dispatch({
+ type: 'ADD_EXPENSE',
+ payload: expense
+ });
+
+ }
+
+ return (
+
+ {props.name}
+ £{props.cost}
+ increaseAllocation(props.name)}>+
+
+
+ );
+};
+
+export default ExpenseItem;
\ No newline at end of file
diff --git a/src/components/ExpenseList.js b/src/components/ExpenseList.js
index 8b13789179..0a958eef93 100644
--- a/src/components/ExpenseList.js
+++ b/src/components/ExpenseList.js
@@ -1 +1,26 @@
+import React, { useContext } from 'react';
+import ExpenseItem from './ExpenseItem';
+import { AppContext } from '../context/AppContext';
+const ExpenseList = () => {
+ const { expenses } = useContext(AppContext);
+
+ return (
+
+
+
+ Department
+ Allocated Budget
+ Increase by 10
+ Delete
+
+
+
+ {expenses.map((expense) => (
+
+ ))}
+
+
+ );
+};
+export default ExpenseList;
\ No newline at end of file
diff --git a/src/components/ExpenseTotal.js b/src/components/ExpenseTotal.js
index 8b13789179..74378d232e 100644
--- a/src/components/ExpenseTotal.js
+++ b/src/components/ExpenseTotal.js
@@ -1 +1,14 @@
-
+import React, { useContext } from 'react';
+import { AppContext } from '../context/AppContext';
+const ExpenseTotal = () => {
+ const { expenses } = useContext(AppContext);
+ const totalExpenses = expenses.reduce((total, item) => {
+ return (total += item.cost);
+ }, 0);
+ return (
+
+ Spent so far: £{totalExpenses}
+
+ );
+};
+export default ExpenseTotal;
\ No newline at end of file
diff --git a/src/components/Remaining.js b/src/components/Remaining.js
index 8b13789179..0648b36eb0 100644
--- a/src/components/Remaining.js
+++ b/src/components/Remaining.js
@@ -1 +1,15 @@
-
+import React, { useContext } from 'react';
+import { AppContext } from '../context/AppContext';
+const Remaining = () => {
+ const { expenses, budget } = useContext(AppContext);
+ const totalExpenses = expenses.reduce((total, item) => {
+ return (total = total + item.cost);
+ }, 0);
+ const alertType = totalExpenses > budget ? 'alert-danger' : 'alert-success';
+ return (
+
+ Remaining: £{budget - totalExpenses}
+
+ );
+};
+export default Remaining;
\ No newline at end of file