diff --git a/src/KBBoard.js b/src/KBBoard.js index c581fb4..8eaaca3 100644 --- a/src/KBBoard.js +++ b/src/KBBoard.js @@ -8,6 +8,7 @@ const KBBoard = () => { const navigate = useNavigate(); const { id } = useParams(); const [error, setError] = useState(''); + const [loading, setLoading] = useState(false) const [info, setInfo] = useState({}); const [categories, setCategories] = useState([]); @@ -88,13 +89,16 @@ const KBBoard = () => { const createTask = async (e) => { e.preventDefault(); + setLoading(true); const newTask = { category_id: taskCategori, title: taskTitle, description: taskDescription }; - axios.post('/api/boards/categories/tasks/create', newTask); + await axios.post('/api/boards/categories/tasks/create', newTask); await loadBoardData(); modalCrTask(null)(); + setLoading(false); }; const createCategory = async (e) => { e.preventDefault(); + setLoading(true); try { const newCategory = { board_id: id, title: categoryTitle}; await axios.post('/api/boards/categories/create', newCategory); @@ -103,11 +107,13 @@ const KBBoard = () => { setError(err.response.data.message) } finally { modalCrCateg(); + setLoading(false); } }; const editTask = async (e) => { e.preventDefault(); + setLoading(true); var newTask = { id: editedTask.id, update_method: "title", value: taskTitle }; await axios.put('/api/boards/categories/tasks/update', newTask); newTask = { id: editedTask.id, update_method: "description", value: taskDescription }; @@ -116,9 +122,11 @@ const KBBoard = () => { await axios.put('/api/boards/categories/tasks/update', newTask); await loadBoardData(); modalEditTask({}, null)(); + setLoading(false); }; const editCategory = async (e) => { e.preventDefault(); + setLoading(true); try { const newCategory = { id: editedCateg.id, update_method: "title", value: categoryTitle}; await axios.put('/api/boards/categories/update', newCategory); @@ -127,23 +135,28 @@ const KBBoard = () => { setError(err.response.data.message) } finally { modalEditCateg({})(); + setLoading(false); } }; const deleteCategory = async (e) => { e.preventDefault(); + setLoading(true); await axios.delete('/api/boards/categories/delete', { data: {id: editedCateg.id} }); await loadBoardData(); modalDelCateg(); modalEditCateg({})(); + setLoading(false); } const deleteTask = async (e) => { e.preventDefault(); + setLoading(true); await axios.delete('/api/boards/categories/tasks/delete', { data: { id: editedTask.id } }); await loadBoardData(); modalDelTask(); modalEditTask({},null)(); + setLoading(false); } @@ -216,8 +229,6 @@ const KBBoard = () => { - - {crCateg && (