diff --git a/src/app/(application)/division/[id]/(fitur-division)/task/[detail]/create-task/page.tsx b/src/app/(application)/division/[id]/(fitur-division)/task/[detail]/create-task/page.tsx
new file mode 100644
index 0000000..64459c4
--- /dev/null
+++ b/src/app/(application)/division/[id]/(fitur-division)/task/[detail]/create-task/page.tsx
@@ -0,0 +1,9 @@
+import { AddDetailTask } from "@/module/task"
+
+function Page() {
+ return (
+
+ )
+}
+
+export default Page
\ No newline at end of file
diff --git a/src/app/api/task/[id]/route.ts b/src/app/api/task/[id]/route.ts
index 0817ebe..bd5695c 100644
--- a/src/app/api/task/[id]/route.ts
+++ b/src/app/api/task/[id]/route.ts
@@ -134,4 +134,55 @@ export async function GET(request: Request, context: { params: { id: string } })
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
+}
+
+
+// CREATE NEW DETAIL TASK DIVISI
+export async function POST(request: Request, context: { params: { id: string } }) {
+ try {
+ const user = await funGetUserByCookies()
+ if (user.id == undefined) {
+ return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
+ }
+
+ const { id } = context.params;
+ const { title, dateStart, dateEnd, idDivision } = (await request.json());
+ const data = await prisma.divisionProject.count({
+ where: {
+ id: id,
+ },
+ });
+
+ if (data == 0) {
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Tambah detail tugas gagal, data tugas tidak ditemukan",
+ },
+ { status: 404 }
+ );
+ }
+
+ const create = await prisma.divisionProjectTask.create({
+ data: {
+ idProject: id,
+ idDivision,
+ title,
+ dateStart: new Date(moment(dateStart).format('YYYY-MM-DD')),
+ dateEnd: new Date(moment(dateEnd).format('YYYY-MM-DD')),
+ },
+ });
+
+ return NextResponse.json(
+ {
+ success: true,
+ message: "Detail tugas berhasil ditambahkan",
+ data,
+ },
+ { status: 200 }
+ );
+ } catch (error) {
+ console.log(error);
+ return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
+ }
}
\ No newline at end of file
diff --git a/src/app/api/task/route.ts b/src/app/api/task/route.ts
index 558cabb..7232356 100644
--- a/src/app/api/task/route.ts
+++ b/src/app/api/task/route.ts
@@ -78,6 +78,7 @@ export async function GET(request: Request) {
}
+// CREATE PROJECT TASK DIVISION
export async function POST(request: Request) {
try {
const user = await funGetUserByCookies()
diff --git a/src/module/task/index.ts b/src/module/task/index.ts
index afbcfd7..4882f48 100644
--- a/src/module/task/index.ts
+++ b/src/module/task/index.ts
@@ -1,3 +1,4 @@
+import AddDetailTask from "./ui/add_detail_task";
import ViewDateEndTask from "./ui/create_date_end_task";
import CreateTask from "./ui/create_task";
import CreateUsersProject from "./ui/create_users_project";
@@ -22,4 +23,5 @@ export { ListTugasDetailTask }
export { ProgressDetailTask }
export { ListFileDetailTask }
export { ListAnggotaDetailTask }
-export { EditDetailTask }
\ No newline at end of file
+export { EditDetailTask }
+export { AddDetailTask }
\ No newline at end of file
diff --git a/src/module/task/lib/api_task.ts b/src/module/task/lib/api_task.ts
index 5aec7e2..5811c06 100644
--- a/src/module/task/lib/api_task.ts
+++ b/src/module/task/lib/api_task.ts
@@ -1,4 +1,4 @@
-import { IFormDateTask, IFormTaskDivision } from "./type_task";
+import { IFormAddDetailTask, IFormDateTask, IFormTaskDivision } from "./type_task";
export const funGetAllTask = async (path?: string) => {
const response = await fetch(`/api/task${(path) ? path : ''}`, { next: { tags: ['task'] } });
@@ -64,4 +64,16 @@ export const funEditDetailTask = async (path: string, data: IFormDateTask) => {
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
+};
+
+
+export const funCreateDetailTask = async (path: string, data: IFormAddDetailTask) => {
+ const response = await fetch(`/api/task/${path}`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ });
+ return await response.json().catch(() => null);
};
\ No newline at end of file
diff --git a/src/module/task/lib/type_task.ts b/src/module/task/lib/type_task.ts
index 1cfa5bd..4ade39a 100644
--- a/src/module/task/lib/type_task.ts
+++ b/src/module/task/lib/type_task.ts
@@ -19,6 +19,13 @@ export interface IFormDateTask {
title: string
}
+export interface IFormAddDetailTask {
+ dateStart: Date,
+ dateEnd: Date,
+ title: string
+ idDivision: string
+}
+
export interface IFormTaskDivision {
idDivision: string
diff --git a/src/module/task/ui/add_detail_task.tsx b/src/module/task/ui/add_detail_task.tsx
new file mode 100644
index 0000000..394ec3b
--- /dev/null
+++ b/src/module/task/ui/add_detail_task.tsx
@@ -0,0 +1,147 @@
+"use client";
+import { LayoutNavbarNew, WARNA } from "@/module/_global";
+import {
+ Avatar,
+ Box,
+ Button,
+ Flex,
+ Group,
+ Input,
+ SimpleGrid,
+ Stack,
+ Text,
+} from "@mantine/core";
+import React, { useState } from "react";
+import { DatePicker } from "@mantine/dates";
+import { useParams, useRouter } from "next/navigation";
+import toast from "react-hot-toast";
+import { IFormDateTask } from "../lib/type_task";
+import moment from "moment";
+import { funCreateDetailTask } from "../lib/api_task";
+import LayoutModal from "@/module/_global/layout/layout_modal";
+
+
+export default function AddDetailTask() {
+ const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
+ const router = useRouter()
+ const [title, setTitle] = useState("")
+ const [openModal, setOpenModal] = useState(false)
+ const param = useParams<{ id: string, detail: string }>()
+
+ function onVerification() {
+ if (value[0] == null || value[1] == null)
+ return toast.error("Error! harus memilih tanggal")
+
+ if (title == "")
+ return toast.error("Error! harus memasukkan judul tugas")
+
+ setOpenModal(true)
+ }
+
+ async function onSubmit() {
+ try {
+ const res = await funCreateDetailTask(param.detail, {
+ title,
+ dateStart: (value[0] != null) ? value[0] : new Date,
+ dateEnd: (value[1] != null) ? value[1] : new Date,
+ idDivision: param.id
+ })
+
+ if (res.success) {
+ toast.success(res.message)
+ setOpenModal(false)
+ router.push(`/division/${param.id}/task/${param.detail}`)
+ } else {
+ toast.error(res.message)
+ }
+ } catch (error) {
+ console.log(error)
+ toast.error("Gagal menambahkan tugas, coba lagi nanti")
+ }
+ }
+
+
+
+ return (
+
+
+
+
+
+
+
+
+ Tanggal Mulai
+
+ {value[0] ? `${moment(value[0]).format('DD-MM-YYYY')}` : ""}
+
+
+
+ Tanggal Berakhir
+
+ {value[1] ? `${moment(value[1]).format('DD-MM-YYYY')}` : ""}
+
+
+
+
+ setTitle(e.target.value)}
+ />
+
+
+
+
+
+
+
+ setOpenModal(false)}
+ description="Apakah Anda yakin ingin menambahkan tugas?"
+ onYes={(val) => {
+ if (val) {
+ onSubmit()
+ }
+ setOpenModal(false)
+ }} />
+
+ );
+}
diff --git a/src/module/task/ui/navbar_detail_division_task.tsx b/src/module/task/ui/navbar_detail_division_task.tsx
index 6e39331..bde2b08 100644
--- a/src/module/task/ui/navbar_detail_division_task.tsx
+++ b/src/module/task/ui/navbar_detail_division_task.tsx
@@ -45,7 +45,7 @@ export default function NavbarDetailDivisionTask() {
size="lg"
radius="lg"
aria-label="Settings"
- onClick={() => { }}
+ onClick={() => { setOpen(true) }}
>
@@ -63,14 +63,14 @@ export default function NavbarDetailDivisionTask() {
cursor: 'pointer'
}}
onClick={() => {
- router.push('/announcement/create')
+ router.push(param.detail + '/create-task')
}}
>
- Tambah Pengumuman
+ Tambah Tugas