Skip to content

samarth Acharya #20

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 4 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
81 changes: 48 additions & 33 deletions client/src/components/AppBar.jsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import { Link } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { setMessage } from '../reducers/messageReducer';
import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import { Link } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { setMessage } from "../reducers/messageReducer";

const linkStyle = {
textDecoration: 'none',
color: 'white',
cursor: 'pointer'
}
textDecoration: "none",
color: "white",
cursor: "pointer",
};

export default function ButtonAppBar() {
const user = useSelector(state => state.auth.user)
const dispatch = useDispatch()
const user = useSelector((state) => state.auth.user);
const dispatch = useDispatch();

const logout = () => {
localStorage.removeItem('expenseTrackerToken')
dispatch(setMessage(['User logged out', true]))
setTimeout(() => dispatch(setMessage(null)), 5000)
}
localStorage.removeItem("expenseTrackerToken");
dispatch(setMessage(["User logged out", true]));
setTimeout(() => dispatch(setMessage(null)), 5000);
};

return (
<Box sx={{ flexGrow: 1, width: '30%' }}>
<Box sx={{ flexGrow: 1, width: "w-full" }}>
<AppBar position="static">
<Toolbar>

<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
<Link style={linkStyle} to='/'>Expense Tracker</Link>
<Link style={linkStyle} to="/">
Expense Tracker
</Link>
</Typography>

{user &&
<>
<Button color="inherit"><Link style={linkStyle} to='/category'>category</Link></Button>
<Button color="inherit" onClick={logout}>Logout</Button>
</>
}
{user && (
<>
<Button color="inherit">
<Link style={linkStyle} to="/category">
category
</Link>
</Button>
<Button color="inherit" onClick={logout}>
Logout
</Button>
</>
)}

{!user &&
<>
<Button color="inherit"><Link style={linkStyle} to='/login'>Login</Link></Button>
<Button color="inherit"><Link style={linkStyle} to='/register'>Register</Link></Button>
</>
}
{!user && (
<>
<Button color="inherit">
<Link style={linkStyle} to="/login">
Login
</Link>
</Button>
<Button color="inherit">
<Link style={linkStyle} to="/register">
Register
</Link>
</Button>
</>
)}
</Toolbar>
</AppBar>
</Box>
Expand Down
132 changes: 74 additions & 58 deletions client/src/components/TransactionList.jsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,113 @@
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
import { IconButton, Typography } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
import EditIcon from '@mui/icons-material/Edit';
import transactionService from '../requests/Transaction.js'
import dayjs from 'dayjs';
import { useDispatch, useSelector } from 'react-redux';
import { removeTransaction } from '../reducers/transactionReducer.js';
import { setEditTransaction } from '../reducers/editTransactionReducer.js';
import { setMessage } from '../reducers/messageReducer.js';
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import { IconButton, Typography } from "@mui/material";
import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import transactionService from "../requests/Transaction.js";
import dayjs from "dayjs";
import { useDispatch, useSelector } from "react-redux";
import { removeTransaction } from "../reducers/transactionReducer.js";
import { setEditTransaction } from "../reducers/editTransactionReducer.js";
import { setMessage } from "../reducers/messageReducer.js";

export default function BasicTable() {

const dispatch = useDispatch()
const transactions = useSelector(state=>state.transactions)
const sortedTrans = transactions.slice().sort((a, b) => a.date > b.date ? -1 : 1)

const dispatch = useDispatch();
const transactions = useSelector((state) => state.transactions);
const sortedTrans = transactions
.slice()
.sort((a, b) => (a.date > b.date ? -1 : 1));

const handleEdit = (transaction) => {
dispatch(setEditTransaction(transaction))
return
}
dispatch(setEditTransaction(transaction));
return;
};

const handleDelete = async (id) => {
if (confirm("Are you sure you want to delete the transaction?")){
const res = await transactionService.remove(id)
dispatch(removeTransaction(id))
if(res.status===204){
dispatch(setMessage(['Deleted Successfully',true]))
setTimeout(()=>dispatch(setMessage(null)),5000)
console.log(id);
if (confirm("Are you sure you want to delete the transaction?")) {
const res = await transactionService.remove(id);
console.log(res);
dispatch(removeTransaction(id));
if (res.status === 204) {
dispatch(setMessage(["Deleted Successfully", true]));
setTimeout(() => dispatch(setMessage(null)), 5000);
}
}
}
};

if(!sortedTrans.length>0){
return(
<Typography variant='h4' sx={{ textAlign: 'center', marginBottom: 5 }}>
if (!sortedTrans.length > 0) {
return (
<Typography variant="h4" sx={{ textAlign: "center", marginBottom: 5 }}>
No data to display
</Typography>
)
</Typography>
);
}

return (
<>

<Typography variant='h4' sx={{ textAlign: 'center', marginBottom: 5 }}>
<Typography variant="h4" sx={{ textAlign: "center", marginBottom: 5 }}>
List of transactions
</Typography>
<TableContainer style={{marginBottom:15}} component={Paper}>
</Typography>
<TableContainer style={{ marginBottom: 15 }} component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell><strong>Amount</strong></TableCell>
<TableCell align="center"><strong>Description</strong></TableCell>
<TableCell align="center"><strong>Category</strong></TableCell>
<TableCell align="center"><strong>Date</strong></TableCell>
<TableCell align="center"><strong>Action</strong></TableCell>
<TableCell>
<strong>Amount</strong>
</TableCell>
<TableCell align="center">
<strong>Description</strong>
</TableCell>
<TableCell align="center">
<strong>Category</strong>
</TableCell>
<TableCell align="center">
<strong>Date</strong>
</TableCell>
<TableCell align="center">
<strong>Action</strong>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{sortedTrans.map((row) => (
<TableRow
key={row.id}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.amount}
</TableCell>
<TableCell align="center">{row.description}</TableCell>
<TableCell align="center">{row.category}</TableCell>
<TableCell align="center">{dayjs(row.date).format('MMMM D, YYYY')}</TableCell>
<TableCell align="center">

{dayjs(row.date).format("MMMM D, YYYY")}
</TableCell>
<TableCell align="center">
<IconButton
color='primary'
sx={{ marginLeft: 1, cursor: 'pointer' }}
onClick={()=>handleEdit()}
>
<EditIcon/>
color="primary"
sx={{ marginLeft: 1, cursor: "pointer" }}
onClick={() => {
handleEdit(row);
}}
>
<EditIcon />
</IconButton>

<IconButton
color='error'
onClick={()=>handleDelete(row.id)}
sx={{ cursor: 'pointer' }}>
color="error"
onClick={() => {
handleDelete(row.id);
}}
sx={{ cursor: "pointer" }}
>
<DeleteIcon />
</IconButton>

</TableCell>
</TableRow>
))}
Expand All @@ -100,4 +116,4 @@ export default function BasicTable() {
</TableContainer>
</>
);
}
}
75 changes: 39 additions & 36 deletions client/src/pages/Category.jsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
import { IconButton, Typography } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
import { useDispatch, useSelector } from 'react-redux';
import {setUser} from '../reducers/authReducer'
import CategoryService from '../requests/Category.js'
import CategoryForm from '../components/CategoryForm.jsx'
import { setMessage } from '../reducers/messageReducer';
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import { IconButton, Typography } from "@mui/material";
import DeleteIcon from "@mui/icons-material/Delete";
import { useDispatch, useSelector } from "react-redux";
import { setUser } from "../reducers/authReducer";
import CategoryService from "../requests/Category.js";
import CategoryForm from "../components/CategoryForm.jsx";
import { setMessage } from "../reducers/messageReducer";
export default function Category() {
const dispatch = useDispatch();

const dispatch = useDispatch()

const categories = useSelector(state=>state.auth.user.categories)
const categories = useSelector((state) => state.auth.user.categories);

const handleDelete = async (name) => {
if (confirm("Are you sure you want to delete the category?")){
const res = await CategoryService.remove(name)
if (confirm("Are you sure you want to delete the category?")) {
const res = await CategoryService.remove(name);
// setTransactions(transactions.filter(trans => trans.id != id))
if(res.status===200){
dispatch(setUser(res.data))
dispatch(setMessage(['Category deleted successfully',true]))
setTimeout(()=>dispatch(setMessage(null)),5000)
if (res.status === 200) {
dispatch(setUser(res.data));
dispatch(setMessage(["Category deleted successfully", true]));
setTimeout(() => dispatch(setMessage(null)), 5000);
}
}
}
};

return (
<>

<CategoryForm/>
<Typography variant='h4' sx={{ textAlign: 'center', margin: 5 }}>
<CategoryForm />
<Typography variant="h4" sx={{ textAlign: "center", margin: 5 }}>
List of categories
</Typography>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell align="center"><strong>Name</strong></TableCell>
<TableCell align="center"><strong>Action</strong></TableCell>
<TableCell align="center">
<strong>Name</strong>
</TableCell>
<TableCell align="center">
<strong>Action</strong>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{categories.map((row) => (
<TableRow
key={row}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell align="center">{row}</TableCell>
<TableCell align="center">

<IconButton
color='error'
onClick={() =>handleDelete(row)}
sx={{ cursor: 'pointer' }}>
color="error"
onClick={() => {
handleDelete(row);
}}
sx={{ cursor: "pointer" }}
>
<DeleteIcon />
</IconButton>

</TableCell>
</TableRow>
))}
Expand All @@ -69,4 +72,4 @@ export default function Category() {
</TableContainer>
</>
);
}
}
Loading