diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index dc18dda..14ba7a5 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -3,10 +3,10 @@ name: CI for Next.js on: push: branches: - - main + - master pull_request: branches: - - main + - master jobs: build: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fc0e569..d3be7a1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Deploy to Netlify on: push: branches: - - main + - master jobs: deploy: diff --git a/package.json b/package.json index de05dde..e53d644 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "postinstall": "prisma generate", "build": "next build --no-lint", "start": "next start", + "typecheck": "tsc --noEmit", "lint": "next lint" }, "dependencies": { diff --git a/src/app/(main)/projects/[id]/_components/DeleteTask.tsx b/src/app/(main)/projects/[id]/_components/DeleteTask.tsx new file mode 100644 index 0000000..d5c9037 --- /dev/null +++ b/src/app/(main)/projects/[id]/_components/DeleteTask.tsx @@ -0,0 +1,69 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { deleteTask } from "@/lib/actions/task.action"; +import { FileWarning } from "lucide-react"; +import * as React from "react"; +import { toast } from "sonner"; + +export function DeleteTaskDialog({ taskId }: { taskId: string }) { + const [loading, setLoading] = React.useState(false); + + const handleDelete = async () => { + try { + setLoading(true); + const res = await deleteTask(taskId); + if (res.success) toast.success("Task deleted successfully."); + toast.error(res.message); + } finally { + setLoading(false); + } + }; + + return ( + + +

+ Delete task +

+
+ + +
+ + Delete task +
+ + Are you sure you want to delete this task? This action cannot be + undone. + +
+ + + + + + + +
+
+ ); +} diff --git a/src/app/(main)/projects/[id]/_components/EditDialog.tsx b/src/app/(main)/projects/[id]/_components/EditDialog.tsx index 5625056..ef29401 100644 --- a/src/app/(main)/projects/[id]/_components/EditDialog.tsx +++ b/src/app/(main)/projects/[id]/_components/EditDialog.tsx @@ -1,18 +1,16 @@ "use client"; -import * as React from "react"; import { Dialog, - DialogTrigger, DialogContent, + DialogDescription, DialogHeader, DialogTitle, - DialogDescription, - DialogFooter, + DialogTrigger } from "@/components/ui/dialog"; -import { Button } from "@/components/ui/button"; -import EditTaskForm from "./EditTaskForm"; +import * as React from "react"; import { Task } from "../../../../../../prisma/src/generated/prisma"; +import EditTaskForm from "./EditTaskForm"; export function EditTaskDialog({ task }: { task: Task }) { const [open, setOpen] = React.useState(false); diff --git a/src/app/(main)/projects/[id]/_components/TaskActions.tsx b/src/app/(main)/projects/[id]/_components/TaskActions.tsx index 6a68e3f..c5d4074 100644 --- a/src/app/(main)/projects/[id]/_components/TaskActions.tsx +++ b/src/app/(main)/projects/[id]/_components/TaskActions.tsx @@ -2,17 +2,18 @@ "use server"; import { - Popover, - PopoverContent, - PopoverTrigger, + Popover, + PopoverContent, + PopoverTrigger, } from "@/components/ui/popover"; import { - Tooltip, - TooltipContent, - TooltipTrigger, + Tooltip, + TooltipContent, + TooltipTrigger, } from "@/components/ui/tooltip"; import { MoreHorizontal } from "lucide-react"; import { EditTaskDialog } from "./EditDialog"; +import { DeleteTaskDialog } from "./DeleteTask"; const TaskActions = async ({ task }: { task: any }) => { return ( @@ -31,6 +32,7 @@ const TaskActions = async ({ task }: { task: any }) => { + ); diff --git a/src/app/(main)/projects/[id]/_components/TasksList.tsx b/src/app/(main)/projects/[id]/_components/TasksList.tsx index a069286..ba50efd 100644 --- a/src/app/(main)/projects/[id]/_components/TasksList.tsx +++ b/src/app/(main)/projects/[id]/_components/TasksList.tsx @@ -19,9 +19,12 @@ const TasksList = async ({ data }: { data: any }) => { return (
-
- - +
+
+ + +
+
diff --git a/src/app/(main)/projects/[id]/page.tsx b/src/app/(main)/projects/[id]/page.tsx index d8b734c..446abb1 100644 --- a/src/app/(main)/projects/[id]/page.tsx +++ b/src/app/(main)/projects/[id]/page.tsx @@ -8,6 +8,7 @@ import formatDate from "@/lib/helper/convert-date"; import TasksList from "./_components/TasksList"; import { Priority, task } from "../../../../../prisma/src/generated/prisma"; import TaskActions from "./_components/TaskActions"; +import { getProjectById } from "@/lib/actions/projects.action"; const tabs = [ { text: "List", value: "list", icon: }, @@ -37,6 +38,8 @@ const ProjectTask = async ({ params, searchParams }: IProps) => { pageSearchParams?.priority, pageSearchParams?.status ); + const project = await getProjectById(id); + if (!project) return; const data = rawData.map((item) => { const avatarUrl = item.assignment.map((item) => ({ username: item.profiles.username || "U", @@ -61,9 +64,9 @@ const ProjectTask = async ({ params, searchParams }: IProps) => {
- U + {project.name.slice(0, 1).toUpperCase()} -

My bim bam boom project

+

{project.name}

diff --git a/src/app/globals.css b/src/app/globals.css index e5e038a..72434fa 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -126,5 +126,5 @@ } @utility button { - @apply flex justify-center items-center px-4 py-2 border border-transparent text-sm font-medium rounded shadow-sm text-white bg-blue-600 hover:bg-button-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors active:scale-95 cursor-pointer; + @apply flex justify-center items-center px-4 py-2 border border-transparent text-sm font-medium rounded shadow-sm text-white bg-blue-600 hover:bg-button-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors active:scale-95 cursor-pointer whitespace-nowrap; } \ No newline at end of file diff --git a/src/lib/actions/task.action.ts b/src/lib/actions/task.action.ts index f5021f1..ad88463 100644 --- a/src/lib/actions/task.action.ts +++ b/src/lib/actions/task.action.ts @@ -75,10 +75,27 @@ export async function updateTask( dueDate: Date; } ) { - await prisma.task.update({ - where: { id }, - data, - }); + try { + return prisma.task.update({ + where: { id }, + data, + }); + } catch (error) { + throw error; + } finally { + revalidatePath(`/projects/${id}`); + } +} - revalidatePath(`/projects/${id}`); -} \ No newline at end of file +export async function deleteTask(id: string) { + try { + await prisma.task.delete({ + where: { id }, + }); + return { success: true, message: "Task deleted successfully!" }; + } catch (error) { + return { success: false, message: "Failed to delete task." }; + } finally { + revalidatePath(`/projects/${id}`); + } +}