import React, { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { add_todo, sort_todo, refresh_filtered_todos, select_last_index, } from "../features/todo/reducer"; import { new_todo_function } from "../api/axios_methods"; function new_button(trigger_id) { return (
); } function new_modal(modal_id, modal_header, modal_body, modal_footer) { return ( ); } export function NewToDo() { const my_last_idx = useSelector(select_last_index); const dispatch = useDispatch(); const [new_text, set_new_text] = useState(""); const [new_due_date, set_new_due_date] = useState(""); const [new_priority, set_new_priority] = useState("Low"); const new_todo_api = new_todo_function(); function handle_exit_modal() { // https://stackoverflow.com/questions/27826381/clearing-form-input-fields-in-bootstrap $("form").get(0).reset(); // Reset form set_new_text(""); set_new_due_date(""); set_new_priority("Low"); } function handle_add_todo() { new_todo_api({ text: new_text, due_date: new_due_date, priority: new_priority, }); dispatch( add_todo({ text: new_text, due_date: new_due_date, priority: new_priority, creation_date: new Date().toString(), }) ); dispatch(sort_todo()); dispatch(refresh_filtered_todos()); handle_exit_modal(); } // Define modal to add a new to do. var modal_header = (
Add a new to do
); var modal_footer = (
); var modal_body = (
set_new_text(e.target.value)} />
{ set_new_due_date(e.target.value); }} />
); return ( <> {new_button("#NewToDo")} {new_modal("NewToDo", modal_header, modal_body, modal_footer)} ); }