Merge pull request 'amalia/14-agustus-25' (#11) from amalia/14-agustus-25 into join

Reviewed-on: bip/sistem-desa-mandiri#11
This commit is contained in:
2025-08-14 17:14:23 +08:00
23 changed files with 914 additions and 41 deletions

View File

@@ -113,7 +113,6 @@ model User {
Announcement Announcement[]
Project Project[]
ProjectMember ProjectMember[]
ProjectComment ProjectComment[]
UserLog UserLog[]
Division Division[]
DivisionMember DivisionMember[]
@@ -184,25 +183,25 @@ model AnnouncementMember {
}
model Project {
id String @id @default(cuid())
Village Village @relation(fields: [idVillage], references: [id])
idVillage String
Group Group @relation(fields: [idGroup], references: [id])
idGroup String
title String
status Int @default(0) // 0 = pending, 1 = ongoing, 2 = done, 3 = cancelled
desc String? @db.Text
reason String? @db.Text
isActive Boolean @default(true)
User User @relation(fields: [createdBy], references: [id])
createdBy String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ProjectMember ProjectMember[]
ProjectFile ProjectFile[]
ProjectComment ProjectComment[]
ProjectTask ProjectTask[]
ProjectLink ProjectLink[]
id String @id @default(cuid())
Village Village @relation(fields: [idVillage], references: [id])
idVillage String
Group Group @relation(fields: [idGroup], references: [id])
idGroup String
title String
status Int @default(0) // 0 = pending, 1 = ongoing, 2 = done, 3 = cancelled
desc String? @db.Text
reason String? @db.Text
report String? @db.Text
isActive Boolean @default(true)
User User @relation(fields: [createdBy], references: [id])
createdBy String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ProjectMember ProjectMember[]
ProjectFile ProjectFile[]
ProjectTask ProjectTask[]
ProjectLink ProjectLink[]
}
model ProjectMember {
@@ -254,18 +253,6 @@ model ProjectTask {
updatedAt DateTime @updatedAt
}
model ProjectComment {
id String @id @default(cuid())
Project Project @relation(fields: [idProject], references: [id])
idProject String
User User @relation(fields: [createdBy], references: [id])
createdBy String
comment String @db.Text
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Division {
id String @id @default(cuid())
Village Village @relation(fields: [idVillage], references: [id])
@@ -314,6 +301,7 @@ model DivisionProject {
title String
desc String? @db.Text
reason String? @db.Text
report String? @db.Text
status Int @default(0) // 0 = pending, 1 = ongoing, 2 = done, 3 = cancelled
isActive Boolean @default(true)
createdAt DateTime @default(now())

View File

@@ -1,4 +1,4 @@
import { ListAnggotaDetailTask, ListFileDetailTask, ListLinkDetailTask, ListTugasDetailTask, NavbarDetailDivisionTask, ProgressDetailTask } from "@/module/task"
import { ListAnggotaDetailTask, ListFileDetailTask, ListLinkDetailTask, ListReportDetailTask, ListTugasDetailTask, NavbarDetailDivisionTask, ProgressDetailTask } from "@/module/task"
import { Box } from "@mantine/core"
function Page() {
@@ -7,6 +7,7 @@ function Page() {
<NavbarDetailDivisionTask />
<Box p={20}>
<ProgressDetailTask />
<ListReportDetailTask />
<ListTugasDetailTask />
<ListFileDetailTask />
<ListLinkDetailTask />

View File

@@ -0,0 +1,8 @@
import { AddReportTask } from "@/module/task"
function Page() {
return (
<AddReportTask />
)
}
export default Page

View File

@@ -1,4 +1,4 @@
import { ListAnggotaDetailProject, ListFileDetailProject, ListLinkDetailProject, ListTugasDetailProject, NavbarDetailProject, ProgressDetailProject } from '@/module/project';
import { ListAnggotaDetailProject, ListFileDetailProject, ListLinkDetailProject, ListReportDetailProject, ListTugasDetailProject, NavbarDetailProject, ProgressDetailProject } from '@/module/project';
import { Box } from '@mantine/core';
function Page() {
@@ -7,6 +7,7 @@ function Page() {
<NavbarDetailProject />
<Box p={20}>
<ProgressDetailProject />
<ListReportDetailProject />
<ListTugasDetailProject />
<ListFileDetailProject />
<ListLinkDetailProject />

View File

@@ -0,0 +1,9 @@
import { AddReportProject } from "@/module/project";
function Page() {
return (
<AddReportProject />
);
}
export default Page;

View File

@@ -0,0 +1,95 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import { NextResponse } from "next/server";
// ADD LINK PROJECT
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params
const { link, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
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: 200 }
);
}
const insertLink = await prisma.projectLink.create({
data: {
idProject: id,
link: link
}
})
// create log user
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah link kegiatan', table: 'projectLink', data: insertLink.id, user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan link kegiatan" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambah link kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// DELETE LINK PROJECT
export async function DELETE(request: Request, context: { params: { id: string } }) {
try {
const { idLink, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.projectLink.count({
where: {
id: idLink
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan link, data tidak ditemukan",
},
{ status: 200 }
);
}
const deleteLink = await prisma.projectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})
// create log user
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus link kegiatan', table: 'projectLink', data: String(idLink), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menghapus link kegiatan" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus link kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -136,6 +136,18 @@ export async function GET(request: Request, context: { params: { id: string } })
}))
allData = fix
} else if (kategori == "link") {
const dataLink = await prisma.projectLink.findMany({
where: {
isActive: true,
idProject: String(id)
},
orderBy: {
createdAt: 'asc'
}
})
allData = dataLink
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: allData, }, { status: 200 });

View File

@@ -0,0 +1,98 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import { NextResponse } from "next/server";
// ADD LINK TASK DIVISI
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params;
const { link, idDivision, user } = (await request.json());
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.divisionProject.count({
where: {
id: id,
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah link tugas gagal, data tugas tidak ditemukan",
},
{ status: 200 }
);
}
const insertlink = await prisma.divisionProjectLink.create({
data: {
idProject: id,
link,
idDivision,
}
})
// create log user
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambahkan link tugas divisi', table: 'divisionProjectLink', data: insertlink.id, user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan link tugas", }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambah link tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// DELETE LINK TASK DIVISI
export async function DELETE(request: Request, context: { params: { id: string } }) {
try {
const { idLink, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.divisionProjectLink.count({
where: {
id: idLink
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan link, data tidak ditemukan",
},
{ status: 200 }
);
}
const deleteLink = await prisma.divisionProjectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})
// create log user
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus link tugas divisi', table: 'divisionProjectLink', data: String(idLink), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menghapus link tugas divisi" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus link tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -151,6 +151,18 @@ export async function GET(request: Request, context: { params: { id: string } })
}))
allData = fix
} else if (kategori == "link") {
const dataLink = await prisma.divisionProjectLink.findMany({
where: {
isActive: true,
idProject: String(id)
},
orderBy: {
createdAt: 'asc'
}
})
allData = dataLink
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan tugas divisi", data: allData }, { status: 200 });

View File

@@ -45,4 +45,50 @@ export async function DELETE(request: Request, context: { params: { id: string }
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// EDIT PROJECT REPORT
export async function PUT(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 { report } = await request.json()
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 dataCreate = await prisma.project.update({
where: {
id
},
data: {
report: report
}
})
// create log user
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate laporan kegiatan', table: 'project', data: String(id) })
return NextResponse.json({ success: true, message: "Laporan kegiatan berhasil diupdate" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mengupdate kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -73,9 +73,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
}
const deleteLink = await prisma.projectLink.delete({
const deleteLink = await prisma.projectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})

View File

@@ -45,4 +45,52 @@ export async function DELETE(request: Request, context: { params: { id: string }
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// EDIT TASK REPORT
export async function PUT(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 { report } = await request.json()
const data = await prisma.divisionProject.count({
where: {
id: id
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
},
{ status: 404 }
);
}
const dataCreate = await prisma.divisionProject.update({
where: {
id
},
data: {
report: report
}
})
// create log user
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate laporan tugas divisi', table: 'divisionProject', data: String(id) })
return NextResponse.json({ success: true, message: "Laporan tugas divisi berhasil diupdate" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mengupdate laporan tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -78,9 +78,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
}
const deleteLink = await prisma.divisionProjectLink.delete({
const deleteLink = await prisma.divisionProjectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})

View File

@@ -5,7 +5,6 @@ import NavbarDetailProject from "./ui/navbar_detail_project";
import ProgressDetailProject from "./ui/progress_detail_project";
import ListTugasDetailProject from "./ui/list_tugas_detail_project";
import ListFileDetailProject from "./ui/list_file_detail_project";
import LiatAnggotaDetailProject from "./ui/list_anggota_detail_project";
import EditTaskProject from "./ui/edit_task_project";
import EditDetailTaskProject from "./ui/edit_detail_task_project";
import ListAnggotaDetailProject from "./ui/list_anggota_detail_project";
@@ -16,6 +15,8 @@ import CreateProject from "./ui/create_project";
import AddFileDetailProject from "./ui/add_file_detail_project";
import WrapLayoutProject from "./ui/wrap_project";
import ListLinkDetailProject from "./ui/list_link_detail_project";
import AddReportProject from "./ui/add_report_project";
import ListReportDetailProject from "./ui/list_report_project";
export { ViewDateEndTask }
export { CreateUsersProject }
@@ -33,4 +34,6 @@ export { AddMemberDetailProject }
export { CreateProject }
export { AddFileDetailProject }
export { WrapLayoutProject }
export { ListLinkDetailProject }
export { ListLinkDetailProject }
export { AddReportProject }
export { ListReportDetailProject }

View File

@@ -122,6 +122,17 @@ export const funEditProject = async (path: string, data: { name: string }) => {
return await response.json().catch(() => null);
}
export const funEditReportProject = async (path: string, data: { report: string }) => {
const response = await fetch(`/api/project/${path}/lainnya`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funDeleteFileProject = async (path: string) => {
const response = await fetch(`/api/project/file/${path}`, {

View File

@@ -0,0 +1,157 @@
"use client"
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
import LayoutModal from '@/module/_global/layout/layout_modal';
import { useHookstate } from '@hookstate/core';
import { Box, Button, rem, Skeleton, Stack, Textarea } 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 { useWibuRealtime } from 'wibu-realtime';
import { funEditReportProject, funGetOneProjectById } from '../lib/api_project';
export default function AddReportProject() {
const router = useRouter()
const [report, setReport] = useState("")
const [openModal, setOpenModal] = useState(false)
const param = useParams<{ id: string }>()
const [loading, setLoading] = useState(true)
const [loadingSubmit, setLoadingSubmit] = useState(false)
const tema = useHookstate(TEMA)
const [touched, setTouched] = useState({
report: false,
});
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
})
async function onSubmit() {
try {
setLoadingSubmit(true)
const res = await funEditReportProject(param.id, { report })
if (res.success) {
setDataRealtime([{
category: "project-report",
id: param.id,
}])
toast.success(res.message)
router.push("./")
} else {
toast.error(res.message)
}
} catch (error) {
console.error(error)
toast.error("Gagal mengedit Laporan Kegiatan, coba lagi nanti")
} finally {
setLoadingSubmit(false)
setOpenModal(false)
}
}
function onCheck() {
if (report == "") {
setTouched({ ...touched, report: true })
return false
}
setOpenModal(true)
}
function onValidation(kategori: string, val: string) {
if (kategori == 'report') {
setReport(val)
if (val === "") {
setTouched({ ...touched, report: true })
} else {
setTouched({ ...touched, report: false })
}
}
}
async function getOneData() {
try {
setLoading(true)
const res = await funGetOneProjectById(param.id, 'data');
if (res.success) {
setReport(res.data.report);
} else {
toast.error(res.message);
}
setLoading(false);
} catch (error) {
console.error(error);
toast.error("Gagal mendapatkan data Kegiatan, coba lagi nanti");
} finally {
setLoading(false);
}
}
useShallowEffect(() => {
getOneData();
}, [param.id])
return (
<Box >
<LayoutNavbarNew back="" title={"Laporan Kegiatan"} menu />
<Box p={20}>
<Stack pt={15}>
{loading ?
<Skeleton height={150} mt={20} radius={10} />
:
<Textarea placeholder="Laporan Kegiatan" label="Laporan Kegiatan" size="md" radius={10}
value={report}
required
error={
touched.report && (
report == "" ? "Laporan Tidak Boleh Kosong" : null
)
}
onChange={(e) => { onValidation('report', e.currentTarget.value) }}
styles={{
input: {
height: "30vh"
}
}}
/>
}
</Stack>
</Box>
<Box pos={'fixed'} bottom={0} p={rem(20)} w={"100%"} style={{
maxWidth: rem(550),
zIndex: 999,
backgroundColor: `${tema.get().bgUtama}`,
}}>
{loading ?
<Skeleton height={50} radius={30} />
:
<Button
c={"white"}
bg={Object.values(touched).some((v) => v == true) || report == "" || report == null ? 'gray' : tema.get().utama}
size="lg"
radius={30}
fullWidth
onClick={() => { onCheck() }}
disabled={Object.values(touched).some((v) => v == true) || report == "" || report == null ? true : false}
>
Simpan
</Button>
}
</Box>
<LayoutModal opened={openModal} loading={loadingSubmit} onClose={() => setOpenModal(false)}
description="Apakah Anda yakin ingin mengedit Laporan Kegiatan ini?"
onYes={(val) => {
if (val) {
onSubmit()
} else {
setOpenModal(false)
}
}} />
</Box>
);
}

View File

@@ -0,0 +1,82 @@
'use client'
import { keyWibu, TEMA } from '@/module/_global';
import { useHookstate } from '@hookstate/core';
import { Box, Spoiler, Text } from '@mantine/core';
import { useShallowEffect } from '@mantine/hooks';
import { useParams } from 'next/navigation';
import { useState } from 'react';
import toast from 'react-hot-toast';
import { useWibuRealtime } from 'wibu-realtime';
import { funGetOneProjectById } from '../lib/api_project';
import { globalRefreshProject } from '../lib/val_project';
export default function ListReportDetailProject() {
const [isData, setData] = useState("")
const param = useParams<{ id: string }>()
const refresh = useHookstate(globalRefreshProject)
const tema = useHookstate(TEMA)
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
})
async function getOneData() {
try {
const res = await funGetOneProjectById(param.id, 'data');
if (res.success) {
setData(res.data.report)
} else {
toast.error(res.message);
}
} catch (error) {
console.error(error);
toast.error("Gagal mendapatkan list Laporan Kegiatan, coba lagi nanti");
}
}
useShallowEffect(() => {
getOneData();
}, [param.id])
useShallowEffect(() => {
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'project-report' && i.id == param.id)) {
refresh.set(true)
getOneData()
}
}, [dataRealTime])
return (
<>
{
isData != "" && isData != null
&&
<Box pt={20}>
<Text fw={"bold"} c={tema.get().utama}>
Laporan Kegiatan
</Text>
<Box
bg={"white"}
style={{
borderRadius: 10,
border: `1px solid ${"#D6D8F6"}`,
}}
pt={10}
pb={10}
pl={20}
pr={20}
>
<Spoiler maxHeight={50} showLabel="Lihat Detail" hideLabel="Tutup Detail">
<Text style={{ overflowWrap: "break-word", whiteSpace: "pre-line" }}>
{isData}
</Text>
</Spoiler>
</Box>
</Box>
}
</>
);
}

View File

@@ -8,6 +8,7 @@ import { useShallowEffect } from '@mantine/hooks';
import { useParams, useRouter } from 'next/navigation';
import { useState } from 'react';
import toast from 'react-hot-toast';
import { AiFillFileText } from 'react-icons/ai';
import { FaFileCirclePlus, FaPencil, FaTrash, FaUsers } from 'react-icons/fa6';
import { HiMenu } from 'react-icons/hi';
import { IoAddCircle } from 'react-icons/io5';
@@ -138,7 +139,7 @@ export default function NavbarDetailProject() {
</ActionIcon>
} />
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)} size='md'>
<Box>
<Stack pt={10}>
<SimpleGrid
@@ -206,6 +207,26 @@ export default function NavbarDetailProject() {
</Box>
</Flex>
<Flex justify={'center'} align={'center'} direction={'column'}
style={{
cursor: 'pointer'
}}
onClick={() => {
if (reason == null) {
router.push(param.id + '/report')
} else {
null
}
}}
>
<Box>
<AiFillFileText size={30} color={reason == null ? tema.get().utama : "gray"} />
</Box>
<Box>
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Laporan</Text>
</Box>
</Flex>
{
(roleLogin.get() != "user" && roleLogin.get() != "coadmin") &&
<>

View File

@@ -1,6 +1,7 @@
import AddDetailTask from "./ui/add_detail_task";
import AddFileDetailTask from "./ui/add_file_detail_task";
import AddMemberDetailTask from "./ui/add_member_detail_task";
import AddReportTask from "./ui/add_report_detail_task";
import CancelTask from "./ui/cancel_task";
import ViewDateEndTask from "./ui/create_date_end_task";
import CreateTask from "./ui/create_task";
@@ -8,6 +9,7 @@ import CreateUsersProject from "./ui/create_users_project";
import ListAnggotaDetailTask from "./ui/detail_list_anggota_task";
import ListFileDetailTask from "./ui/detail_list_file_task";
import ListLinkDetailTask from "./ui/detail_list_link_task";
import ListReportDetailTask from "./ui/detail_list_report_task";
import ListTugasDetailTask from "./ui/detail_list_tugas_task";
import ProgressDetailTask from "./ui/detail_progress_task";
import EditDetailTask from "./ui/edit_detail_task";
@@ -34,4 +36,6 @@ export { AddMemberDetailTask }
export { CancelTask }
export { EditTask }
export { AddFileDetailTask }
export { ListLinkDetailTask }
export { ListLinkDetailTask }
export { AddReportTask }
export { ListReportDetailTask }

View File

@@ -61,6 +61,17 @@ export const funEditDetailTask = async (path: string, data: IFormDateTask) => {
return await response.json().catch(() => null);
};
export const funEditReportTask = async (path: string, data: { report: string }) => {
const response = await fetch(`/api/task/${path}/lainnya`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
};
export const funCreateDetailTask = async (path: string, data: IFormAddDetailTask) => {
const response = await fetch(`/api/task/${path}`, {

View File

@@ -0,0 +1,156 @@
"use client"
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
import LayoutModal from '@/module/_global/layout/layout_modal';
import { useHookstate } from '@hookstate/core';
import { Box, Button, rem, Skeleton, Stack, Textarea } 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 { useWibuRealtime } from 'wibu-realtime';
import { funEditReportTask, funGetTaskDivisionById } from '../lib/api_task';
export default function AddReportTask() {
const router = useRouter()
const [report, setReport] = useState("")
const [openModal, setOpenModal] = useState(false)
const param = useParams<{ id: string, detail: string }>()
const [loading, setLoading] = useState(true)
const [loadingSubmit, setLoadingSubmit] = useState(false)
const tema = useHookstate(TEMA)
const [touched, setTouched] = useState({
report: false,
});
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
})
async function onSubmit() {
try {
setLoadingSubmit(true)
const res = await funEditReportTask(param.detail, { report })
if (res.success) {
setDataRealtime([{
category: "tugas-detail-report",
id: param.detail,
}])
toast.success(res.message)
router.push("./")
} else {
toast.error(res.message)
}
} catch (error) {
console.error(error)
toast.error("Gagal mengedit Laporan Kegiatan, coba lagi nanti")
} finally {
setLoadingSubmit(false)
setOpenModal(false)
}
}
function onCheck() {
if (report == "") {
setTouched({ ...touched, report: true })
return false
}
setOpenModal(true)
}
function onValidation(kategori: string, val: string) {
if (kategori == 'report') {
setReport(val)
if (val === "") {
setTouched({ ...touched, report: true })
} else {
setTouched({ ...touched, report: false })
}
}
}
async function getOneData() {
try {
setLoading(true)
const res = await funGetTaskDivisionById(param.detail, 'data');
if (res.success) {
setReport(res.data.report);
} else {
toast.error(res.message);
}
} catch (error) {
console.error(error);
toast.error("Gagal mendapatkan data Tugas, coba lagi nanti");
} finally {
setLoading(false);
}
}
useShallowEffect(() => {
getOneData();
}, [param.detail])
return (
<Box >
<LayoutNavbarNew back="" title={"Laporan Kegiatan"} menu />
<Box p={20}>
<Stack pt={15}>
{loading ?
<Skeleton height={150} mt={20} radius={10} />
:
<Textarea placeholder="Laporan Kegiatan" label="Laporan Kegiatan" size="md" radius={10}
value={report}
required
error={
touched.report && (
report == "" ? "Laporan Tidak Boleh Kosong" : null
)
}
onChange={(e) => { onValidation('report', e.currentTarget.value) }}
styles={{
input: {
height: "30vh"
}
}}
/>
}
</Stack>
</Box>
<Box pos={'fixed'} bottom={0} p={rem(20)} w={"100%"} style={{
maxWidth: rem(550),
zIndex: 999,
backgroundColor: `${tema.get().bgUtama}`,
}}>
{loading ?
<Skeleton height={50} radius={30} />
:
<Button
c={"white"}
bg={Object.values(touched).some((v) => v == true) || report == "" || report == null ? 'gray' : tema.get().utama}
size="lg"
radius={30}
fullWidth
onClick={() => { onCheck() }}
disabled={Object.values(touched).some((v) => v == true) || report == "" || report == null ? true : false}
>
Simpan
</Button>
}
</Box>
<LayoutModal opened={openModal} loading={loadingSubmit} onClose={() => setOpenModal(false)}
description="Apakah Anda yakin ingin mengedit Laporan Kegiatan ini?"
onYes={(val) => {
if (val) {
onSubmit()
} else {
setOpenModal(false)
}
}} />
</Box>
);
}

View File

@@ -0,0 +1,83 @@
'use client'
import { keyWibu, TEMA } from '@/module/_global';
import { useHookstate } from '@hookstate/core';
import { Box, Spoiler, Text } from '@mantine/core';
import { useShallowEffect } from '@mantine/hooks';
import { useParams } from 'next/navigation';
import { useState } from 'react';
import toast from 'react-hot-toast';
import { useWibuRealtime } from 'wibu-realtime';
import { funGetTaskDivisionById } from '../lib/api_task';
import { globalRefreshTask } from '../lib/val_task';
export default function ListReportDetailTask() {
const [isData, setData] = useState("")
const param = useParams<{ id: string, detail: string }>()
const refresh = useHookstate(globalRefreshTask)
const tema = useHookstate(TEMA)
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
})
async function getOneData() {
try {
const res = await funGetTaskDivisionById(param.detail, 'data');
if (res.success) {
setData(res.data.report)
} else {
toast.error(res.message);
}
} catch (error) {
console.error(error);
toast.error("Gagal mendapatkan list Laporan Kegiatan, coba lagi nanti");
}
}
useShallowEffect(() => {
getOneData();
}, [param.detail])
useShallowEffect(() => {
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-detail-report' && i.id == param.detail)) {
refresh.set(true)
getOneData()
}
}, [dataRealTime])
return (
<>
{
isData != "" && isData != null
&&
<Box pt={20}>
<Text fw={"bold"} c={tema.get().utama}>
Laporan Kegiatan
</Text>
<Box
bg={"white"}
style={{
borderRadius: 10,
border: `1px solid ${"#D6D8F6"}`,
}}
pt={10}
pb={10}
pl={20}
pr={20}
>
<Spoiler maxHeight={50} showLabel="Lihat Detail" hideLabel="Tutup Detail">
<Text style={{ overflowWrap: "break-word", whiteSpace: "pre-line" }}>
{isData}
</Text>
</Spoiler>
</Box>
</Box>
}
</>
);
}

View File

@@ -9,6 +9,7 @@ import { useShallowEffect } from "@mantine/hooks";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-hot-toast";
import { AiFillFileText } from "react-icons/ai";
import { FaFileCirclePlus, FaPencil, FaTrash, FaUsers } from "react-icons/fa6";
import { HiMenu } from "react-icons/hi";
import { IoAddCircle } from "react-icons/io5";
@@ -138,7 +139,7 @@ export default function NavbarDetailDivisionTask() {
} />
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)} size='md'>
<Box>
<Stack pt={10}>
<SimpleGrid
@@ -206,6 +207,26 @@ export default function NavbarDetailDivisionTask() {
</Box>
</Flex>
<Flex justify={'center'} align={'center'} direction={'column'}
style={{
cursor: 'pointer'
}}
onClick={() => {
if (reason == null) {
router.push(param.detail + '/report')
} else {
null
}
}}
>
<Box>
<AiFillFileText size={30} color={reason == null ? tema.get().utama : "gray"} />
</Box>
<Box>
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Laporan</Text>
</Box>
</Flex>
{
(roleLogin.get() != "user" && roleLogin.get() != "coadmin") || adminLogin.get() ?
<>