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