Skip to content

Commit

Permalink
Merge pull request #73 from Goldenrash-lab/un/feature/adding-function…
Browse files Browse the repository at this point in the history
…ality

Un/feature/adding functionality
  • Loading branch information
Goldenrash-lab authored Jan 13, 2024
2 parents 71e146f + 337ddf1 commit 045b5df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
StyledTheadItem,
WrapTable,
} from './TransactionDashboard.styled';
import { fetchTransactionsThunk } from 'store/Transactions/transactionsThunk';
import { useDispatch, useSelector } from 'react-redux';
import { transactionsData } from 'store/Transactions/selectors';
import { categoriesThunk } from 'store/Categories/categoriesThunk';
Expand All @@ -17,7 +16,6 @@ const TransactionsDashboard = () => {
const dispatch = useDispatch();

useEffect(() => {
dispatch(fetchTransactionsThunk());
dispatch(categoriesThunk());
}, [dispatch]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React from 'react';
import Edit from '../helpers/Edit';
import {
EditButton,
Expand All @@ -14,18 +14,14 @@ import { formatCurrency } from '../TransactionsList';
import { useDispatch, useSelector } from 'react-redux';
import { selectCategories } from 'store/Categories/categoriesSelectors';
import { transactionsData } from 'store/Transactions/selectors';
import {
deleteTransactionThunk,
fetchTransactionsThunk,
} from 'store/Transactions/transactionsThunk';
import { deleteTransactionThunk } from 'store/Transactions/transactionsThunk';
import { toast } from 'react-toastify';
import { deleteTransaction } from 'store/Transactions/transactionsSlice';

const TransactionMobile = () => {
const categories = useSelector(selectCategories);
const transactions = useSelector(transactionsData);
const dispatch = useDispatch();
useEffect(() => {
dispatch(fetchTransactionsThunk());
}, [dispatch]);

return (
<div>
Expand Down Expand Up @@ -71,6 +67,14 @@ const TransactionMobile = () => {
<StyledButton
onClick={() =>
dispatch(deleteTransactionThunk(transaction.id))
.unwrap()
.then(() => {
dispatch(deleteTransaction(transaction.id));
toast.success('Transaction is deleted!');
})
.catch(err => {
toast.error(err);
})
}
>
Delete
Expand Down
1 change: 0 additions & 1 deletion src/store/Transactions/transactionsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const transactionsSlice = createSlice({
},
reducers: {
deleteTransaction: (state, action) => {
console.log(action.payload);
state.transactions = state.transactions.filter(
transaction => transaction.id !== action.payload
);
Expand Down

0 comments on commit 045b5df

Please sign in to comment.