Merge pull request #281 from bipproduction/amalia/02-okt-24
Amalia/02 okt 24
This commit is contained in:
@@ -122,11 +122,20 @@ export async function POST(request: Request) {
|
|||||||
const userRoleLogin = user.idUserRole
|
const userRoleLogin = user.idUserRole
|
||||||
const sent = (await request.json())
|
const sent = (await request.json())
|
||||||
|
|
||||||
|
let fixGroup
|
||||||
|
if (sent.data.idGroup == "null" || sent.data.idGroup == undefined || sent.data.idGroup == "") {
|
||||||
|
fixGroup = user.idGroup
|
||||||
|
} else {
|
||||||
|
fixGroup = sent.data.idGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const data = await prisma.division.create({
|
const data = await prisma.division.create({
|
||||||
data: {
|
data: {
|
||||||
name: sent.data.name,
|
name: sent.data.name,
|
||||||
idVillage: String(user.idVillage),
|
idVillage: String(user.idVillage),
|
||||||
idGroup: sent.data.idGroup,
|
idGroup: fixGroup,
|
||||||
desc: sent.data.desc,
|
desc: sent.data.desc,
|
||||||
createdBy: String(user.id)
|
createdBy: String(user.id)
|
||||||
},
|
},
|
||||||
@@ -214,7 +223,7 @@ export async function POST(request: Request) {
|
|||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data divisi', table: 'division', data: data.id })
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data divisi', table: 'division', data: data.id })
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil menambahkan divisi", data, }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil menambahkan divisi", notif: dataNotif, }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy:{
|
orderBy: {
|
||||||
createdAt: 'desc'
|
createdAt: 'desc'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -247,7 +247,7 @@ export async function POST(request: Request) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
select:{
|
select: {
|
||||||
id: true
|
id: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -273,7 +273,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id })
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id })
|
||||||
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan", notif: dataNotif }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import _, { ceil } from "lodash";
|
|
||||||
import { NextResponse } from "next/server";
|
|
||||||
import path from "path";
|
|
||||||
import fs from "fs";
|
|
||||||
import moment from "moment";
|
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
|
import _, { ceil } from "lodash";
|
||||||
|
import moment from "moment";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA TUGAS DIVISI
|
// GET ALL DATA TUGAS DIVISI
|
||||||
@@ -113,6 +111,8 @@ export async function POST(request: Request) {
|
|||||||
const body = await request.formData()
|
const body = await request.formData()
|
||||||
const dataBody = body.get("data")
|
const dataBody = body.get("data")
|
||||||
const cekFile = body.has("file0")
|
const cekFile = body.has("file0")
|
||||||
|
const userId = user.id
|
||||||
|
const userRoleLogin = user.idUserRole
|
||||||
|
|
||||||
const { title, task, member, idDivision } = JSON.parse(dataBody as string)
|
const { title, task, member, idDivision } = JSON.parse(dataBody as string)
|
||||||
|
|
||||||
@@ -233,6 +233,25 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
if (userRoleLogin != "supadmin") {
|
||||||
|
const perbekel = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idUserRole: "supadmin",
|
||||||
|
idVillage: user.idVillage
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dataNotif.push({
|
||||||
|
idUserTo: perbekel?.id,
|
||||||
|
idUserFrom: userId,
|
||||||
|
category: 'division/' + idDivision + '/task',
|
||||||
|
idContent: data.id,
|
||||||
|
title: 'Tugas Baru',
|
||||||
|
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
@@ -242,7 +261,7 @@ export async function POST(request: Request) {
|
|||||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id })
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id })
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi", notif:dataNotif }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export async function GET(request: Request) {
|
|||||||
if (user.id == undefined) {
|
if (user.id == undefined) {
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
}
|
}
|
||||||
if (idGroup == "null" || idGroup == undefined) {
|
|
||||||
|
if (idGroup == "null" || idGroup == undefined || idGroup == "") {
|
||||||
fixGroup = user.idGroup
|
fixGroup = user.idGroup
|
||||||
} else {
|
} else {
|
||||||
fixGroup = idGroup
|
fixGroup = idGroup
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ export default function WrapLayout({ children, role, theme, user }: { children:
|
|||||||
}, [role, theme])
|
}, [role, theme])
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
console.log(data)
|
|
||||||
if (data && data.some((i: any) => i.idUserTo == user)) {
|
if (data && data.some((i: any) => i.idUserTo == user)) {
|
||||||
setTampilNotif(true)
|
setTampilNotif(true)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { ActionIcon, Avatar, Box, Button, Checkbox, Divider, Flex, Grid, Group, rem, Stack, Text, TextInput } from '@mantine/core';
|
import { ActionIcon, Avatar, Box, Button, Checkbox, Divider, Flex, Grid, Group, rem, Stack, Text, TextInput } from '@mantine/core';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
@@ -9,6 +9,7 @@ import toast from 'react-hot-toast';
|
|||||||
import { globalMemberDivision } from '../lib/val_division';
|
import { globalMemberDivision } from '../lib/val_division';
|
||||||
import { funCreateDivision } from '../lib/api_division';
|
import { funCreateDivision } from '../lib/api_division';
|
||||||
import { IFormMemberDivision } from '../lib/type_division';
|
import { IFormMemberDivision } from '../lib/type_division';
|
||||||
|
import { useWibuRealtime } from 'wibu-realtime';
|
||||||
|
|
||||||
export default function NavbarAdminDivision({ data, onSuccess }: { data: any, onSuccess: (val: any) => void }) {
|
export default function NavbarAdminDivision({ data, onSuccess }: { data: any, onSuccess: (val: any) => void }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -16,6 +17,10 @@ export default function NavbarAdminDivision({ data, onSuccess }: { data: any, on
|
|||||||
const memberValue = member.get() as IFormMemberDivision[]
|
const memberValue = member.get() as IFormMemberDivision[]
|
||||||
const [value, setValue] = useState<string[]>([]);
|
const [value, setValue] = useState<string[]>([]);
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
|
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
@@ -24,8 +29,8 @@ export default function NavbarAdminDivision({ data, onSuccess }: { data: any, on
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await funCreateDivision({ data: data, member: memberValue, admin: value })
|
const response = await funCreateDivision({ data: data, member: memberValue, admin: value })
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
setDataRealtime(response.notif)
|
||||||
toast.success(response.message);
|
toast.success(response.message);
|
||||||
router.push("/division")
|
router.push("/division")
|
||||||
onSuccess(true)
|
onSuccess(true)
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { globalRole, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||||
import { Avatar, Box, Button, Divider, Flex, Grid, Group, rem, Select, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import React, { useRef, useState } from "react";
|
|
||||||
import { IoIosArrowDropright } from "react-icons/io";
|
|
||||||
import ResultsDateAndTask from "./results_date-and_task";
|
|
||||||
import ResultsFile from "./results_file";
|
|
||||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
import toast from "react-hot-toast";
|
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
||||||
import { useHookstate } from "@hookstate/core";
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { Avatar, Box, Button, Divider, Flex, Grid, Group, rem, Select, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||||
|
import { Dropzone } from "@mantine/dropzone";
|
||||||
|
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useRef, useState } from "react";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { FaTrash } from "react-icons/fa6";
|
||||||
|
import { IoIosArrowDropright } from "react-icons/io";
|
||||||
|
import { useWibuRealtime } from "wibu-realtime";
|
||||||
|
import { funCreateProject } from "../lib/api_project";
|
||||||
|
import { IFormDateProject, IFormMemberProject, IListFileTaskProject } from "../lib/type_project";
|
||||||
import { globalMemberProject } from "../lib/val_project";
|
import { globalMemberProject } from "../lib/val_project";
|
||||||
import ViewDateEndTask from "./create_date_end_task";
|
import ViewDateEndTask from "./create_date_end_task";
|
||||||
import { IFormDateProject, IFormMemberProject, IListFileTaskProject } from "../lib/type_project";
|
|
||||||
import CreateUsersProject from "./create_users_project";
|
import CreateUsersProject from "./create_users_project";
|
||||||
import { FaTrash } from "react-icons/fa6";
|
import ResultsDateAndTask from "./results_date-and_task";
|
||||||
import { Dropzone } from "@mantine/dropzone";
|
import ResultsFile from "./results_file";
|
||||||
import _ from "lodash";
|
|
||||||
import { funCreateProject } from "../lib/api_project";
|
|
||||||
|
|
||||||
export default function CreateProject() {
|
export default function CreateProject() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -52,6 +53,11 @@ export default function CreateProject() {
|
|||||||
desc: false
|
desc: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [data, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number) {
|
||||||
setListFile([...listFile.filter((val, i) => i !== index)])
|
setListFile([...listFile.filter((val, i) => i !== index)])
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
||||||
@@ -111,6 +117,7 @@ export default function CreateProject() {
|
|||||||
const response = await funCreateProject(fd)
|
const response = await funCreateProject(fd)
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
setDataRealtime(response.notif)
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
member.set([])
|
member.set([])
|
||||||
setFileForm([])
|
setFileForm([])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
import { keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||||
import { Avatar, Box, Button, Center, Divider, Flex, Grid, Group, Input, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
import { Avatar, Box, Button, Center, Divider, Flex, Grid, Group, Input, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
@@ -19,6 +19,7 @@ import { FaTrash } from "react-icons/fa6";
|
|||||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
import { funCreateTask } from "../lib/api_task";
|
import { funCreateTask } from "../lib/api_task";
|
||||||
import { useMediaQuery } from "@mantine/hooks";
|
import { useMediaQuery } from "@mantine/hooks";
|
||||||
|
import { useWibuRealtime } from "wibu-realtime";
|
||||||
|
|
||||||
export default function CreateTask() {
|
export default function CreateTask() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -46,6 +47,10 @@ export default function CreateTask() {
|
|||||||
task: false,
|
task: false,
|
||||||
member: false
|
member: false
|
||||||
});
|
});
|
||||||
|
const [data, setData] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number) {
|
||||||
setListFile([...listFile.filter((val, i) => i !== index)])
|
setListFile([...listFile.filter((val, i) => i !== index)])
|
||||||
@@ -76,6 +81,7 @@ export default function CreateTask() {
|
|||||||
const response = await funCreateTask(fd)
|
const response = await funCreateTask(fd)
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
setData(response.notif)
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
setTitle("")
|
setTitle("")
|
||||||
member.set([])
|
member.set([])
|
||||||
|
|||||||
Reference in New Issue
Block a user