Skip to content

bugs #22

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 1 commit into
base: main
Choose a base branch
from
Open

bugs #22

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
9 changes: 6 additions & 3 deletions client/src/components/AppBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Button from '@mui/material/Button';
import { Link } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { setMessage } from '../reducers/messageReducer';

import { useNavigate } from 'react-router-dom';
import { removeUser } from '../reducers/authReducer';
const linkStyle = {
textDecoration: 'none',
color: 'white',
Expand All @@ -16,15 +17,17 @@ const linkStyle = {
export default function ButtonAppBar() {
const user = useSelector(state => state.auth.user)
const dispatch = useDispatch()

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

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

Expand Down
4 changes: 2 additions & 2 deletions client/src/components/CategoryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Content = () => {

const handleSubmit = async (e) => {
e.preventDefault()
const res = CategoryService.create({category: name})
const res = await CategoryService.create(name)
dispatch(setUser(res.data))
dispatch(setMessage([`Category '${name}' added successfully`,true]))
setTimeout(()=>dispatch(setMessage(null)),5000)
Expand All @@ -36,7 +36,7 @@ const Content = () => {
<Box component='form' onSubmit={handleSubmit} sx={{ display: 'flex', flexWrap: 'wrap',justifyContent:'center'
}}>
<TextField size='small' sx={{ marginRight: 5 }} onChange={handleInput} value={name} type="text" name="amount" placeholder="New Category Name" />
<Button variant="contained" type="submit">Submit</Button>
<Button variant="contained" type="submit" onChange={handleSubmit}>Submit</Button>
</Box>

</CardContent>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/TransactionChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TransactionChart = ({chartData}) => {
}

return (
<Paper style={{ marginTop: 20, width: '20%' }}>
<Paper style={{ marginTop: 20, width: '100%' }}>
<Chart
data={chartData}
>
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/TransactionForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dayjs from 'dayjs';
import { useDispatch, useSelector } from 'react-redux';
import { setEditTransaction } from '../reducers/editTransactionReducer'
import { setMessage } from '../reducers/messageReducer'

import { addTransaction } from '../reducers/transactionReducer';
const Content = () => {

const categories = useSelector(state => state.auth.user.categories)
Expand Down Expand Up @@ -43,7 +43,8 @@ const Content = () => {
e.preventDefault()

if (!editTransaction) {
await TransactionService.create(form)
const fix=await TransactionService.create(form)
dispatch(addTransaction(fix));
setForm(initialForm)
dispatch(setMessage(['Expense added successfully', true]))

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/TransactionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function BasicTable() {
<IconButton
color='primary'
sx={{ marginLeft: 1, cursor: 'pointer' }}
onClick={()=>handleEdit()}
onClick={()=>handleEdit(row)}
>
<EditIcon/>
</IconButton>
Expand Down
4 changes: 2 additions & 2 deletions server/routes/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const router = Router()
import User from '../models/User.js'

router.delete('/:name',async (req,res)=>{
req.user.categories.filter(n=>n!==req.params.name)
const user = await User.findByIdAndUpdate(req.user.id,{categories:req.user.categories},{new:true})
const fix=req.user.categories.filter(n=>n!==req.params.name)
const user = await User.findByIdAndUpdate(req.user.id,{categories:fix},{new:true})
res.status(200).json(user)
})

Expand Down
4 changes: 2 additions & 2 deletions server/routes/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ router.get('/', async (req, res) => {

router.post('/', async (req, res) => {
const newTrans = Transaction({ ...req.body, user: req.user.id })
const newT = newTrans.save()
const newT = await newTrans.save()
return res.json(newT)
})

router.put('/:id', async (req, res) => {
const id = req.params.id
const trans = await Transaction.findById(id)
const updatedTrans = await Transaction.findByIdAndUpdate(id, req.body)
const updatedTrans = await Transaction.findByIdAndUpdate(id, req.body,{new:true})
res.json(updatedTrans)
})

Expand Down