rev: hapus data yang telah dibatalkan
Deskripsi; - update realtime data yg telah dihapuskan No Issues
This commit is contained in:
@@ -3,6 +3,8 @@ import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// HAPUS PROJECT YG TELAH DIBATALKAN
|
||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
@@ -37,7 +39,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
|
||||
// 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 });
|
||||
return NextResponse.json({ success: true, message: "Kegiatan berhasil dihapus", user: user.id }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// PEMBATALAN TASK DIVISI
|
||||
// PENGHAPUSAN TUGAS DIVISI
|
||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
@@ -40,7 +40,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// 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 });
|
||||
return NextResponse.json({ success: true, message: "Tugas berhasil dihapuskan", user: user.id }, { 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 });
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { funGetUserByCookies } from '@/module/auth';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { ActionIcon, Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
@@ -23,6 +24,7 @@ export default function NavbarDetailProject() {
|
||||
const [isOpen, setOpen] = useState(false)
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const memberProject = useHookstate(globalIsMemberProject)
|
||||
const [isUser, setUser] = useState('')
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
@@ -35,10 +37,12 @@ export default function NavbarDetailProject() {
|
||||
async function getOneData() {
|
||||
try {
|
||||
const res = await funGetOneProjectById(param.id, 'data');
|
||||
const userLogin = await funGetUserByCookies()
|
||||
if (res.success) {
|
||||
setName(res.data.title);
|
||||
setReason(res.data.reason);
|
||||
setGrup(res.data.idGroup);
|
||||
setUser(String(userLogin?.id))
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
@@ -56,6 +60,7 @@ export default function NavbarDetailProject() {
|
||||
setDataRealtime([{
|
||||
category: "project-delete",
|
||||
id: param.id,
|
||||
user: res.user
|
||||
}])
|
||||
toast.success(res.message)
|
||||
router.push("/project")
|
||||
@@ -80,7 +85,7 @@ export default function NavbarDetailProject() {
|
||||
getOneData()
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'project-delete') && i.id == param.id)) {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'project-delete' && i.id == param.id && i.user != isUser)) {
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list kegiatan")
|
||||
setTimeout(() => {
|
||||
router.push("/project")
|
||||
|
||||
@@ -14,6 +14,7 @@ import { MdCancel } from "react-icons/md";
|
||||
import { funDeleteTask, funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
|
||||
export default function NavbarDetailDivisionTask() {
|
||||
const router = useRouter()
|
||||
@@ -25,6 +26,7 @@ export default function NavbarDetailDivisionTask() {
|
||||
const memberDivision = useHookstate(globalIsMemberDivision)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [isUser, setUser] = useState('')
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
@@ -35,9 +37,11 @@ export default function NavbarDetailDivisionTask() {
|
||||
async function getOneData() {
|
||||
try {
|
||||
const res = await funGetTaskDivisionById(param.detail, 'data');
|
||||
const userLogin = await funGetUserByCookies()
|
||||
if (res.success) {
|
||||
setName(res.data.title);
|
||||
setReason(res.data.reason);
|
||||
setUser(String(userLogin?.id))
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
@@ -56,6 +60,7 @@ export default function NavbarDetailDivisionTask() {
|
||||
setDataRealtime([{
|
||||
category: "tugas-delete",
|
||||
id: param.detail,
|
||||
user: res.user
|
||||
}])
|
||||
toast.success(res.message)
|
||||
router.push("/division/" + param.id + "/task")
|
||||
@@ -81,7 +86,7 @@ export default function NavbarDetailDivisionTask() {
|
||||
getOneData()
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-delete' && i.id == param.detail)) {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-delete' && i.id == param.detail && i.user != isUser)) {
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list tugas divisi")
|
||||
setTimeout(() => {
|
||||
router.push("/division/" + param.id + "/task")
|
||||
|
||||
Reference in New Issue
Block a user