feat: Add priority pages and reusable component for task management, update devDependencies
This commit is contained in:
9
tasker-client/src/app/priority/backlog/page.tsx
Normal file
9
tasker-client/src/app/priority/backlog/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from "react";
|
||||
import ReusablePriorityPage from "../reusablePriorityPage";
|
||||
import { Priority } from "@/state/api";
|
||||
|
||||
const Backlog = () => {
|
||||
return <ReusablePriorityPage priority={Priority.Backlog} />;
|
||||
};
|
||||
|
||||
export default Backlog;
|
||||
9
tasker-client/src/app/priority/high/page.tsx
Normal file
9
tasker-client/src/app/priority/high/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from "react";
|
||||
import ReusablePriorityPage from "../reusablePriorityPage";
|
||||
import { Priority } from "@/state/api";
|
||||
|
||||
const High = () => {
|
||||
return <ReusablePriorityPage priority={Priority.High} />;
|
||||
};
|
||||
|
||||
export default High;
|
||||
9
tasker-client/src/app/priority/low/page.tsx
Normal file
9
tasker-client/src/app/priority/low/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from "react";
|
||||
import ReusablePriorityPage from "../reusablePriorityPage";
|
||||
import { Priority } from "@/state/api";
|
||||
|
||||
const Low = () => {
|
||||
return <ReusablePriorityPage priority={Priority.Low} />;
|
||||
};
|
||||
|
||||
export default Low;
|
||||
9
tasker-client/src/app/priority/medium/page.tsx
Normal file
9
tasker-client/src/app/priority/medium/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from "react";
|
||||
import ReusablePriorityPage from "../reusablePriorityPage";
|
||||
import { Priority } from "@/state/api";
|
||||
|
||||
const Medium = () => {
|
||||
return <ReusablePriorityPage priority={Priority.Medium} />;
|
||||
};
|
||||
|
||||
export default Medium;
|
||||
156
tasker-client/src/app/priority/reusablePriorityPage/index.tsx
Normal file
156
tasker-client/src/app/priority/reusablePriorityPage/index.tsx
Normal file
@@ -0,0 +1,156 @@
|
||||
"use client";
|
||||
|
||||
import { useAppSelector } from "@/app/redux";
|
||||
import Header from "@/app/components/Header";
|
||||
import ModalNewTask from "@/app/components/ModalNewTask";
|
||||
import TaskCard from "@/app/components/TaskCard";
|
||||
import { dataGridSxStyles } from "@/lib/utils";
|
||||
import { Priority, Task, useGetTasksByUserQuery } from "@/state/api";
|
||||
import { DataGrid, GridColDef } from "@mui/x-data-grid";
|
||||
import React, { useState } from "react";
|
||||
|
||||
type Props = {
|
||||
priority: Priority;
|
||||
};
|
||||
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "title",
|
||||
headerName: "Title",
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: "description",
|
||||
headerName: "Description",
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
field: "status",
|
||||
headerName: "Status",
|
||||
width: 130,
|
||||
renderCell: (params) => (
|
||||
<span className="inline-flex rounded-full bg-green-100 px-2 text-xs font-semibold leading-5 text-green-800">
|
||||
{params.value}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
field: "priority",
|
||||
headerName: "Priority",
|
||||
width: 75,
|
||||
},
|
||||
{
|
||||
field: "tags",
|
||||
headerName: "Tags",
|
||||
width: 130,
|
||||
},
|
||||
{
|
||||
field: "startDate",
|
||||
headerName: "Start Date",
|
||||
width: 130,
|
||||
},
|
||||
{
|
||||
field: "dueDate",
|
||||
headerName: "Due Date",
|
||||
width: 130,
|
||||
},
|
||||
{
|
||||
field: "author",
|
||||
headerName: "Author",
|
||||
width: 150,
|
||||
renderCell: (params) => params.value.username || "Unknown",
|
||||
},
|
||||
{
|
||||
field: "assignee",
|
||||
headerName: "Assignee",
|
||||
width: 150,
|
||||
renderCell: (params) => params.value.username || "Unassigned",
|
||||
},
|
||||
];
|
||||
|
||||
const ReusablePriorityPage = ({ priority }: Props) => {
|
||||
const [view, setView] = useState("list");
|
||||
const [isModalNewTaskOpen, setIsModalNewTaskOpen] = useState(false);
|
||||
|
||||
// const { data: currentUser } = useGetAuthUserQuery({});
|
||||
// const userId = currentUser?.userDetails?.userId ?? null;
|
||||
const userId = 1;
|
||||
const {
|
||||
data: tasks,
|
||||
isLoading,
|
||||
isError: isTasksError,
|
||||
} = useGetTasksByUserQuery(userId || 0, {
|
||||
skip: userId === null,
|
||||
});
|
||||
|
||||
const isDarkMode = useAppSelector((state) => state.global.isDarkMode);
|
||||
|
||||
const filteredTasks = tasks?.filter(
|
||||
(task: Task) => task.priority === priority,
|
||||
);
|
||||
|
||||
if (isTasksError || !tasks) return <div>Error fetching tasks</div>;
|
||||
|
||||
return (
|
||||
<div className="m-5 p-4">
|
||||
<ModalNewTask
|
||||
isOpen={isModalNewTaskOpen}
|
||||
onClose={() => setIsModalNewTaskOpen(false)}
|
||||
/>
|
||||
<Header
|
||||
name="Priority Page"
|
||||
buttonComponent={
|
||||
<button
|
||||
className="mr-3 rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
||||
onClick={() => setIsModalNewTaskOpen(true)}
|
||||
>
|
||||
Add Task
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
<div className="mb-4 flex justify-start">
|
||||
<button
|
||||
className={`px-4 py-2 ${
|
||||
view === "list" ? "bg-gray-300" : "bg-white"
|
||||
} rounded-l`}
|
||||
onClick={() => setView("list")}
|
||||
>
|
||||
List
|
||||
</button>
|
||||
<button
|
||||
className={`px-4 py-2 ${
|
||||
view === "table" ? "bg-gray-300" : "bg-white"
|
||||
} rounded-l`}
|
||||
onClick={() => setView("table")}
|
||||
>
|
||||
Table
|
||||
</button>
|
||||
</div>
|
||||
{isLoading ? (
|
||||
<div>Loading tasks...</div>
|
||||
) : view === "list" ? (
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
{filteredTasks?.map((task: Task) => (
|
||||
<TaskCard key={task.id} task={task} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
view === "table" &&
|
||||
filteredTasks && (
|
||||
<div className="z-0 w-full">
|
||||
<DataGrid
|
||||
rows={filteredTasks}
|
||||
columns={columns}
|
||||
checkboxSelection
|
||||
getRowId={(row) => row.id}
|
||||
className="border border-gray-200 bg-white shadow dark:border-stroke-dark dark:bg-dark-secondary dark:text-gray-200"
|
||||
sx={dataGridSxStyles(isDarkMode)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ReusablePriorityPage;
|
||||
9
tasker-client/src/app/priority/urgent/page.tsx
Normal file
9
tasker-client/src/app/priority/urgent/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from "react";
|
||||
import ReusablePriorityPage from "../reusablePriorityPage";
|
||||
import { Priority } from "@/state/api";
|
||||
|
||||
const Urgent = () => {
|
||||
return <ReusablePriorityPage priority={Priority.Urgent} />;
|
||||
};
|
||||
|
||||
export default Urgent;
|
||||
Reference in New Issue
Block a user