upd: task divisi
Deskripsi: - cancel task - edit title task No Issues
This commit is contained in:
@@ -257,7 +257,8 @@ model DivisionProject {
|
||||
Division Division @relation(fields: [idDivision], references: [id])
|
||||
idDivision String
|
||||
title String
|
||||
desc String @db.Text
|
||||
desc String? @db.Text
|
||||
reason String? @db.Text
|
||||
status Int @default(0) // 0 = pending, 1 = ongoing, 2 = done, 3 = cancelled
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { CancelTask } from "@/module/task"
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<CancelTask />
|
||||
)
|
||||
}
|
||||
|
||||
export default Page
|
||||
@@ -0,0 +1,9 @@
|
||||
import { EditTask } from "@/module/task"
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<EditTask />
|
||||
)
|
||||
}
|
||||
|
||||
export default Page
|
||||
@@ -188,3 +188,103 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PEMBATALAN TASK DIVISI
|
||||
export async function DELETE(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 { reason } = (await request.json());
|
||||
const data = await prisma.divisionProject.count({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (data == 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Pembatalan tugas gagal, data tugas tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const update = await prisma.divisionProject.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
reason: reason,
|
||||
status: 3
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tugas berhasil dibatalkan",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal membatalkan tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// EDIT TASK DIVISI
|
||||
export async function PUT(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 } = (await request.json());
|
||||
const data = await prisma.divisionProject.count({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (data == 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Tugas gagal diedit, data tugas tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const update = await prisma.divisionProject.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
title
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tugas berhasil diedit",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengedit tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import AddDetailTask from "./ui/add_detail_task";
|
||||
import AddMemberDetailTask from "./ui/add_member_detail_task";
|
||||
import CancelTask from "./ui/cancel_task";
|
||||
import ViewDateEndTask from "./ui/create_date_end_task";
|
||||
import CreateTask from "./ui/create_task";
|
||||
import CreateUsersProject from "./ui/create_users_project";
|
||||
@@ -8,6 +9,7 @@ import ListFileDetailTask from "./ui/detail_list_file_task";
|
||||
import ListTugasDetailTask from "./ui/detail_list_tugas_task";
|
||||
import ProgressDetailTask from "./ui/detail_progress_task";
|
||||
import EditDetailTask from "./ui/edit_detail_task";
|
||||
import EditTask from "./ui/edit_task";
|
||||
import FileSave from "./ui/file_save";
|
||||
import NavbarDetailDivisionTask from "./ui/navbar_detail_division_task";
|
||||
import NavbarDivisionTask from "./ui/navbar_division_task";
|
||||
@@ -26,4 +28,6 @@ export { ListFileDetailTask }
|
||||
export { ListAnggotaDetailTask }
|
||||
export { EditDetailTask }
|
||||
export { AddDetailTask }
|
||||
export { AddMemberDetailTask }
|
||||
export { AddMemberDetailTask }
|
||||
export { CancelTask }
|
||||
export { EditTask }
|
||||
@@ -87,4 +87,29 @@ export const funAddMemberTask = async (path: string, data: IFormAddMemberTask) =
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
export const funCancelTask = async (path: string, data: { reason: string }) => {
|
||||
const response = await fetch(`/api/task/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const funEditTask = async (path: string, data: { title: string }) => {
|
||||
const response = await fetch(`/api/task/${path}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
87
src/module/task/ui/cancel_task.tsx
Normal file
87
src/module/task/ui/cancel_task.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
import { LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Stack,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import React, { useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import toast from "react-hot-toast";
|
||||
import { funCancelTask } from "../lib/api_task";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
|
||||
|
||||
export default function CancelTask() {
|
||||
const router = useRouter()
|
||||
const [alasan, setAlasan] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
|
||||
function onVerification() {
|
||||
if (alasan == "")
|
||||
return toast.error("Error! harus memasukkan alasan pembatalan tugas")
|
||||
|
||||
setOpenModal(true)
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
const res = await funCancelTask(param.detail, { reason: alasan })
|
||||
if (res.success) {
|
||||
toast.success(res.message)
|
||||
router.push("./")
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.error("Gagal membatalkan tugas, coba lagi nanti")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back="" title={"Pembatalan Tugas"} menu />
|
||||
<Box p={20}>
|
||||
<Stack pt={15}>
|
||||
<Textarea styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
value={alasan}
|
||||
size="md" placeholder='Contoh : Tugas tidak sesuai' label="Alasan Pembatalan"
|
||||
onChange={(event) => setAlasan(event.target.value)}
|
||||
/>
|
||||
</Stack>
|
||||
<Box mt={"xl"}>
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => { onVerification() }}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
|
||||
<LayoutModal opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin membatalkan tugas ini? Pembatalan tugas bersifat permanen"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit()
|
||||
}
|
||||
setOpenModal(false)
|
||||
}} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
110
src/module/task/ui/edit_task.tsx
Normal file
110
src/module/task/ui/edit_task.tsx
Normal file
@@ -0,0 +1,110 @@
|
||||
"use client";
|
||||
import { LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Input,
|
||||
Stack,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import React, { useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import toast from "react-hot-toast";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { funEditTask, funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
|
||||
|
||||
export default function EditTask() {
|
||||
const router = useRouter()
|
||||
const [title, setTitle] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
|
||||
function onVerification() {
|
||||
if (title == "")
|
||||
return toast.error("Error! harus memasukkan judul tugas")
|
||||
|
||||
setOpenModal(true)
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
const res = await funEditTask(param.detail, { title })
|
||||
if (res.success) {
|
||||
toast.success(res.message)
|
||||
router.push("./")
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.error("Gagal mengedit tugas, coba lagi nanti")
|
||||
}
|
||||
}
|
||||
|
||||
async function getOneData() {
|
||||
try {
|
||||
const res = await funGetTaskDivisionById(param.detail, 'data');
|
||||
if (res.success) {
|
||||
setTitle(res.data.title);
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan data tugas divisi, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneData();
|
||||
}, [param.detail])
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back="" title={"Edit Judul Tugas"} menu />
|
||||
<Box p={20}>
|
||||
<Stack pt={15}>
|
||||
<Input
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
placeholder="Tugas"
|
||||
size="md"
|
||||
value={title}
|
||||
onChange={(e) => { setTitle(e.target.value) }}
|
||||
/>
|
||||
</Stack>
|
||||
<Box mt={"xl"}>
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => { onVerification() }}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
|
||||
<LayoutModal opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin mengedit tugas ini?"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit()
|
||||
}
|
||||
setOpenModal(false)
|
||||
}} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import { funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { HiMenu } from "react-icons/hi";
|
||||
import { IoAddCircle } from "react-icons/io5";
|
||||
import { RiFilter2Line } from "react-icons/ri";
|
||||
import { FaUsers } from "react-icons/fa6";
|
||||
import { FaPencil, FaUsers } from "react-icons/fa6";
|
||||
import { MdCancel } from "react-icons/md";
|
||||
|
||||
export default function NavbarDetailDivisionTask() {
|
||||
const router = useRouter()
|
||||
@@ -90,10 +90,39 @@ export default function NavbarDetailDivisionTask() {
|
||||
<Text c={WARNA.biruTua} ta='center'>Tambah anggota</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => { router.push(param.detail + '/cancel') }}
|
||||
>
|
||||
<Box>
|
||||
<MdCancel size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => { router.push(param.detail + '/edit') }}
|
||||
>
|
||||
<Box>
|
||||
<FaPencil size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua} ta='center'>Edit</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user