diff --git a/CHANGELOG.md b/CHANGELOG.md index c094971c..c54941f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [1.2.39](https://github.com/bipproduction/hipmi/compare/v1.2.38...v1.2.39) (2025-01-12) + +## [1.2.38](https://github.com/bipproduction/hipmi/compare/v1.2.37...v1.2.38) (2025-01-03) + + +### Bug Fixes + +* user ([215accb](https://github.com/bipproduction/hipmi/commit/215accbcaa989e43f43dfc5f400d5411013f4ef3)) + +## [1.2.37](https://github.com/bipproduction/hipmi/compare/v1.2.36...v1.2.37) (2025-01-02) + ## [1.2.36](https://github.com/bipproduction/hipmi/compare/v1.2.35...v1.2.36) (2024-12-30) ## [1.2.35](https://github.com/bipproduction/hipmi/compare/v1.2.34...v1.2.35) (2024-12-27) diff --git a/bun.lockb b/bun.lockb index d9e86731..8d2a8fec 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 273e1449..ded3f924 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.2.36", + "version": "1.2.39", "private": true, "prisma": { "seed": "npx tsx prisma/seed.ts --yes" @@ -87,6 +87,7 @@ "react-quill": "^2.0.0", "react-responsive-carousel": "^3.2.23", "react-toastify": "^9.1.3", + "sharp": "^0.33.5", "socket.io-client": "^4.7.2", "tailwindcss": "3.3.3", "ts-node": "^10.9.2", diff --git a/prisma/migrations/20250108154615_new_database/migration.sql b/prisma/migrations/20250108154615_new_database/migration.sql new file mode 100644 index 00000000..3476e5af --- /dev/null +++ b/prisma/migrations/20250108154615_new_database/migration.sql @@ -0,0 +1,198 @@ +/* + Warnings: + + - You are about to drop the column `imagesId` on the `Job` table. All the data in the column will be lost. + - You are about to drop the column `active` on the `MasterBank` table. All the data in the column will be lost. + - You are about to drop the column `name` on the `MasterBank` table. All the data in the column will be lost. + - You are about to drop the column `imagesBackgroundId` on the `Profile` table. All the data in the column will be lost. + - You are about to drop the column `imagesId` on the `Profile` table. All the data in the column will be lost. + - You are about to drop the `ImagesBackground` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `namaAkun` to the `MasterBank` table without a default value. This is not possible if the table is not empty. + - Added the required column `namaBank` to the `MasterBank` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE "Job" DROP CONSTRAINT "Job_imagesId_fkey"; + +-- DropForeignKey +ALTER TABLE "Notifikasi" DROP CONSTRAINT "NotifikasiAdmin"; + +-- DropForeignKey +ALTER TABLE "Notifikasi" DROP CONSTRAINT "NotifikasiUser"; + +-- DropForeignKey +ALTER TABLE "Portofolio" DROP CONSTRAINT "Portofolio_logoId_fkey"; + +-- DropForeignKey +ALTER TABLE "Profile" DROP CONSTRAINT "Profile_imagesBackgroundId_fkey"; + +-- DropForeignKey +ALTER TABLE "Profile" DROP CONSTRAINT "Profile_imagesId_fkey"; + +-- DropIndex +DROP INDEX "Profile_imagesBackgroundId_key"; + +-- DropIndex +DROP INDEX "Profile_imagesId_key"; + +-- AlterTable +ALTER TABLE "BeritaInvestasi" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "DokumenInvestasi" ADD COLUMN "fileId" TEXT, +ALTER COLUMN "url" DROP NOT NULL; + +-- AlterTable +ALTER TABLE "Donasi" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Donasi_Cerita" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Donasi_Invoice" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Donasi_Kabar" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Donasi_PencairanDana" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Donasi_TemporaryCreate" ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "Event" ADD COLUMN "isArsip" BOOLEAN DEFAULT false, +ADD COLUMN "tanggalSelesai" TIMESTAMP(3), +ALTER COLUMN "tanggal" DROP NOT NULL; + +-- AlterTable +ALTER TABLE "Event_Peserta" ADD COLUMN "isPresent" BOOLEAN NOT NULL DEFAULT false; + +-- AlterTable +ALTER TABLE "Investasi" ADD COLUMN "imageId" TEXT, +ADD COLUMN "prospektusFileId" TEXT; + +-- AlterTable +ALTER TABLE "Job" DROP COLUMN "imagesId", +ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "MasterBank" DROP COLUMN "active", +DROP COLUMN "name", +ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT true, +ADD COLUMN "namaAkun" TEXT NOT NULL, +ADD COLUMN "namaBank" TEXT NOT NULL; + +-- AlterTable +ALTER TABLE "Notifikasi" ALTER COLUMN "userId" DROP NOT NULL, +ALTER COLUMN "adminId" DROP NOT NULL; + +-- AlterTable +ALTER TABLE "Profile" DROP COLUMN "imagesBackgroundId", +DROP COLUMN "imagesId", +ADD COLUMN "imageBackgroundId" TEXT, +ADD COLUMN "imageId" TEXT; + +-- AlterTable +ALTER TABLE "ProspektusInvestasi" ADD COLUMN "fileId" TEXT, +ADD COLUMN "title" TEXT; + +-- AlterTable +ALTER TABLE "User" ALTER COLUMN "active" SET DEFAULT false; + +-- AlterTable +ALTER TABLE "UserSession" ALTER COLUMN "expires" DROP NOT NULL; + +-- AlterTable +ALTER TABLE "Voting" ADD COLUMN "isArsip" BOOLEAN NOT NULL DEFAULT false; + +-- DropTable +DROP TABLE "ImagesBackground"; + +-- CreateTable +CREATE TABLE "Investasi_Invoice" ( + "id" TEXT NOT NULL, + "isActive" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "nominal" TEXT NOT NULL, + "lembarTerbeli" TEXT NOT NULL, + "investasiId" TEXT, + "masterBankId" TEXT, + "statusInvoiceId" TEXT, + "authorId" TEXT, + "imagesId" TEXT, + "imageId" TEXT, + + CONSTRAINT "Investasi_Invoice_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "InvestasiMaster_StatusInvoice" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "isActive" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "InvestasiMaster_StatusInvoice_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "BusinessMaps" ( + "id" TEXT NOT NULL, + "isActive" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "namePin" TEXT NOT NULL, + "latitude" DOUBLE PRECISION NOT NULL, + "longitude" DOUBLE PRECISION NOT NULL, + "authorId" TEXT, + "portofolioId" TEXT, + "imageId" TEXT, + "pinId" TEXT, + + CONSTRAINT "BusinessMaps_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "MasterKategoriApp" ( + "id" TEXT NOT NULL, + "isActive" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "name" TEXT NOT NULL, + "value" TEXT, + + CONSTRAINT "MasterKategoriApp_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "BusinessMaps_portofolioId_key" ON "BusinessMaps"("portofolioId"); + +-- AddForeignKey +ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_investasiId_fkey" FOREIGN KEY ("investasiId") REFERENCES "Investasi"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_masterBankId_fkey" FOREIGN KEY ("masterBankId") REFERENCES "MasterBank"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_statusInvoiceId_fkey" FOREIGN KEY ("statusInvoiceId") REFERENCES "InvestasiMaster_StatusInvoice"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_imagesId_fkey" FOREIGN KEY ("imagesId") REFERENCES "Images"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Notifikasi" ADD CONSTRAINT "NotifikasiUser" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Notifikasi" ADD CONSTRAINT "NotifikasiAdmin" FOREIGN KEY ("adminId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BusinessMaps" ADD CONSTRAINT "BusinessMaps_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BusinessMaps" ADD CONSTRAINT "BusinessMaps_portofolioId_fkey" FOREIGN KEY ("portofolioId") REFERENCES "Portofolio"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/src/app/(user)/waiting-room/page.tsx b/src/app/(user)/waiting-room/page.tsx index abb6e4d0..8d19813d 100644 --- a/src/app/(user)/waiting-room/page.tsx +++ b/src/app/(user)/waiting-room/page.tsx @@ -1,19 +1,12 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; -import { funGlobal_checkActivationUseById } from "@/app_modules/_global/fun/get/fun_check_activation_use_by_id"; import WaitingRoom_View from "@/app_modules/waiting_room/view"; export default async function Page() { const userLoginId = await funGetUserIdByToken(); - const activationUser = await funGlobal_checkActivationUseById({ - userId: userLoginId as string, - }); return ( <> - + ); } diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index 97c36643..871e8f3f 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -1,5 +1,6 @@ import { prisma } from "@/app/lib"; import { randomOTP } from "@/app_modules/auth/fun/rondom_otp"; +import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { @@ -17,12 +18,13 @@ export async function POST(req: Request) { ); const sendWa = await res.json(); + if (sendWa.status !== "success") return NextResponse.json( { success: false, message: "Nomor Whatsapp Tidak Aktif" }, { status: 400 } ); - + const createOtpId = await prisma.kodeOtp.create({ data: { nomor: nomor, @@ -45,14 +47,14 @@ export async function POST(req: Request) { { status: 200 } ); } catch (error) { - console.log(error); - + backendLogger.log("Error Login", error); return NextResponse.json( - { success: false, message: "Server Whatsapp Error !! " }, + { success: false, message: error as Error }, { status: 500 } ); } } + return NextResponse.json( { success: false, message: "Method Not Allowed" }, { status: 405 } diff --git a/src/app/api/auth/register/route.ts b/src/app/api/auth/register/route.ts index c307d724..53f83014 100644 --- a/src/app/api/auth/register/route.ts +++ b/src/app/api/auth/register/route.ts @@ -1,5 +1,6 @@ import { sessionCreate } from "@/app/auth/_lib/session_create"; import prisma from "@/app/lib/prisma"; +import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { @@ -23,7 +24,7 @@ export async function POST(req: Request) { data: { username: data.username, nomor: data.nomor, - active: true, + active: false, }, }); @@ -38,7 +39,15 @@ export async function POST(req: Request) { { status: 200 } ); } catch (error) { - console.log(error); + backendLogger.log("Error registrasi:", error); + return NextResponse.json( + { + success: false, + message: "Server Error", + reason: (error as Error).message, + }, + { status: 500 } + ); } } diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index 69c64a8c..c8c2e9ea 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -1,5 +1,6 @@ import { sessionCreate } from "@/app/auth/_lib/session_create"; import prisma from "@/app/lib/prisma"; +import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { @@ -42,7 +43,15 @@ export async function POST(req: Request) { { status: 200 } ); } catch (error) { - console.log(error); + backendLogger.log("Error Validasi:", error); + return NextResponse.json( + { + success: false, + message: "Server Error", + reason: (error as Error).message, + }, + { status: 500 } + ); } } return NextResponse.json( diff --git a/src/app/api/collaboration/[id]/route.ts b/src/app/api/collaboration/[id]/route.ts new file mode 100644 index 00000000..3abcd9ce --- /dev/null +++ b/src/app/api/collaboration/[id]/route.ts @@ -0,0 +1,113 @@ +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET( + request: Request, + context: { params: { id: string } } +) { + try { + let fixData; + const { id } = context.params; + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("kategori"); + const page = searchParams.get("page"); + const takeData = 10; + const dataSkip = Number(page) * takeData - takeData; + + // Buatkan api untuk list partisipasi + + const userLoginId = await funGetUserIdByToken(); + + if (userLoginId == null) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, user id tidak ada", + }, + { status: 500 } + ); + } + + if (kategori == "detail") { + fixData = await prisma.projectCollaboration.findFirst({ + where: { + id: id, + }, + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + // jumlah_partisipan: true, + Author: { + select: { + id: true, + Profile: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + isActive: true, + }, + }, + }, + }); + } else if (kategori == "list_partisipan") { + fixData = await prisma.projectCollaboration_Partisipasi.findMany({ + take: takeData, + skip: dataSkip, + where: { + projectCollaborationId: id, + isActive: true, + }, + select: { + id: true, + User: { + select: { + id: true, + Profile: true, + }, + }, + deskripsi_diri: true, + }, + }); + } else if (kategori == "cek_partisipasi") { + const cek = await prisma.projectCollaboration_Partisipasi.findFirst({ + where: { + projectCollaborationId: id, + userId: userLoginId, + }, + }); + + if (cek === null) { + fixData = false; + } else { + fixData = true; + } + } + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get collaboration by id", error); + + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/collaboration/get/route.ts b/src/app/api/collaboration/get/route.ts new file mode 100644 index 00000000..d0e21f1c --- /dev/null +++ b/src/app/api/collaboration/get/route.ts @@ -0,0 +1,176 @@ +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET(request: Request) { + try { + let fixData; + + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("kategori"); + const page = searchParams.get("page"); + + const takeData = 5; + const skipData = page ? Number(page) * takeData - takeData : 0; + + const userLoginId = await funGetUserIdByToken(); + + if (userLoginId == null) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, user id tidak ada", + }, + { status: 500 } + ); + } + + if (kategori == "beranda") { + fixData = await prisma.projectCollaboration.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + projectCollaborationMaster_StatusId: 1, + isActive: true, + }, + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + Author: { + select: { + id: true, + Profile: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + isActive: true, + }, + }, + }, + }); + } else if (kategori == "partisipasi") { + fixData = await prisma.projectCollaboration_Partisipasi.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + userId: userLoginId, + isActive: true, + AND: { + ProjectCollaboration: { + isActive: true, + }, + }, + }, + select: { + id: true, + isActive: true, + ProjectCollaboration: { + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + Author: { + select: { + id: true, + Profile: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + isActive: true, + }, + }, + }, + }, + }, + }); + } else if (kategori == "proyeksaya") { + fixData = await prisma.projectCollaboration.findMany({ + take: takeData, + skip: skipData, + orderBy: { createdAt: "desc" }, + where: { userId: userLoginId, isActive: true }, + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + // jumlah_partisipan: true, + Author: { + select: { + id: true, + Profile: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + isActive: true, + }, + }, + }, + }); + } else if (kategori == "grup") { + fixData = await prisma.projectCollaboration_AnggotaRoomChat.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + userId: userLoginId as string, + }, + select: { + ProjectCollaboration_RoomChat: { + select: { + id: true, + name: true, + isActive: true, + ProjectCollaboration_AnggotaRoomChat: { + select: { + User: true, + }, + }, + }, + }, + }, + }); + } + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get collaboration: ", error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/collaboration/group/[id]/route.ts b/src/app/api/collaboration/group/[id]/route.ts new file mode 100644 index 00000000..83b64866 --- /dev/null +++ b/src/app/api/collaboration/group/[id]/route.ts @@ -0,0 +1,82 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET( + request: Request, + context: { params: { id: string } } +) { + try { + let fixData; + const { id } = context.params; + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("kategori"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + // data room { id, grup_name} + if (kategori == "detail") { + fixData = await prisma.projectCollaboration_RoomChat.findFirst({ + where: { + id: id, + }, + select: { + id: true, + name: true, + }, + }); + } else if (kategori == "info_group") { + fixData = await prisma.projectCollaboration_RoomChat.findFirst({ + where: { + id: id, + }, + select: { + id: true, + name: true, + ProjectCollaboration: { + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + ProjectCollaborationMaster_Industri: true, + }, + }, + ProjectCollaboration_AnggotaRoomChat: { + select: { + User: { + select: { + id: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, + }, + }, + }, + }); + } + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Gagal mendapatkan data", error); + return NextResponse.json( + { success: false, message: "Gagal mendapatkan data" }, + { status: 500 } + ); + } +} diff --git a/src/app/api/get-cookie/route.ts b/src/app/api/get-cookie/route.ts new file mode 100644 index 00000000..8b4959b8 --- /dev/null +++ b/src/app/api/get-cookie/route.ts @@ -0,0 +1,15 @@ +import { cookies } from 'next/headers' +import { NextResponse } from 'next/server'; + +export const dynamic = "force-dynamic"; +export async function GET(request: Request) { + try { + const cookiesKey = process.env.NEXT_PUBLIC_BASE_SESSION_KEY! + const cookieStore = cookies(); + const hipmiKey = cookieStore.get(cookiesKey)?.value || ''; + return NextResponse.json({ token: hipmiKey }); + } catch (error) { + console.error(error); + return NextResponse.json({ error }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/api/image/delete/route.ts b/src/app/api/image/delete/route.ts index a38d0e37..42d360e3 100644 --- a/src/app/api/image/delete/route.ts +++ b/src/app/api/image/delete/route.ts @@ -25,9 +25,7 @@ export async function DELETE(req: Request) { backendLogger.info("Server status code: " + res.status); const data = await res.json(); if (res.ok) { - backendLogger.info( - `Success delete ${keyOfDirectory}` - ); + backendLogger.info(`Success delete ${keyOfDirectory}`); return NextResponse.json({ success: true }); } else { const errorText = await res.json(); diff --git a/src/app/api/image/upload/route.ts b/src/app/api/image/upload/route.ts index a1004088..bf558db0 100644 --- a/src/app/api/image/upload/route.ts +++ b/src/app/api/image/upload/route.ts @@ -1,8 +1,13 @@ import { funGetDirectoryNameByValue } from "@/app_modules/_global/fun/get"; import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; +import sharp from "sharp"; export async function POST(request: Request) { + let fixFormData; const formData = await request.formData(); + const file: any = formData.get("file"); + const mimeType = file.type; + console.log("MIME Type:", mimeType); const valueOfDir = formData.get("dirId"); const keyOfDirectory = await funGetDirectoryNameByValue({ @@ -11,9 +16,33 @@ export async function POST(request: Request) { if (request.method === "POST") { try { + if (mimeType != "application/pdf") { + // Resize ukuran + const imageBuffer = await file.arrayBuffer(); + const resize = await sharp(imageBuffer).resize(2000).toBuffer(); + + // Convert buffer ke Blob + const blob = new Blob([resize], { type: file.type }); + + // Convert Blob ke File + const resizedFile = new File([blob], file.name, { + type: file.type, + lastModified: new Date().getTime(), + }); + + // Buat FormData baru + const newFormData = new FormData(); + newFormData.append("file", resizedFile); + newFormData.append("dirId", formData.get("dirId") as string); + + fixFormData = newFormData; + } else { + fixFormData = formData; + } + const res = await fetch("https://wibu-storage.wibudev.com/api/upload", { method: "POST", - body: formData, + body: fixFormData, headers: { Authorization: `Bearer ${process.env.WS_APIKEY}`, }, diff --git a/src/app/api/new/home/route.ts b/src/app/api/new/home/route.ts index bdb110d8..7ef3a890 100644 --- a/src/app/api/new/home/route.ts +++ b/src/app/api/new/home/route.ts @@ -43,7 +43,7 @@ export async function GET(request: Request) { where: { id: userLoginId, }, - select: { + include: { Profile: { select: { id: true, diff --git a/src/app/api/new/investasi/route.ts b/src/app/api/new/investasi/route.ts index ea13150c..3f7a3592 100644 --- a/src/app/api/new/investasi/route.ts +++ b/src/app/api/new/investasi/route.ts @@ -14,7 +14,8 @@ export async function GET(request: Request) { const kategori = searchParams.get("cat") const status = searchParams.get("status") const page = searchParams.get("page") - const dataSkip = Number(page) * 5 - 5; + const dataTake = 10 + const dataSkip = Number(page) * dataTake - dataTake; if (kategori == "bursa") { const data = await prisma.investasi.findMany({ @@ -61,7 +62,7 @@ export async function GET(request: Request) { // cek data yang lewat // klo ada, update status const dataAwal = await prisma.investasi.findMany({ - take: 5, + take: dataTake, skip: dataSkip, orderBy: [ { @@ -100,28 +101,28 @@ export async function GET(request: Request) { } const data = await prisma.investasi.findMany({ - take: 5, - skip: dataSkip, - orderBy: { - updatedAt: "desc", - }, - where: { - authorId: userLoginId, - masterStatusInvestasiId: status, - }, - select: { - id: true, - title: true, - targetDana: true, - imageId: true, - countDown: true, - updatedAt: true, - MasterPencarianInvestor: { - select: { - name: true - } - } - } + take: dataTake, + skip: dataSkip, + orderBy: { + updatedAt: "desc", + }, + where: { + authorId: userLoginId, + masterStatusInvestasiId: status, + }, + select: { + id: true, + title: true, + targetDana: true, + imageId: true, + countDown: true, + updatedAt: true, + MasterPencarianInvestor: { + select: { + name: true, + }, + }, + }, }); dataFix = data.map((v: any) => ({ diff --git a/src/app/api/new/portofolio/[id]/route.ts b/src/app/api/new/portofolio/[id]/route.ts index 747cabd0..24a7497f 100644 --- a/src/app/api/new/portofolio/[id]/route.ts +++ b/src/app/api/new/portofolio/[id]/route.ts @@ -1,173 +1,234 @@ -import { prisma } from "@/app/lib"; +import { DIRECTORY_ID, prisma } from "@/app/lib"; import { NextResponse } from "next/server"; import fs from "fs"; +import { funGlobal_DeleteFileById } from "@/app_modules/_global/fun"; +import { apiDeleteImageById } from "@/app_modules/_global/lib/api_image"; +import backendLogger from "@/util/backendLogger"; export const dynamic = "force-dynamic"; - - // GET ONE DATA PORTOFOLIO BY ID PORTOFOLIO -export async function GET(request: Request, context: { params: { id: string } }) { - try { - let dataFix - const { id } = context.params; - const { searchParams } = new URL(request.url); - const kategori = searchParams.get('cat'); +export async function GET( + request: Request, + context: { params: { id: string } } +) { + try { + let dataFix; + const { id } = context.params; + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("cat"); - if (kategori == "bisnis") { - const data = await prisma.portofolio.findUnique({ - where: { - id: id, - }, + if (kategori == "bisnis") { + const data = await prisma.portofolio.findUnique({ + where: { + id: id, + }, + select: { + id_Portofolio: true, + namaBisnis: true, + alamatKantor: true, + tlpn: true, + deskripsi: true, + logoId: true, + MasterBidangBisnis: { select: { - id_Portofolio: true, - namaBisnis: true, - alamatKantor: true, - tlpn: true, - deskripsi: true, - logoId: true, - MasterBidangBisnis: { - select: { - name: true - } - }, - Profile: { - select: { - userId: true - } - } - } - }); - - dataFix = { - id_Portofolio: data?.id_Portofolio, - namaBisnis: data?.namaBisnis, - alamatKantor: data?.alamatKantor, - tlpn: data?.tlpn, - deskripsi: data?.deskripsi, - logoId: data?.logoId, - bidangBisnis: data?.MasterBidangBisnis?.name, - authorId: data?.Profile?.userId - } - - } else if (kategori == "lokasi") { - const data = await prisma.portofolio.findUnique({ - where: { - id: id, + name: true, }, + }, + Profile: { select: { - logoId: true, - BusinessMaps: { - select: { - id: true, - namePin: true, - latitude: true, - longitude: true, - imageId: true, - pinId: true - } - } - } - }); - - dataFix = { - mapId: data?.BusinessMaps?.id, - logoId: data?.logoId, - namePin: data?.BusinessMaps?.namePin, - latitude: data?.BusinessMaps?.latitude, - longitude: data?.BusinessMaps?.longitude, - imageId: data?.BusinessMaps?.imageId, - pinId: data?.BusinessMaps?.pinId - } - - } else if (kategori == "sosmed") { - const data = await prisma.portofolio.findUnique({ - where: { - id: id, + userId: true, }, + }, + }, + }); + + dataFix = { + id_Portofolio: data?.id_Portofolio, + namaBisnis: data?.namaBisnis, + alamatKantor: data?.alamatKantor, + tlpn: data?.tlpn, + deskripsi: data?.deskripsi, + logoId: data?.logoId, + bidangBisnis: data?.MasterBidangBisnis?.name, + authorId: data?.Profile?.userId, + }; + } else if (kategori == "lokasi") { + const data = await prisma.portofolio.findUnique({ + where: { + id: id, + }, + select: { + logoId: true, + BusinessMaps: { select: { - Portofolio_MediaSosial: { - select: { - facebook: true, - twitter: true, - instagram: true, - tiktok: true, - youtube: true - } - } - } - }); + id: true, + namePin: true, + latitude: true, + longitude: true, + imageId: true, + pinId: true, + }, + }, + }, + }); - dataFix = { - facebook: data?.Portofolio_MediaSosial?.facebook, - twitter: data?.Portofolio_MediaSosial?.twitter, - instagram: data?.Portofolio_MediaSosial?.instagram, - tiktok: data?.Portofolio_MediaSosial?.tiktok, - youtube: data?.Portofolio_MediaSosial?.youtube - } - } + dataFix = { + mapId: data?.BusinessMaps?.id, + logoId: data?.logoId, + namePin: data?.BusinessMaps?.namePin, + latitude: data?.BusinessMaps?.latitude, + longitude: data?.BusinessMaps?.longitude, + imageId: data?.BusinessMaps?.imageId, + pinId: data?.BusinessMaps?.pinId, + }; + } else if (kategori == "sosmed") { + const data = await prisma.portofolio.findUnique({ + where: { + id: id, + }, + select: { + Portofolio_MediaSosial: { + select: { + facebook: true, + twitter: true, + instagram: true, + tiktok: true, + youtube: true, + }, + }, + }, + }); - return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: dataFix }, { status: 200 }); + dataFix = { + facebook: data?.Portofolio_MediaSosial?.facebook, + twitter: data?.Portofolio_MediaSosial?.twitter, + instagram: data?.Portofolio_MediaSosial?.instagram, + tiktok: data?.Portofolio_MediaSosial?.tiktok, + youtube: data?.Portofolio_MediaSosial?.youtube, + }; + } - } catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); - } + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: dataFix }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, coba lagi nanti (error: 500)", + reason: (error as Error).message, + }, + { status: 500 } + ); + } } // DELETE ONE DATA PORTOFOLIO -export async function DELETE(request: Request, context: { params: { id: string } }) { - try { - const { id } = context.params +export async function DELETE( + request: Request, + context: { params: { id: string } } +) { + try { + const { id } = context.params; - const data = await prisma.portofolio.findUnique({ - where: { - id: id - } - }) + const data = await prisma.portofolio.findUnique({ + where: { + id: id, + }, + include: { + BusinessMaps: { + select: { + pinId: true, + imageId: true, + }, + }, + }, + }); - const findLogo = await prisma.images.findFirst({ - where: { - id: String(data?.logoId), - }, - select: { - id: true, - url: true, - }, - }); + try { + const id = data?.logoId; + const deleteLogo = await fetch( + `https://wibu-storage.wibudev.com/api/files/${id}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); - if (findLogo) { - fs.unlinkSync(`./public/portofolio/logo/${findLogo.url}`) - const deleteLogo = await prisma.images.delete({ - where: { - id: String(findLogo?.id), - }, - }); + if (deleteLogo.ok) { + backendLogger.info(`Success delete logo`); } + if (data?.BusinessMaps?.pinId != null) { + const pinId = data?.BusinessMaps?.pinId; + const deletePin = await fetch( + `https://wibu-storage.wibudev.com/api/files/${pinId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); + if (deletePin.ok) { + backendLogger.info(`Success delete pin`); + } - const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({ - where: { - portofolioId: id, - }, - }); + const imageId = data?.BusinessMaps?.imageId; + const deleteImage = await fetch( + `https://wibu-storage.wibudev.com/api/files/${imageId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); - const deleteMap = await prisma.businessMaps.delete({ - where: { - portofolioId: id - } - }) + if (deleteImage.ok) { + backendLogger.info(`Success delete image`); + } + } + } catch (error) { + backendLogger.error("Error delete logo", error); + } - const deletePortofolio = await prisma.portofolio.delete({ - where: { - id: id, - }, - }); + const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({ + where: { + portofolioId: id, + }, + }); - return NextResponse.json({ success: true, message: "Berhasil menghapus data" }, { status: 200 }); + const deleteMap = await prisma.businessMaps.delete({ + where: { + portofolioId: id, + }, + }); - } catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus data, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); - } -} \ No newline at end of file + const deletePortofolio = await prisma.portofolio.delete({ + where: { + id: id, + }, + }); + + return NextResponse.json( + { success: true, message: "Berhasil menghapus data" }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return NextResponse.json( + { + success: false, + message: "Gagal menghapus data, coba lagi nanti (error: 500)", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/user-validate/route.ts b/src/app/api/user-validate/route.ts new file mode 100644 index 00000000..8842f6f1 --- /dev/null +++ b/src/app/api/user-validate/route.ts @@ -0,0 +1,33 @@ +import { decrypt } from "@/app/auth/_lib/decrypt"; +import { prisma } from "@/app/lib"; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET(req: NextRequest) { + const token = req.headers.get('Authorization')?.split(' ')[1]; + + const decripted = await decrypt({ + token: token!, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY! + }) + + if (!decripted) { + return NextResponse.json({ + success: false, + message: "Unauthorized" + }, { status: 401 }) + } + + const user = await prisma.user.findUnique({ + where: { + id: decripted.id + } + }) + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data", + data: user + }) +} \ No newline at end of file diff --git a/src/app/api/user/activation/route.ts b/src/app/api/user/activation/route.ts new file mode 100644 index 00000000..965e1805 --- /dev/null +++ b/src/app/api/user/activation/route.ts @@ -0,0 +1,53 @@ +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET(request: Request) { + try { + let fixData + const userLoginId = await funGetUserIdByToken(); + + if (userLoginId == null) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, user id tidak ada", + }, + { status: 500 } + ); + } + + const activationUser = await prisma.user.findFirst({ + where: { + id: userLoginId, + }, + select: { + active: true, + }, + }); + + fixData = activationUser?.active + + return NextResponse.json( + { + success: true, + message: "Berhasil mendapatkan data", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get activation user: ", error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/user/get-cookies/route.ts b/src/app/api/user/get-cookies/route.ts new file mode 100644 index 00000000..f59b5fe8 --- /dev/null +++ b/src/app/api/user/get-cookies/route.ts @@ -0,0 +1,24 @@ +import { decrypt } from "@/app/auth/_lib/decrypt"; +import _ from "lodash"; +import { cookies } from "next/headers"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET() { + // const data = await req.text(); + // console.log(data); + const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); + + if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) { + return NextResponse.json({ status: 401, message: "Unauthorized" }); + } + + const token = c.value; + const dataUser = await decrypt({ + token: token, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + }); + + return NextResponse.json({ status: 200, message: "OK", data: dataUser }); +} diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 258227c5..1ae5f208 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -1,11 +1,12 @@ + import { decrypt } from "@/app/auth/_lib/decrypt"; import _ from "lodash"; import { cookies } from "next/headers"; import { NextResponse } from "next/server"; +export const dynamic = "force-dynamic"; + export async function GET() { - // const data = await req.text(); - // console.log(data); const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) { @@ -18,5 +19,7 @@ export async function GET() { encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, }); - return NextResponse.json({ status: 200, message: "OK", data: dataUser }); + const id = dataUser?.id + + return NextResponse.json({ status: 200, message: "OK", data: id }); } diff --git a/src/app/api/validasi/route.ts b/src/app/api/validation/route.ts similarity index 99% rename from src/app/api/validasi/route.ts rename to src/app/api/validation/route.ts index 4562aa95..ba9c6587 100644 --- a/src/app/api/validasi/route.ts +++ b/src/app/api/validation/route.ts @@ -1,9 +1,11 @@ + import { NextResponse } from "next/server"; + export async function GET(req: Request) { const auth = req.headers.get("Authorization"); const token = auth?.split(" ")[1]; if (!token) return NextResponse.json({ success: false }, { status: 401 }); - return NextResponse.json({ success: true }); + return NextResponse.json({ success: true }); } diff --git a/src/app/dev/colab/detail/group/[id]/page.tsx b/src/app/dev/colab/detail/group/[id]/page.tsx index d93ed4f9..ebd48b78 100644 --- a/src/app/dev/colab/detail/group/[id]/page.tsx +++ b/src/app/dev/colab/detail/group/[id]/page.tsx @@ -15,6 +15,8 @@ export default async function Page({ params }: { params: { id: string } }) { "ProjectCollaboration", "ProjectCollaboration_AnggotaRoomChat", ]); + + let listMsg = await colab_getMessageByRoomId({ roomId: roomId, page: 1 }); const dataUserLogin = await user_getOneByUserId(userLoginId as string); diff --git a/src/app/dev/colab/detail/info-grup/[id]/page.tsx b/src/app/dev/colab/detail/info-grup/[id]/page.tsx index 375df71c..d4001193 100644 --- a/src/app/dev/colab/detail/info-grup/[id]/page.tsx +++ b/src/app/dev/colab/detail/info-grup/[id]/page.tsx @@ -1,14 +1,9 @@ -import prisma from "@/app/lib/prisma"; import { Colab_DetailInfoGrup } from "@/app_modules/colab"; -import colab_getListAnggotaByRoomId from "@/app_modules/colab/fun/get/room_chat/get_list_anggota_by_room_id"; - -export default async function Page({ params }: { params: { id: string } }) { - let roomId = params.id; - const dataRoom = await colab_getListAnggotaByRoomId(roomId); +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/colab/detail/main_detail/[id]/page.tsx b/src/app/dev/colab/detail/main_detail/[id]/page.tsx index 9d3958da..5d8311ca 100644 --- a/src/app/dev/colab/detail/main_detail/[id]/page.tsx +++ b/src/app/dev/colab/detail/main_detail/[id]/page.tsx @@ -1,24 +1,13 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Colab_MainDetail } from "@/app_modules/colab"; -import colab_funCekPartisipasiById from "@/app_modules/colab/fun/get/cek_partisipasi_by_user_id"; -import colab_getListPartisipanByColabId from "@/app_modules/colab/fun/get/get_list_partisipan_by_id"; -import colab_getOneCollaborationById from "@/app_modules/colab/fun/get/get_one_by_id"; -export default async function Page({ params }: { params: { id: string } }) { - let colabId = params.id; +export default async function Page() { const userLoginId = await funGetUserIdByToken(); - const dataColab = await colab_getOneCollaborationById(colabId); - const listPartisipan = await colab_getListPartisipanByColabId(colabId); - const cekPartisipan = await colab_funCekPartisipasiById(colabId); - return ( <> ); diff --git a/src/app/dev/colab/detail/proyek/partisipasi/[id]/layout.tsx b/src/app/dev/colab/detail/proyek/partisipasi/[id]/layout.tsx index 2d9fef0e..e7cdc81a 100644 --- a/src/app/dev/colab/detail/proyek/partisipasi/[id]/layout.tsx +++ b/src/app/dev/colab/detail/proyek/partisipasi/[id]/layout.tsx @@ -3,7 +3,9 @@ import { LayoutColab_DetailPartisipasiProyek } from "@/app_modules/colab"; export default async function Layout({ children }: { children: any }) { return ( <> - {children} + + {children} + ); } diff --git a/src/app/dev/colab/detail/proyek/partisipasi/[id]/page.tsx b/src/app/dev/colab/detail/proyek/partisipasi/[id]/page.tsx index 68b18d99..323e5439 100644 --- a/src/app/dev/colab/detail/proyek/partisipasi/[id]/page.tsx +++ b/src/app/dev/colab/detail/proyek/partisipasi/[id]/page.tsx @@ -1,18 +1,9 @@ import { Colab_DetailPartisipasiProyek } from "@/app_modules/colab"; -import colab_getListPartisipanByColabId from "@/app_modules/colab/fun/get/get_list_partisipan_by_id"; -import colab_getOneCollaborationById from "@/app_modules/colab/fun/get/get_one_by_id"; - -export default async function Page({params}: {params: {id: string}}) { - const colabId = params.id - const dataColab = await colab_getOneCollaborationById(colabId) - const listPartisipan = await colab_getListPartisipanByColabId(colabId) +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/colab/detail/proyek/saya/[id]/layout.tsx b/src/app/dev/colab/detail/proyek/saya/[id]/layout.tsx index d7c38cc1..1b84d85b 100644 --- a/src/app/dev/colab/detail/proyek/saya/[id]/layout.tsx +++ b/src/app/dev/colab/detail/proyek/saya/[id]/layout.tsx @@ -3,19 +3,12 @@ import React from "react"; export default async function Layout({ children, - params, }: { children: React.ReactNode; - params: { id: string }; }) { - let colabId = params.id; - - return ( <> - - {children} - + {children} ); } diff --git a/src/app/dev/colab/detail/proyek/saya/[id]/page.tsx b/src/app/dev/colab/detail/proyek/saya/[id]/page.tsx index 2c5d724f..e1527440 100644 --- a/src/app/dev/colab/detail/proyek/saya/[id]/page.tsx +++ b/src/app/dev/colab/detail/proyek/saya/[id]/page.tsx @@ -1,19 +1,9 @@ import { Colab_DetailProyekSaya } from "@/app_modules/colab"; -import colab_getListPartisipanByColabId from "@/app_modules/colab/fun/get/get_list_partisipan_by_id"; -import colab_getOneCollaborationById from "@/app_modules/colab/fun/get/get_one_by_id"; - -export default async function Page({ params }: { params: { id: string } }) { - const colabId = params.id; - const dataColab = await colab_getOneCollaborationById(colabId); - const listPartisipan = await colab_getListPartisipanByColabId(colabId); +export default async function Page() { return ( <> - {/*
{JSON.stringify(listPartisipan, null,2)}
*/} - + ); } diff --git a/src/app/dev/colab/main/beranda/page.tsx b/src/app/dev/colab/main/beranda/page.tsx index c5143fa7..97b20f59 100644 --- a/src/app/dev/colab/main/beranda/page.tsx +++ b/src/app/dev/colab/main/beranda/page.tsx @@ -1,14 +1,12 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Colab_Beranda } from "@/app_modules/colab"; -import colab_getListAllProyek from "@/app_modules/colab/fun/get/get_list_all_proyek"; export default async function Page() { - const listData = await colab_getListAllProyek({ page: 1 }); const userLoginId = await funGetUserIdByToken(); return ( <> - + ); } diff --git a/src/app/dev/colab/main/grup/page.tsx b/src/app/dev/colab/main/grup/page.tsx index 2d9237a9..d6069ea9 100644 --- a/src/app/dev/colab/main/grup/page.tsx +++ b/src/app/dev/colab/main/grup/page.tsx @@ -1,12 +1,10 @@ -import colab_getListRoomChatByAuthorId from "@/app_modules/colab/fun/get/room_chat/get_list_room_by_author_id"; import Colab_GrupDiskus from "@/app_modules/colab/main/grup"; export default async function Page() { - const listRoom = await colab_getListRoomChatByAuthorId({page: 1}); - + // const listRoom = await colab_getListRoomChatByAuthorId({page: 1}); return ( <> - + ); } diff --git a/src/app/dev/colab/main/proyek/page.tsx b/src/app/dev/colab/main/proyek/page.tsx index abb00e7e..9b4e35ee 100644 --- a/src/app/dev/colab/main/proyek/page.tsx +++ b/src/app/dev/colab/main/proyek/page.tsx @@ -1,17 +1,12 @@ import { Colab_Proyek } from "@/app_modules/colab"; -import colab_getListPartisipasiProyekByAuthorId from "@/app_modules/colab/fun/get/pasrtisipan/get_list_partisipasi_proyek_by_author_id"; -import colab_getListAllProyekSayaByAuthorId from "@/app_modules/colab/fun/get/pasrtisipan/get_list_proyek_saya_by_author_id"; export default async function Page() { - const listPartisipasiProyek = await colab_getListPartisipasiProyekByAuthorId({page: 1}) - const listProyekSaya = await colab_getListAllProyekSayaByAuthorId({page: 1}) + // const listPartisipasiProyek = await colab_getListPartisipasiProyekByAuthorId({page: 1}) + // const listProyekSaya = await colab_getListAllProyekSayaByAuthorId({page: 1}) return ( <> - + ); } diff --git a/src/app/dev/donasi/detail/draft/[id]/page.tsx b/src/app/dev/donasi/detail/draft/[id]/page.tsx index f15353f6..c251cc42 100644 --- a/src/app/dev/donasi/detail/draft/[id]/page.tsx +++ b/src/app/dev/donasi/detail/draft/[id]/page.tsx @@ -4,6 +4,7 @@ import { Donasi_getOneById } from "@/app_modules/donasi/fun/get/get_one_donasi_b export default async function Page({ params }: { params: { id: string } }) { const donasiId = params.id const dataDonasi = await Donasi_getOneById(donasiId); + return ( <> diff --git a/src/app/dev/katalog/[id]/layout.tsx b/src/app/dev/katalog/[id]/layout.tsx index 98b718f6..79911004 100644 --- a/src/app/dev/katalog/[id]/layout.tsx +++ b/src/app/dev/katalog/[id]/layout.tsx @@ -1,24 +1,12 @@ +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { LayoutKatalogNew } from "@/app_modules/katalog/main"; -export default async function Layout({ children, params, }: { children: any; params: { id: string } }) { - // const profileId = params.id; - // const dataProfile = await Profile_getOneProfileAndUserById(profileId); - // const authorId = dataProfile?.userId; - - // const userLoginId = await funGetUserIdByToken(); - // const userRoleId = dataProfile?.User?.masterUserRoleId; +export default async function Layout({ children }: { children: any }) { + const userLoginId = await funGetUserIdByToken(); return ( <> - {/* - {children} - */} - {children} + {children} ); } diff --git a/src/app/dev/katalog/[id]/page.tsx b/src/app/dev/katalog/[id]/page.tsx index 98ab33e3..997d4b80 100644 --- a/src/app/dev/katalog/[id]/page.tsx +++ b/src/app/dev/katalog/[id]/page.tsx @@ -1,20 +1,8 @@ import { ViewKatalogNew } from "@/app_modules/katalog"; -export default async function Page({ params }: { params: { id: string } }) { - // let profileId = params.id; - // const userLoginId = await funGetUserIdByToken(); - - // const listPorto = await funGetListPortofolio(profileId); - // const dataProfile = await Profile_getOneProfileAndUserById(profileId); - +export default async function Page() { return ( <> - {/* */} - ); diff --git a/src/app/dev/portofolio/daftar-portofolio/[id]/page.tsx b/src/app/dev/portofolio/daftar-portofolio/[id]/page.tsx index 2252757b..5b2146ad 100644 --- a/src/app/dev/portofolio/daftar-portofolio/[id]/page.tsx +++ b/src/app/dev/portofolio/daftar-portofolio/[id]/page.tsx @@ -1,16 +1,8 @@ import { ListDetailPortofolioNew } from "@/app_modules/katalog/portofolio"; -export default async function Page({ params }: { params: { id: string } }) { - // const profileId = params.id; - // const dataPortofolio = await portofolio_funGetAllDaftarByid({ - // profileId, - // page: 1, - // }); - - +export default async function Page() { return ( <> - {/* */} ); diff --git a/src/app/dev/portofolio/main/[id]/layout.tsx b/src/app/dev/portofolio/main/[id]/layout.tsx index 1be53c84..b6c68e76 100644 --- a/src/app/dev/portofolio/main/[id]/layout.tsx +++ b/src/app/dev/portofolio/main/[id]/layout.tsx @@ -1,20 +1,14 @@ +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { PortofolioLayoutNew } from "@/app_modules/katalog/portofolio"; -export default async function Layout({ children, params, }: { children: any; params: { id: string }; }) { - // let portoId = params.id; - // const getPorto = await portofolio_getOneById(portoId); - // const userLoginId = await funGetUserIdByToken(); +export default async function Layout({ children, }: { children: any; }) { + const userLoginId = await funGetUserIdByToken(); return ( <> - {/* + {children} - */} - {children} + ); } diff --git a/src/app/dev/portofolio/main/[id]/page.tsx b/src/app/dev/portofolio/main/[id]/page.tsx index ab45a811..741c8aff 100644 --- a/src/app/dev/portofolio/main/[id]/page.tsx +++ b/src/app/dev/portofolio/main/[id]/page.tsx @@ -1,19 +1,16 @@ +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Portofolio_UiDetailNew } from "@/app_modules/katalog/portofolio"; const mapboxToken = process.env.MAPBOX_TOKEN!; -export default async function Page({ params }: { params: { id: string } }) { - // const portofolioId = params.id; - // const dataPortofolio = await portofolio_getOneById(portofolioId); - // const userLoginId = await funGetUserIdByToken(); +export default async function Page() { + const userLoginId = await funGetUserIdByToken() return ( <> - {/* */} - + userLoginId={userLoginId} + /> ); } diff --git a/src/app/dev/vote/detail/kontribusi/[id]/page.tsx b/src/app/dev/vote/detail/kontribusi/[id]/page.tsx index d42fc576..06ad3e1d 100644 --- a/src/app/dev/vote/detail/kontribusi/[id]/page.tsx +++ b/src/app/dev/vote/detail/kontribusi/[id]/page.tsx @@ -1,13 +1,9 @@ import { Vote_DetailKontribusi } from "@/app_modules/vote"; -import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id"; - -export default async function Page({ params }: { params: { id: string } }) { - let voteId = params.id; - const dataVote = await voting_funGetOneVotingbyId(voteId); +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/vote/detail/main/[id]/page.tsx b/src/app/dev/vote/detail/main/[id]/page.tsx index 19084182..b26b402a 100644 --- a/src/app/dev/vote/detail/main/[id]/page.tsx +++ b/src/app/dev/vote/detail/main/[id]/page.tsx @@ -2,7 +2,6 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Vote_MainDetail } from "@/app_modules/vote"; export default async function Page({ params }: { params: { id: string } }) { - const voteId = params.id; const userLoginId = await funGetUserIdByToken(); return ( <> diff --git a/src/app/dev/vote/detail/semua_riwayat/[id]/page.tsx b/src/app/dev/vote/detail/semua_riwayat/[id]/page.tsx index 6d943acd..e4637b7d 100644 --- a/src/app/dev/vote/detail/semua_riwayat/[id]/page.tsx +++ b/src/app/dev/vote/detail/semua_riwayat/[id]/page.tsx @@ -1,19 +1,9 @@ import { Vote_DetailSemuaRiwayat } from "@/app_modules/vote"; -import { Vote_getListKontributorById } from "@/app_modules/vote/fun/get/get_list_kontributor_by_id"; -import { Vote_getOnePublishbyId } from "@/app_modules/vote/fun/get/get_one_publish_by_id"; - - -export default async function Page({params}: {params: {id: string}}) { - let voteId = params.id - const dataVote = await Vote_getOnePublishbyId(voteId) - const listKontributor = await Vote_getListKontributorById(voteId) +export default async function Page() { return ( <> - + ); } diff --git a/src/app/lib/global_state.ts b/src/app/lib/global_state.ts index d8792fc0..4efaf286 100644 --- a/src/app/lib/global_state.ts +++ b/src/app/lib/global_state.ts @@ -19,27 +19,30 @@ export type ITypeStatusNotifikasi = | "Menunggu" | "Gagal"; - /** * @param kategoriApp | "JOB", "VOTING", "EVENT", "DONASI", "INVESTASI", "COLLABORATION", "FORUM" * @type string */ export type IRealtimeData = { status?: ITypeStatusNotifikasi; - appId: string; + appId?: string; userId: string; - pesan: string; - title: string; - kategoriApp: + pesan?: string; + title?: string; + kategoriApp?: | "JOB" | "VOTING" | "EVENT" | "DONASI" | "INVESTASI" | "COLLABORATION" - | "FORUM"; + | "FORUM" + | "ACCESS"; // Untuk trigger akses user }; +// Access User +export const gs_access_user = atom(false); + export const gs_realtimeData = atom(null); export const gs_admin_ntf = atom(0); export const gs_user_ntf = atom(0); @@ -63,4 +66,4 @@ export const gs_donasiTriggerBeranda = atom(false); // investasi export const gs_adminInvestasi_triggerReview = atom(false); -export const gs_investasiTriggerBeranda = atom(false); \ No newline at end of file +export const gs_investasiTriggerBeranda = atom(false); diff --git a/src/app/lib/id-derectory.ts b/src/app/lib/id-derectory.ts index dc430470..f2c1303f 100644 --- a/src/app/lib/id-derectory.ts +++ b/src/app/lib/id-derectory.ts @@ -1,6 +1,6 @@ const DIRECTORY_ID = { - profile_foto: "cm0x93rgo000jbp5tj8baoaus", - profile_background: "cm0x93ze8000lbp5t1a8uc9wl", + profile_foto: "cm5ni43ub001pxpug0qw4p11e", + profile_background: "cm5ni4hnq001l12p9gpagxgtv", portofolio_logo: "cm0yjl6ug000310njwmk6j0tx", map_pin: "cm0yjq8up000710njv5klra32", map_image: "cm0yjqnxl000910njplqho07w", diff --git a/src/app/lib/realtime_provider.tsx b/src/app/lib/realtime_provider.tsx index 6ae944d7..d85d0186 100644 --- a/src/app/lib/realtime_provider.tsx +++ b/src/app/lib/realtime_provider.tsx @@ -4,6 +4,7 @@ import { useShallowEffect } from "@mantine/hooks"; import { useAtom } from "jotai"; import { WibuRealtime } from "wibu-pkg"; import { + gs_access_user, gs_admin_ntf, gs_adminDonasi_triggerReview, gs_adminEvent_triggerReview, @@ -31,6 +32,9 @@ export type TypeNotification = { userId?: string; }; +// Tambahkan flag global untuk mencegah inisialisasi ulang +let isWibuRealtimeInitialized = false; + export default function RealtimeProvider({ userId, WIBU_REALTIME_TOKEN, @@ -42,6 +46,9 @@ export default function RealtimeProvider({ const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf); const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf); + // ACCESS USER + const [isAccessUser, setIsAccessUser] = useAtom(gs_access_user); + // JOB const [isTriggerJobBeranda, setIsTriggerJobBeranda] = useAtom(gs_jobTiggerBeranda); @@ -83,152 +90,168 @@ export default function RealtimeProvider({ useShallowEffect(() => { try { - WibuRealtime.init({ - project: "hipmi", - WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN, - onData(data: TypeNotification) { - if ( - data.type == "notification" && - data.pushNotificationTo == "ADMIN" - ) { - setNewAdminNtf((e) => e + 1); - } + if (!isWibuRealtimeInitialized) { + WibuRealtime.init({ + project: "hipmi", + WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN, + onData(data: TypeNotification) { + // Notifikasi ke admin + if ( + data.type == "notification" && + data.pushNotificationTo == "ADMIN" + ) { + setNewAdminNtf((e) => e + 1); + } - // Notifikasi ke semua user , yang datanya di acc admin - if ( - data.type == "notification" && - data.pushNotificationTo == "USER" && - data.dataMessage?.userId == userId - ) { - setNewUserNtf((e) => e + 1); - setDataRealtime(data.dataMessage as any); - } + // trigger access + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "ACCESS" && + data.dataMessage?.userId == userId + ) { + setIsAccessUser(data.dataMessage.status as any); + } - // ---------------------- JOB ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "ADMIN" && - data.dataMessage?.kategoriApp == "JOB" - ) { - setIsAdminJob_TriggerReview(true); - } + // Notifikasi ke semua user , yang datanya di acc admin + if ( + data.type == "notification" && + data.pushNotificationTo == "USER" && + data.dataMessage?.userId == userId + ) { + setNewUserNtf((e) => e + 1); + setDataRealtime(data.dataMessage as any); + } - if ( - data.type == "trigger" && - data.pushNotificationTo == "USER" && - data.dataMessage?.kategoriApp == "JOB" && - data.dataMessage.status == "Publish" - ) { - setIsTriggerJobBeranda(true); - } - // ---------------------- JOB ------------------------- // + // ---------------------- JOB ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "JOB" + ) { + setIsAdminJob_TriggerReview(true); + } - // ---------------------- EVENT ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "ADMIN" && - data.dataMessage?.kategoriApp == "EVENT" - ) { - setIsAdminEvent_TriggerReview(true); - } + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "JOB" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerJobBeranda(true); + } + // ---------------------- JOB ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "USER" && - data.dataMessage?.kategoriApp == "EVENT" && - data.dataMessage.status == "Publish" - ) { - setIsTriggerEventBeranda(true); - } + // ---------------------- EVENT ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "EVENT" + ) { + setIsAdminEvent_TriggerReview(true); + } - if ( - data.type == "notification" && - data.pushNotificationTo == "USER" && - data.dataMessage?.status == "Peserta Event" && - userId !== data.dataMessage?.userId - ) { - setNewUserNtf((e) => e + 1); - } - // ---------------------- EVENT ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "EVENT" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerEventBeranda(true); + } - // ---------------------- VOTING ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "ADMIN" && - data.dataMessage?.kategoriApp == "VOTING" - ) { - setIsAdminVoting_TriggerReview(true); - } + if ( + data.type == "notification" && + data.pushNotificationTo == "USER" && + data.dataMessage?.status == "Peserta Event" && + userId !== data.dataMessage?.userId + ) { + setNewUserNtf((e) => e + 1); + } + // ---------------------- EVENT ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "USER" && - data.dataMessage?.kategoriApp == "VOTING" && - data.dataMessage.status == "Publish" - ) { - setIsTriggerVotingBeranda(true); - } + // ---------------------- VOTING ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "VOTING" + ) { + setIsAdminVoting_TriggerReview(true); + } - if ( - data.type == "notification" && - data.pushNotificationTo == "USER" && - data.dataMessage?.status == "Voting Masuk" && - userId !== data.dataMessage?.userId - ) { - setNewUserNtf((e) => e + 1); - } - // ---------------------- VOTING ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "VOTING" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerVotingBeranda(true); + } - // ---------------------- DONASI ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "ADMIN" && - data.dataMessage?.kategoriApp == "DONASI" - ) { - setIsAdminDonasi_TriggerReview(true); - } + if ( + data.type == "notification" && + data.pushNotificationTo == "USER" && + data.dataMessage?.status == "Voting Masuk" && + userId !== data.dataMessage?.userId + ) { + setNewUserNtf((e) => e + 1); + } + // ---------------------- VOTING ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "USER" && - data.dataMessage?.kategoriApp == "DONASI" && - data.dataMessage.status == "Publish" - ) { - setIsTriggerDonasiBeranda(true); - } + // ---------------------- DONASI ------------------------- // + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "DONASI" + ) { + setIsAdminDonasi_TriggerReview(true); + } - // if ( - // data.type == "notification" && - // data.pushNotificationTo == "ADMIN" && - // data.dataMessage?.status == "Menunggu" && - // userId !== data.dataMessage?.userId - // ) { + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "DONASI" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerDonasiBeranda(true); + } - // } - // ---------------------- DONASI ------------------------- // + // if ( + // data.type == "notification" && + // data.pushNotificationTo == "ADMIN" && + // data.dataMessage?.status == "Menunggu" && + // userId !== data.dataMessage?.userId + // ) { - // ---------------------- INVESTASI ------------------------- // + // } + // ---------------------- DONASI ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "ADMIN" && - data.dataMessage?.kategoriApp == "INVESTASI" - ) { - setIsAdminInvestasi_TriggerReview(true); - } + // ---------------------- INVESTASI ------------------------- // - if ( - data.type == "trigger" && - data.pushNotificationTo == "USER" && - data.dataMessage?.kategoriApp == "INVESTASI" && - data.dataMessage.status == "Publish" - ) { - setIsTriggerInvestasiBeranda(true); - } + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "INVESTASI" + ) { + setIsAdminInvestasi_TriggerReview(true); + } - // ---------------------- INVESTASI ------------------------- // - }, - }); + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "INVESTASI" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerInvestasiBeranda(true); + } + + // ---------------------- INVESTASI ------------------------- // + }, + }); + + // Tandai bahwa WibuRealtime telah diinisialisasi + isWibuRealtimeInitialized = true; + } } catch (error) { console.log("Error Realtime:", error); } diff --git a/src/app/lib/router_hipmi/router_investasi.ts b/src/app/lib/router_hipmi/router_investasi.ts index 7d185e12..6eec841f 100644 --- a/src/app/lib/router_hipmi/router_investasi.ts +++ b/src/app/lib/router_hipmi/router_investasi.ts @@ -8,8 +8,8 @@ export const NEW_RouterInvestasi = { * @param param status id | 1: Publish, 2: Review, 3: Draft, 4: Reject * @type string */ - portofolio: ({ id }: { id: "1" | "2" | "3" | "4" }) => - `/dev/investasi/main/portofolio/${id}`, + portofolio: ({ id }: { id: "1" | "2" | "3" | "4" }) => `/dev/investasi/main/portofolio/${id}`, + // portofolio: ({ id }: { id?: string }) => `/dev/investasi/main/portofolio/${id}`, // TRANSAKSI pembelian: "/dev/investasi/transaksi/pembelian/", diff --git a/src/app/zCoba/skeleton/page.tsx b/src/app/zCoba/skeleton/page.tsx index a25e6542..a5b62d10 100644 --- a/src/app/zCoba/skeleton/page.tsx +++ b/src/app/zCoba/skeleton/page.tsx @@ -5,7 +5,8 @@ import { UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, } from "@/app_modules/_global/ui"; -import { Center, Grid, Group, Skeleton, Stack } from "@mantine/core"; +import { Button, Grid, Skeleton, Stack } from "@mantine/core"; +import Link from "next/link"; export default function Voting_ComponentSkeletonViewPuh() { return ( @@ -13,8 +14,44 @@ export default function Voting_ComponentSkeletonViewPuh() { } > + + + + + + {Array.from(new Array(2)).map((e, i) => ( + + + + + + + + + ))} + + + + {/* @@ -23,12 +60,35 @@ export default function Voting_ComponentSkeletonViewPuh() { - - + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
-
+ */} {/* diff --git a/src/app/zCoba/upload/fun_upload.ts b/src/app/zCoba/upload/fun_upload.ts new file mode 100644 index 00000000..baa3e4e2 --- /dev/null +++ b/src/app/zCoba/upload/fun_upload.ts @@ -0,0 +1,52 @@ +"use server"; + +import _ from "lodash"; +// import { v4 } from "uuid"; +import fs from "fs"; +import sharp from "sharp"; + +export default async function fun_upload({ + file, + dirId, +}: { + file: File; + dirId: string; +}) { + // const file: any = formData.get("file"); + // const fName = file.name; + // const fileSize = file.size; + + // // Convert ke KB + // const fileSizeInKB = fileSize / 1024; + + // // Convert ke MB + // const fileSizeInMB = fileSize / (1024 * 1024); + + // console.log(`Ukuran file dalam bytes: ${fileSize}`); + // console.log(`Ukuran file dalam KB: ${fileSizeInKB.toFixed(2)} KB`); + // console.log(`Ukuran file dalam MB: ${fileSizeInMB.toFixed(2)} MB`); + + const imageBuffer = await file.arrayBuffer(); + const resize = await sharp(imageBuffer).resize(2000).toBuffer(); + + const newFile = Buffer.from(resize); + console.log("file new",newFile); + // fs.writeFileSync(`./public/upload/${fName}`, upFolder as any); + + const formData = new FormData(); + formData.append("file", file); + formData.append("dirId", dirId); + + // const upload = await fetch("/api/image/upload", { + // method: "POST", + // body: formData, + // }); + + // const res = await upload.json(); + + // if (upload.ok) { + // return { success: true, data: res.data, message: res.message }; + // } else { + // return { success: false, data: {}, message: res.message }; + // } +} diff --git a/src/app/zCoba/upload/page.tsx b/src/app/zCoba/upload/page.tsx new file mode 100644 index 00000000..26b6bfdc --- /dev/null +++ b/src/app/zCoba/upload/page.tsx @@ -0,0 +1,137 @@ +"use client"; + +import { MainColor } from "@/app_modules/_global/color"; +import { ComponentGlobal_BoxUploadImage } from "@/app_modules/_global/component"; +import { MAX_SIZE } from "@/app_modules/_global/lib"; +import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; +import { + UIGlobal_LayoutHeaderTamplate, + UIGlobal_LayoutTamplate, +} from "@/app_modules/_global/ui"; +import { clientLogger } from "@/util/clientLogger"; +import { + AspectRatio, + Button, + Center, + FileButton, + Image, + Stack, +} from "@mantine/core"; +import { IconImageInPicture, IconUpload } from "@tabler/icons-react"; +import { useState } from "react"; +import fun_upload from "./fun_upload"; +import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; + +export default function Page() { + return ( + <> + } + > + + + + ); +} + +function Upload() { + const [file, setFile] = useState(null); + const [image, setImage] = useState(null); + const [isLoading, setLoading] = useState(false); + + async function onUpload() { + if (!file) return alert("File Kosong"); + try { + setLoading(true); + const formData = new FormData(); + formData.append("file", file as File); + + const uploadPhoto = await funGlobal_UploadToStorage({ + file: file, + dirId: "cm5ohsepe002bq4nlxeejhg7q", + }); + + if (uploadPhoto.success) { + setLoading(false); + alert("berhasil upload"); + console.log("uploadPhoto", uploadPhoto); + } else { + setLoading(false); + console.log("gagal upload", uploadPhoto); + } + } catch (error) { + console.error("Error upload img:", error); + } + } + + return ( + <> + + + {image ? ( + + Avatar + + ) : ( +
+ +
+ )} +
+ +
+ { + try { + const buffer = URL.createObjectURL( + new Blob([new Uint8Array(await files.arrayBuffer())]) + ); + + // if (files.size > MAX_SIZE) { + // ComponentGlobal_NotifikasiPeringatan( + // PemberitahuanMaksimalFile + // ); + // return; + // } else { + + // } + + console.log("ini buffer", buffer); + + setFile(files); + setImage(buffer); + } catch (error) { + clientLogger.error("Upload error:", error); + } + }} + accept="image/png,image/jpeg" + > + {(props) => ( + + )} + +
+ + +
+ + ); +} diff --git a/src/app_modules/_global/button/comp_button_upload_photo.tsx b/src/app_modules/_global/button/comp_button_upload_photo.tsx index 378e7126..fa1185d0 100644 --- a/src/app_modules/_global/button/comp_button_upload_photo.tsx +++ b/src/app_modules/_global/button/comp_button_upload_photo.tsx @@ -1,12 +1,10 @@ "use client"; +import { clientLogger } from "@/util/clientLogger"; import { Button, FileButton } from "@mantine/core"; import { IconCamera } from "@tabler/icons-react"; +import { useState } from "react"; import { MainColor } from "../color"; -import { MAX_SIZE } from "../lib"; -import { PemberitahuanMaksimalFile } from "../lib/max_size"; -import { ComponentGlobal_NotifikasiPeringatan } from "../notif_global"; -import { clientLogger } from "@/util/clientLogger"; export function ComponentGlobal_ButtonUploadFileImage({ onSetFile, @@ -15,22 +13,27 @@ export function ComponentGlobal_ButtonUploadFileImage({ onSetFile: File | any; onSetImage: any | null; }) { + const [isLoading, setIsLoading] = useState(false); + return ( { try { + setIsLoading(true); const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); - if (files.size > MAX_SIZE) { - ComponentGlobal_NotifikasiPeringatan(PemberitahuanMaksimalFile); - return; - } else { - onSetFile(files); - onSetImage(buffer); - } + // if (files.size > MAX_SIZE) { + // ComponentGlobal_NotifikasiPeringatan(PemberitahuanMaksimalFile); + // return; + // } else { + // } + onSetFile(files); + onSetImage(buffer); + setIsLoading(false); } catch (error) { + setIsLoading(false); clientLogger.error("Upload error:", error); } }} @@ -39,6 +42,8 @@ export function ComponentGlobal_ButtonUploadFileImage({ {(props) => ( ) : (
+
+ )} + + {_.isEmpty(data) ? ( + + +
+ Partispasi User ({data?.length}) +
+ +
+
+ ) : ( + + +
+ Partispasi User ({data?.length}) +
{" "} + + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={async () => { + const respone = await apiGetOneCollaborationById({ + id: params.id, + kategori: "list_partisipan", + page: `${activePage + 1}`, + }); + + setActivePage((val) => val + 1); + + return respone.data; + }} + > + {(item) => ( + + )} +
+
+
+
+ )} +
+ - - +