Skip to content

Commit

Permalink
Added toast for deleting / adding TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrh6 committed Jun 24, 2024
1 parent 410d645 commit e317fa4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.1",
"react-spinners": "^0.13.8"
"react-spinners": "^0.13.8",
"react-toastify": "^10.0.5"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
4 changes: 3 additions & 1 deletion src/layouts/MainLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Outlet } from 'react-router-dom';

import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import Navbar from '../components/Navbar';

const MainLayout = () => {
return (
<>
<Navbar />
<Outlet />
<ToastContainer />
</>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/pages/AddTODOPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react/prop-types */
import { useState } from 'react';
import { toast } from 'react-toastify';
import { useNavigate } from 'react-router-dom';

const AddTODOPage = ({ addTODOSubmit }) => {
Expand All @@ -19,6 +20,7 @@ const AddTODOPage = ({ addTODOSubmit }) => {
};

addTODOSubmit(newTODO);
toast.success('TODO added successfully!');
return navigate('/todos');
};

Expand Down
2 changes: 2 additions & 0 deletions src/pages/TODOPage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/prop-types */
import { useParams, useLoaderData, Link, useNavigate } from 'react-router-dom';
import { FaCheckCircle, FaClock } from 'react-icons/fa';
import { toast } from 'react-toastify';
import defaultTODOs from '../todos.json';
import { backend } from '../others/others';

Expand Down Expand Up @@ -79,6 +80,7 @@ const TODOPage = ({ deleteTODO }) => {
)
) {
deleteTODO(todo.id);
toast.success('TODO was deleted!');
navigate('/todos');
}
}}
Expand Down

0 comments on commit e317fa4

Please sign in to comment.