Skip to content

Testing felix1 #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .canvas

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ __pycache__
instance
.vscode
package-lock.json

.env
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sqlalchemy-serializer = "*"
flask-restful = "*"
flask-cors = "*"
faker = "*"
flask-bcrypt = "*"
python-dotenv = "*"

[requires]
python_full_version = "3.8.13"
587 changes: 587 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"ajv": "^8.17.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "5.0.1",
"recharts": "^2.12.7",
"web-vitals": "^2.1.4"
},
"devDependencies": {"@babel/plugin-proposal-private-property-in-object":"^7.21.11"},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
2 changes: 1 addition & 1 deletion client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Reciplease</title>
<title>FlatPay</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
33 changes: 33 additions & 0 deletions client/src/Routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import Transactions from './components/Transaction/Transactions';
import CreditPage from './pages/CreditPage';
import DebitPage from './pages/DebitPage';
import StatsPage from './pages/StatsPage';
import FriendshipPage from './pages/FriendshipPage';

function Routes({ currentUser }) {
if (!currentUser) return <Redirect to="/" />;

return (
<Switch>
<Route exact path="/">
<Transactions currentUser={currentUser} />
</Route>
<Route path="/credit">
<CreditPage currentUser={currentUser} />
</Route>
<Route path="/debit">
<DebitPage currentUser={currentUser} />
</Route>
<Route path="/stats">
<StatsPage currentUser={currentUser} />
</Route>
<Route path="/friendship">
<FriendshipPage currentUser={currentUser} />
</Route>
</Switch>
);
}

export default Routes;
54 changes: 50 additions & 4 deletions client/src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
import React, { useEffect, useState } from "react";
import { Switch, Route } from "react-router-dom";
import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Redirect } from 'react-router-dom';
import NavBar from './NavBar';
import UserPanel from './UserPanel/UserPanel';
import CreditPage from '../pages/CreditPage';
import DebitPage from '../pages/DebitPage';
import StatsPage from '../pages/StatsPage';
import FriendshipPage from '../pages/FriendshipPage';

function App() {
return <h1>Project Client</h1>;
const [currentUser, setCurrentUser] = useState(null);

useEffect(() => {
fetch('/check_session')
.then(res => {
if (res.status === 200) {
res.json().then(data => setCurrentUser(data));
}
});
}, []);

return (
<Router>
<div className="App">
<h1>FlatPay</h1>
<NavBar currentUser={currentUser} setCurrentUser={setCurrentUser} />
<Switch>
<Route exact path="/">
<UserPanel currentUser={currentUser} setCurrentUser={setCurrentUser} />
</Route>
{currentUser && (
<>
<Route path="/credit">
<CreditPage currentUser={currentUser} />
</Route>
<Route path="/debit">
<DebitPage currentUser={currentUser} />
</Route>
<Route path="/stats">
<StatsPage currentUser={currentUser} />
</Route>
<Route path="/friendship">
<FriendshipPage currentUser={currentUser} />
</Route>
</>
)}
<Redirect to="/" />
</Switch>
</div>
</Router>
);
}

export default App;
export default App;
29 changes: 29 additions & 0 deletions client/src/components/NavBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { Link, useHistory } from 'react-router-dom';

function NavBar({ currentUser, setCurrentUser }) {
const history = useHistory();

const handleLogout = () => {
fetch('/logout', { method: 'DELETE' })
.then(() => {
setCurrentUser(null);
history.push('/');
});
};

if (!currentUser) return null;

return (
<nav>
<Link to="/">Home</Link>
<Link to="/credit">Credit</Link>
<Link to="/debit">Debit</Link>
<Link to="/stats">Stats</Link>
<Link to="/friendship">Friends</Link>
<button onClick={handleLogout}>Logout</button>
</nav>
);
}

export default NavBar;
7 changes: 7 additions & 0 deletions client/src/components/Transaction/Payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

export default function Payment() {
return (
<div>Send Payment</div>
)
}
93 changes: 93 additions & 0 deletions client/src/components/Transaction/TransactionRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { useState, useEffect } from 'react';

function TransactionRequest({ createRequest, currentUser }) {

const [amount, setAmount] = useState('');
const [selectedUser, setSelectedUser] = useState('');
const [year, setYear] = useState(new Date().getFullYear());
const [users, setUsers] = useState([]);
const [userRole, setUserRole] = useState('sender');


useEffect(() => {
fetch('/users')

.then(res => res.json())
.then(data => setUsers(data.filter(user => user.id !== currentUser.id)));
}, [currentUser.id]);


function handleSubmit(e) {
e.preventDefault();
const requestData = {
amount: parseFloat(amount),
year: parseInt(year),
[userRole === 'sender' ? 'requestee' : 'requestor']: parseInt(selectedUser),
[userRole === 'sender' ? 'requestor' : 'requestee']: currentUser.id
};
createRequest(requestData);
setAmount('');
setSelectedUser('');
setYear(new Date().getFullYear());
}

return (
<form onSubmit={handleSubmit}>
<h3>New Transaction:</h3>

<div>
<label>
<input
type="radio"
value="sender"
checked={userRole === 'sender'}
onChange={() => setUserRole('sender')}
/>
Payment
</label>
<label>
<input
type="radio"
value="receiver"
checked={userRole === 'receiver'}
onChange={() => setUserRole('receiver')}
/>
Request
</label>
</div>


<select value={selectedUser} onChange={(e) => setSelectedUser(e.target.value)} required>
<option value="">Select a User</option>
{users.map(user => (
<option key={user.id} name = "user" value={user.id}>
{user.username}
</option>
))}
</select>

<input
type="number"
value={amount}
onChange={(e) => setAmount(e.target.value)}
placeholder="Amount"
required
/>

<input
type="number"
value={year}
onChange={(e) => setYear(e.target.value)}
placeholder="Year"
min="1900"
max="2099"
step="1"
required
/>

<button type="submit">Add Transaction</button>
</form>
);
}

export default TransactionRequest;
Loading