Bug: incorrect toast showing up on fail to creating task
After logging in and trying to create a new task fron the Tasks section, while creating a new task:
- If task description is not provided or,
- taskserver is not running
the task creation fails ad the backend returns error
400and500respectively. instead of showingtask creation failed, the toast showstask created successfully. I think the problem is in filefrontend/src/components/HomeComponents/Tasks/Tasks.tsx, right here:
if (response) {
console.log("Task added successfully!")
toast.success("Task added successfully!", {
position: "bottom-left",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
})
setNewTask({
description: "",
priority: "",
project: "",
due: "",
})
setIsAddTaskOpen(false)
}
as fetch always returns a Response object, the if(response) check is always true. instead it should be this: if(response.ok).
I would like to solve this issue. please assign me.
attaching a demo video for reference:
Screencast from 2025-01-05 05-08-25.webm
as shown in the video, although no description is provided (in the first case) and the taskserver is not running (in second case), the server returns error, but the frontend shows success toast.
this seems about right, but i think that, for the empty description part, we can do something better... like if possible, stop the user at the dialog itself and prompt them to enter a non-empty description.
this also should be changed in the edit-description function
Sure @its-me-abhishek i believe there are two possible ways to handle it:
- update the submit task functionality and make it a
formcomponent with all the necessary checks - update the
handleAddTaskfunction to implement all the necessary checks there.
personally i think implementing both of these together will ensure maximum safety. same for the edit description functinality in handleEditTaskDesc function. we can implement a form structure and also make necessary checks in handleSaveClick function before the handleEditTaskDesc is called with the validated data.
It would be best if you can suggest a minlength for the description. that way all checks can be safely done via that.
PS. the response.ok should be implemented together with all these.
update the submit task functionality and make it a form component with all the necessary checks
why is this required?
for the minLength, i think that 1 should work... as we cannot have an empty string as a description
Ok will implement that. Along with it i have observed one more bug in the Due date input, invalid dates like 2025-33-33 can be submitted without throwing any errors. Will try to prevent that too along with the description validation.