Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions apps/web/src/components/task/task-comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function TaskComment({

async function handleSubmit(data: z.infer<typeof commentSchema>) {
if (!user?.id) {
toast.error("You must be logged in to add or update a comment.");
return;
}

Expand All @@ -52,30 +53,33 @@ function TaskComment({
userId: user.id,
content: data.comment,
});
toast.success("Comment updated successfully.");
onSubmit?.();
} else {
await createComment({
taskId: taskId,
content: data.comment,
userId: user?.id,
});
toast.success("Comment added successfully.");
onSubmit?.();
}

await queryClient.invalidateQueries({
queryKey: ["activities", taskId],
});

toast.success(
commentId
? "Comment updated successfully"
: "Comment added successfully",
);
form.reset();
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to add comment",
);
// Log error for debugging
console.error("TaskComment error:", error);
let message = "Unable to submit your comment. Please try again or contact support.";
if (error instanceof Error) {
message = error.message;
} else if (typeof error === "string") {
message = error;
}
toast.error(message);
}
}

Expand Down
32 changes: 24 additions & 8 deletions apps/web/src/components/task/task-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function TaskInfo({
});

const handleChange = async (data: z.infer<typeof taskInfoSchema>) => {
if (!task) return;
if (!task) {
toast.error("No task found. Unable to update.");
return;
}

setIsSaving(true);
try {
Expand All @@ -79,16 +82,24 @@ function TaskInfo({
});
toast.success("Task updated successfully");
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to update task",
);
console.error("Error updating task:", error);
let message = "An unexpected error occurred while updating the task.";
if (error instanceof Error) {
message = error.message;
} else if (typeof error === "string") {
message = error;
}
toast.error(message);
} finally {
setIsSaving(false);
}
};

const handleDeleteTask = async () => {
if (!task) return;
if (!task) {
toast.error("No task found. Unable to delete.");
return;
}

try {
await deleteTask(task.id);
Expand All @@ -104,9 +115,14 @@ function TaskInfo({
},
});
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to delete task",
);
console.error("Error deleting task:", error);
let message = "An unexpected error occurred while deleting the task.";
if (error instanceof Error) {
message = error.message;
} else if (typeof error === "string") {
message = error;
}
toast.error(message);
}
};

Expand Down