Uodated Frontend
Uodated Frontend
1. Project Structure
src/
├── components/
│ ├── LandingPage.js
│ ├── Login.js
│ ├── Signup.js
│ ├── Navbar.js
│ ├── Home.js
│ ├── TransactionHistory.js
│ ├── AddTransaction.js
│ ├── Reports.js
│ ├── ChatBuddy.js
│ └── Profile.js
├── App.js
├── index.js
├── api/
│ └── api.js
├── styles/
│ ├── App.css
│ └── Components.css
└── context/
├── SessionContext.js
└── SessionProvider.js
2. Session Management
context/SessionContext.js
import { createContext } from 'react';
context/SessionProvider.js
useEffect(() => {
if (user) setSession(user);
}, []);
setSession(userData);
localStorage.setItem('user', JSON.stringify(userData));
};
setSession(null);
localStorage.removeItem('user');
};
return (
</SessionContext.Provider>
);
};
3. API Configuration
api/api.js
headers: {
'Content-Type': 'application/json',
},
});
api.interceptors.request.use((config) => {
if (token) {
return config;
});
4. Pages Implementation
LandingPage.js
import '../styles/Components.css';
<div className="landing-page">
<div className="landing-actions">
<Link to="/login">
<button className="btn">Login</button>
</Link>
<Link to="/signup">
<button className="btn">Signup</button>
</Link>
</div>
</div>
);
Login.js
e.preventDefault();
try {
login(response.data.user);
navigate('/home');
} catch (error) {
};
return (
<div className="login-container">
<h2>Login</h2>
<form onSubmit={handleLogin}>
<input
type="email"
placeholder="Email"
value={email}
required
/>
<input
type="password"
placeholder="Password"
value={password}
required
/>
<button type="submit">Login</button>
</form>
</div>
);
};
Signup.js
e.preventDefault();
try {
navigate('/login');
} catch (error) {
};
return (
<div className="signup-container">
<h2>Signup</h2>
<form onSubmit={handleSignup}>
<input
type="text"
placeholder="Name"
value={name}
required
/>
<input
type="email"
placeholder="Email"
value={email}
required
/>
<input
type="password"
placeholder="Password"
value={password}
required
/>
<button type="submit">Signup</button>
</form>
</div>
);
};
Navbar.js
return (
<nav className="navbar">
<h1>Finance Tracker</h1>
<div className="links">
<Link to="/home">Home</Link>
<Link to="/transactions">Transactions</Link>
<Link to="/reports">Reports</Link>
<Link to="/chat">ChatBuddy</Link>
<Link to="/profile">Profile</Link>
{session ? (
<button onClick={logout}>Logout</button>
):(
<Link to="/login">Login</Link>
)}
</div>
</nav>
);
};
Styling
App.css
body {
margin: 0;
background-color: #f4f4f9;
color: #333;
h1, h2, h3 {
color: #2d3e50;
Components.css
.landing-page {
text-align: center;
padding: 50px;
.landing-actions {
margin-top: 20px;
.btn {
background-color: #2d3e50;
color: white;
border: none;
margin: 5px;
cursor: pointer;
font-size: 16px;
border-radius: 5px;
.btn:hover {
background-color: #1d2937;
.navbar {
display: flex;
justify-content: space-between;
background-color: #2d3e50;
.navbar .links a {
color: white;
text-decoration: none;
margin-right: 15px;
text-decoration: underline;
}
TransactionHistory.js
This page displays the user's past transactions with filter and categorize
options.
import '../styles/Components.css';
useEffect(() => {
try {
setTransactions(response.data);
} catch (error) {
};
fetchTransactions();
}, [session]);
});
return (
<div className="transaction-history">
<h2>Transaction History</h2>
<div className="filter">
<label>Filter:</label>
<option value="all">All</option>
<option value="income">Income</option>
<option value="expense">Expense</option>
</select>
</div>
<table>
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Type</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
{filteredTransactions.map((transaction) => (
<tr key={transaction.id}>
<td>{transaction.date}</td>
<td>{transaction.description}</td>
<td>{transaction.category}</td>
<td>{transaction.type}</td>
<td>{transaction.amount}</td>
</tr>
))}
</tbody>
</table>
</div>
);
};
AddTransaction.js
e.preventDefault();
try {
await api.post('/transactions', {
userId: session.id,
description,
amount,
type,
category,
date,
});
setDescription('');
setAmount('');
setCategory('');
setDate('');
} catch (error) {
};
return (
<div className="add-transaction">
<h2>Add Transaction</h2>
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="Description"
value={description}
required
/>
<input
type="number"
placeholder="Amount"
value={amount}
required
/>
<option value="income">Income</option>
<option value="expense">Expense</option>
</select>
<input
type="text"
placeholder="Category"
value={category}
required
/>
<input
type="date"
value={date}
required
/>
</form>
</div>
);
};
Reports.js
useEffect(() => {
try {
setChartData(response.data);
} catch (error) {
};
fetchReportData();
}, [session]);
return (
<div className="reports">
<h2>Financial Reports</h2>
<div className="charts">
<div>
<h3>Expense Distribution</h3>
</div>
<div>
<h3>Monthly Spending</h3>
</div>
</div>
</div>
);
};
ChatBuddy.js
AI-driven chatbot for assistance.
try {
} catch (error) {
setInput('');
};
return (
<div className="chat-buddy">
<h2>ChatBuddy</h2>
<div className="chat-window">
{msg.text}
</div>
))}
</div>
<input
type="text"
placeholder="Ask ChatBuddy..."
value={input}
/>
<button onClick={handleSend}>Send</button>
</div>
);
};
Profile.js
try {
} catch (error) {
};
return (
<div className="profile">
<h2>Profile</h2>
<input
type="text"
value={name}
placeholder="Name"
/>
<input
type="email"
value={email}
placeholder="Email"
/>
<button onClick={handleSave}>Save</button>
</div>
);
};