Merge pull request 'join' (#17) from join into staging
Reviewed-on: bip/sistem-desa-mandiri#17
This commit is contained in:
@@ -113,7 +113,6 @@ model User {
|
||||
Announcement Announcement[]
|
||||
Project Project[]
|
||||
ProjectMember ProjectMember[]
|
||||
ProjectComment ProjectComment[]
|
||||
UserLog UserLog[]
|
||||
Division Division[]
|
||||
DivisionMember DivisionMember[]
|
||||
@@ -184,24 +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[]
|
||||
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 {
|
||||
@@ -228,33 +228,44 @@ model ProjectFile {
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model ProjectTask {
|
||||
id String @id @default(cuid())
|
||||
Project Project @relation(fields: [idProject], references: [id])
|
||||
idProject String
|
||||
title String
|
||||
desc String?
|
||||
status Int @default(0) // 0 = todo, 1 = done
|
||||
notifikasi Boolean @default(false)
|
||||
dateStart DateTime @db.Date
|
||||
dateEnd DateTime @db.Date
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model ProjectComment {
|
||||
model ProjectLink {
|
||||
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
|
||||
link String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model ProjectTask {
|
||||
id String @id @default(cuid())
|
||||
Project Project @relation(fields: [idProject], references: [id])
|
||||
idProject String
|
||||
title String
|
||||
desc String?
|
||||
status Int @default(0) // 0 = todo, 1 = done
|
||||
notifikasi Boolean @default(false)
|
||||
dateStart DateTime @db.Date
|
||||
dateEnd DateTime @db.Date
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ProjectTaskDetail ProjectTaskDetail[]
|
||||
}
|
||||
|
||||
model ProjectTaskDetail {
|
||||
id String @id @default(cuid())
|
||||
ProjectTask ProjectTask @relation(fields: [idTask], references: [id])
|
||||
idTask String
|
||||
date DateTime @db.Date
|
||||
timeStart DateTime? @db.Time()
|
||||
timeEnd DateTime? @db.Time()
|
||||
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])
|
||||
@@ -280,6 +291,7 @@ model Division {
|
||||
DivisionCalendar DivisionCalendar[]
|
||||
DivisionCalendarReminder DivisionCalendarReminder[]
|
||||
ContainerFileDivision ContainerFileDivision[]
|
||||
DivisionProjectLink DivisionProjectLink[]
|
||||
}
|
||||
|
||||
model DivisionMember {
|
||||
@@ -302,6 +314,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())
|
||||
@@ -309,6 +322,19 @@ model DivisionProject {
|
||||
DivisionProjectTask DivisionProjectTask[]
|
||||
DivisionProjectMember DivisionProjectMember[]
|
||||
DivisionProjectFile DivisionProjectFile[]
|
||||
DivisionProjectLink DivisionProjectLink[]
|
||||
}
|
||||
|
||||
model DivisionProjectLink {
|
||||
id String @id @default(cuid())
|
||||
Division Division @relation(fields: [idDivision], references: [id])
|
||||
idDivision String
|
||||
DivisionProject DivisionProject @relation(fields: [idProject], references: [id])
|
||||
idProject String
|
||||
link String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model DivisionProjectTask {
|
||||
@@ -326,6 +352,19 @@ model DivisionProjectTask {
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
DivisionProjectTaskDetail DivisionProjectTaskDetail[]
|
||||
}
|
||||
|
||||
model DivisionProjectTaskDetail {
|
||||
id String @id @default(cuid())
|
||||
DivisionProjectTask DivisionProjectTask @relation(fields: [idTask], references: [id])
|
||||
idTask String
|
||||
date DateTime @db.Date
|
||||
timeStart DateTime? @db.Time()
|
||||
timeEnd DateTime? @db.Time()
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model DivisionProjectMember {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NavbarDetailDivisionTask, ProgressDetailTask, ListTugasDetailTask, ListFileDetailTask, ListAnggotaDetailTask } from "@/module/task"
|
||||
import { ListAnggotaDetailTask, ListFileDetailTask, ListLinkDetailTask, ListReportDetailTask, ListTugasDetailTask, NavbarDetailDivisionTask, ProgressDetailTask } from "@/module/task"
|
||||
import { Box } from "@mantine/core"
|
||||
|
||||
function Page() {
|
||||
@@ -7,8 +7,10 @@ function Page() {
|
||||
<NavbarDetailDivisionTask />
|
||||
<Box p={20}>
|
||||
<ProgressDetailTask />
|
||||
<ListReportDetailTask />
|
||||
<ListTugasDetailTask />
|
||||
<ListFileDetailTask />
|
||||
<ListLinkDetailTask />
|
||||
<ListAnggotaDetailTask />
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { AddReportTask } from "@/module/task"
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<AddReportTask />
|
||||
)
|
||||
}
|
||||
export default Page
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ListAnggotaDetailProject, ListFileDetailProject, ListTugasDetailProject, NavbarDetailProject, ProgressDetailProject } from '@/module/project';
|
||||
import { ListAnggotaDetailProject, ListFileDetailProject, ListLinkDetailProject, ListReportDetailProject, ListTugasDetailProject, NavbarDetailProject, ProgressDetailProject } from '@/module/project';
|
||||
import { Box } from '@mantine/core';
|
||||
import React from 'react';
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
@@ -8,8 +7,10 @@ function Page() {
|
||||
<NavbarDetailProject />
|
||||
<Box p={20}>
|
||||
<ProgressDetailProject />
|
||||
<ListReportDetailProject />
|
||||
<ListTugasDetailProject />
|
||||
<ListFileDetailProject />
|
||||
<ListLinkDetailProject />
|
||||
<ListAnggotaDetailProject />
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
9
src/app/(application)/project/[id]/report/page.tsx
Normal file
9
src/app/(application)/project/[id]/report/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AddReportProject } from "@/module/project";
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<AddReportProject />
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
@@ -70,7 +70,9 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const dataFCM = member.map((v: any) => ({
|
||||
const memberFilter = member.filter((v: any) => v.idUser != userMobile.id)
|
||||
|
||||
const dataFCM = memberFilter.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||
}))
|
||||
@@ -106,7 +108,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
token: tokenUnique,
|
||||
title: "Komentar Baru",
|
||||
body: `${userSent?.name}: ${data.comment}`,
|
||||
data: { id: data.id, category: "discussion", content: id }
|
||||
data: { id: data.id, category: "discussion-general", content: id }
|
||||
})
|
||||
|
||||
// create log user
|
||||
|
||||
@@ -86,7 +86,9 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const dataFCM = member.map((v: any) => ({
|
||||
const memberFilter = member.filter((v: any) => v.idUser != userMobile.id)
|
||||
|
||||
const dataFCM = memberFilter.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||
}))
|
||||
@@ -122,7 +124,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
token: tokenUnique,
|
||||
title: "Komentar Baru",
|
||||
body: `${userSent?.name}: ${comment}`,
|
||||
data: { id: data.id, category: `division/${dataDivision?.idDivision}/discussion/`, content: id }
|
||||
data: { id: data.id, category: `division/${dataDivision?.idDivision}/discussion`, content: id }
|
||||
})
|
||||
|
||||
// create log user
|
||||
|
||||
@@ -47,4 +47,51 @@ 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 { id } = context.params
|
||||
const { report, 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 dataCreate = await prisma.project.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
report: report
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate laporan kegiatan', table: 'project', data: String(id), user: userMobile.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 });
|
||||
}
|
||||
}
|
||||
95
src/app/api/mobile/project/[id]/link/route.ts
Normal file
95
src/app/api/mobile/project/[id]/link/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
@@ -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 });
|
||||
@@ -150,7 +162,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const { name, dateStart, dateEnd, user } = await request.json()
|
||||
const { name, dateStart, dateEnd, user, dataDetail } = await request.json()
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -185,6 +197,51 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: dataCreate.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
|
||||
const dataDetailCreate = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.projectTask.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idProject: id,
|
||||
}
|
||||
})
|
||||
|
||||
const semua = dataTask.length
|
||||
const selesai = dataTask.filter((item) => item.status == 1).length
|
||||
const prosess = Math.ceil((selesai / semua) * 100)
|
||||
let statusProject = 1
|
||||
|
||||
if (prosess == 100) {
|
||||
statusProject = 2
|
||||
} else if (prosess == 0) {
|
||||
statusProject = 0
|
||||
}
|
||||
|
||||
|
||||
const update = await prisma.project.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
status: statusProject
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data tahapan kegiatan', table: 'projectTask', data: String(dataCreate.id), user: userMobile.id })
|
||||
|
||||
|
||||
@@ -171,12 +171,14 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const { id } = context.params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const user = searchParams.get("user");
|
||||
const kategori = searchParams.get("cat");
|
||||
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 });
|
||||
}
|
||||
|
||||
let dataFix
|
||||
const data = await prisma.projectTask.findUnique({
|
||||
where: {
|
||||
id: String(id),
|
||||
@@ -195,7 +197,29 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data: fixData }, { status: 200 });
|
||||
if (kategori == "detailTask") {
|
||||
const dataDetail = await prisma.projectTaskDetail.findMany({
|
||||
where: {
|
||||
idTask: String(id)
|
||||
},
|
||||
orderBy: {
|
||||
date: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailFix = dataDetail.map((data: any) => ({
|
||||
...data,
|
||||
date: moment(data?.date).format('DD-MM-YYYY'),
|
||||
timeStart: data.timeStart == null ? "" : moment.utc(data.timeStart).format("HH:mm"),
|
||||
timeEnd: data.timeEnd == null ? "" : moment.utc(data.timeEnd).format("HH:mm")
|
||||
}))
|
||||
|
||||
dataFix = dataDetailFix
|
||||
} else {
|
||||
dataFix = fixData
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data: dataFix }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -207,7 +231,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd, user } = (await request.json());
|
||||
const { title, dateStart, dateEnd, user, dataDetail } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -240,6 +264,26 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailDelete = await prisma.projectTaskDetail.deleteMany({
|
||||
where: {
|
||||
idTask: id
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate tahapan kegiatan', table: 'projectTask', data: String(id), user: userMobile.id })
|
||||
|
||||
|
||||
@@ -179,16 +179,33 @@ export async function POST(request: Request) {
|
||||
|
||||
if (task.length > 0) {
|
||||
const dataProject = task.map((v: any) => ({
|
||||
..._.omit(v, ["dateStart", "dateEnd", "name", "dateEndFix", "dateStartFix"]),
|
||||
..._.omit(v, ["dateStart", "dateEnd", "name", "dateEndFix", "dateStartFix", "dataDetail"]),
|
||||
idProject: data.id,
|
||||
title: v.title,
|
||||
dateStart: new Date(v.dateStartFix),
|
||||
dateEnd: new Date(v.dateEndFix),
|
||||
}))
|
||||
|
||||
let dataDetailFix = []
|
||||
for (let i = 0; i < dataProject.length; i++) {
|
||||
const insertTask = await prisma.projectTask.create({
|
||||
data: dataProject[i],
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
const dataDetail = task[i].dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: insertTask.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
dataDetailFix.push(...dataDetail)
|
||||
}
|
||||
|
||||
const insertTask = await prisma.projectTask.createMany({
|
||||
data: dataProject
|
||||
const insertDetail = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,51 @@ 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 { id } = context.params
|
||||
const { report, 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: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
const dataCreate = await prisma.divisionProject.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
report: report
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate laporan tugas divisi', table: 'divisionProject', data: String(id), user: userMobile.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 });
|
||||
}
|
||||
}
|
||||
98
src/app/api/mobile/task/[id]/link/route.ts
Normal file
98
src/app/api/mobile/task/[id]/link/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
@@ -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 });
|
||||
@@ -167,7 +179,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd, idDivision, user } = (await request.json());
|
||||
const { title, dateStart, dateEnd, idDivision, user, dataDetail } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -203,6 +215,20 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
});
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: create.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.divisionProjectTask.findMany({
|
||||
where: {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
@@ -166,6 +167,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const { id } = context.params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const user = searchParams.get("user");
|
||||
const kategori = searchParams.get("cat");
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -183,7 +185,30 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan detail tugas, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan detail tugas divisi", data }, { status: 200 });
|
||||
let dataFix
|
||||
if (kategori == "detailTask") {
|
||||
const dataDetail = await prisma.divisionProjectTaskDetail.findMany({
|
||||
where: {
|
||||
idTask: String(id)
|
||||
},
|
||||
orderBy: {
|
||||
date: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailFix = dataDetail.map((data: any) => ({
|
||||
...data,
|
||||
date: moment(data?.date).format('DD-MM-YYYY'),
|
||||
timeStart: data.timeStart == null ? "" : moment.utc(data.timeStart).format("HH:mm"),
|
||||
timeEnd: data.timeEnd == null ? "" : moment.utc(data.timeEnd).format("HH:mm")
|
||||
}))
|
||||
|
||||
dataFix = dataDetailFix
|
||||
} else {
|
||||
dataFix = data
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan detail tugas divisi", data: dataFix }, { status: 200 });
|
||||
|
||||
}
|
||||
catch (error) {
|
||||
@@ -198,7 +223,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd, user } = (await request.json());
|
||||
const { title, dateStart, dateEnd, user, dataDetail } = (await request.json());
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -232,6 +257,26 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
},
|
||||
});
|
||||
|
||||
const dataDetailDelete = await prisma.divisionProjectTaskDetail.deleteMany({
|
||||
where: {
|
||||
idTask: id
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data detail task divisi', table: 'divisionProjectTask', data: id, user: userMobile.id })
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ export async function POST(request: Request) {
|
||||
|
||||
if (task.length > 0) {
|
||||
const dataTask = task.map((v: any) => ({
|
||||
..._.omit(v, ["dateStart", "dateEnd", "title", "dateStartFix", "dateEndFix"]),
|
||||
..._.omit(v, ["dateStart", "dateEnd", "title", "dateStartFix", "dateEndFix", "dataDetail"]),
|
||||
idDivision: idDivision,
|
||||
idProject: data.id,
|
||||
title: v.title,
|
||||
@@ -150,9 +150,26 @@ export async function POST(request: Request) {
|
||||
dateEnd: new Date(v.dateEndFix),
|
||||
}))
|
||||
|
||||
let dataDetailFix = []
|
||||
for (let i = 0; i < dataTask.length; i++) {
|
||||
const insertTask = await prisma.divisionProjectTask.create({
|
||||
data: dataTask[i],
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
const dataDetail = task[i].dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: insertTask.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
dataDetailFix.push(...dataDetail)
|
||||
}
|
||||
|
||||
const insertTask = await prisma.divisionProjectTask.createMany({
|
||||
data: dataTask
|
||||
const insertDetail = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
@@ -350,7 +367,7 @@ export async function POST(request: Request) {
|
||||
token: tokenUnique,
|
||||
title: "Tugas Baru",
|
||||
body: "Anda memiliki tugas baru. Silahkan periksa detailnya.",
|
||||
data: { id: data.id, category:'division/' + idDivision + '/task', content: data.id }
|
||||
data: { id: data.id, category: 'division/' + idDivision + '/task', content: data.id }
|
||||
})
|
||||
|
||||
// create log user
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
93
src/app/api/project/[id]/link/route.ts
Normal file
93
src/app/api/project/[id]/link/route.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// ADD LINK PROJECT
|
||||
export async function POST(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 { link } = (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 insertLink = await prisma.projectLink.create({
|
||||
data: {
|
||||
idProject: id,
|
||||
link: link
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambah link kegiatan', table: 'projectLink', data: insertLink.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 user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { idLink } = (await request.json())
|
||||
|
||||
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: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const deleteLink = await prisma.projectLink.update({
|
||||
where: {
|
||||
id: idLink
|
||||
},
|
||||
data: {
|
||||
isActive: false
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus link kegiatan', table: 'projectLink', data: String(idLink) })
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,17 @@ 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 });
|
||||
@@ -152,7 +163,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
|
||||
const { id } = context.params
|
||||
const { name, dateStart, dateEnd, } = await request.json()
|
||||
const { name, dateStart, dateEnd, dataDetail } = await request.json()
|
||||
|
||||
const data = await prisma.project.count({
|
||||
where: {
|
||||
@@ -181,6 +192,50 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: dataCreate.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.projectTask.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idProject: id,
|
||||
}
|
||||
})
|
||||
|
||||
const semua = dataTask.length
|
||||
const selesai = dataTask.filter((item) => item.status == 1).length
|
||||
const prosess = Math.ceil((selesai / semua) * 100)
|
||||
let statusProject = 1
|
||||
|
||||
if (prosess == 100) {
|
||||
statusProject = 2
|
||||
} else if (prosess == 0) {
|
||||
statusProject = 0
|
||||
}
|
||||
|
||||
|
||||
const update = await prisma.project.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
status: statusProject
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data tahapan kegiatan', table: 'projectTask', data: String(dataCreate.id) })
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
@@ -171,7 +172,11 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const kategori = searchParams.get("cat");
|
||||
const { id } = context.params;
|
||||
|
||||
let dataFix
|
||||
const data = await prisma.projectTask.findUnique({
|
||||
where: {
|
||||
id: String(id),
|
||||
@@ -188,7 +193,28 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data }, { status: 200 });
|
||||
if (kategori == "detailTask") {
|
||||
const dataDetail = await prisma.projectTaskDetail.findMany({
|
||||
where: {
|
||||
idTask: String(id)
|
||||
},
|
||||
orderBy: {
|
||||
date: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailFix = dataDetail.map((data: any) => ({
|
||||
...data,
|
||||
timeStart: moment.utc(data.timeStart).format("HH:mm"),
|
||||
timeEnd: moment.utc(data.timeEnd).format("HH:mm")
|
||||
}))
|
||||
|
||||
dataFix = dataDetailFix
|
||||
} else {
|
||||
dataFix = data
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data: dataFix }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -205,17 +231,17 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd } = (await request.json());
|
||||
const { title, dateStart, dateEnd, dataDetail } = (await request.json());
|
||||
|
||||
|
||||
|
||||
const dataTask = await prisma.projectTask.count({
|
||||
const dataTaskLama = await prisma.projectTask.findUnique({
|
||||
where: {
|
||||
id
|
||||
}
|
||||
})
|
||||
|
||||
if (dataTask == 0) {
|
||||
if (dataTaskLama?.title == undefined) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
@@ -235,6 +261,26 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailDelete = await prisma.projectTaskDetail.deleteMany({
|
||||
where: {
|
||||
idTask: id
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate tahapan kegiatan', table: 'projectTask', data: String(id) })
|
||||
|
||||
|
||||
@@ -169,15 +169,34 @@ export async function POST(request: Request) {
|
||||
|
||||
if (task.length > 0) {
|
||||
const dataProject = task.map((v: any) => ({
|
||||
..._.omit(v, ["dateStart", "dateEnd", "name"]),
|
||||
..._.omit(v, ["dateStart", "dateEnd", "name", "dataDetail"]),
|
||||
idProject: data.id,
|
||||
title: v.title,
|
||||
dateStart: new Date(v.dateStart),
|
||||
dateEnd: new Date(v.dateEnd),
|
||||
}))
|
||||
|
||||
const insertTask = await prisma.projectTask.createMany({
|
||||
data: dataProject
|
||||
let dataDetailFix = []
|
||||
|
||||
for (let i = 0; i < dataProject.length; i++) {
|
||||
const insertTask = await prisma.projectTask.create({
|
||||
data: dataProject[i],
|
||||
select:{
|
||||
id: true
|
||||
}
|
||||
})
|
||||
const dataDetail = task[i].dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: insertTask.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
dataDetailFix.push(...dataDetail)
|
||||
}
|
||||
|
||||
const insertDetail = await prisma.projectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
98
src/app/api/task/[id]/link/route.ts
Normal file
98
src/app/api/task/[id]/link/route.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// ADD LINK TASK DIVISI
|
||||
export async function POST(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 { link, idDivision } = (await request.json());
|
||||
|
||||
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: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const insertlink = await prisma.divisionProjectLink.create({
|
||||
data: {
|
||||
idProject: id,
|
||||
link,
|
||||
idDivision,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambahkan link tugas divisi', table: 'divisionProjectLink', data: insertlink.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 user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { idLink } = (await request.json())
|
||||
|
||||
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: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const deleteLink = await prisma.divisionProjectLink.update({
|
||||
where: {
|
||||
id: idLink
|
||||
},
|
||||
data: {
|
||||
isActive: false
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus link tugas divisi', table: 'divisionProjectLink', data: String(idLink) })
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,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 });
|
||||
@@ -171,7 +183,8 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd, idDivision } = (await request.json());
|
||||
const { title, dateStart, dateEnd, idDivision, dataDetail } = (await request.json());
|
||||
|
||||
const data = await prisma.divisionProject.count({
|
||||
where: {
|
||||
id: id,
|
||||
@@ -201,6 +214,20 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
});
|
||||
|
||||
if(dataDetail.length>0){
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: create.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.divisionProjectTask.findMany({
|
||||
where: {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
@@ -155,12 +156,15 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const kategori = searchParams.get("cat");
|
||||
const user = await funGetUserByCookies()
|
||||
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
let dataFix
|
||||
const data = await prisma.divisionProjectTask.findUnique({
|
||||
where: {
|
||||
id: String(id),
|
||||
@@ -172,7 +176,28 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan detail tugas, data tidak ditemukan", }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan detail tugas divisi", data }, { status: 200 });
|
||||
if (kategori == "detailTask") {
|
||||
const dataDetail = await prisma.divisionProjectTaskDetail.findMany({
|
||||
where: {
|
||||
idTask: String(id)
|
||||
},
|
||||
orderBy: {
|
||||
date: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
const dataDetailFix = dataDetail.map((data: any) => ({
|
||||
...data,
|
||||
timeStart: moment.utc(data.timeStart).format("HH:mm"),
|
||||
timeEnd: moment.utc(data.timeEnd).format("HH:mm")
|
||||
}))
|
||||
|
||||
dataFix = dataDetailFix
|
||||
} else {
|
||||
dataFix = data
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan detail tugas divisi", data: dataFix }, { status: 200 });
|
||||
|
||||
}
|
||||
catch (error) {
|
||||
@@ -192,7 +217,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd } = (await request.json());
|
||||
const { title, dateStart, dateEnd, dataDetail } = (await request.json());
|
||||
const data = await prisma.divisionProjectTask.count({
|
||||
where: {
|
||||
id: id,
|
||||
@@ -220,6 +245,26 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
},
|
||||
});
|
||||
|
||||
const dataDetailDelete = await prisma.divisionProjectTaskDetail.deleteMany({
|
||||
where: {
|
||||
idTask: id
|
||||
}
|
||||
})
|
||||
|
||||
if (dataDetail.length > 0) {
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
|
||||
const dataDetailCreate = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data detail task divisi', table: 'divisionProjectTask', data: id })
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ export async function POST(request: Request) {
|
||||
|
||||
if (task.length > 0) {
|
||||
const dataTask = task.map((v: any) => ({
|
||||
..._.omit(v, ["dateStart", "dateEnd", "title"]),
|
||||
..._.omit(v, ["dateStart", "dateEnd", "title", "dataDetail"]),
|
||||
idDivision: idDivision,
|
||||
idProject: data.id,
|
||||
title: v.title,
|
||||
@@ -148,8 +148,26 @@ export async function POST(request: Request) {
|
||||
dateEnd: new Date(v.dateEnd),
|
||||
}))
|
||||
|
||||
const insertTask = await prisma.divisionProjectTask.createMany({
|
||||
data: dataTask
|
||||
let dataDetailFix = []
|
||||
for (let i = 0; i < dataTask.length; i++) {
|
||||
const insertTask = await prisma.divisionProjectTask.create({
|
||||
data: dataTask[i],
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
const dataDetail = task[i].dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
idTask: insertTask.id,
|
||||
date: new Date(v.date),
|
||||
timeStart: v.timeStart == null ? null : new Date(new Date('1970-01-01 ' + v.timeStart).getTime() - (new Date('1970-01-01 ' + v.timeStart).getTimezoneOffset() * 60000)).toISOString(),
|
||||
timeEnd: v.timeEnd == null ? null : new Date(new Date('1970-01-01 ' + v.timeEnd).getTime() - (new Date('1970-01-01 ' + v.timeEnd).getTimezoneOffset() * 60000)).toISOString(),
|
||||
}))
|
||||
dataDetailFix.push(...dataDetail)
|
||||
}
|
||||
|
||||
const insertDetail = await prisma.divisionProjectTaskDetail.createMany({
|
||||
data: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "1.5.8", tahap: "beta", update: "-update notif komen diskusi" }, { status: 200 });
|
||||
return NextResponse.json({ success: true, version: "1.7.0", tahap: "beta", update: "-api mobile; -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
9
src/lib/getDatesInRange.ts
Normal file
9
src/lib/getDatesInRange.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function getDatesInRange(startDate: Date, endDate: Date) {
|
||||
const dates = [];
|
||||
const currentDate = new Date(startDate);
|
||||
while (currentDate <= endDate) {
|
||||
dates.push(new Date(currentDate));
|
||||
currentDate.setDate(currentDate.getDate() + 1);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
7
src/lib/urlCompleted.ts
Normal file
7
src/lib/urlCompleted.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function urlCompleted(url: string) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||
return url
|
||||
} else {
|
||||
return `https://${url}`
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
@@ -15,6 +14,9 @@ import AddMemberDetailProject from "./ui/add_member_detail_project";
|
||||
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 }
|
||||
@@ -31,4 +33,7 @@ export { CancelProject }
|
||||
export { AddMemberDetailProject }
|
||||
export { CreateProject }
|
||||
export { AddFileDetailProject }
|
||||
export { WrapLayoutProject }
|
||||
export { WrapLayoutProject }
|
||||
export { ListLinkDetailProject }
|
||||
export { AddReportProject }
|
||||
export { ListReportDetailProject }
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IFormAddDetailproject, IFormAddMemberProject, IFormDateProject, NewIFormDateProject } from "./type_project";
|
||||
import { IFormAddDetailproject, IFormAddMemberProject, NewIFormDateProject } from "./type_project";
|
||||
|
||||
|
||||
export const funGetAllProject = async (path?: string) => {
|
||||
@@ -49,8 +49,8 @@ export const funUpdateStatusProject = async (path: string, data: { status: numbe
|
||||
}
|
||||
|
||||
|
||||
export const funGetDetailProject = async (path: string) => {
|
||||
const response = await fetch(`/api/project/detail/${path}`);
|
||||
export const funGetDetailProject = async (path: string, kat?: string) => {
|
||||
const response = await fetch(`/api/project/detail/${path}${(kat) ? `?cat=${kat}` : ''}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
@@ -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}`, {
|
||||
@@ -149,6 +160,17 @@ export const funAddFileProject = async (path: string, data: FormData) => {
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funDeleteLinkProject = async (path: string, data: { idLink: string }) => {
|
||||
const response = await fetch(`/api/project/${path}/link`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funDeleteProject = async (path: string) => {
|
||||
const response = await fetch(`/api/project/${path}/lainnya`, {
|
||||
method: "DELETE",
|
||||
@@ -159,3 +181,14 @@ export const funDeleteProject = async (path: string) => {
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
export const funAddLinkProject = async (path: string, data: { link: string }) => {
|
||||
const response = await fetch(`/api/project/${path}/link`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,13 @@ export interface IDataFileProject {
|
||||
id: string
|
||||
name: string
|
||||
extension: string
|
||||
idStorage:string
|
||||
idStorage: string
|
||||
}
|
||||
|
||||
|
||||
export interface IDataLinkProject {
|
||||
id: string
|
||||
link: string
|
||||
}
|
||||
|
||||
export interface IDataMemberProject {
|
||||
@@ -46,10 +52,11 @@ export interface IFormDateProject {
|
||||
title: string,
|
||||
}
|
||||
|
||||
export interface NewIFormDateProject{
|
||||
export interface NewIFormDateProject {
|
||||
dateStart: string,
|
||||
dateEnd: string,
|
||||
title: string,
|
||||
dataDetail: any[]
|
||||
}
|
||||
|
||||
export interface IFormMemberProject {
|
||||
@@ -62,7 +69,8 @@ export interface IFormMemberProject {
|
||||
export interface IFormAddDetailproject {
|
||||
dateStart: string,
|
||||
dateEnd: string,
|
||||
name: string
|
||||
name: string,
|
||||
dataDetail: any[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client"
|
||||
import { getDatesInRange } from '@/lib/getDatesInRange';
|
||||
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
@@ -11,6 +12,7 @@ import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funCreateDetailProject } from '../lib/api_project';
|
||||
import { ModalAddDetailTaskProject } from './modal_add_detail_task_project';
|
||||
|
||||
export default function AddDetailTaskProject() {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
@@ -21,6 +23,8 @@ export default function AddDetailTaskProject() {
|
||||
const param = useParams<{ id: string }>()
|
||||
const tema = useHookstate(TEMA)
|
||||
const [acuan, setAcuan] = useState(false)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any>([])
|
||||
const [touched, setTouched] = useState({
|
||||
title: false,
|
||||
date: false
|
||||
@@ -33,10 +37,16 @@ export default function AddDetailTaskProject() {
|
||||
async function onSubmit() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
|
||||
const res = await funCreateDetailProject(param.id, {
|
||||
name,
|
||||
dateStart: (value[0] != null) ? moment(value[0]).format('YYYY-MM-DD') : moment(new Date).format('YYYY-MM-DD'),
|
||||
dateEnd: (value[1] != null) ? moment(value[1]).format('YYYY-MM-DD') : moment(new Date).format('YYYY-MM-DD'),
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
@@ -94,8 +104,15 @@ export default function AddDetailTaskProject() {
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +136,6 @@ export default function AddDetailTaskProject() {
|
||||
style={{ borderRadius: 10, border: `1px solid ${"#D6D8F6"}` }}
|
||||
>
|
||||
<DatePicker
|
||||
styles={{}}
|
||||
type="range"
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
@@ -160,6 +176,16 @@ export default function AddDetailTaskProject() {
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} pb={100}>
|
||||
<TextInput
|
||||
styles={{
|
||||
@@ -201,6 +227,15 @@ export default function AddDetailTaskProject() {
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<ModalAddDetailTaskProject
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}}
|
||||
/>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menambahkan tugas?"
|
||||
|
||||
157
src/module/project/ui/add_report_project.tsx
Normal file
157
src/module/project/ui/add_report_project.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
import { getDatesInRange } from "@/lib/getDatesInRange";
|
||||
import { LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { ActionIcon, Box, Button, Flex, Group, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||
@@ -9,6 +10,7 @@ import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { HiChevronLeft } from "react-icons/hi2";
|
||||
import { NewIFormDateProject } from "../lib/type_project";
|
||||
import { ModalAddDetailTaskProject } from "./modal_add_detail_task_project";
|
||||
|
||||
|
||||
export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boolean) => void, onSet: (val: NewIFormDateProject) => void }) {
|
||||
@@ -16,6 +18,8 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
const [title, setTitle] = useState("")
|
||||
const tema = useHookstate(TEMA)
|
||||
const [acuan, setAcuan] = useState(false)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any[]>([])
|
||||
const [touched, setTouched] = useState({
|
||||
title: false,
|
||||
date: false
|
||||
@@ -28,10 +32,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
if (title == "")
|
||||
return toast.error("Error! harus memasukkan judul tugas")
|
||||
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
|
||||
onSet({
|
||||
dateStart: moment(value[0]).format('YYYY-MM-DD'),
|
||||
dateEnd: moment(value[1]).format('YYYY-MM-DD'),
|
||||
title: title
|
||||
title,
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,8 +82,15 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,6 +161,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} pb={100}>
|
||||
<TextInput
|
||||
styles={{
|
||||
@@ -184,6 +211,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<ModalAddDetailTaskProject
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ export default function CreateProject() {
|
||||
setIndexDelTask(i)
|
||||
setOpenDrawerTask(true)
|
||||
}}>
|
||||
<ResultsDateAndTask dateStart={v.dateStart} dateEnd={v.dateEnd} title={v.title} />
|
||||
<ResultsDateAndTask dateStart={v.dateStart} dateEnd={v.dateEnd} title={v.title} dataDetail={v.dataDetail} />
|
||||
</Box>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client"
|
||||
import { getDatesInRange } from '@/lib/getDatesInRange';
|
||||
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
@@ -11,6 +12,7 @@ import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funEditDetailProject, funGetDetailProject } from '../lib/api_project';
|
||||
import { ModalAddDetailTaskProject } from './modal_add_detail_task_project';
|
||||
|
||||
export default function EditDetailTaskProject() {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
@@ -19,6 +21,8 @@ export default function EditDetailTaskProject() {
|
||||
const param = useParams<{ id: string }>()
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any>([])
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [touched, setTouched] = useState({
|
||||
@@ -40,11 +44,15 @@ export default function EditDetailTaskProject() {
|
||||
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
const res = await funEditDetailProject(param.id, {
|
||||
title: name,
|
||||
dateStart: moment(value[0]).format('YYYY-MM-DD'),
|
||||
dateEnd: moment(value[1]).format('YYYY-MM-DD'),
|
||||
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
@@ -77,6 +85,18 @@ export default function EditDetailTaskProject() {
|
||||
new Date(moment(res.data.dateStart).format('YYYY-MM-DD')),
|
||||
new Date(moment(res.data.dateEnd).format('YYYY-MM-DD')),
|
||||
])
|
||||
|
||||
const res2 = await funGetDetailProject(param.id, 'detailTask');
|
||||
if (res2.data.length == 0) {
|
||||
const datanya = getDatesInRange(new Date(moment(res.data.dateStart).format('YYYY-MM-DD')) , new Date(moment(res.data.dateEnd).format('YYYY-MM-DD')))
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
} else {
|
||||
setDataDetail(res2.data)
|
||||
}
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
@@ -112,8 +132,15 @@ export default function EditDetailTaskProject() {
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,6 +214,16 @@ export default function EditDetailTaskProject() {
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} pb={100}>
|
||||
{loading ?
|
||||
<Skeleton height={40} mt={20} radius={10} />
|
||||
@@ -234,6 +271,17 @@ export default function EditDetailTaskProject() {
|
||||
}
|
||||
</Box>
|
||||
|
||||
|
||||
<ModalAddDetailTaskProject
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}}
|
||||
/>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin mengubah data?"
|
||||
onYes={(val) => {
|
||||
|
||||
231
src/module/project/ui/list_link_detail_project.tsx
Normal file
231
src/module/project/ui/list_link_detail_project.tsx
Normal file
@@ -0,0 +1,231 @@
|
||||
'use client'
|
||||
import { urlCompleted } from '@/lib/urlCompleted';
|
||||
import { globalRole, keyWibu, LayoutDrawer, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Flex, Grid, Group, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { FaTrash } from 'react-icons/fa6';
|
||||
import { LuLink } from 'react-icons/lu';
|
||||
import { RiExternalLinkLine } from 'react-icons/ri';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funDeleteLinkProject, funGetOneProjectById } from '../lib/api_project';
|
||||
import { IDataLinkProject } from '../lib/type_project';
|
||||
import { globalIsMemberProject } from '../lib/val_project';
|
||||
|
||||
export default function ListLinkDetailProject() {
|
||||
const [isData, setData] = useState<IDataLinkProject[]>([])
|
||||
const param = useParams<{ id: string }>()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadingDelete, setLoadingDelete] = useState(false)
|
||||
const [idData, setIdData] = useState('')
|
||||
const [linkData, setLinkData] = useState('')
|
||||
const [openDrawer, setOpenDrawer] = useState(false)
|
||||
const [isOpenModal, setOpenModal] = useState(false)
|
||||
const tema = useHookstate(TEMA)
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const memberProject = useHookstate(globalIsMemberProject)
|
||||
const isMobile = useMediaQuery("(max-width: 350px)");
|
||||
const [reason, setReason] = useState("")
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
async function getOneDataCancel() {
|
||||
try {
|
||||
const res = await funGetOneProjectById(param.id, 'data');
|
||||
if (res.success) {
|
||||
setReason(res.data.reason);
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan data Kegiatan, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneDataCancel();
|
||||
}, [param.id])
|
||||
|
||||
async function getOneData(loading: boolean) {
|
||||
try {
|
||||
setLoading(loading)
|
||||
const res = await funGetOneProjectById(param.id, 'link');
|
||||
if (res.success) {
|
||||
setData(res.data)
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan link kegiatan, coba lagi nanti");
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneData(true);
|
||||
}, [param.id])
|
||||
|
||||
|
||||
async function onDelete() {
|
||||
try {
|
||||
setLoadingDelete(true)
|
||||
const res = await funDeleteLinkProject(param.id, { idLink: idData });
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "project-detail-link",
|
||||
id: param.id,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
getOneData(false)
|
||||
setIdData("")
|
||||
setOpenDrawer(false)
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus link, coba lagi nanti");
|
||||
} finally {
|
||||
setOpenModal(false)
|
||||
setLoadingDelete(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'project-detail-link' && i.id == param.id)) {
|
||||
getOneData(false)
|
||||
} else if (dataRealTime && dataRealTime.some((i: any) => i.category == 'project-detail-status' && i.id == param.id)) {
|
||||
getOneDataCancel()
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
return (
|
||||
<>
|
||||
{
|
||||
isData.length > 0
|
||||
&&
|
||||
<Box pt={20}>
|
||||
<Text fw={'bold'} c={tema.get().utama}>Link</Text>
|
||||
<Box bg={"white"} style={{
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
padding: 20
|
||||
}}>
|
||||
{
|
||||
isData.map((item, index) => {
|
||||
return (
|
||||
<Box
|
||||
key={index}
|
||||
style={{
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
padding: 10
|
||||
}}
|
||||
mb={10}
|
||||
|
||||
onClick={() => {
|
||||
setLinkData(item.link)
|
||||
setIdData(item.id)
|
||||
setOpenDrawer(true)
|
||||
}}
|
||||
>
|
||||
<Grid justify='center' align='center'>
|
||||
<Grid.Col span={{
|
||||
base: 1.5,
|
||||
xs: 1,
|
||||
sm: 1,
|
||||
md: 1,
|
||||
lg: 1,
|
||||
xl: 1,
|
||||
}}>
|
||||
<LuLink size={30} />
|
||||
</Grid.Col>
|
||||
<Grid.Col
|
||||
span={{
|
||||
base: 10.5,
|
||||
xs: 11,
|
||||
sm: 11,
|
||||
md: 11,
|
||||
lg: 11,
|
||||
xl: 11,
|
||||
}}
|
||||
>
|
||||
<Text style={{
|
||||
overflowWrap: "break-word"
|
||||
}} pl={isMobile ? 10 : 0} truncate="end">{item.link}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Group>
|
||||
</Group>
|
||||
</Box>
|
||||
)
|
||||
})
|
||||
}
|
||||
</Box>
|
||||
|
||||
|
||||
<LayoutDrawer opened={openDrawer} title={<Text truncate="end">Menu</Text>} onClose={() => setOpenDrawer(false)}>
|
||||
<Box>
|
||||
<Stack pt={10}>
|
||||
<SimpleGrid cols={{ base: 3, sm: 3, lg: 3 }}>
|
||||
{
|
||||
<Flex onClick={() => { window.open(urlCompleted(linkData), '_blank', 'noopener,noreferrer') }} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<RiExternalLinkLine size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama}>Buka Link</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
|
||||
{
|
||||
(roleLogin.get() == "user" || roleLogin.get() == "coadmin") && !memberProject.get() ? <></>
|
||||
:
|
||||
<Flex onClick={() => {
|
||||
reason == null ?
|
||||
setOpenModal(true)
|
||||
: setOpenModal(false)
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"}>Hapus</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
<LayoutModal loading={loadingDelete} opened={isOpenModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus link ini? Link yang dihapus tidak dapat dikembalikan"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onDelete()
|
||||
} else {
|
||||
setOpenModal(false)
|
||||
}
|
||||
}} />
|
||||
|
||||
</Box>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
82
src/module/project/ui/list_report_project.tsx
Normal file
82
src/module/project/ui/list_report_project.tsx
Normal 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>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
import { globalRole, keyWibu, LayoutDrawer, SkeletonDetailListTugasTask, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Center, Checkbox, Divider, Flex, Grid, Group, SimpleGrid, Stack, Text, Loader } from '@mantine/core';
|
||||
import { Box, Center, Checkbox, Divider, Flex, Grid, Group, Loader, SimpleGrid, Stack, Text } 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 { AiOutlineFileDone, AiOutlineFileSync } from 'react-icons/ai';
|
||||
import { FaCheck, FaPencil, FaTrash } from 'react-icons/fa6';
|
||||
import { IoTimeOutline } from 'react-icons/io5';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funDeleteDetailProject, funGetOneProjectById, funUpdateStatusProject } from '../lib/api_project';
|
||||
import { IDataListTaskProject } from '../lib/type_project';
|
||||
import { globalIsMemberProject, globalRefreshProject, valStatusDetailProject } from '../lib/val_project';
|
||||
import { ModalListDetailTaskProject } from './modal_list_detail_task_project';
|
||||
|
||||
export default function ListTugasDetailProject() {
|
||||
const [isData, setData] = useState<IDataListTaskProject[]>([])
|
||||
@@ -32,6 +34,7 @@ export default function ListTugasDetailProject() {
|
||||
const [loadingStatus, setLoadingStatus] = useState(false)
|
||||
const [pilihStatus, setPilihStatus] = useState(0)
|
||||
const [reason, setReason] = useState("")
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -259,6 +262,15 @@ export default function ListTugasDetailProject() {
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex onClick={() => {setOpenModalDetailTask(true)}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<IoTimeOutline size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama}>Detail Waktu</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex onClick={() => { setOpenModal(true) }} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
@@ -272,6 +284,8 @@ export default function ListTugasDetailProject() {
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
<ModalListDetailTaskProject open={openModalDetailTask} onClose={() => setOpenModalDetailTask(false)} task={idData} />
|
||||
|
||||
<LayoutModal loading={loadingDelete} opened={isOpenModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus tahapan tugas ini?"
|
||||
onYes={(val) => {
|
||||
|
||||
100
src/module/project/ui/modal_add_detail_task_project.tsx
Normal file
100
src/module/project/ui/modal_add_detail_task_project.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import { TEMA } from "@/module/_global";
|
||||
import { Box, Button, Grid, Modal, SimpleGrid, Text } from "@mantine/core";
|
||||
import { TimeInput } from "@mantine/dates";
|
||||
import moment from "moment";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function ModalAddDetailTaskProject({ open, onClose, data, onSubmit }: { open: boolean, onClose: () => void, data: any[], onSubmit: (data: any) => void }) {
|
||||
const [dataDetail, setDataDetail] = useState(data)
|
||||
const [touched, setTouched] = useState<any>([])
|
||||
|
||||
useEffect(() => {
|
||||
setDataDetail(data)
|
||||
}, [data])
|
||||
|
||||
function onInputTime(date: any, value: any, cat: 'timeStart' | 'timeEnd') {
|
||||
if (cat == "timeEnd") {
|
||||
if (value == "" || dataDetail.find((data: any) => data.date == date)?.timeStart > value) {
|
||||
setTouched((touched: any) => [...touched, { date: date, timeEnd: true }])
|
||||
} else {
|
||||
setTouched((touched: any) => touched.filter((item: any) => item.date != date))
|
||||
}
|
||||
} else {
|
||||
if (value == "" || dataDetail.find((data: any) => data.date == date)?.timeEnd < value) {
|
||||
setTouched((touched: any) => [...touched, { date: date, timeEnd: true }])
|
||||
} else {
|
||||
setTouched((touched: any) => touched.filter((item: any) => item.date != date))
|
||||
}
|
||||
}
|
||||
|
||||
setDataDetail(dataDetail.map((data: any) => {
|
||||
if (data.date == date) {
|
||||
return {
|
||||
...data,
|
||||
[cat]: value
|
||||
}
|
||||
}
|
||||
return data
|
||||
}))
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={open} onClose={() => onClose()} centered withCloseButton={false} title={"Detail Tanggal dan Waktu Tugas"}>
|
||||
<Box p={10}>
|
||||
<Box>
|
||||
{
|
||||
dataDetail.map((data: any, index: any) => (
|
||||
<Box key={index} py={10} style={{ borderBottom: `1px solid ${"#D6D8F6"}` }}>
|
||||
<Text fw={"bold"}>{moment(data.date).format('DD-MM-YYYY')}</Text>
|
||||
<SimpleGrid cols={{ base: 2, sm: 2, lg: 2 }}>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Awal"
|
||||
value={data.timeStart}
|
||||
onChange={(event) => onInputTime(data.date, event.target.value, 'timeStart')}
|
||||
/>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Akhir"
|
||||
value={data.timeEnd}
|
||||
onChange={(event) => onInputTime(data.date, event.target.value, 'timeEnd')}
|
||||
error={touched.find((item: any) => item.date == data.date)?.timeEnd ? "Waktu akhir harus lebih dari waktu awal" : ""}
|
||||
/>
|
||||
</SimpleGrid>
|
||||
</Box>
|
||||
))
|
||||
}
|
||||
</Box>
|
||||
<Grid mt={10}>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="light" fullWidth color='#969494' onClick={() => onClose()}>Batalkan</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="light" disabled={touched.length > 0} fullWidth color={TEMA.get().utama} onClick={() => { onSubmit(dataDetail) }}>Simpan</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
99
src/module/project/ui/modal_list_detail_task_project.tsx
Normal file
99
src/module/project/ui/modal_list_detail_task_project.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import { Box, Modal, SimpleGrid, Skeleton, Text } from "@mantine/core";
|
||||
import { TimeInput } from "@mantine/dates";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import moment from "moment";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { funGetDetailProject } from "../lib/api_project";
|
||||
|
||||
export function ModalListDetailTaskProject({ open, onClose, task, }: { open: boolean, onClose: () => void, task: string }) {
|
||||
const [dataDetail, setDataDetail] = useState([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
async function getData() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await funGetDetailProject(task, 'detailTask')
|
||||
if (response.success) {
|
||||
setDataDetail(response.data)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan detail tugas Kegiatan, coba lagi nanti");
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if(task!=""){
|
||||
getData()
|
||||
}
|
||||
}, [task])
|
||||
|
||||
return (
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={open} onClose={() => onClose()} centered withCloseButton={false} title={"Detail Tanggal dan Waktu Tugas"}>
|
||||
<Box p={10}>
|
||||
<Box>
|
||||
{
|
||||
loading ?
|
||||
Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<Box key={i}>
|
||||
<Box>
|
||||
<Skeleton width={"100%"} mb={15} height={30} radius={"md"} />
|
||||
</Box>
|
||||
</Box>
|
||||
))
|
||||
:
|
||||
dataDetail.length > 0 ?
|
||||
dataDetail.map((data: any, index: any) => (
|
||||
<Box key={index} py={10} style={{ borderBottom: `1px solid ${"#D6D8F6"}` }}>
|
||||
<Text fw={"bold"}>{moment(data.date).format('DD-MM-YYYY')}</Text>
|
||||
<SimpleGrid cols={{ base: 2, sm: 2, lg: 2 }}>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Awal"
|
||||
value={data.timeStart}
|
||||
readOnly
|
||||
/>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Akhir"
|
||||
value={data.timeEnd}
|
||||
readOnly
|
||||
/>
|
||||
</SimpleGrid>
|
||||
</Box>
|
||||
))
|
||||
:
|
||||
<Text ta="center" c={"gray"}>Tidak ada detail tugas</Text>
|
||||
}
|
||||
</Box>
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -3,17 +3,19 @@ import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from '@/modu
|
||||
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 { ActionIcon, Box, Button, Flex, Grid, Modal, SimpleGrid, Stack, Text, TextInput } 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 { 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';
|
||||
import { LuLink } from 'react-icons/lu';
|
||||
import { MdCancel } from 'react-icons/md';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funDeleteProject, funGetOneProjectById } from '../lib/api_project';
|
||||
import { funAddLinkProject, funDeleteProject, funGetOneProjectById } from '../lib/api_project';
|
||||
import { globalIsMemberProject } from '../lib/val_project';
|
||||
|
||||
export default function NavbarDetailProject() {
|
||||
@@ -28,7 +30,10 @@ export default function NavbarDetailProject() {
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [openNewLink, setOpenNewLink] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [loadingLink, setLoadingLink] = useState(false)
|
||||
const [valLink, setValLink] = useState("")
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -52,6 +57,30 @@ export default function NavbarDetailProject() {
|
||||
}
|
||||
}
|
||||
|
||||
async function addLinkProject() {
|
||||
try {
|
||||
setLoadingLink(true)
|
||||
const res = await funAddLinkProject(param.id, { link: valLink });
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "project-detail-link",
|
||||
id: param.id,
|
||||
user: res.user
|
||||
}])
|
||||
toast.success(res.message)
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menambahkan link, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingLink(false)
|
||||
setOpenNewLink(false)
|
||||
setValLink("")
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDataProject() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
@@ -110,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
|
||||
@@ -157,6 +186,47 @@ export default function NavbarDetailProject() {
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
if (reason == null) {
|
||||
setOpen(false)
|
||||
setOpenNewLink(true)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<LuLink size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Tambah link</Text>
|
||||
</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") &&
|
||||
<>
|
||||
@@ -229,11 +299,50 @@ export default function NavbarDetailProject() {
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
</LayoutDrawer >
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus kegiatan ini?"
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
|
||||
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={openNewLink} onClose={() => setOpenNewLink(false)} centered withCloseButton={false}>
|
||||
<Box p={20}>
|
||||
<Text ta={"center"} fw={"bold"}>Tambah Link</Text>
|
||||
<Box mt={20} mb={20}>
|
||||
<TextInput
|
||||
styles={{
|
||||
input: {
|
||||
color: tema.get().utama,
|
||||
borderRadius: '#828AFC',
|
||||
borderColor: '#828AFC',
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
radius={10}
|
||||
placeholder="Masukkan link"
|
||||
value={valLink}
|
||||
onChange={(e) => setValLink(e.target.value)}
|
||||
/>
|
||||
</Box>
|
||||
<Grid mt={40}>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="subtle" fullWidth color='#969494' onClick={() => setOpenNewLink(false)}>Batalkan</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button loading={loadingLink} disabled={loadingLink || valLink == "" ? true : false} variant="subtle" fullWidth color={tema.get().utama} onClick={() => { addLinkProject() }}>Tambah</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Modal>
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
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";
|
||||
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";
|
||||
@@ -32,4 +35,7 @@ export { AddDetailTask }
|
||||
export { AddMemberDetailTask }
|
||||
export { CancelTask }
|
||||
export { EditTask }
|
||||
export { AddFileDetailTask }
|
||||
export { AddFileDetailTask }
|
||||
export { ListLinkDetailTask }
|
||||
export { AddReportTask }
|
||||
export { ListReportDetailTask }
|
||||
@@ -44,8 +44,8 @@ export const funUpdateStatusDetailTask = async (path: string, data: { status: nu
|
||||
};
|
||||
|
||||
|
||||
export const funGetDetailTask = async (path: string) => {
|
||||
const response = await fetch(`/api/task/detail/${path}`);
|
||||
export const funGetDetailTask = async (path: string, kat?:string) => {
|
||||
const response = await fetch(`/api/task/detail/${path}${(kat) ? `?cat=${kat}` : ''}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
@@ -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}`, {
|
||||
@@ -154,4 +165,27 @@ export const funDeleteTask = async (path: string) => {
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
};
|
||||
|
||||
export const funAddLinkTask = async (path: string, data: { link: string, idDivision: string }) => {
|
||||
const response = await fetch(`/api/task/${path}/link`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
export const funDeleteLinkTask = async (path: string, data: { idLink: string }) => {
|
||||
const response = await fetch(`/api/task/${path}/link`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -16,14 +16,16 @@ export interface IFormMemberTask {
|
||||
export interface IFormDateTask {
|
||||
dateStart: string,
|
||||
dateEnd: string,
|
||||
title: string
|
||||
title: string,
|
||||
dataDetail: any[]
|
||||
}
|
||||
|
||||
export interface IFormAddDetailTask {
|
||||
dateStart: string,
|
||||
dateEnd: string,
|
||||
title: string
|
||||
idDivision: string
|
||||
idDivision: string,
|
||||
dataDetail: any[]
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +72,9 @@ export interface IDataFileTaskDivision {
|
||||
extension: string,
|
||||
nameInStorage: string,
|
||||
idStorage: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface IDataLinkTaskDivision {
|
||||
id: string
|
||||
link: string
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
import { getDatesInRange } from "@/lib/getDatesInRange";
|
||||
import { keyWibu, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
@@ -11,6 +12,7 @@ import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import { funCreateDetailTask } from "../lib/api_task";
|
||||
import { ModalAddDetailTugasTask } from "./modal_add_detail_tugas_task";
|
||||
|
||||
export default function AddDetailTask() {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
@@ -18,6 +20,8 @@ export default function AddDetailTask() {
|
||||
const [title, setTitle] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any>([])
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const tema = useHookstate(TEMA)
|
||||
const [acuan, setAcuan] = useState(false)
|
||||
@@ -57,11 +61,17 @@ export default function AddDetailTask() {
|
||||
async function onSubmit() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
|
||||
const res = await funCreateDetailTask(param.detail, {
|
||||
title,
|
||||
dateStart: (value[0] != null) ? moment(value[0]).format('YYYY-MM-DD') : moment(new Date).format('YYYY-MM-DD'),
|
||||
dateEnd: (value[1] != null) ? moment(value[1]).format('YYYY-MM-DD') : moment(new Date).format('YYYY-MM-DD'),
|
||||
idDivision: param.id
|
||||
idDivision: param.id,
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
@@ -96,8 +106,15 @@ export default function AddDetailTask() {
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +180,16 @@ export default function AddDetailTask() {
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} pb={100}>
|
||||
<TextInput
|
||||
styles={{
|
||||
@@ -202,6 +229,15 @@ export default function AddDetailTask() {
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<ModalAddDetailTugasTask
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}} />
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menambahkan tugas?"
|
||||
onYes={(val) => {
|
||||
|
||||
156
src/module/task/ui/add_report_detail_task.tsx
Normal file
156
src/module/task/ui/add_report_detail_task.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
import { getDatesInRange } from "@/lib/getDatesInRange";
|
||||
import { LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { ActionIcon, Box, Button, Flex, Group, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||
@@ -9,13 +10,16 @@ import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { HiChevronLeft } from "react-icons/hi2";
|
||||
import { IFormDateTask } from "../lib/type_task";
|
||||
import { ModalAddDetailTugasTask } from "./modal_add_detail_tugas_task";
|
||||
|
||||
|
||||
export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boolean) => void, onSet: (val: IFormDateTask) => void }) {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
const [title, setTitle] = useState("")
|
||||
const [acuan, setAcuan] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any[]>([])
|
||||
const tema = useHookstate(TEMA)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [touched, setTouched] = useState({
|
||||
title: false,
|
||||
date: false
|
||||
@@ -28,10 +32,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
if (title == "")
|
||||
return toast.error("Error! harus memasukkan judul tugas")
|
||||
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
|
||||
onSet({
|
||||
dateStart: moment(value[0]).format('YYYY-MM-DD'),
|
||||
dateEnd: moment(value[1]).format('YYYY-MM-DD'),
|
||||
title: title
|
||||
title: title,
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
|
||||
}
|
||||
@@ -73,8 +83,15 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +162,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} mb={100}>
|
||||
<TextInput
|
||||
styles={{
|
||||
@@ -181,6 +208,16 @@ export default function ViewDateEndTask({ onClose, onSet }: { onClose: (val: boo
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<ModalAddDetailTugasTask
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ export default function CreateTask() {
|
||||
setIndexDelTask(i)
|
||||
setOpenDrawerTask(true)
|
||||
}}>
|
||||
<ResultsDateAndTask dateStart={v.dateStart} dateEnd={v.dateEnd} title={v.title} />
|
||||
<ResultsDateAndTask dateStart={v.dateStart} dateEnd={v.dateEnd} title={v.title} dataDetail={v.dataDetail} />
|
||||
</Box>
|
||||
)
|
||||
})
|
||||
|
||||
230
src/module/task/ui/detail_list_link_task.tsx
Normal file
230
src/module/task/ui/detail_list_link_task.tsx
Normal file
@@ -0,0 +1,230 @@
|
||||
'use client'
|
||||
import { urlCompleted } from '@/lib/urlCompleted';
|
||||
import { globalRole, keyWibu, LayoutDrawer, TEMA } from '@/module/_global';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { globalIsMemberDivision } from '@/module/division_new';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Flex, Grid, Group, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { FaTrash } from 'react-icons/fa6';
|
||||
import { LuLink } from 'react-icons/lu';
|
||||
import { RiExternalLinkLine } from 'react-icons/ri';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funDeleteLinkTask, funGetTaskDivisionById } from '../lib/api_task';
|
||||
import { IDataLinkTaskDivision } from '../lib/type_task';
|
||||
|
||||
export default function ListLinkDetailTask() {
|
||||
const isMobile = useMediaQuery("(max-width: 350px)");
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const memberDivision = useHookstate(globalIsMemberDivision)
|
||||
const [isData, setData] = useState<IDataLinkTaskDivision[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const [openDrawer, setOpenDrawer] = useState(false)
|
||||
const [isOpenModal, setOpenModal] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [linkData, setLinkData] = useState('')
|
||||
const [idData, setIdData] = useState('')
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
|
||||
async function getOneDataCancel() {
|
||||
try {
|
||||
const res = await funGetTaskDivisionById(param.detail, 'data');
|
||||
if (res.success) {
|
||||
setReason(res.data.reason);
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan data tugas divisi, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneDataCancel();
|
||||
}, [param.detail])
|
||||
|
||||
async function getOneData(loading: boolean) {
|
||||
try {
|
||||
setLoading(loading)
|
||||
const res = await funGetTaskDivisionById(param.detail, 'link');
|
||||
if (res.success) {
|
||||
setData(res.data)
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan file tugas divisi, coba lagi nanti");
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneData(true);
|
||||
}, [param.detail])
|
||||
|
||||
|
||||
async function onDelete() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const res = await funDeleteLinkTask(param.detail, { idLink: idData });
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "tugas-detail-link",
|
||||
id: param.detail,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
getOneData(false)
|
||||
setIdData("")
|
||||
setOpenDrawer(false)
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus file, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
setOpenModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-detail-link' && i.id == param.detail)) {
|
||||
getOneData(false)
|
||||
} else if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-detail-status' && i.id == param.detail)) {
|
||||
getOneDataCancel()
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
return (
|
||||
<>
|
||||
{
|
||||
isData.length > 0
|
||||
&&
|
||||
<Box pt={20}>
|
||||
<Text fw={'bold'} c={tema.get().utama}>Link</Text>
|
||||
<Box bg={"white"} style={{
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
padding: 20
|
||||
}}>
|
||||
{
|
||||
isData.map((item, index) => {
|
||||
return (
|
||||
<Box
|
||||
key={index}
|
||||
style={{
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
padding: 10
|
||||
}}
|
||||
mb={10}
|
||||
|
||||
onClick={() => {
|
||||
setLinkData(item.link)
|
||||
setIdData(item.id)
|
||||
setOpenDrawer(true)
|
||||
}}
|
||||
>
|
||||
<Grid justify='center' align='center'>
|
||||
<Grid.Col span={{
|
||||
base: 1.5,
|
||||
xs: 1,
|
||||
sm: 1,
|
||||
md: 1,
|
||||
lg: 1,
|
||||
xl: 1,
|
||||
}}>
|
||||
<LuLink size={30} />
|
||||
</Grid.Col>
|
||||
<Grid.Col
|
||||
span={{
|
||||
base: 10.5,
|
||||
xs: 11,
|
||||
sm: 11,
|
||||
md: 11,
|
||||
lg: 11,
|
||||
xl: 11,
|
||||
}}
|
||||
>
|
||||
<Text style={{
|
||||
overflowWrap: "break-word"
|
||||
}} pl={isMobile ? 10 : 0} truncate="end">{item.link}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Group>
|
||||
</Group>
|
||||
</Box>
|
||||
)
|
||||
})
|
||||
}
|
||||
</Box>
|
||||
|
||||
|
||||
<LayoutDrawer opened={openDrawer} title={<Text truncate="end">Menu</Text>} onClose={() => setOpenDrawer(false)}>
|
||||
<Box>
|
||||
<Stack pt={10}>
|
||||
<SimpleGrid cols={{ base: 3, sm: 3, lg: 3 }}>
|
||||
{
|
||||
<Flex onClick={() => { window.open(urlCompleted(linkData), '_blank', 'noopener,noreferrer') }} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<RiExternalLinkLine size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama}>Buka Link</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
|
||||
{
|
||||
(roleLogin.get() == "user" || roleLogin.get() == "coadmin") && !memberDivision.get() ? <></>
|
||||
:
|
||||
<Flex onClick={() => {
|
||||
reason == null ?
|
||||
setOpenModal(true)
|
||||
: setOpenModal(false)
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"}>Hapus</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={isOpenModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus link ini? Link yang dihapus tidak dapat dikembalikan"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onDelete()
|
||||
} else {
|
||||
setOpenModal(false)
|
||||
}
|
||||
}} />
|
||||
|
||||
</Box>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
83
src/module/task/ui/detail_list_report_task.tsx
Normal file
83
src/module/task/ui/detail_list_report_task.tsx
Normal 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>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
'use client'
|
||||
import { globalRole, keyWibu, LayoutDrawer, SkeletonDetailListTugasTask, TEMA } from "@/module/_global"
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal"
|
||||
import { globalIsMemberDivision } from "@/module/division_new"
|
||||
import { useHookstate } from "@hookstate/core"
|
||||
import { Box, Center, Checkbox, Divider, Flex, Grid, Group, SimpleGrid, Stack, Text, Loader } from "@mantine/core"
|
||||
import { Box, Center, Checkbox, Divider, Flex, Grid, Group, Loader, SimpleGrid, Stack, Text } from "@mantine/core"
|
||||
import { useShallowEffect } from "@mantine/hooks"
|
||||
import "moment/locale/id"
|
||||
import { useParams, useRouter } from "next/navigation"
|
||||
@@ -10,15 +11,17 @@ import { useState } from "react"
|
||||
import toast from "react-hot-toast"
|
||||
import { AiOutlineFileDone, AiOutlineFileSync } from "react-icons/ai"
|
||||
import { FaCheck, FaPencil, FaTrash } from "react-icons/fa6"
|
||||
import { IoTimeOutline } from "react-icons/io5"
|
||||
import { useWibuRealtime } from "wibu-realtime"
|
||||
import { funDeleteDetailTask, funGetTaskDivisionById, funUpdateStatusDetailTask } from "../lib/api_task"
|
||||
import { IDataListTaskDivision } from "../lib/type_task"
|
||||
import { globalRefreshTask, valStatusDetailTask } from "../lib/val_task"
|
||||
import { globalIsMemberDivision } from "@/module/division_new"
|
||||
import { ModalListDetailTugasTask } from "./modal_list_tugas_task"
|
||||
|
||||
export default function ListTugasDetailTask() {
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const memberDivision = useHookstate(globalIsMemberDivision)
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [openDrawer, setOpenDrawer] = useState(false)
|
||||
const [openDrawerStatus, setOpenDrawerStatus] = useState(false)
|
||||
const [isOpenModal, setOpenModal] = useState(false)
|
||||
@@ -268,6 +271,15 @@ export default function ListTugasDetailTask() {
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex onClick={() => { setOpenModalDetailTask(true) }} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<IoTimeOutline size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama}>Detail Waktu</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex onClick={() => { setOpenModal(true) }} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
@@ -281,6 +293,8 @@ export default function ListTugasDetailTask() {
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
<ModalListDetailTugasTask open={openModalDetailTask} onClose={() => setOpenModalDetailTask(false)} task={idData} />
|
||||
|
||||
<LayoutModal loading={loadingHapus} opened={isOpenModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus tugas ini?"
|
||||
onYes={(val) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
import { getDatesInRange } from "@/lib/getDatesInRange";
|
||||
import { LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
@@ -10,11 +11,14 @@ import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { funEditDetailTask, funGetDetailTask } from "../lib/api_task";
|
||||
import { ModalAddDetailTugasTask } from "./modal_add_detail_tugas_task";
|
||||
|
||||
|
||||
export default function EditDetailTask() {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
const router = useRouter()
|
||||
const [openModalDetailTask, setOpenModalDetailTask] = useState(false)
|
||||
const [dataDetail, setDataDetail] = useState<any>([])
|
||||
const [title, setTitle] = useState("")
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
@@ -36,10 +40,15 @@ export default function EditDetailTask() {
|
||||
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const dataDetailFix = dataDetail.map((v: any) => ({
|
||||
...v,
|
||||
date: moment(v.date).format("YYYY-MM-DD"),
|
||||
}))
|
||||
const res = await funEditDetailTask(param.detail, {
|
||||
title: title,
|
||||
dateStart: moment(value[0]).format('YYYY-MM-DD'),
|
||||
dateEnd: moment(value[1]).format('YYYY-MM-DD'),
|
||||
dataDetail: dataDetailFix
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
@@ -69,6 +78,18 @@ export default function EditDetailTask() {
|
||||
new Date(moment(res.data.dateStart).format('YYYY-MM-DD')),
|
||||
new Date(moment(res.data.dateEnd).format('YYYY-MM-DD')),
|
||||
])
|
||||
|
||||
const res2 = await funGetDetailTask(param.detail, 'detailTask');
|
||||
if (res2.data.length == 0) {
|
||||
const datanya = getDatesInRange(new Date(moment(res.data.dateStart).format('YYYY-MM-DD')), new Date(moment(res.data.dateEnd).format('YYYY-MM-DD')))
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
} else {
|
||||
setDataDetail(res2.data)
|
||||
}
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
@@ -104,8 +125,15 @@ export default function EditDetailTask() {
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
setDataDetail([])
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
const datanya = getDatesInRange(value[0]!, value[1]!)
|
||||
setDataDetail(datanya.map((data: any) => ({
|
||||
date: data,
|
||||
timeStart: null,
|
||||
timeEnd: null
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +208,16 @@ export default function EditDetailTask() {
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
|
||||
<Button
|
||||
variant="light"
|
||||
size="compact-md"
|
||||
radius={5}
|
||||
onClick={() => { setOpenModalDetailTask(true) }}
|
||||
mt={5}
|
||||
disabled={value[0] == null || value[1] == null || touched.date}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
<Stack pt={15} pb={100}>
|
||||
{loading ?
|
||||
<Skeleton height={40} mt={20} radius={10} />
|
||||
@@ -229,6 +266,16 @@ export default function EditDetailTask() {
|
||||
}
|
||||
</Box>
|
||||
|
||||
<ModalAddDetailTugasTask
|
||||
open={openModalDetailTask}
|
||||
onClose={() => setOpenModalDetailTask(false)}
|
||||
data={dataDetail}
|
||||
onSubmit={(data) => {
|
||||
setDataDetail(data)
|
||||
setOpenModalDetailTask(false)
|
||||
}}
|
||||
/>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin mengubah data?"
|
||||
onYes={(val) => {
|
||||
|
||||
100
src/module/task/ui/modal_add_detail_tugas_task.tsx
Normal file
100
src/module/task/ui/modal_add_detail_tugas_task.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import { TEMA } from "@/module/_global";
|
||||
import { Box, Button, Grid, Modal, SimpleGrid, Text } from "@mantine/core";
|
||||
import { TimeInput } from "@mantine/dates";
|
||||
import moment from "moment";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function ModalAddDetailTugasTask({ open, onClose, data, onSubmit }: { open: boolean, onClose: () => void, data: any[], onSubmit: (data: any) => void }) {
|
||||
const [dataDetail, setDataDetail] = useState(data)
|
||||
const [touched, setTouched] = useState<any>([])
|
||||
|
||||
useEffect(() => {
|
||||
setDataDetail(data)
|
||||
}, [data])
|
||||
|
||||
function onInputTime(date: any, value: any, cat: 'timeStart' | 'timeEnd') {
|
||||
if (cat == "timeEnd") {
|
||||
if (value == "" || dataDetail.find((data: any) => data.date == date)?.timeStart > value) {
|
||||
setTouched((touched: any) => [...touched, { date: date, timeEnd: true }])
|
||||
} else {
|
||||
setTouched((touched: any) => touched.filter((item: any) => item.date != date))
|
||||
}
|
||||
} else {
|
||||
if (value == "" || dataDetail.find((data: any) => data.date == date)?.timeEnd < value) {
|
||||
setTouched((touched: any) => [...touched, { date: date, timeEnd: true }])
|
||||
} else {
|
||||
setTouched((touched: any) => touched.filter((item: any) => item.date != date))
|
||||
}
|
||||
}
|
||||
|
||||
setDataDetail(dataDetail.map((data: any) => {
|
||||
if (data.date == date) {
|
||||
return {
|
||||
...data,
|
||||
[cat]: value
|
||||
}
|
||||
}
|
||||
return data
|
||||
}))
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={open} onClose={() => onClose()} centered withCloseButton={false} title={"Detail Tanggal dan Waktu Tugas"}>
|
||||
<Box p={10}>
|
||||
<Box>
|
||||
{
|
||||
dataDetail.map((data: any, index: any) => (
|
||||
<Box key={index} py={10} style={{ borderBottom: `1px solid ${"#D6D8F6"}` }}>
|
||||
<Text fw={"bold"}>{moment(data.date).format('DD-MM-YYYY')}</Text>
|
||||
<SimpleGrid cols={{ base: 2, sm: 2, lg: 2 }}>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Awal"
|
||||
value={data.timeStart}
|
||||
onChange={(event) => onInputTime(data.date, event.target.value, 'timeStart')}
|
||||
/>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Akhir"
|
||||
value={data.timeEnd}
|
||||
onChange={(event) => onInputTime(data.date, event.target.value, 'timeEnd')}
|
||||
error={touched.find((item: any) => item.date == data.date)?.timeEnd ? "Waktu akhir harus lebih dari waktu awal" : ""}
|
||||
/>
|
||||
</SimpleGrid>
|
||||
</Box>
|
||||
))
|
||||
}
|
||||
</Box>
|
||||
<Grid mt={10}>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="light" fullWidth color='#969494' onClick={() => onClose()}>Batalkan</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="light" disabled={touched.length > 0} fullWidth color={TEMA.get().utama} onClick={() => { onSubmit(dataDetail) }}>Simpan</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
99
src/module/task/ui/modal_list_tugas_task.tsx
Normal file
99
src/module/task/ui/modal_list_tugas_task.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import { Box, Modal, SimpleGrid, Skeleton, Text } from "@mantine/core";
|
||||
import { TimeInput } from "@mantine/dates";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import moment from "moment";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { funGetDetailTask } from "../lib/api_task";
|
||||
|
||||
export function ModalListDetailTugasTask({ open, onClose, task, }: { open: boolean, onClose: () => void, task: string }) {
|
||||
const [dataDetail, setDataDetail] = useState([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
async function getData() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await funGetDetailTask(task, 'detailTask')
|
||||
if (response.success) {
|
||||
setDataDetail(response.data)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan detail tugas Kegiatan, coba lagi nanti");
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if(task!=""){
|
||||
getData()
|
||||
}
|
||||
}, [task])
|
||||
|
||||
return (
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={open} onClose={() => onClose()} centered withCloseButton={false} title={"Detail Tanggal dan Waktu Tugas"}>
|
||||
<Box p={10}>
|
||||
<Box>
|
||||
{
|
||||
loading ?
|
||||
Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<Box key={i}>
|
||||
<Box>
|
||||
<Skeleton width={"100%"} mb={15} height={30} radius={"md"} />
|
||||
</Box>
|
||||
</Box>
|
||||
))
|
||||
:
|
||||
dataDetail.length > 0 ?
|
||||
dataDetail.map((data: any, index: any) => (
|
||||
<Box key={index} py={10} style={{ borderBottom: `1px solid ${"#D6D8F6"}` }}>
|
||||
<Text fw={"bold"}>{moment(data.date).format('DD-MM-YYYY')}</Text>
|
||||
<SimpleGrid cols={{ base: 2, sm: 2, lg: 2 }}>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Awal"
|
||||
value={data.timeStart}
|
||||
readOnly
|
||||
/>
|
||||
<TimeInput
|
||||
styles={{
|
||||
input: {
|
||||
border: `1px solid ${"#D6D8F6"}`,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
label="Waktu Akhir"
|
||||
value={data.timeEnd}
|
||||
readOnly
|
||||
/>
|
||||
</SimpleGrid>
|
||||
</Box>
|
||||
))
|
||||
:
|
||||
<Text ta="center" c={"gray"}>Tidak ada detail tugas</Text>
|
||||
}
|
||||
</Box>
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
'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 { globalIsAdminDivision, globalIsMemberDivision } from "@/module/division_new";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { ActionIcon, Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { ActionIcon, Box, Button, Flex, Grid, Modal, SimpleGrid, Stack, Text, TextInput } 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 { 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";
|
||||
import { LuLink } from "react-icons/lu";
|
||||
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";
|
||||
import { funAddLinkTask, funDeleteTask, funGetTaskDivisionById } from "../lib/api_task";
|
||||
|
||||
export default function NavbarDetailDivisionTask() {
|
||||
const router = useRouter()
|
||||
@@ -29,6 +31,9 @@ export default function NavbarDetailDivisionTask() {
|
||||
const [isUser, setUser] = useState('')
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [openNewLink, setOpenNewLink] = useState(false)
|
||||
const [valLink, setValLink] = useState("")
|
||||
const [loadingLink, setLoadingLink] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -80,6 +85,29 @@ export default function NavbarDetailDivisionTask() {
|
||||
getOneData();
|
||||
}, [param.detail])
|
||||
|
||||
async function addLinkProject() {
|
||||
try {
|
||||
setLoadingLink(true)
|
||||
const res = await funAddLinkTask(param.detail, { link: valLink, idDivision: param.id });
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "tugas-detail-link",
|
||||
id: param.detail,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menambahkan link, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingLink(false)
|
||||
setOpenNewLink(false)
|
||||
setValLink("")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'tugas-detail' || i.category == 'tugas-detail-status') && i.id == param.detail)) {
|
||||
@@ -111,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
|
||||
@@ -158,6 +186,47 @@ export default function NavbarDetailDivisionTask() {
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
if (reason == null) {
|
||||
setOpen(false)
|
||||
setOpenNewLink(true)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<LuLink size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Tambah link</Text>
|
||||
</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() ?
|
||||
<>
|
||||
@@ -239,7 +308,46 @@ export default function NavbarDetailDivisionTask() {
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus tugas divisi ini?"
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }}
|
||||
/>
|
||||
|
||||
<Modal styles={{
|
||||
body: {
|
||||
borderRadius: 20
|
||||
},
|
||||
content: {
|
||||
borderRadius: 20,
|
||||
border: `2px solid ${"#828AFC"}`
|
||||
}
|
||||
}} opened={openNewLink} onClose={() => setOpenNewLink(false)} centered withCloseButton={false}>
|
||||
<Box p={20}>
|
||||
<Text ta={"center"} fw={"bold"}>Tambah Link</Text>
|
||||
<Box mt={20} mb={20}>
|
||||
<TextInput
|
||||
styles={{
|
||||
input: {
|
||||
color: tema.get().utama,
|
||||
borderRadius: '#828AFC',
|
||||
borderColor: '#828AFC',
|
||||
},
|
||||
}}
|
||||
size="md"
|
||||
radius={10}
|
||||
placeholder="Masukkan link"
|
||||
value={valLink}
|
||||
onChange={(e) => setValLink(e.target.value)}
|
||||
/>
|
||||
</Box>
|
||||
<Grid mt={40}>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="subtle" fullWidth color='#969494' onClick={() => setOpenNewLink(false)}>Batalkan</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button loading={loadingLink} disabled={loadingLink || valLink == "" ? true : false} variant="subtle" fullWidth color={tema.get().utama} onClick={() => { addLinkProject() }}>Tambah</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
}
|
||||
26
xsendMany.ts
26
xsendMany.ts
@@ -22,7 +22,7 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
title,
|
||||
body,
|
||||
},
|
||||
tokens:token,
|
||||
tokens: token,
|
||||
data,
|
||||
android: {
|
||||
priority: "high",
|
||||
@@ -44,18 +44,22 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
},
|
||||
};
|
||||
|
||||
// Kirim pesan
|
||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||
if (response.failureCount > 0) {
|
||||
const failedTokens: any[] = [];
|
||||
response.responses.forEach((resp, idx) => {
|
||||
if (!resp.success) {
|
||||
failedTokens.push(token[idx]);
|
||||
}
|
||||
});
|
||||
const del = await deleteDeviceError({ device: failedTokens });
|
||||
if (token.length > 0) {
|
||||
// Kirim pesan
|
||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||
if (response.failureCount > 0) {
|
||||
const failedTokens: any[] = [];
|
||||
response.responses.forEach((resp, idx) => {
|
||||
if (!resp.success) {
|
||||
failedTokens.push(token[idx]);
|
||||
}
|
||||
});
|
||||
const del = await deleteDeviceError({ device: failedTokens });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return { success: true, message: "Notifikasi berhasil dikirim", };
|
||||
} catch (error) {
|
||||
console.error("Error mengirim notifikasi:", error);
|
||||
|
||||
Reference in New Issue
Block a user