├── README.md └── app ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── react-todo-app.gif ├── react-todo-screenshot.jpg └── src ├── App.css ├── App.js ├── App.test.js ├── Todo ├── Favourite.js ├── NewTodo.js ├── SearchBox.css ├── SearchBox.js ├── ToDo.css ├── ToDoContainer.js ├── ToDoList.css ├── ToDoList.js ├── ToDoSchema.js ├── TodoItem.css └── TodoItem.js ├── index.css ├── index.js ├── reportWebVitals.js ├── setupTests.js └── util └── PushNotifier.js /README.md: -------------------------------------------------------------------------------- 1 | # React-todo-list-app (Formik,Yup,Bootstrap, Toast, localstorage) 2 | 3 | Todo list application developed in react using functional components and bootstrap.

4 | 14 | 15 | ## Live app on stackblitz
16 | 17 | [https://stackblitz.com/edit/react-todo-app-bootstrap?file=src%2FApp.js](https://stackblitz.com/edit/react-todo-app-bootstrap?file=src%2FApp.js) 18 | 19 | # Kickstart 20 | 21 | 1. checkout the repository 22 | 2. cd app 23 | 3. npm install 24 | 4. npm start 25 | 26 | ## Demo - Todo manager 27 | 28 | ![Debounce React Input](./app/react-todo-app.gif) 29 | 30 | ## Demo - screenshot 31 | 32 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /app/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validation", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@apollo/client": "^3.7.17", 7 | "@testing-library/jest-dom": "^5.17.0", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "bootstrap": "^5.3.0", 11 | "formik": "^2.4.2", 12 | "graphql": "^16.7.1", 13 | "react": "^18.2.0", 14 | "react-bootstrap": "^2.8.0", 15 | "react-dom": "^18.2.0", 16 | "react-icons": "^4.10.1", 17 | "react-scripts": "5.0.1", 18 | "react-toastify": "^9.1.3", 19 | "web-vitals": "^2.1.4", 20 | "yup": "^1.2.0" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazyobject/React-todo-list-app/a9d756cf3a3f6884e11770c088cd9faf70b3da76/app/public/favicon.ico -------------------------------------------------------------------------------- /app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazyobject/React-todo-list-app/a9d756cf3a3f6884e11770c088cd9faf70b3da76/app/public/logo192.png -------------------------------------------------------------------------------- /app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazyobject/React-todo-list-app/a9d756cf3a3f6884e11770c088cd9faf70b3da76/app/public/logo512.png -------------------------------------------------------------------------------- /app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /app/react-todo-app.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazyobject/React-todo-list-app/a9d756cf3a3f6884e11770c088cd9faf70b3da76/app/react-todo-app.gif -------------------------------------------------------------------------------- /app/react-todo-screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazyobject/React-todo-list-app/a9d756cf3a3f6884e11770c088cd9faf70b3da76/app/react-todo-screenshot.jpg -------------------------------------------------------------------------------- /app/src/App.css: -------------------------------------------------------------------------------- 1 | @media (prefers-reduced-motion: no-preference) { 2 | .App-logo { 3 | animation: App-logo-spin infinite 20s linear; 4 | } 5 | } 6 | .custom-icons:hover{ 7 | margin-bottom: 3px; 8 | } 9 | .containerTitle{ 10 | background-color: #666666; 11 | -webkit-background-clip: text; 12 | -moz-background-clip: text; 13 | background-clip: text; 14 | color: transparent; 15 | text-shadow: rgba(255,255,255,0.5) 0px 3px 3px; 16 | } 17 | .App-header { 18 | background-color: #282c34; 19 | min-height: 100vh; 20 | display: flex; 21 | flex-direction: column; 22 | align-items: center; 23 | justify-content: center; 24 | font-size: calc(10px + 2vmin); 25 | color: white; 26 | } 27 | 28 | .App-link { 29 | color: #61dafb; 30 | } 31 | 32 | @keyframes App-logo-spin { 33 | from { 34 | transform: rotate(0deg); 35 | } 36 | to { 37 | transform: rotate(360deg); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import ToDoContainer from "./Todo/ToDoContainer"; 3 | import "../node_modules/bootstrap/dist/css/bootstrap.min.css"; 4 | 5 | function App() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | 13 | export default App; 14 | -------------------------------------------------------------------------------- /app/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /app/src/Todo/Favourite.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { BsFillHeartFill } from "react-icons/bs"; 3 | 4 | const Favourite = (props) => { 5 | const { updateFavouriteStatus, todo } = props; 6 | return ( 7 | <> 8 | {todo.favourite === "true" ? ( 9 | { 13 | updateFavouriteStatus(todo.key, "false"); 14 | }} 15 | className="custom-icons" 16 | title="Remove from favourites." 17 | /> 18 | ) : ( 19 | { 23 | updateFavouriteStatus(todo.key, "true"); 24 | }} 25 | className="custom-icons" 26 | title="Add to favourites." 27 | /> 28 | )} 29 | 30 | ); 31 | }; 32 | 33 | export default Favourite; 34 | -------------------------------------------------------------------------------- /app/src/Todo/NewTodo.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import Button from "react-bootstrap/Button"; 3 | import Modal from "react-bootstrap/Modal"; 4 | import { BsPlusSquareFill } from "react-icons/bs"; 5 | import { useFormik } from "formik"; 6 | import * as Yup from "yup"; 7 | import PushNotifier from "../util/PushNotifier"; 8 | import { toast } from "react-toastify"; 9 | 10 | const initialValues = { 11 | todoTitle: "", 12 | }; 13 | 14 | const validation = Yup.object({ 15 | todoTitle: Yup.string().min(5).max(100).required("todo is required"), 16 | }); 17 | 18 | const NewTodo = (props) => { 19 | const { todoData, updateData } = props; 20 | const [show, setShow] = useState(false); 21 | const handleClose = () => setShow(false); 22 | const handleShow = () => setShow(true); 23 | 24 | const saveNewTodo = (newTodoTitle) => { 25 | let nextKey = todoData.length > 0 ? todoData[0].key + 1 : 1; 26 | const dateTime = new Date().toLocaleString(); 27 | const updatedToDo = [ 28 | { 29 | key: nextKey, 30 | todoTitle: newTodoTitle, 31 | dateTime: dateTime, 32 | status: "incomplete", 33 | favourite: "false", 34 | }, 35 | ...todoData, 36 | ]; 37 | updateData(updatedToDo); 38 | toast("Task added to the list!"); 39 | }; 40 | 41 | const { values, errors, touched, handleBlur, handleChange, handleSubmit } = 42 | useFormik({ 43 | initialValues, 44 | validationSchema: validation, 45 | onSubmit: (values, action) => { 46 | saveNewTodo(values.todoTitle); 47 | action.resetForm(); 48 | handleClose(); 49 | }, 50 | }); 51 | 52 | return ( 53 | <> 54 | 55 | 62 | 63 | 64 | Create new todo 65 | 66 | 67 |
68 |
69 |
70 | 73 | 81 | {errors.todoTitle && touched.todoTitle ? ( 82 | {errors.todoTitle} 83 | ) : null} 84 |
85 |
86 |
87 |
88 | 89 | 92 | 95 | 96 |
97 | 98 | ); 99 | }; 100 | 101 | export default NewTodo; 102 | -------------------------------------------------------------------------------- /app/src/Todo/SearchBox.css: -------------------------------------------------------------------------------- 1 | .search-hover { 2 | border: 1px solid #ccc; 3 | outline: none; 4 | background-size: 20px; 5 | background-position: 13px; 6 | border-radius: 8px; 7 | width: 50px; 8 | height: 38px; 9 | padding: 10px; 10 | transition: all 0.5s; 11 | } 12 | .search-hover:hover { 13 | width: 250px; 14 | padding-left: 50px; 15 | } -------------------------------------------------------------------------------- /app/src/Todo/SearchBox.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./SearchBox.css"; 3 | import debounce from "lodash.debounce"; 4 | import { useCallback } from "react"; 5 | 6 | const SearchBox = (props) => { 7 | const { todoData, setFilterState } = props; 8 | 9 | const changeHandler = (event) => { 10 | const searchCriteria = event.target.value.toLowerCase(); 11 | setFilterState(["Search - ", searchCriteria]); 12 | }; 13 | 14 | const debouncedChangeHandler = useCallback(debounce(changeHandler, 400), []); 15 | 16 | return ( 17 | 24 | ); 25 | }; 26 | 27 | export default SearchBox; 28 | -------------------------------------------------------------------------------- /app/src/Todo/ToDo.css: -------------------------------------------------------------------------------- 1 | .form-label{ 2 | color:gray; 3 | } 4 | 5 | .actionButtons{ 6 | text-align: right; 7 | } 8 | 9 | 10 | .actionButtons Button { 11 | margin-left:20px; 12 | } 13 | 14 | .buttonContainer{ 15 | margin-bottom: 10px; 16 | } -------------------------------------------------------------------------------- /app/src/Todo/ToDoContainer.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import "./ToDo.css"; 3 | import Dropdown from "react-bootstrap/Dropdown"; 4 | import NewTodo from "./NewTodo"; 5 | import ToDoList from "./ToDoList"; 6 | import SearchBox from "./SearchBox"; 7 | 8 | const ToDoContainer = () => { 9 | const initialData = function () { 10 | const dataFromLocalStore = localStorage.getItem("todoData"); 11 | 12 | return dataFromLocalStore ? JSON.parse(dataFromLocalStore) : []; 13 | }; 14 | const [todoData, setToDoData] = useState(initialData); 15 | const [filterState, setFilterState] = useState("all"); 16 | const [filteredData, setFilteredData] = useState([]); 17 | 18 | const updateData = (newDataToReplace) => { 19 | setToDoData(newDataToReplace); 20 | localStorage.setItem("todoData", JSON.stringify(newDataToReplace)); 21 | }; 22 | 23 | useEffect(() => { 24 | let filteredTodo; 25 | if (filterState.includes("Search - ")) { 26 | filteredTodo = todoData.filter((item) => { 27 | return item.todoTitle.toLowerCase().search(filterState[1]) !== -1; 28 | }); 29 | } else { 30 | if (filterState === "favourite") { 31 | filteredTodo = todoData.filter((todo) => { 32 | return todo.favourite === "true"; 33 | }); 34 | } else { 35 | if (filterState === "all") { 36 | filteredTodo = todoData; 37 | } else { 38 | filteredTodo = todoData.filter((todo) => { 39 | return todo.status === filterState; 40 | }); 41 | } 42 | } 43 | } 44 | setFilteredData(filteredTodo); 45 | }, [filterState, todoData]); 46 | 47 | return ( 48 |
49 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |

61 |

62 | Todo List - {filterState} ({filteredData.length}) 63 |
64 |

65 |
66 |
67 | 71 |
72 |
73 | 77 |
78 |
79 | 80 | 84 | Status 85 | 86 | 87 | 88 | { 91 | setFilterState("all"); 92 | }} 93 | > 94 | All 95 | 96 | { 99 | setFilterState("incomplete"); 100 | }} 101 | > 102 | Incomplete 103 | 104 | { 107 | setFilterState("complete"); 108 | }} 109 | > 110 | Completed 111 | 112 | { 115 | setFilterState("favourite"); 116 | }} 117 | > 118 | Favourite 119 | 120 | 121 | 122 |
123 |
124 |
125 | 130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | ); 139 | }; 140 | 141 | export default ToDoContainer; 142 | -------------------------------------------------------------------------------- /app/src/Todo/ToDoList.css: -------------------------------------------------------------------------------- 1 | .listContainer { 2 | padding:20px; 3 | background-color: rgb(238, 238, 238); 4 | border-radius:0.5rem 0.5rem 0.5rem 0.5rem; 5 | box-shadow: rgb(50 50 93 / 25%) 0px 50px 100px -20px, rgb(0 0 0 / 30%) 0px 30px 60px -30px, rgb(10 37 64 / 35%) 0px -2px 6px 0px inset 6 | } 7 | .listContainer li{ 8 | margin:5px; 9 | border-radius:0.5rem 0.5rem 0.5rem 0.5rem; 10 | text-transform: capitalize; 11 | box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px 0px; 12 | } 13 | .listContainer li:hover{ 14 | box-shadow: blue 0px 2px 4px 0px, rgba(0, 0, 0, 0.3) 0px 7px 13px -3px, rgba(0, 0, 0, 0.2) 0px -3px 0px 0px inset; 15 | } 16 | .listContainer li small{ 17 | font-size: 11px; 18 | } 19 | 20 | .icons-blue{ 21 | color:blue; 22 | } 23 | .icons-red{ 24 | color:red; 25 | margin-right: 10px; 26 | } -------------------------------------------------------------------------------- /app/src/Todo/ToDoList.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import PushNotifier from "../util/PushNotifier"; 3 | import "./ToDoList.css"; 4 | import TodoItem from "./TodoItem"; 5 | import { toast } from "react-toastify"; 6 | 7 | const ToDoList = (props) => { 8 | const { filteredData, updateData, todoData } = props; 9 | 10 | const deleteTodo = (todoId) => { 11 | const afterDeleting = filteredData.filter((todo) => todo.key !== todoId); 12 | updateData(afterDeleting); 13 | toast("Task deleted successfully!"); 14 | }; 15 | 16 | return ( 17 | <> 18 | 19 |
20 |
21 |
22 |
    23 | {filteredData.length ? ( 24 | filteredData.map((todo) => { 25 | return ( 26 |
  • 30 | 36 |
  • 37 | ); 38 | }) 39 | ) : ( 40 |
  • No To do yet
  • 41 | )} 42 |
43 |
44 |
45 |
46 | 47 | ); 48 | }; 49 | 50 | export default ToDoList; 51 | -------------------------------------------------------------------------------- /app/src/Todo/ToDoSchema.js: -------------------------------------------------------------------------------- 1 | import * as Yup from "yup"; 2 | 3 | export const todoSchema = Yup.object({ 4 | email: Yup.string().email().required("Email id is required"), 5 | first: Yup.string().min(2).max(20).required("First name is required"), 6 | last: Yup.string().min(2).max(20).required("Last name is required"), 7 | password: Yup.string().min(6).required("Please enter your password"), 8 | repassword: Yup.string() 9 | .required("Confirm password is required") 10 | .oneOf([Yup.ref("password"), null], "Password must match"), 11 | }); 12 | -------------------------------------------------------------------------------- /app/src/Todo/TodoItem.css: -------------------------------------------------------------------------------- 1 | .itemContainer{ 2 | text-align: left; 3 | width: 80%; 4 | } -------------------------------------------------------------------------------- /app/src/Todo/TodoItem.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { BsPencilSquare, BsTrash } from "react-icons/bs"; 3 | import { useFormik } from "formik"; 4 | import * as Yup from "yup"; 5 | import PushNotifier from "../util/PushNotifier"; 6 | import Favourite from "./Favourite"; 7 | import { 8 | BsCheckCircle, 9 | BsXCircle, 10 | BsFillCheckCircleFill, 11 | BsArrowClockwise, 12 | } from "react-icons/bs"; 13 | import "./TodoItem.css"; 14 | import { toast } from "react-toastify"; 15 | 16 | // todo - bring this fom schema file 17 | const validation = Yup.object({ 18 | todoTitle: Yup.string().min(5).max(100).required("Task title is required"), 19 | key: Yup.number().required("key required"), 20 | }); 21 | 22 | const TodoItem = (props) => { 23 | const { todo, deleteTodo, updateData, todoData } = props; 24 | const [mode, setMode] = useState("view"); 25 | 26 | // formik and yup validation 27 | const initialValues = { 28 | todoTitle: todo.todoTitle, 29 | key: todo.key, 30 | }; 31 | 32 | // complete the task 33 | const updateTaskStatus = (key, status) => { 34 | const updatedAfterStatusChange = todoData.map((todo) => { 35 | let obj = 36 | todo.key === key 37 | ? { 38 | ...todo, 39 | status: status, 40 | } 41 | : todo; 42 | return obj; 43 | }); 44 | updateData(updatedAfterStatusChange); 45 | toast(`Task marked as ${status}`); 46 | }; 47 | 48 | // add to favourite 49 | const updateFavouriteStatus = (key, status) => { 50 | const updatedAfterStatusChange = todoData.map((todo) => { 51 | let obj = 52 | todo.key === key 53 | ? { 54 | ...todo, 55 | favourite: status, 56 | } 57 | : todo; 58 | return obj; 59 | }); 60 | updateData(updatedAfterStatusChange); 61 | const msg = 62 | status === "true" 63 | ? "Task added to favourites" 64 | : "Task removed from favourites"; 65 | toast(msg); 66 | }; 67 | 68 | const { errors, touched, handleBlur, handleChange, handleSubmit } = useFormik( 69 | { 70 | initialValues, 71 | validationSchema: validation, 72 | onSubmit: (values, action) => { 73 | const updatedTodo = todoData.map((todo) => { 74 | let obj = 75 | todo.key === values.key 76 | ? { 77 | ...todo, 78 | todoTitle: values.todoTitle, 79 | dateTime: new Date().toLocaleString(), 80 | } 81 | : todo; 82 | return obj; 83 | }); 84 | updateData(updatedTodo); 85 | setMode("view"); 86 | toast("Task edited successfully!"); 87 | }, 88 | } 89 | ); 90 | 91 | return ( 92 | <> 93 | 94 | {todo.status === "complete" ? ( 95 | <> 96 |
97 | {todo.todoTitle} 98 | 102 |
103 | {todo.dateTime} 104 |
105 | 106 | ) : ( 107 | <> 108 |
109 | {mode === "view" ? ( 110 | <> 111 | {todo.todoTitle} 112 | 116 | 117 | ) : ( 118 |
119 | 127 | 128 | { 132 | setMode("view"); 133 | }} 134 | title="Cancel" 135 | /> 136 | 146 | {errors.todoTitle && touched.todoTitle ? ( 147 | {errors.todoTitle} 148 | ) : null} 149 | 150 | )} 151 |
152 | {todo.dateTime} 153 |
154 | 155 | )} 156 |
157 |
158 | {todo.status === "incomplete" ? ( 159 | { 169 | updateTaskStatus(todo.key, "complete"); 170 | }} 171 | /> 172 | ) : ( 173 | { 183 | updateTaskStatus(todo.key, "incomplete"); 184 | }} 185 | /> 186 | )} 187 |
188 |
189 | { 197 | deleteTodo(todo.key); 198 | }} 199 | /> 200 |
201 |
202 | { 212 | todo.status === "incomplete" ? setMode("edit") : void 0; 213 | }} 214 | /> 215 |
216 |
217 | 218 | ); 219 | }; 220 | 221 | export default TodoItem; 222 | -------------------------------------------------------------------------------- /app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /app/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /app/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /app/src/util/PushNotifier.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ToastContainer } from "react-toastify"; 3 | import "react-toastify/dist/ReactToastify.css"; 4 | 5 | const PushNotifier = (props) => { 6 | return ( 7 | 19 | ); 20 | }; 21 | export default PushNotifier; 22 | --------------------------------------------------------------------------------