Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Olfdev committed Aug 15, 2023
1 parent 6b24e2e commit 46c53f7
Show file tree
Hide file tree
Showing 18 changed files with 397 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Chez vous, partout et ailleurs"
content="Your Bank, everywhere"
/>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>ArgentBank</title>
Expand Down
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Footer from './components/Footer';
import Home from './pages/Home';
import Login from './pages/Login';
import Profile from './pages/Profile';
import TransactionBody from './components/Transactionbody';
import Error from './pages/Error';
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'
import { useSelector } from 'react-redux';
Expand All @@ -17,8 +18,9 @@ export default function App() {
<Header />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/login" element={ (isAuthenticated) ? <Navigate to="/profile" /> : <Login />}/>
<Route path="/profile" element={ (isAuthenticated) ? <Profile /> : <Navigate to="/login" />}/>
<Route path="/login" element={ (isAuthenticated) ? <Navigate to="/account" /> : <Login />}/>
<Route path="/account" element={ (isAuthenticated) ? <Profile /> : <Navigate to="/login" />}/>
<Route path="/account/:accountType" element={ (isAuthenticated) ? <TransactionBody /> : <Navigate to="/login" />}/>
<Route path="*" element={<Error />} />
</Routes>
<Footer />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function Footer(){
return (
<footer className="footer">
<p className="footer-text">Copyright 2020 Argent Bank</p>
<p className="footer-text">Copyright 2023 Argent Bank</p>
</footer>
);
}
2 changes: 1 addition & 1 deletion src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Header(){
<div>
{isAuthenticated ? (
<>
<Link className="main-nav-item" to="/profile">
<Link className="main-nav-item" to="/account">
<i className="fa fa-user-circle"></i>
{user && <>{user.firstName}</>}
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Homepage(){
<div className="feature-item">
<i alt="Security Icon" className="fa-solid fa-shield-halved feature-icon"></i>
<h3 className="feature-item-title">Security you can trust</h3>
<p> We use top of the line encryption to make sure your data and money is always safe.</p>
<p>We use top of the line encryption to make sure your data and money is always safe.</p>
</div>
</section>
</>
Expand Down
14 changes: 7 additions & 7 deletions src/components/Loginpage.jsx → src/components/Loginbody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { useAuthMutation, useGetProfileMutation } from '../rtk/ApiSlice';
import { setToken, setUser } from '../rtk/AuthSlice';
import { Link, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';

export default function LoginPage() {
const [email, setEmail] = useState('');
Expand All @@ -12,8 +12,7 @@ export default function LoginPage() {
const navigate = useNavigate();

const [auth, { isLoading: authIsLoading, isSuccess: authIsSuccess, data: authData, error: authError }] = useAuthMutation();
// const [profile, { error: profileError, data: profileData, isSuccess: profileIsSuccess }] = useGetProfileMutation();
const [profile, { data: profileData, isSuccess: profileIsSuccess }] = useGetProfileMutation();
const [getProfile, { data: profileData, isSuccess: profileIsSuccess }] = useGetProfileMutation();

const handleLogin = () => {
auth({ email, password });
Expand All @@ -22,13 +21,14 @@ export default function LoginPage() {
useEffect(() => {
if (authIsSuccess && authData) {
dispatch(setToken(authData.body.token));
profile();
getProfile();
}
}, [authIsSuccess, authData, dispatch, profile]);
}, [authIsSuccess, authData, dispatch, getProfile]);

useEffect(() => {
if (profileIsSuccess && profileData) {
dispatch(setUser(profileData.body)); // Store user profile info in Redux
//console.log(profileData.body);
navigate('/profile');
}
}, [profileIsSuccess, profileData, dispatch, navigate]);
Expand All @@ -55,9 +55,9 @@ export default function LoginPage() {
</form>
{authError && <p className='perror'>{authError.data.message.replace("Error: ", "")}</p>}
{authIsSuccess && <p className='psuccess'>{authData.message}</p>}
<Link to="/profile">
{/* <Link to="/profile">
{authIsSuccess && <button>Go to Profile Page</button>}
</Link>
</Link> */}
</section>
</div>
);
Expand Down
26 changes: 26 additions & 0 deletions src/components/Profilebody.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useSelector } from 'react-redux';
import { Link } from 'react-router-dom';

export default function AccountPage({ setViewTransactions }){
const user = useSelector(state => state.auth.user);

return (
<>
<h2 className="sr-only">Accounts</h2>
{user && user.accounts.map(account => (
<section className="account" key={account.account_type}>
<div className="account-content-wrapper">
<p className="account-title">Argent Bank - {account.account_type} {'(' + account.account_number + ')'}</p>
<h3 className="account-amount">$2,082.79</h3>
<p className="account-title">Available Balance</p>
</div>
<div className="account-content-wrapper cta">
{/* <Link to={`/transactions/${account.account_type.toLowerCase().replace(/\s+/g, '_')}`} className="transaction-button">View transactions</Link> */}
{/* <Link to={`/transactions/${account.account_type}`} className="transaction-button" onClick={() => setViewTransactions(true)}>View transactions</Link> */}
<Link to={`${account.account_type}`}><button className="transaction-button" onClick={() => setViewTransactions(true)}>View transactions</button></Link>
</div>
</section>
))}
</>
);
}
41 changes: 0 additions & 41 deletions src/components/Profilepage.jsx

This file was deleted.

89 changes: 89 additions & 0 deletions src/components/Transactionbody.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useEffect, useState } from 'react';
import { useGetTransactionMutation, useUpdateTransactionMutation } from '../rtk/ApiSlice';
import { useParams } from 'react-router-dom';
//import Error from '../pages/Error';

export default function TransactionPage() {
const { accountType } = useParams();
//console.log(accountType);
const [getTransactions, { data, error, isError, isLoading }] = useGetTransactionMutation();
const [collapseStates, setCollapseStates] = useState({});

useEffect(() => {
getTransactions(accountType);
}, [getTransactions, accountType]);

return (
<main>
<div className="main bg-dark">
<div className='account-trans'>
<div className='account-content-wrapper'>
<h3>Argent Bank - {accountType} Account</h3>
<h1>$2,082.79</h1>
<p>Available balance</p>
</div>
</div>
{isLoading ? (
<p>Loading transactions...</p>
) : isError ? (
<p className="perror">{error.message}</p>
) : (
<>
<h2 className="sr-only">Transactions for {accountType} Account</h2>
<div className="account-table-header-wrapper">
<h3 className="">Date</h3>
<h3>Description</h3>
<h3>Amount</h3>
<h3>Balance</h3>
</div>
<section className=""></section>
{data && data.body.transactions && (() => {
const filteredTransactions = data.body.transactions.filter(transaction => transaction.account_type === accountType);
if (filteredTransactions.length === 0) {
return <h2>No transactions found</h2>;
}
return filteredTransactions
.reverse()
.map((transaction) => {
const europeanDate = new Date(transaction.date).toLocaleDateString('en-GB');

const toggleCollapse = () => {
setCollapseStates(prevState => ({
...prevState,
[transaction.date]: !prevState[transaction.date]
}));
};

return (
<div className="table-transactions" key={transaction.date}>
<div className="account-table-transaction" onClick={toggleCollapse}>
<p className="">{europeanDate}</p>
<p className="">{transaction.description}</p>
<p className="">${Number(transaction.amount.$numberDecimal).toFixed(2)}</p>
<p>$2,082.79</p>
<i className={`fa-solid fa-angle-${collapseStates[transaction.date] ? 'up' : 'down'}`}></i>
</div>
<div className={`account-collapse ${collapseStates[transaction.date] ? 'down' : ''}`}>
<div className="account-table-details">
<p className="">Transaction type</p>
<p className="">{transaction.type}</p>
</div>
<div className="account-table-details">
<p className="">Category</p>
<p className="">{transaction.category}</p>
</div>
<div className="account-table-details">
<p className="">Notes</p>
<p className="">{transaction.note}</p>
</div>
</div>
</div>
);
});
})()}
</>
)}
</div>
</main>
);
}
Loading

0 comments on commit 46c53f7

Please sign in to comment.