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 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({
|
||||
data: {
|
||||
name: sent.data.name,
|
||||
idVillage: String(user.idVillage),
|
||||
idGroup: sent.data.idGroup,
|
||||
idGroup: fixGroup,
|
||||
desc: sent.data.desc,
|
||||
createdBy: String(user.id)
|
||||
},
|
||||
@@ -214,7 +223,7 @@ export async function POST(request: Request) {
|
||||
// create log user
|
||||
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) {
|
||||
console.error(error);
|
||||
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'
|
||||
}
|
||||
})
|
||||
@@ -247,7 +247,7 @@ export async function POST(request: Request) {
|
||||
]
|
||||
}
|
||||
},
|
||||
select:{
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
@@ -273,7 +273,7 @@ export async function POST(request: Request) {
|
||||
|
||||
// create log user
|
||||
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) {
|
||||
console.error(error);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
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 _, { ceil } from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// GET ALL DATA TUGAS DIVISI
|
||||
@@ -113,6 +111,8 @@ export async function POST(request: Request) {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const userId = user.id
|
||||
const userRoleLogin = user.idUserRole
|
||||
|
||||
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.'
|
||||
}))
|
||||
|
||||
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({
|
||||
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 })
|
||||
|
||||
|
||||
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) {
|
||||
console.error(error);
|
||||
|
||||
@@ -20,7 +20,8 @@ export async function GET(request: Request) {
|
||||
if (user.id == undefined) {
|
||||
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
|
||||
} else {
|
||||
fixGroup = idGroup
|
||||
|
||||
@@ -25,7 +25,6 @@ export default function WrapLayout({ children, role, theme, user }: { children:
|
||||
}, [role, theme])
|
||||
|
||||
useShallowEffect(() => {
|
||||
console.log(data)
|
||||
if (data && data.some((i: any) => i.idUserTo == user)) {
|
||||
setTampilNotif(true)
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { ActionIcon, Avatar, Box, Button, Checkbox, Divider, Flex, Grid, Group, rem, Stack, Text, TextInput } from '@mantine/core';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@@ -9,6 +9,7 @@ import toast from 'react-hot-toast';
|
||||
import { globalMemberDivision } from '../lib/val_division';
|
||||
import { funCreateDivision } from '../lib/api_division';
|
||||
import { IFormMemberDivision } from '../lib/type_division';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
|
||||
export default function NavbarAdminDivision({ data, onSuccess }: { data: any, onSuccess: (val: any) => void }) {
|
||||
const router = useRouter()
|
||||
@@ -16,6 +17,10 @@ export default function NavbarAdminDivision({ data, onSuccess }: { data: any, on
|
||||
const memberValue = member.get() as IFormMemberDivision[]
|
||||
const [value, setValue] = useState<string[]>([]);
|
||||
const tema = useHookstate(TEMA)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
async function onSubmit() {
|
||||
if (value.length === 0) {
|
||||
@@ -24,8 +29,8 @@ export default function NavbarAdminDivision({ data, onSuccess }: { data: any, on
|
||||
|
||||
try {
|
||||
const response = await funCreateDivision({ data: data, member: memberValue, admin: value })
|
||||
|
||||
if (response.success) {
|
||||
setDataRealtime(response.notif)
|
||||
toast.success(response.message);
|
||||
router.push("/division")
|
||||
onSuccess(true)
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
"use client";
|
||||
import { globalRole, 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 { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
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 { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
||||
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 ViewDateEndTask from "./create_date_end_task";
|
||||
import { IFormDateProject, IFormMemberProject, IListFileTaskProject } from "../lib/type_project";
|
||||
import CreateUsersProject from "./create_users_project";
|
||||
import { FaTrash } from "react-icons/fa6";
|
||||
import { Dropzone } from "@mantine/dropzone";
|
||||
import _ from "lodash";
|
||||
import { funCreateProject } from "../lib/api_project";
|
||||
import ResultsDateAndTask from "./results_date-and_task";
|
||||
import ResultsFile from "./results_file";
|
||||
|
||||
export default function CreateProject() {
|
||||
const router = useRouter();
|
||||
@@ -52,6 +53,11 @@ export default function CreateProject() {
|
||||
desc: false
|
||||
});
|
||||
|
||||
const [data, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
function deleteFile(index: number) {
|
||||
setListFile([...listFile.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)
|
||||
|
||||
if (response.success) {
|
||||
setDataRealtime(response.notif)
|
||||
toast.success(response.message)
|
||||
member.set([])
|
||||
setFileForm([])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"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 { useParams, useRouter } from "next/navigation";
|
||||
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 { funCreateTask } from "../lib/api_task";
|
||||
import { useMediaQuery } from "@mantine/hooks";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
|
||||
export default function CreateTask() {
|
||||
const router = useRouter()
|
||||
@@ -46,6 +47,10 @@ export default function CreateTask() {
|
||||
task: false,
|
||||
member: false
|
||||
});
|
||||
const [data, setData] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
function deleteFile(index: number) {
|
||||
setListFile([...listFile.filter((val, i) => i !== index)])
|
||||
@@ -76,6 +81,7 @@ export default function CreateTask() {
|
||||
const response = await funCreateTask(fd)
|
||||
|
||||
if (response.success) {
|
||||
setData(response.notif)
|
||||
toast.success(response.message)
|
||||
setTitle("")
|
||||
member.set([])
|
||||
|
||||
Reference in New Issue
Block a user