aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 15:32:54 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 15:32:54 -0600
commitac4a146682ede7bf661938b78a970d7da8bd868a (patch)
tree30020143572191ab723772c0b0b0eea83612268b /src
parentc8fd1b88958ad0a5cd9b87395f9995f0f4176a30 (diff)
downloadToDo-App-FE-ac4a146682ede7bf661938b78a970d7da8bd868a.tar.gz
ToDo-App-FE-ac4a146682ede7bf661938b78a970d7da8bd868a.zip
Delete a specific to do with API.
Diffstat (limited to '')
-rw-r--r--src/ToDo-UI/ListToDo.jsx8
-rw-r--r--src/api/axios_methods.js13
2 files changed, 18 insertions, 3 deletions
diff --git a/src/ToDo-UI/ListToDo.jsx b/src/ToDo-UI/ListToDo.jsx
index 657de44..74c36de 100644
--- a/src/ToDo-UI/ListToDo.jsx
+++ b/src/ToDo-UI/ListToDo.jsx
@@ -11,7 +11,7 @@ import {
select_current_sorting,
} from "../features/todo/reducer";
-import { edit_todo_function } from "../api/axios_methods";
+import { edit_todo_function, remove_todo_function } from "../api/axios_methods";
function sort_table_header(prefix, current_sorting) {
if (prefix.toLowerCase().startsWith(current_sorting.substr(0, 3))) {
@@ -148,6 +148,7 @@ export function ListToDos() {
const [edit_priority, set_edit_priority] = useState("Low");
const edit_todo_api = edit_todo_function();
+ const remove_todo_api = remove_todo_function();
function handle_open_modal(id, text, due_date, done, priority) {
set_edit_id(id);
@@ -211,8 +212,9 @@ export function ListToDos() {
type="button"
className="btn btn-outline-dark"
onClick={(e) => {
- dispatch(remove_todo(item.id)),
- dispatch(refresh_filtered_todos());
+ remove_todo_api({ id: item.id });
+ dispatch(remove_todo(item.id));
+ dispatch(refresh_filtered_todos());
}}
>
Delete
diff --git a/src/api/axios_methods.js b/src/api/axios_methods.js
index 68f119f..8748cb7 100644
--- a/src/api/axios_methods.js
+++ b/src/api/axios_methods.js
@@ -47,3 +47,16 @@ export function edit_todo_function() {
}
};
}
+
+// removeToDo().
+export function remove_todo_function() {
+ // Remove an existing to do by its id.
+ // DELETE "/todos/{id}"
+ return async (data) => {
+ try {
+ await api.delete(`/todos/${data.id}`);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+}