rev: hapus kegiatan
Deskripsi: - hapus data pada saat status batal pada fitur kegiatan dan tugas divisi No Issues
This commit is contained in:
46
src/app/api/project/[id]/lainnya/route.ts
Normal file
46
src/app/api/project/[id]/lainnya/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
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 data = await prisma.project.count({
|
||||
where: {
|
||||
id: id,
|
||||
}
|
||||
})
|
||||
|
||||
if (data == 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const dataDelete = await prisma.project.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
isActive: false
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus data kegiatan', table: 'project', data: String(id) })
|
||||
return NextResponse.json({ success: true, message: "Kegiatan berhasil dihapus" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menghapus kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
48
src/app/api/task/[id]/lainnya/route.ts
Normal file
48
src/app/api/task/[id]/lainnya/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// 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 data = await prisma.divisionProject.count({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (data == 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Penghapusan tugas gagal, data tugas tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const update = await prisma.divisionProject.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
}
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus tugas divisi', table: 'divisionProject', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Tugas berhasil dihapuskan", }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menghapus tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ export default function DetailEventDivision() {
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'calendar-detail-delete' && i.id == isDataCalender?.idCalendar && i.idUserFrom != isUserLogin)) {
|
||||
toast.error("Data telah di hapus, anda akan beralih ke halaman list acara")
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list acara")
|
||||
setTimeout(() => {
|
||||
router.push(`/division/${param.id}/calender`)
|
||||
}, 1000)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
"use client"
|
||||
import { keyWibu, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { MdDelete, MdEdit } from 'react-icons/md';
|
||||
import { funDeleteCalenderById } from '../lib/api_calender';
|
||||
import { FaUsers } from 'react-icons/fa6';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { FaTrash, FaUsers } from 'react-icons/fa6';
|
||||
import { MdEdit } from 'react-icons/md';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funDeleteCalenderById } from '../lib/api_calender';
|
||||
|
||||
export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: string, close: (val: boolean) => void }) {
|
||||
const router = useRouter()
|
||||
@@ -82,7 +82,7 @@ export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: s
|
||||
</Flex>
|
||||
<Flex onClick={() => setModal(true)} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<MdDelete size={30} color={tema.get().utama} />
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text ta={"center"} c={tema.get().utama}>Hapus Acara</Text>
|
||||
|
||||
@@ -19,7 +19,7 @@ export const funGetOneProjectById = async (path: string, kategori: string) => {
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funGetAllMemberById = async (path?: string, id?:string) => {
|
||||
export const funGetAllMemberById = async (path?: string, id?: string) => {
|
||||
const response = await fetch(`/api/project/${id}/member/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -148,3 +148,14 @@ export const funAddFileProject = async (path: string, data: FormData) => {
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funDeleteProject = async (path: string) => {
|
||||
const response = await fetch(`/api/project/${path}/lainnya`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
'use client'
|
||||
import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { ActionIcon, Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { FaFileCirclePlus, FaPencil, FaUsers } from 'react-icons/fa6';
|
||||
import { FaFileCirclePlus, FaPencil, FaTrash, FaUsers } from 'react-icons/fa6';
|
||||
import { HiMenu } from 'react-icons/hi';
|
||||
import { IoAddCircle } from 'react-icons/io5';
|
||||
import { MdCancel } from 'react-icons/md';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funGetOneProjectById } from '../lib/api_project';
|
||||
import { funDeleteProject, funGetOneProjectById } from '../lib/api_project';
|
||||
import { globalIsMemberProject } from '../lib/val_project';
|
||||
|
||||
export default function NavbarDetailProject() {
|
||||
@@ -24,6 +25,8 @@ export default function NavbarDetailProject() {
|
||||
const memberProject = useHookstate(globalIsMemberProject)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -39,10 +42,32 @@ export default function NavbarDetailProject() {
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan data Kegiatan, coba lagi nanti");
|
||||
toast.error("Gagal mendapatkan data kegiatan, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDataProject() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const res = await funDeleteProject(param.id);
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "project-delete",
|
||||
id: param.id,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
router.push("/project")
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus data kegiatan, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
setOpenModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +79,13 @@ export default function NavbarDetailProject() {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'project-detail' || i.category == 'project-detail-status') && i.id == param.id)) {
|
||||
getOneData()
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'project-delete') && i.id == param.id)) {
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list kegiatan")
|
||||
setTimeout(() => {
|
||||
router.push("/project")
|
||||
}, 1000)
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
return (
|
||||
@@ -158,24 +190,34 @@ export default function NavbarDetailProject() {
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Edit</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.id + '/cancel')
|
||||
: null
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
{
|
||||
reason == null ?
|
||||
<Flex justify={'center'} align={'center'} direction={'column'} style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.id + '/cancel')
|
||||
: null
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
:
|
||||
<Flex justify={'center'} align={'center'} direction={'column'} style={{ cursor: 'pointer' }}
|
||||
onClick={() => { setOpenModal(true) }}
|
||||
>
|
||||
<Box>
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama} ta='center'>Hapus</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -183,6 +225,10 @@ export default function NavbarDetailProject() {
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus kegiatan ini?"
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -144,4 +144,14 @@ export const funAddFileTask = async (path: string, data: FormData) => {
|
||||
body: data,
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funDeleteTask = async (path: string) => {
|
||||
const response = await fetch(`/api/task/${path}/lainnya`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -7,12 +7,13 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaFileCirclePlus, FaPencil, FaUsers } from "react-icons/fa6";
|
||||
import { FaFileCirclePlus, FaPencil, FaTrash, FaUsers } from "react-icons/fa6";
|
||||
import { HiMenu } from "react-icons/hi";
|
||||
import { IoAddCircle } from "react-icons/io5";
|
||||
import { MdCancel } from "react-icons/md";
|
||||
import { funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { funDeleteTask, funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
|
||||
export default function NavbarDetailDivisionTask() {
|
||||
const router = useRouter()
|
||||
@@ -24,6 +25,8 @@ export default function NavbarDetailDivisionTask() {
|
||||
const memberDivision = useHookstate(globalIsMemberDivision)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -45,6 +48,29 @@ export default function NavbarDetailDivisionTask() {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDataProject() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const res = await funDeleteTask(param.detail);
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "tugas-delete",
|
||||
id: param.detail,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
router.push("/division/" + param.id + "/task")
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus data tugas divisi, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
setOpenModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneData();
|
||||
}, [param.detail])
|
||||
@@ -54,6 +80,13 @@ export default function NavbarDetailDivisionTask() {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'tugas-detail' || i.category == 'tugas-detail-status') && i.id == param.detail)) {
|
||||
getOneData()
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-delete' && i.id == param.detail)) {
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list tugas divisi")
|
||||
setTimeout(() => {
|
||||
router.push("/division/" + param.id + "/task")
|
||||
}, 1000)
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
return (
|
||||
@@ -156,23 +189,39 @@ export default function NavbarDetailDivisionTask() {
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Edit</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
{
|
||||
reason == null ?
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.detail + '/cancel')
|
||||
: null
|
||||
}} >
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
:
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => { setOpenModal(true) }} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama} ta='center'>Hapus</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.detail + '/cancel')
|
||||
: null
|
||||
}} >
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
</> : <></>
|
||||
|
||||
}
|
||||
@@ -182,6 +231,10 @@ export default function NavbarDetailDivisionTask() {
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus tugas divisi ini?"
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user