Skip to content
Merged
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
11 changes: 9 additions & 2 deletions backend/controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ export const createTask = async (req, res) => {
}

// fetch details for task from request body
const { title, description, tags, priority, status, dueDate } = req.body;
if (!title || !priority || !status) {
const {
title,
description,
tags,
priority,
status = "Due",
dueDate,
} = req.body;
if (!title || !priority || !dueDate) {
return res
.status(400)
.json({ success: false, message: "Please enter all the details" });
Expand Down
2 changes: 2 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions frontend/src/components/Routine/TaskLibrary.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from "react";
import { useDraggable } from "@dnd-kit/core";
import useTasks from "../../hooks/useTasks.js";
import EmptyState from "../EmptyState";

/* ---------------- Draggable Task Item ---------------- */
Expand Down Expand Up @@ -59,9 +58,8 @@ function DraggableTask({ task }) {
}

/* ---------------- Task Library ---------------- */
export default function TaskLibrary({ onAddTask }) {
const { tasks } = useTasks();

export default function TaskLibrary({ tasks, onAddTask }) {

const [query, setQuery] = useState("");

const filteredTasks = tasks?.filter((task) =>
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/components/Task/TaskFormModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ export default function TaskFormModal({ task, onClose, onSubmit, errorMessage, o
return alert("Due date cannot be more than 1 year in the future");
}

onSubmit({
title: title.trim(),
description: description.trim(),
tags,
priority,
dueDate,
});
onSubmit({
title: title.trim(),
description: description.trim(),
tags,
priority,
status: "Due",
dueDate,
});
};

const toggleCategory = (categoryName) => {
Expand Down
37 changes: 24 additions & 13 deletions frontend/src/hooks/useTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,30 @@ const useTasks = () => {

// create new task
const addTask = async (taskData) => {
try {
await api.post("/tasks", taskData);
getTasks();
} catch (error) {
if (error.response?.status === 409) {
throw new Error(
error.response.data?.message ||
"Task with the same title and due date already exists"
);
}
throw error;
}
};
try {
const response = await api.post("/tasks", taskData);

console.log("Task added:", response.data);

// instantly update UI
setTasks((prev) => [response.data.newTask, ...prev]);

} catch (error) {

console.log("FULL ERROR:", error);

console.log(
error?.response?.data?.message ||
error?.response?.data ||
error.message
);

alert(
error?.response?.data?.message ||
"Failed to create task"
);
}
};

// update task
const updateTask = async (id, updates) => {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/RoutineBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export default function RoutineBuilder() {
{/* Main Layout */}
<div className="grid grid-cols-12 gap-6 animate-in delay-200">
<aside className="col-span-12 md:col-span-3">
<TaskLibrary
tasks={tasks}
onAddTask={() => setIsModalOpen(true)}
/>
{/*
* TaskLibrary's "Add Task" button opens the modal directly
* (user is already at the top section of the page, no scroll needed).
Expand Down Expand Up @@ -303,4 +307,4 @@ export default function RoutineBuilder() {
</div>
</DndContext>
);
}
}
Loading