Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the size of the progress bar and newline task edit. #64

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 20 additions & 18 deletions frontend/src/api/taskAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ export default class TaskAPI {
return response.data as KanbanTask;
}

static createTaskObservable(
boardId: number,
taskData: Partial<KanbanTask>
): Observable<KanbanTask> {
return from(TaskAPI.createTask(boardId)).pipe(
switchMap((task) => {
return from(TaskAPI.updateTask(boardId, task.id, taskData)).pipe(
catchError((error) => {
throw new TaskApiError(
`Error creating task with boardId ${boardId}`,
task,
error
);
})
);
})
);
}

static async deleteTask(boardId: number, taskId: number): Promise<void> {
const token = localStorage.getItem("token");

Expand Down Expand Up @@ -58,24 +77,7 @@ export default class TaskAPI {
return response.data as KanbanTask;
}

static createTaskObservable(
boardId: number,
taskData: Partial<KanbanTask>
): Observable<KanbanTask> {
return from(TaskAPI.createTask(boardId)).pipe(
switchMap((task) => {
return from(TaskAPI.updateTask(boardId, task.id, taskData)).pipe(
catchError((error) => {
throw new TaskApiError(
`Error creating task with boardId ${boardId}`,
task,
error
);
})
);
})
);
}


static updateTaskObservable(
boardId: number,
Expand Down
45 changes: 45 additions & 0 deletions frontend/src/components/forms/notification-popup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect } from "react";

type NotificationType = "success" | "error" | "info" | undefined;

interface NotificationPopupProps {
message: string;
isVisible: boolean;
onClose: () => void;
type?: NotificationType;
}



const NotificationPopup = ({
message,
isVisible,
onClose,
type = "info",
}: NotificationPopupProps) => {
useEffect(() => {
if (isVisible) {
const timer = setTimeout(onClose, 3000); // 1 second auto-close
return () => clearTimeout(timer);
}
}, [isVisible, onClose]);

if (!isVisible) return null;

const typeStyles = {
success: "bg-green-500 text-white",
error: "bg-red-500 text-white",
info: "bg-blue-500 text-white",
};

return (
<div
className={`fixed bottom-4 right-4 px-4 py-2 rounded shadow-lg transition-opacity duration-300 ${typeStyles[type]}`}
style={{ zIndex: 1000 }}
>
<span>{message}</span>
</div>
);
};

export default NotificationPopup;
31 changes: 29 additions & 2 deletions frontend/src/components/kanbans/kanban-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { kanbanColumns } from "../../utilities/kanban-category-mapping";
import { Droppable, DragDropContext } from "react-beautiful-dnd";
import UserAPI from "../../api/userAPI";
import ConfirmationModal from "../forms/confirmation-form";

import NotificationPopup from "../forms/notification-popup";
export default function KanbanDisplay({
kanban,
setKanban,
Expand All @@ -23,6 +23,12 @@ export default function KanbanDisplay({
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false);
const [taskToDelete, setTaskToDelete] = useState<number | null>(null);
const [addTaskError, setAddTaskError] = useState<string | null>(null);
const [notification, setNotification] = useState<{ message: string; isVisible: boolean; type: "success" | "error" | "info" }>({
message: "",
isVisible: false,
type: "info"
});


useEffect(() => {
const subscription = UserAPI.getUserObservable().subscribe({
Expand All @@ -39,6 +45,12 @@ export default function KanbanDisplay({
};
}, []);


const showNotification = (message: string, type: "success" | "error" | "info" = "info") => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to extract this to a custom type under /utils/types.tsx. I am not that fussed, so I'll leave it up to you

setNotification({ message, isVisible: true, type });
setTimeout(() => setNotification({ message: "", isVisible: false, type }), 3000);
};

const handleDeleteTask = (taskId: number) => {
setTaskToDelete(taskId);
setIsConfirmModalOpen(true);
Expand All @@ -54,9 +66,11 @@ export default function KanbanDisplay({
});
setSelectedTask(null);
setIsConfirmModalOpen(false);
showNotification("Task deleted successfully", "success");
})
.catch((error) => {
console.error("Error deleting task:", error);

});
}
};
Expand Down Expand Up @@ -105,6 +119,7 @@ export default function KanbanDisplay({
next: (task) => {
console.log("Task created:", task);
setIsTaskModalOpen(false);
showNotification("Task created successfully", "success");
},
error: (error) => {
setAddTaskError(error.error.response.data);
Expand Down Expand Up @@ -138,15 +153,26 @@ export default function KanbanDisplay({
next: (updatedTask) => {
console.log("Task updated:", updatedTask);
setKanban({ ...kanban, tasks: updatedTasks });
showNotification("Task updated successfully", "success");
},
error: (error) => {
console.error("Error updating task:", error);
},
});
};


return (

<div style={{ padding: "0 20px" }}>
{/* Notification Popup */}
<NotificationPopup
message={notification.message}
isVisible={notification.isVisible}
onClose={() => setNotification({ ...notification, isVisible: false })}
type={notification.type || "info"}
/>

<header className="flex flex-col items-start mb-6 w-full">
<h1 className="text-4xl font-bold break-words sm:max-w-full max-w-64">
{kanban.name}
Expand All @@ -168,6 +194,7 @@ export default function KanbanDisplay({
</span>
</div>
<ProgressBar progress={progress} />


<div className="mt-4 w-full flex justify-start">
<button
Expand Down Expand Up @@ -240,7 +267,7 @@ function ProgressBar({ progress }: { progress: number }) {
background: "#ddd",
borderRadius: "4px",
width: "100%",
height: "10px",
height: "30px",
marginTop: "5px",
}}
>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/kanbans/kanban-task-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const DetailedTaskView = ({
name="urgency"
value={updatedTask.urgency}
onChange={handleInputChange}
className="p-2 rounded text-black"
className="block w-full p-2 rounded text-black mt-1"
>
<option value="1">High</option>
<option value="2">Medium</option>
Expand All @@ -183,7 +183,7 @@ const DetailedTaskView = ({
name="dueDate"
value={updatedTask.dueDate}
onChange={handleInputChange}
className="p-2 rounded text-black"
className="block w-full p-2 rounded text-black mt-1"
/>
) : (
<span className="ml-2">{task.dueDate}</span>
Expand Down Expand Up @@ -266,7 +266,7 @@ const DetailedTaskView = ({
name="taskCategory"
value={updatedTask.taskCategory}
onChange={handleInputChange}
className="p-2 rounded text-black"
className="block w-full p-2 rounded text-black mt-1"
>
<option value="1">Backlog</option>
<option value="2">In Progress</option>
Expand Down