From b829daf5254db3c4faf5db5eaf55a2ecb02bf066 Mon Sep 17 00:00:00 2001 From: amel Date: Mon, 2 Sep 2024 14:01:27 +0800 Subject: [PATCH 1/4] upd: task divisi Deskripsi: - tambah file pada detail task divisi No Issues --- src/app/api/task/[id]/route.ts | 8 +++++++- src/app/api/task/file/[id]/route.ts | 7 +++---- src/app/api/task/route.ts | 2 +- src/module/task/lib/type_task.ts | 1 + src/module/task/ui/add_file_detail_task.tsx | 19 ++++++++++++------- .../task/ui/detail_list_anggota_task.tsx | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/api/task/[id]/route.ts b/src/app/api/task/[id]/route.ts index b68849f..54c312c 100644 --- a/src/app/api/task/[id]/route.ts +++ b/src/app/api/task/[id]/route.ts @@ -112,7 +112,12 @@ export async function GET(request: Request, context: { params: { id: string } }) User: { select: { name: true, - email: true + email: true, + Position: { + select: { + name: true + } + } } } } @@ -123,6 +128,7 @@ export async function GET(request: Request, context: { params: { id: string } }) ..._.omit(v, ["User"]), name: v.User.name, email: v.User.email, + position: v.User.Position.name })) allData = fix diff --git a/src/app/api/task/file/[id]/route.ts b/src/app/api/task/file/[id]/route.ts index 73eebbd..0998ba0 100644 --- a/src/app/api/task/file/[id]/route.ts +++ b/src/app/api/task/file/[id]/route.ts @@ -116,8 +116,8 @@ export async function POST(request: Request, context: { params: { id: string } } for (var pair of body.entries()) { if (String(pair[0]) == "file" + a) { const file = body.get(pair[0]) as File - const fName = file.name.split(".")[0] const fExt = file.name.split(".").pop() + const fName = file.name.replace("." + fExt, "") const insertToContainer = await prisma.containerFileDivision.create({ @@ -218,14 +218,13 @@ export async function PUT(request: Request, context: { params: { id: string } }) file: v.ContainerFileDivision.name + '.' + v.ContainerFileDivision.extension, })) - const cek = dataOmit.some((i: any) => i.file == fileName) if (cek) { - return NextResponse.json({ success: true, message: "Cek berhasil" }, { status: 200 }); - } else { return NextResponse.json({ success: false, message: "File sudah pernah diupload" }, { status: 400 }); + } else { + return NextResponse.json({ success: true, message: "Cek berhasil" }, { status: 200 }); } } catch (error) { diff --git a/src/app/api/task/route.ts b/src/app/api/task/route.ts index af82503..2e27cc6 100644 --- a/src/app/api/task/route.ts +++ b/src/app/api/task/route.ts @@ -157,8 +157,8 @@ export async function POST(request: Request) { for (var pair of body.entries()) { if (String(pair[0]) == "file" + a) { const file = body.get(pair[0]) as File - const fName = file.name.split(".")[0] const fExt = file.name.split(".").pop() + const fName = file.name.replace("." + fExt, "") const insertToContainer = await prisma.containerFileDivision.create({ diff --git a/src/module/task/lib/type_task.ts b/src/module/task/lib/type_task.ts index 6c89dce..3226642 100644 --- a/src/module/task/lib/type_task.ts +++ b/src/module/task/lib/type_task.ts @@ -60,6 +60,7 @@ export interface IDataMemberTaskDivision { idUser: string name: string email: string + position: string } export interface IDataFileTaskDivision { diff --git a/src/module/task/ui/add_file_detail_task.tsx b/src/module/task/ui/add_file_detail_task.tsx index bbbe383..54d9076 100644 --- a/src/module/task/ui/add_file_detail_task.tsx +++ b/src/module/task/ui/add_file_detail_task.tsx @@ -20,11 +20,11 @@ import { IListFileTask } from "../lib/type_task"; import ResultsFile from "./results_file"; import { FaTrash } from "react-icons/fa6"; import { funAddFileTask, funCekNamFileUploadTask } from "../lib/api_task"; +import LayoutModal from "@/module/_global/layout/layout_modal"; export default function AddFileDetailTask() { const router = useRouter() - const [title, setTitle] = useState("") const [openModal, setOpenModal] = useState(false) const [fileForm, setFileForm] = useState([]) const [listFile, setListFile] = useState([]) @@ -139,8 +139,6 @@ export default function AddFileDetailTask() { } - - { - if ( - title !== "" - ) { + if (fileForm.length > 0) { setOpenModal(true) } else { - toast.error("Semua form harus diisi") + toast.error("Silahkan pilih file yang akan diupload") } }}> Simpan @@ -184,6 +180,15 @@ export default function AddFileDetailTask() { + setOpenModal(false)} + description="Apakah Anda yakin ingin menambahkan file?" + onYes={(val) => { + if (val) { + onSubmit() + } + setOpenModal(false) + }} /> + ); } diff --git a/src/module/task/ui/detail_list_anggota_task.tsx b/src/module/task/ui/detail_list_anggota_task.tsx index 9ddba9f..e452549 100644 --- a/src/module/task/ui/detail_list_anggota_task.tsx +++ b/src/module/task/ui/detail_list_anggota_task.tsx @@ -108,7 +108,7 @@ export default function ListAnggotaDetailTask() { {v.name} - {v.email} + {v.position} From 65b3d61b49650dcaf164b2148f651619169af319 Mon Sep 17 00:00:00 2001 From: amel Date: Mon, 2 Sep 2024 14:10:36 +0800 Subject: [PATCH 2/4] fix:home Deskripsi: - fix tanggal, salah manggil nama field No Issues --- src/app/api/home/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/home/route.ts b/src/app/api/home/route.ts index 69b0864..3b00121 100644 --- a/src/app/api/home/route.ts +++ b/src/app/api/home/route.ts @@ -70,7 +70,7 @@ export async function GET(request: Request) { allData = data.map((v: any) => ({ ..._.omit(v, ["ProjectTask", "createdAt"]), progress: ceil((v.ProjectTask.filter((i: any) => i.status == 1).length * 100) / v.ProjectTask.length), - createdAt: moment(v.dateStart).format("LL") + createdAt: moment(v.createdAt).format("LL") })) } else if (kategori == "division") { From 9ee3e0a2ffe93586f118dae9d32a7d608e593619 Mon Sep 17 00:00:00 2001 From: amel Date: Mon, 2 Sep 2024 14:39:52 +0800 Subject: [PATCH 3/4] upd: project Deskripsi: - upload file pada project No Issues --- src/app/(application)/project/create/page.tsx | 4 +- src/app/api/project/route.ts | 56 ++++++++++++------- src/module/project/lib/api_project.ts | 10 +--- src/module/project/ui/create_project.tsx | 36 ++++++------ .../project/ui/create_users_project.tsx | 4 +- src/module/user/lib/type_user.ts | 1 + 6 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/app/(application)/project/create/page.tsx b/src/app/(application)/project/create/page.tsx index 3aac089..e571503 100644 --- a/src/app/(application)/project/create/page.tsx +++ b/src/app/(application)/project/create/page.tsx @@ -3,8 +3,8 @@ import React from "react"; function Page({ searchParams }: { searchParams: any }) { - if (searchParams.page == "file-save") - return + // if (searchParams.page == "file-save") + // return return ; } diff --git a/src/app/api/project/route.ts b/src/app/api/project/route.ts index 75a7af2..6eb8346 100644 --- a/src/app/api/project/route.ts +++ b/src/app/api/project/route.ts @@ -3,7 +3,8 @@ import { funGetUserByCookies } from "@/module/auth"; import _ from "lodash"; import moment from "moment"; import { NextResponse } from "next/server"; - +import path from "path"; +import fs from "fs"; // GET ALL DATA PROJECT @@ -80,7 +81,11 @@ export async function POST(request: Request) { return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); } - const { idGroup, title, task, member, file } = (await request.json()) + const body = await request.formData() + const dataBody = body.get("data") + const cekFile = body.has("file0") + + const { idGroup, title, task, member } = JSON.parse(dataBody as string) const userId = user.id @@ -112,7 +117,7 @@ export async function POST(request: Request) { if (member.length > 0) { const dataMember = member.map((v: any) => ({ - ..._.omit(v, ["idUser", "name"]), + ..._.omit(v, ["idUser", "name", "img"]), idProject: data.id, idUser: v.idUser, })) @@ -122,27 +127,36 @@ export async function POST(request: Request) { }) } - let fileFix: any[] = [] + if (cekFile) { + let a = 0 + const root = path.join(process.cwd(), "./public/file/project/"); + for (var pair of body.entries()) { + if (String(pair[0]) == "file" + a) { + const file = body.get(pair[0]) as File + const fExt = file.name.split(".").pop() + const fName = file.name.replace("." + fExt, "") - if (file.length > 0) { - file.map((v: any, index: any) => { - const f: any = file[index].get('file') - const fName = f.name - const fExt = fName.split(".").pop() - const dataFile = { - name: fName, - extension: fExt, - idProject: data.id, + const insertToTable = await prisma.projectFile.create({ + data: { + idProject: data.id, + name: fName, + extension: String(fExt) + }, + select: { + id: true + } + }) + + const nameFix = insertToTable.id + '.' + fExt + const filePath = path.join(root, nameFix) + // Konversi ArrayBuffer ke Buffer + const buffer = Buffer.from(await file.arrayBuffer()); + // Tulis file ke sistem + fs.writeFileSync(filePath, buffer); } - - fileFix.push(dataFile) - }) - - const insertFile = await prisma.divisionProjectFile.createMany({ - data: fileFix - }) - + a++ + } } diff --git a/src/module/project/lib/api_project.ts b/src/module/project/lib/api_project.ts index f02bea5..8f82bf1 100644 --- a/src/module/project/lib/api_project.ts +++ b/src/module/project/lib/api_project.ts @@ -6,16 +6,10 @@ export const funGetAllProject = async (path?: string) => { return await response.json().catch(() => null); } -export const funCreateProject = async (data: IFormProject) => { - if (data.title.length < 3) - return { success: false, message: 'Nama Kegiatan minimal 3 karakter' } - +export const funCreateProject = async (data: FormData) => { const response = await fetch(`/api/project`, { method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), + body: data, }); return await response.json().catch(() => null); } diff --git a/src/module/project/ui/create_project.tsx b/src/module/project/ui/create_project.tsx index bd4ad38..a40ab93 100644 --- a/src/module/project/ui/create_project.tsx +++ b/src/module/project/ui/create_project.tsx @@ -36,7 +36,7 @@ export default function CreateProject() { const [openTugas, setOpenTugas] = useState(false) const [dataTask, setDataTask] = useState([]) const openRef = useRef<() => void>(null) - const [fileForm, setFileForm] = useState([]) + const [fileForm, setFileForm] = useState([]) const [listFile, setListFile] = useState([]) const [indexDelFile, setIndexDelFile] = useState(0) const [indexDelTask, setIndexDelTask] = useState(0) @@ -91,16 +91,22 @@ export default function CreateProject() { async function onSubmit() { try { - const response = await funCreateProject({ title: body.title, idGroup: body.idGroup, task: dataTask, file: fileForm, member: memberValue }) + const fd = new FormData(); + for (let i = 0; i < fileForm.length; i++) { + fd.append(`file${i}`, fileForm[i]); + } + + fd.append("data", JSON.stringify({ + title: body.title, + idGroup: body.idGroup, + task: dataTask, + member: memberValue + })) + + const response = await funCreateProject(fd) if (response.success) { toast.success(response.message) - // setBody({ - // idGroup: "", - // title: "", - // desc: "", - // }) - member.set([]) setFileForm([]) setListFile([]) @@ -111,7 +117,7 @@ export default function CreateProject() { } } catch (error) { console.log(error) - toast.error("Gagal menambahkan tugas divisi, coba lagi nanti"); + toast.error("Gagal menambahkan kegiatan, coba lagi nanti"); } } @@ -289,7 +295,7 @@ export default function CreateProject() { key={i} > - + {v.name} @@ -342,15 +348,13 @@ export default function CreateProject() { onClose={() => setOpenDrawer(false)} title={"Pilih File"} > - + { if (!files || _.isEmpty(files)) return toast.error('Tidak ada file yang dipilih') - const fd = new FormData(); - fd.append("file", files[0]); - setFileForm([...fileForm, fd]) + setFileForm([...fileForm, files[0]]) setListFile([...listFile, { name: files[0].name, extension: files[0].type.split("/")[1] }]) }} activateOnClick={false} @@ -379,7 +383,7 @@ export default function CreateProject() { diperangkat - router.push("/project/create?page=file-save")}> + {/* router.push("/project/create?page=file-save")}> sudah ada - + */} diff --git a/src/module/project/ui/create_users_project.tsx b/src/module/project/ui/create_users_project.tsx index 32bf50d..b673d9d 100644 --- a/src/module/project/ui/create_users_project.tsx +++ b/src/module/project/ui/create_users_project.tsx @@ -24,7 +24,7 @@ export default function CreateUsersProject({ grup, onClose }: { grup?: string, o if (selectedFiles.some((i: any) => i.idUser == dataMember[index].id)) { setSelectedFiles(selectedFiles.filter((i: any) => i.idUser != dataMember[index].id)) } else { - setSelectedFiles([...selectedFiles, { idUser: dataMember[index].id, name: dataMember[index].name }]) + setSelectedFiles([...selectedFiles, { idUser: dataMember[index].id, name: dataMember[index].name, img: dataMember[index].img }]) } }; @@ -114,7 +114,7 @@ export default function CreateUsersProject({ grup, onClose }: { grup?: string, o onClick={() => handleFileClick(index)} >
- +
{v.name} diff --git a/src/module/user/lib/type_user.ts b/src/module/user/lib/type_user.ts index 0b94cec..d9f1081 100644 --- a/src/module/user/lib/type_user.ts +++ b/src/module/user/lib/type_user.ts @@ -5,6 +5,7 @@ export type TypeUser = { phone: string email: string gender: string + img:string isActive: boolean, group: string, position: string From 132227ae80c116f4ac5c93b7adfb7a1e50481164 Mon Sep 17 00:00:00 2001 From: amel Date: Mon, 2 Sep 2024 15:34:51 +0800 Subject: [PATCH 4/4] upd: kegiatan atau project Deskripsi: - hapus file dan tambah file NO Issues --- .../project/[id]/add-file/page.tsx | 9 + src/app/api/project/[id]/route.ts | 10 +- src/app/api/project/file/[id]/route.ts | 203 ++++++++++++++++++ src/app/api/task/[id]/route.ts | 2 + src/module/project/index.ts | 4 +- src/module/project/lib/api_project.ts | 29 ++- src/module/project/lib/type_project.ts | 2 + .../project/ui/add_file_detail_project.tsx | 195 +++++++++++++++++ .../ui/list_anggota_detail_project.tsx | 2 +- .../project/ui/list_file_detail_project.tsx | 83 ++++++- .../project/ui/navbar_detail_project.tsx | 25 ++- src/module/task/lib/type_task.ts | 1 + .../task/ui/detail_list_anggota_task.tsx | 4 +- 13 files changed, 553 insertions(+), 16 deletions(-) create mode 100644 src/app/(application)/project/[id]/add-file/page.tsx create mode 100644 src/app/api/project/file/[id]/route.ts create mode 100644 src/module/project/ui/add_file_detail_project.tsx diff --git a/src/app/(application)/project/[id]/add-file/page.tsx b/src/app/(application)/project/[id]/add-file/page.tsx new file mode 100644 index 0000000..7286e51 --- /dev/null +++ b/src/app/(application)/project/[id]/add-file/page.tsx @@ -0,0 +1,9 @@ +import { AddFileDetailProject } from "@/module/project"; + +export default function Page() { + return ( + <> + + + ) +} \ No newline at end of file diff --git a/src/app/api/project/[id]/route.ts b/src/app/api/project/[id]/route.ts index f08b29f..ffd6e94 100644 --- a/src/app/api/project/[id]/route.ts +++ b/src/app/api/project/[id]/route.ts @@ -108,7 +108,13 @@ export async function GET(request: Request, context: { params: { id: string } }) User: { select: { name: true, - email: true + email: true, + img: true, + Position: { + select: { + name: true + } + } } } } @@ -118,6 +124,8 @@ export async function GET(request: Request, context: { params: { id: string } }) ..._.omit(v, ["User"]), name: v.User.name, email: v.User.email, + img: v.User.img, + position: v.User.Position.name })) allData = fix diff --git a/src/app/api/project/file/[id]/route.ts b/src/app/api/project/file/[id]/route.ts new file mode 100644 index 0000000..4eba164 --- /dev/null +++ b/src/app/api/project/file/[id]/route.ts @@ -0,0 +1,203 @@ +import { prisma } from "@/module/_global"; +import { funGetUserByCookies } from "@/module/auth"; +import { NextResponse } from "next/server"; +import fs from "fs"; +import path from "path"; +import _ from "lodash"; + +// HAPUS FILE PROJECT BUKAN PAKE ISACTIVE +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 { id } = context.params; + const data = await prisma.projectFile.count({ + where: { + id: id, + }, + }); + + if (data == 0) { + return NextResponse.json( + { + success: false, + message: "Hapus file gagal, data tidak ditemukan", + }, + { status: 404 } + ); + } + + const dataRelasi = await prisma.projectFile.findUnique({ + where: { + id: id, + } + }) + + + fs.unlink(`./public/file/project/${dataRelasi?.id}.${dataRelasi?.extension}`, (err) => { }) + + const deleteRelasi = await prisma.projectFile.delete({ + where: { + id: id, + }, + }); + + + return NextResponse.json( + { + success: true, + message: "File berhasil dihapus", + data, + }, + { status: 200 } + ); + + } catch (error) { + console.log(error); + return NextResponse.json({ success: false, message: "Gagal menghapus file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + } +} + + +// CEK FILE PROJECT APAKAH PERNAH DIUPLOAD PADA PROJECT YG SAMA +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 body = await request.formData() + const file = body.get("file") as File + const fileName = file.name + + const dataCek = await prisma.project.count({ + where: { + id: id, + }, + }); + + if (dataCek == 0) { + return NextResponse.json( + { + success: false, + message: "Upload file gagal, data kegiatan tidak ditemukan", + }, + { status: 404 } + ); + } + + const dataTaskFile = await prisma.projectFile.findMany({ + where: { + idProject: id, + isActive: true + }, + select: { + id: true, + name: true, + extension: true + } + }) + + const dataOmit = dataTaskFile.map((v: any) => ({ + ..._.omit(v, [""]), + file: v.name + '.' + v.extension, + })) + + const cek = dataOmit.some((i: any) => i.file == fileName) + + + if (cek) { + return NextResponse.json({ success: false, message: "File sudah pernah diupload" }, { status: 400 }); + } else { + return NextResponse.json({ success: true, message: "Cek berhasil" }, { status: 200 }); + } + + } catch (error) { + console.log(error); + return NextResponse.json({ success: false, message: "Upload file gagal, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + } +} + + +// TAMBAH FILE 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 body = await request.formData() + const cekFile = body.has("file0") + + const dataCek = await prisma.project.count({ + where: { + id: id, + }, + }); + + if (dataCek == 0) { + return NextResponse.json( + { + success: false, + message: "Tambah file kegiatan gagal, data tugas tidak ditemukan", + }, + { status: 404 } + ); + } + + const dataProject = await prisma.project.findUnique({ + where: { + id: id, + }, + }); + + + + if (cekFile) { + let a = 0 + const root = path.join(process.cwd(), "./public/file/project/"); + for (var pair of body.entries()) { + if (String(pair[0]) == "file" + a) { + const file = body.get(pair[0]) as File + const fExt = file.name.split(".").pop() + const fName = file.name.replace("." + fExt, "") + + + const insertToTable = await prisma.projectFile.create({ + data: { + idProject: id, + name: fName, + extension: String(fExt) + }, + select: { + id: true + } + }) + + const nameFix = insertToTable.id + '.' + fExt + const filePath = path.join(root, nameFix) + // Konversi ArrayBuffer ke Buffer + const buffer = Buffer.from(await file.arrayBuffer()); + // Tulis file ke sistem + fs.writeFileSync(filePath, buffer); + } + a++ + } + } + + + return NextResponse.json({ success: true, message: "Berhasil mengupload file kegiatan" }, { status: 200 }); + + } catch (error) { + console.log(error); + return NextResponse.json({ success: false, message: "Gagal mengupload file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/api/task/[id]/route.ts b/src/app/api/task/[id]/route.ts index 54c312c..bcfa2f5 100644 --- a/src/app/api/task/[id]/route.ts +++ b/src/app/api/task/[id]/route.ts @@ -113,6 +113,7 @@ export async function GET(request: Request, context: { params: { id: string } }) select: { name: true, email: true, + img: true, Position: { select: { name: true @@ -128,6 +129,7 @@ export async function GET(request: Request, context: { params: { id: string } }) ..._.omit(v, ["User"]), name: v.User.name, email: v.User.email, + img: v.User.img, position: v.User.Position.name })) diff --git a/src/module/project/index.ts b/src/module/project/index.ts index da4b362..8ea7aa8 100644 --- a/src/module/project/index.ts +++ b/src/module/project/index.ts @@ -21,6 +21,7 @@ import AddDetailTaskProject from "./ui/add_detail_task_project"; import CancelProject from "./ui/cancel_project"; import AddMemberDetailProject from "./ui/add_member_detail_project"; import CreateProject from "./ui/create_project"; +import AddFileDetailProject from "./ui/add_file_detail_project"; export { ViewProject } export { ViewDateEndTask } @@ -43,4 +44,5 @@ export { EditDetailTaskProject } export { AddDetailTaskProject } export { CancelProject } export { AddMemberDetailProject } -export { CreateProject } \ No newline at end of file +export { CreateProject } +export { AddFileDetailProject } \ No newline at end of file diff --git a/src/module/project/lib/api_project.ts b/src/module/project/lib/api_project.ts index 8f82bf1..2c18ad4 100644 --- a/src/module/project/lib/api_project.ts +++ b/src/module/project/lib/api_project.ts @@ -120,4 +120,31 @@ export const funEditProject = async (path: string, data: { name: string }) => { body: JSON.stringify(data), }); return await response.json().catch(() => null); -} \ No newline at end of file +} + + +export const funDeleteFileProject = async (path: string) => { + const response = await fetch(`/api/project/file/${path}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }); + return await response.json().catch(() => null); +}; + +export const funCekNamFileUploadProject = async (path: string, data: FormData) => { + const response = await fetch(`/api/project/file/${path}`, { + method: "PUT", + body: data, + }); + return await response.json().catch(() => null); +}; + +export const funAddFileProject = async (path: string, data: FormData) => { + const response = await fetch(`/api/project/file/${path}`, { + method: "POST", + body: data, + }); + return await response.json().catch(() => null); +}; diff --git a/src/module/project/lib/type_project.ts b/src/module/project/lib/type_project.ts index 8eedbc8..a309ff6 100644 --- a/src/module/project/lib/type_project.ts +++ b/src/module/project/lib/type_project.ts @@ -26,6 +26,8 @@ export interface IDataMemberProject { idUser: string name: string email: string + img: string + position: string } export interface IFormProject { diff --git a/src/module/project/ui/add_file_detail_project.tsx b/src/module/project/ui/add_file_detail_project.tsx new file mode 100644 index 0000000..b40e6fe --- /dev/null +++ b/src/module/project/ui/add_file_detail_project.tsx @@ -0,0 +1,195 @@ +"use client"; +import { LayoutDrawer, LayoutNavbarNew, WARNA } from "@/module/_global"; +import { + Box, + Button, + Flex, + Group, + rem, + SimpleGrid, + Stack, + Text, +} from "@mantine/core"; +import React, { useRef, useState } from "react"; +import { useParams, useRouter } from "next/navigation"; +import toast from "react-hot-toast"; +import { IoIosArrowDropright } from "react-icons/io"; +import { Dropzone } from "@mantine/dropzone"; +import _ from "lodash"; +import ResultsFile from "./results_file"; +import { FaTrash } from "react-icons/fa6"; +import LayoutModal from "@/module/_global/layout/layout_modal"; +import { IListFileTaskProject } from "../lib/type_project"; +import { funAddFileProject, funCekNamFileUploadProject } from "../lib/api_project"; + + +export default function AddFileDetailProject() { + const router = useRouter() + const [openModal, setOpenModal] = useState(false) + const [fileForm, setFileForm] = useState([]) + const [listFile, setListFile] = useState([]) + const param = useParams<{ id: string }>() + const [indexDelFile, setIndexDelFile] = useState(0) + const [openDrawerFile, setOpenDrawerFile] = useState(false) + const openRef = useRef<() => void>(null) + + function deleteFile(index: number) { + setListFile([...listFile.filter((val, i) => i !== index)]) + setFileForm([...fileForm.filter((val, i) => i !== index)]) + setOpenDrawerFile(false) + } + + + async function cekFileName(data: any) { + try { + const fd = new FormData(); + fd.append(`file`, data); + const res = await funCekNamFileUploadProject(param.id, fd) + if (res.success) { + setFileForm([...fileForm, data]) + setListFile([...listFile, { name: data.name, extension: data.type.split("/")[1] }]) + } else { + toast.error(res.message) + } + } catch (error) { + console.log(error) + toast.error("Gagal menambahkan file, coba lagi nanti") + } + } + + async function onSubmit() { + try { + const fd = new FormData(); + for (let i = 0; i < fileForm.length; i++) { + fd.append(`file${i}`, fileForm[i]); + } + + const response = await funAddFileProject(param.id, fd) + console.group(response) + if (response.success) { + toast.success(response.message) + setFileForm([]) + setListFile([]) + router.push(`/project/${param.id}`) + } else { + toast.error(response.message) + } + } catch (error) { + console.log(error) + toast.error("Gagal menambahkan file, coba lagi nanti"); + } + } + + + + return ( + + + + + + { + if (!files || _.isEmpty(files)) + return toast.error('Tidak ada file yang dipilih') + cekFileName(files[0]) + }} + activateOnClick={false} + maxSize={3 * 1024 ** 2} + accept={['text/csv', 'image/png', 'image/jpeg', 'image/heic', 'application/pdf']} + onReject={(files) => { + return toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf dengan ukuran maksimal 3 MB') + }} + > + + openRef.current?.()} + > + Upload File + + + + { + listFile.length > 0 && + + File + + { + listFile.map((v, i) => { + return ( + { + setIndexDelFile(i) + setOpenDrawerFile(true) + }}> + + + ) + }) + } + + + } + + + + + + setOpenDrawerFile(false)} + title={""} + > + + + deleteFile(indexDelFile)}> + + + + + Hapus File + + + + + + + setOpenModal(false)} + description="Apakah Anda yakin ingin menambahkan file?" + onYes={(val) => { + if (val) { + onSubmit() + } + setOpenModal(false) + }} /> + + + ); +} diff --git a/src/module/project/ui/list_anggota_detail_project.tsx b/src/module/project/ui/list_anggota_detail_project.tsx index 24878fc..18c0852 100644 --- a/src/module/project/ui/list_anggota_detail_project.tsx +++ b/src/module/project/ui/list_anggota_detail_project.tsx @@ -100,7 +100,7 @@ export default function ListAnggotaDetailProject() { }} > - + {v.name} diff --git a/src/module/project/ui/list_file_detail_project.tsx b/src/module/project/ui/list_file_detail_project.tsx index c1f2bc3..b247f66 100644 --- a/src/module/project/ui/list_file_detail_project.tsx +++ b/src/module/project/ui/list_file_detail_project.tsx @@ -1,18 +1,24 @@ 'use client' -import { WARNA } from '@/module/_global'; -import { Box, Group, Skeleton, Text } from '@mantine/core'; +import { LayoutDrawer, WARNA } from '@/module/_global'; +import { Box, Flex, Group, SimpleGrid, Skeleton, Stack, Text } from '@mantine/core'; import React, { useState } from 'react'; import toast from 'react-hot-toast'; -import { funGetOneProjectById } from '../lib/api_project'; +import { funDeleteFileProject, funGetOneProjectById } from '../lib/api_project'; import { useParams } from 'next/navigation'; import { useShallowEffect } from '@mantine/hooks'; import { IDataFileProject } from '../lib/type_project'; -import { BsFiletypeCsv, BsFiletypeHeic, BsFiletypeJpg, BsFiletypePdf, BsFiletypePng } from 'react-icons/bs'; +import { BsFileTextFill, BsFiletypeCsv, BsFiletypeHeic, BsFiletypeJpg, BsFiletypePdf, BsFiletypePng } from 'react-icons/bs'; +import LayoutModal from '@/module/_global/layout/layout_modal'; +import { FaTrash } from 'react-icons/fa6'; export default function ListFileDetailProject() { const [isData, setData] = useState([]) const param = useParams<{ id: string }>() const [loading, setLoading] = useState(true) + const [idData, setIdData] = useState('') + const [nameData, setNameData] = useState('') + const [openDrawer, setOpenDrawer] = useState(false) + const [isOpenModal, setOpenModal] = useState(false) async function getOneData() { try { @@ -26,7 +32,7 @@ export default function ListFileDetailProject() { } catch (error) { console.error(error); - toast.error("Gagal mendapatkan file Kegiatan, coba lagi nanti"); + toast.error("Gagal mendapatkan file kegiatan, coba lagi nanti"); } finally { setLoading(false) } @@ -36,6 +42,25 @@ export default function ListFileDetailProject() { getOneData(); }, [param.id]) + + async function onDelete() { + try { + const res = await funDeleteFileProject(idData); + if (res.success) { + toast.success(res.message) + getOneData() + setIdData("") + setOpenDrawer(false) + } else { + toast.error(res.message); + } + } catch (error) { + console.error(error); + toast.error("Gagal menghapus file, coba lagi nanti"); + } + + } + return ( <> @@ -70,6 +95,12 @@ export default function ListFileDetailProject() { padding: 10 }} mb={10} + + onClick={() => { + setNameData(item.name + '.' + item.extension) + setIdData(item.id) + setOpenDrawer(true) + }} > {item.extension == "pdf" && } @@ -77,13 +108,53 @@ export default function ListFileDetailProject() { {item.extension == "png" && } {item.extension == "jpg" || item.extension == "jpeg" && } {item.extension == "heic" && } - {item.name} + {item.name + '.' + item.extension} ) }) } + + + + setOpenDrawer(false)}> + + + + { }} justify={'center'} align={'center'} direction={'column'} > + + + + + Lihat file + + + + { setOpenModal(true) }} justify={'center'} align={'center'} direction={'column'} > + + + + + Hapus file + + + + + + + + + setOpenModal(false)} + description="Apakah Anda yakin ingin menghapus file ini? File yang dihapus tidak dapat dikembalikan" + onYes={(val) => { + if (val) { + onDelete() + } + setOpenModal(false) + }} />
); diff --git a/src/module/project/ui/navbar_detail_project.tsx b/src/module/project/ui/navbar_detail_project.tsx index 5bbbce6..6c5b2c5 100644 --- a/src/module/project/ui/navbar_detail_project.tsx +++ b/src/module/project/ui/navbar_detail_project.tsx @@ -4,7 +4,7 @@ import { ActionIcon, Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core'; import { useParams, useRouter } from 'next/navigation'; import React, { useState } from 'react'; import toast from 'react-hot-toast'; -import { FaPencil, FaUsers } from 'react-icons/fa6'; +import { FaFileCirclePlus, FaPencil, FaUsers } from 'react-icons/fa6'; import { HiMenu } from 'react-icons/hi'; import { IoAddCircle } from 'react-icons/io5'; import { MdCancel } from 'react-icons/md'; @@ -93,13 +93,15 @@ export default function NavbarDetailProject() { style={{ cursor: 'pointer' }} - onClick={() => { router.push(param.id + '/cancel') }} + onClick={() => { + router.push(param.id + '/add-file') + }} > - + - Batal + Tambah file @@ -116,6 +118,21 @@ export default function NavbarDetailProject() { Edit + + { router.push(param.id + '/cancel') }} + > + + + + + Batal + + + diff --git a/src/module/task/lib/type_task.ts b/src/module/task/lib/type_task.ts index 3226642..8202e05 100644 --- a/src/module/task/lib/type_task.ts +++ b/src/module/task/lib/type_task.ts @@ -60,6 +60,7 @@ export interface IDataMemberTaskDivision { idUser: string name: string email: string + img: string position: string } diff --git a/src/module/task/ui/detail_list_anggota_task.tsx b/src/module/task/ui/detail_list_anggota_task.tsx index e452549..e0f5cc8 100644 --- a/src/module/task/ui/detail_list_anggota_task.tsx +++ b/src/module/task/ui/detail_list_anggota_task.tsx @@ -102,13 +102,13 @@ export default function ListAnggotaDetailTask() { }} > - + {v.name} - {v.position} + {v.email}