From 51105a24c8f64fb9da11234fdd1985dde8c2e915 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 4 Feb 2025 11:10:10 +0800 Subject: [PATCH 1/9] fix home deskripsi: - pemanggilan api di rapikan --- ...2026a78b8cb786880c7c733460d7dbe-audit.json | 5 + ...c6075347623def466341a14f8ba4a12-audit.json | 5 + logs/backend/combined-2025-02-03.log | 1 + logs/backend/combined-2025-02-04.log | 0 logs/backend/error-2025-02-04.log | 0 src/app/api/new/home/route.ts | 125 +++++++------ src/app_modules/home/component/body_home.tsx | 58 ++---- .../home/component/footer_home.tsx | 171 +++++++----------- src/app_modules/home/view_home_new.tsx | 106 ++++++----- 9 files changed, 225 insertions(+), 246 deletions(-) create mode 100644 logs/backend/combined-2025-02-04.log create mode 100644 logs/backend/error-2025-02-04.log diff --git a/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json b/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json index c36243a8..66eedd43 100644 --- a/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json +++ b/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json @@ -54,6 +54,11 @@ "date": 1738549408639, "name": "logs/backend/combined-2025-02-03.log", "hash": "f3f6220a7d5836dbdd5893576479feee4d13abcdfe1ee2e89375e18abea72ee5" + }, + { + "date": 1738635038169, + "name": "logs/backend/combined-2025-02-04.log", + "hash": "b197eb2d58bbab3566e05fdb2bcc52ee608c4fe6ffb54fc958060c8dc4ff305f" } ], "hashType": "sha256" diff --git a/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json b/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json index 6ca6c1de..07566270 100644 --- a/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json +++ b/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json @@ -54,6 +54,11 @@ "date": 1738549408637, "name": "logs/backend/error-2025-02-03.log", "hash": "ffd13b033c90d60d10c935a41fe42f3a4d065311cbf7beda1b76b9c5c985e90b" + }, + { + "date": 1738635038164, + "name": "logs/backend/error-2025-02-04.log", + "hash": "7490b9f6c36fa2500bafa66c4aa590053c50234150ad9ad86ad9400f0ba76a43" } ], "hashType": "sha256" diff --git a/logs/backend/combined-2025-02-03.log b/logs/backend/combined-2025-02-03.log index cc577fc7..90ff1a4a 100644 --- a/logs/backend/combined-2025-02-03.log +++ b/logs/backend/combined-2025-02-03.log @@ -5,3 +5,4 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-02-03T06:56:34.648Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-03T07:06:48.864Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-03T07:32:02.910Z"} +{"id":"f6b224a2-3aeb-4cbc-afee-075a7965ab70","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-03T09:53:34.492Z"} diff --git a/logs/backend/combined-2025-02-04.log b/logs/backend/combined-2025-02-04.log new file mode 100644 index 00000000..e69de29b diff --git a/logs/backend/error-2025-02-04.log b/logs/backend/error-2025-02-04.log new file mode 100644 index 00000000..e69de29b diff --git a/src/app/api/new/home/route.ts b/src/app/api/new/home/route.ts index 7ef3a890..2e74f72b 100644 --- a/src/app/api/new/home/route.ts +++ b/src/app/api/new/home/route.ts @@ -3,67 +3,82 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { NextResponse } from "next/server"; export const dynamic = "force-dynamic"; - // GET DATA HOME export async function GET(request: Request) { - try { - let fixData - const { searchParams } = new URL(request.url) - const kategori = searchParams.get("cat") + try { + let fixData; + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("cat"); - const userLoginId = await funGetUserIdByToken() - if (userLoginId == null) { - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, user id tidak ada" }, { status: 500 }); - } + const userLoginId = await funGetUserIdByToken(); + if (userLoginId == null) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, user id tidak ada", + }, + { status: 500 } + ); + } - if (kategori == "job") { - fixData = await prisma.job.findMany({ - take: 2, - orderBy: { - createdAt: "desc", - }, - where: { - isActive: true, - masterStatusId: "1" - }, + if (kategori == "job") { + fixData = await prisma.job.findMany({ + take: 2, + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + masterStatusId: "1", + }, + select: { + id: true, + Author: { select: { - id: true, - Author: { - select: { - id: true, - username: true, - }, - }, - title: true, - deskripsi: true + id: true, + username: true, }, - }); - } else if (kategori == "cek_profile") { - const data = await prisma.user.findUnique({ - where: { - id: userLoginId, + }, + title: true, + deskripsi: true, + }, + }); + } else if (kategori == "cek_profile") { + const data = await prisma.user.findUnique({ + where: { + id: userLoginId, + }, + include: { + Profile: { + select: { + id: true, + imageId: true, }, - include: { - Profile: { - select: { - id: true, - imageId: true, - } - } - } - }); + }, + }, + }); - fixData = { - profile: data?.Profile?.id, - imageId: data?.Profile?.imageId - } + fixData = { + profile: data?.Profile?.id, + imageId: data?.Profile?.imageId, + }; + } - } - - return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: fixData }, { status: 200 }); - - } catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti ", reason: (error as Error).message, }, { status: 500 }); - } -} \ No newline at end of file + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, coba lagi nanti ", + reason: (error as Error).message, + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); + } +} diff --git a/src/app_modules/home/component/body_home.tsx b/src/app_modules/home/component/body_home.tsx index 9ecff402..8ffa4604 100644 --- a/src/app_modules/home/component/body_home.tsx +++ b/src/app_modules/home/component/body_home.tsx @@ -3,10 +3,10 @@ import { AccentColor, MainColor } from "@/app_modules/_global/color"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { clientLogger } from "@/util/clientLogger"; import { ActionIcon, Box, - Flex, Grid, Group, Image, @@ -22,40 +22,20 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; import { apiGetDataHome } from "../fun/get/api_home"; import { listMenuHomeBody, menuHomeJob } from "./list_menu_home"; -import { clientLogger } from "@/util/clientLogger"; -export default function BodyHome() { +export default function BodyHome({ dataUser }: { dataUser: any | null }) { const router = useRouter(); - const [dataUser, setDataUser] = useState(null); const [dataJob, setDataJob] = useState(null); const [loadingJob, setLoadingJob] = useState(true); const [loading, setLoading] = useState(true); useShallowEffect(() => { - cekUserLogin(); getHomeJob(); }, []); - async function cekUserLogin() { - try { - const response = await apiGetDataHome({ - path: "?cat=cek_profile", - }); - - if (response) { - setDataUser(response.data); - } - } catch (error) { - clientLogger.error("Error get data profile", error); - } - } - - - async function getHomeJob() { try { setLoadingJob(true); - const response = await apiGetDataHome({ path: "?cat=job", }); @@ -101,21 +81,14 @@ export default function BodyHome() { border: `2px solid ${AccentColor.blue}`, }} onClick={() => { - if (dataUser == null) { + if (!dataUser) { return null; - } else if ( - Object.keys(dataUser).length == 0 || - dataJob?.length == null - ) { + } else if (dataUser.profile === undefined) { router.push(RouterProfile.create, { scroll: false }); + } else if (e.link == "") { + ComponentGlobal_NotifikasiPeringatan("Cooming Soon"); } else { - if (e.link == "") { - return ComponentGlobal_NotifikasiPeringatan( - "Cooming Soon !!" - ); - } else { - router.push(e.link, { scroll: false }); - } + router.push(e.link, { scroll: false }); } }} > @@ -147,21 +120,14 @@ export default function BodyHome() { > { - if (dataUser == null) { + if (!dataUser) { return null; - } else if ( - Object.keys(dataUser).length == 0 || - dataJob?.length == null - ) { + } else if (dataUser.profile === undefined) { router.push(RouterProfile.create, { scroll: false }); + } else if (menuHomeJob.link == "") { + ComponentGlobal_NotifikasiPeringatan("Cooming Soon "); } else { - if (menuHomeJob.link == "") { - return ComponentGlobal_NotifikasiPeringatan( - "Cooming Soon !!" - ); - } else { - return router.push(menuHomeJob.link, { scroll: false }); - } + router.push(menuHomeJob.link, { scroll: false }); } }} > diff --git a/src/app_modules/home/component/footer_home.tsx b/src/app_modules/home/component/footer_home.tsx index 87a6a4f2..f4187e24 100644 --- a/src/app_modules/home/component/footer_home.tsx +++ b/src/app_modules/home/component/footer_home.tsx @@ -1,6 +1,8 @@ import { APIs } from "@/app/lib"; import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; +import { MainColor } from "@/app_modules/_global/color"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { ActionIcon, Box, @@ -9,37 +11,14 @@ import { Stack, Text, } from "@mantine/core"; -import { useShallowEffect } from "@mantine/hooks"; -import { IconUserCircle } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { apiGetDataHome } from "../fun/get/api_home"; import { Home_ComponentAvatarProfile } from "./comp_avatar_profile"; import { listMenuHomeFooter } from "./list_menu_home"; -import { MainColor } from "@/app_modules/_global/color"; -import { clientLogger } from "@/util/clientLogger"; -import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { IconUser } from "@tabler/icons-react"; +import { IconUserCircle } from "@tabler/icons-react"; -export default function FooterHome() { +export default function FooterHome({ dataUser }: { dataUser: any | null }) { const router = useRouter(); - const [dataUser, setDataUser] = useState(null); - - useShallowEffect(() => { - cekUserLogin(); - }, []); - - async function cekUserLogin() { - try { - const response = await apiGetDataHome({ - path: "?cat=cek_profile", - }); - if (response) { - setDataUser(response.data); - } - } catch (error) { - clientLogger.error("Error get data profile", error); - } - } return ( - {dataUser == null ? ( - - {Array.from(new Array(4)).map((_, i) => ( -
- - - -
- ))} -
- ) : ( - - {listMenuHomeFooter.map((e) => ( -
- { - if (dataUser == null) { - return null; - } else if (Object.keys(dataUser).length === 0) { - router.push(RouterProfile.create, { scroll: false }); - } else { - if (e.link == "") { - ComponentGlobal_NotifikasiPeringatan("Cooming Soon"); - } else { - router.push(e.link, { scroll: false }); - } - } - }} - > - - {e.icon} - - - {e.name} - - -
- ))} - -
+ + {listMenuHomeFooter.map((e) => ( +
{ - if ( - dataUser.profile === undefined || - dataUser?.profile === null - ) { + if (!dataUser) { + return null; + } else if (dataUser.profile === undefined) { router.push(RouterProfile.create, { scroll: false }); + } else if (e.link == "") { + ComponentGlobal_NotifikasiPeringatan("Cooming Soon"); } else { + router.push(e.link, { scroll: false }); + } + }} + > + + {e.icon} + + + {e.name} + + +
+ ))} + +
+ + {!dataUser ? ( + + ) : dataUser.profile === undefined ? ( + + router.push(RouterProfile.create, { scroll: false }) + } + > + + + ) : ( + { router.push( RouterProfile.katalogOLD + `${dataUser?.profile}`, { scroll: false, } ); - } - }} - > - - {dataUser.profile === undefined || - dataUser?.profile === null ? ( - - ) : ( - - )} + }} + > + - - Profile - - -
-
- )} + )} + + Profile + + +
+
); } diff --git a/src/app_modules/home/view_home_new.tsx b/src/app_modules/home/view_home_new.tsx index 7673e2f2..c8728cf0 100644 --- a/src/app_modules/home/view_home_new.tsx +++ b/src/app_modules/home/view_home_new.tsx @@ -1,9 +1,11 @@ "use client"; import { API_RouteNotifikasi } from "@/app/lib/api_user_router/route_api_notifikasi"; import { gs_count_ntf, gs_user_ntf } from "@/app/lib/global_state"; +import global_limit from "@/app/lib/limit"; import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; import { RouterNotifikasi } from "@/app/lib/router_hipmi/router_notifikasi"; import { RouterUserSearch } from "@/app/lib/router_hipmi/router_user_search"; +import { clientLogger } from "@/util/clientLogger"; import { ActionIcon, Indicator, Text } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { IconBell, IconUserSearch } from "@tabler/icons-react"; @@ -17,8 +19,6 @@ import { gs_notifikasi_kategori_app } from "../notifikasi/lib"; import BodyHome from "./component/body_home"; import FooterHome from "./component/footer_home"; import { apiGetDataHome } from "./fun/get/api_home"; -import { clientLogger } from "@/util/clientLogger"; -import CustomSkeleton from "../components/CustomSkeleton"; export default function HomeViewNew() { const [countNtf, setCountNtf] = useAtom(gs_count_ntf); @@ -27,10 +27,6 @@ export default function HomeViewNew() { const [categoryPage, setCategoryPage] = useAtom(gs_notifikasi_kategori_app); const router = useRouter(); - useShallowEffect(() => { - onLoadNotifikasi(); - }, []); - useShallowEffect(() => { if (countNtf != null) { setCountNtf(countNtf + newUserNtf); @@ -38,15 +34,32 @@ export default function HomeViewNew() { } }, [newUserNtf, countNtf]); - async function onLoadNotifikasi() { - const loadNotif = await fetch(API_RouteNotifikasi.get_count_by_id()); - const data = await loadNotif.json().then((res) => res.data); - setCountNtf(data); + useShallowEffect(() => { + hanlderLoadData(); + }, []); + + async function hanlderLoadData() { + try { + const listLoadData = [ + global_limit(() => onLoadNotifikasi()), + global_limit(() => cekUserLogin()), + ]; + + await Promise.all(listLoadData); + } catch (error) { + clientLogger.error("Error handler load data", error); + } } - useShallowEffect(() => { - cekUserLogin(); - }, []); + async function onLoadNotifikasi() { + try { + const loadNotif = await fetch(API_RouteNotifikasi.get_count_by_id()); + const data = await loadNotif.json().then((res) => res.data); + setCountNtf(data); + } catch (error) { + clientLogger.error("Error load notifikasi", error); + } + } async function cekUserLogin() { try { @@ -68,22 +81,26 @@ export default function HomeViewNew() { + !dataUser && !countNtf ? ( + + + + ) : dataUser.profile === undefined ? ( + { + router.push(RouterProfile.create, { scroll: false }); + }} + > + + ) : ( { - if ( - dataUser.profile != undefined || - dataUser?.profile != null - ) { - router.push(RouterUserSearch.main, { scroll: false }); - } else { - router.push(RouterProfile.create, { scroll: false }); - } + router.push(RouterUserSearch.main, { scroll: false }); }} > @@ -91,27 +108,32 @@ export default function HomeViewNew() { ) } customButtonRight={ - dataUser == null ? ( - + !dataUser && !countNtf ? ( + + + + ) : dataUser.profile === undefined ? ( + { + router.push(RouterProfile.create, { scroll: false }); + }} + > + + ) : ( { - if ( - dataUser.profile != undefined || - dataUser?.profile != null - ) { - setCategoryPage("Semua"); - router.push( - RouterNotifikasi.categoryApp({ name: "semua" }), - { - scroll: false, - } - ); - } else { - router.push(RouterProfile.create, { scroll: false }); - } + setCategoryPage("Semua"); + router.push( + RouterNotifikasi.categoryApp({ name: "semua" }), + { + scroll: false, + } + ); }} > {countNtf != null && countNtf > 0 ? ( @@ -134,9 +156,9 @@ export default function HomeViewNew() { } /> } - footer={} + footer={} > - + ); From 46d49992b4d0849b0ea2079a5f53aa01b1edbb6d Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 4 Feb 2025 12:09:21 +0800 Subject: [PATCH 2/9] fix login deskripsi: - fix api login --- logs/backend/combined-2025-02-04.log | 1 + logs/backend/error-2025-02-04.log | 1 + src/app/api/auth/login/route.ts | 85 +++++++++++---------- src/app_modules/auth/_lib/api_fetch_auth.ts | 13 ++++ src/app_modules/auth/login/view.tsx | 28 ++----- src/middleware.ts | 2 +- 6 files changed, 67 insertions(+), 63 deletions(-) create mode 100644 src/app_modules/auth/_lib/api_fetch_auth.ts diff --git a/logs/backend/combined-2025-02-04.log b/logs/backend/combined-2025-02-04.log index e69de29b..95b71089 100644 --- a/logs/backend/combined-2025-02-04.log +++ b/logs/backend/combined-2025-02-04.log @@ -0,0 +1 @@ +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T03:16:37.809Z"} diff --git a/logs/backend/error-2025-02-04.log b/logs/backend/error-2025-02-04.log index e69de29b..95b71089 100644 --- a/logs/backend/error-2025-02-04.log +++ b/logs/backend/error-2025-02-04.log @@ -0,0 +1 @@ +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T03:16:37.809Z"} diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index 871e8f3f..1d22ba3c 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -4,59 +4,60 @@ import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { - if (req.method === "POST") { + if (req.method !== "POST") { + return NextResponse.json( + { success: false, message: "Method Not Allowed" }, + { status: 405 } + ); + } + + try { const codeOtp = randomOTP(); const body = await req.json(); const { nomor } = body; - - try { - const res = await fetch( - `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. + const res = await fetch( + `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. \n >> Kode OTP anda: ${codeOtp}. ` - ); + ); - 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, - otp: codeOtp, - }, - }); - - if (!createOtpId) - return NextResponse.json( - { success: false, message: "Gagal Membuat Kode OTP" }, - { status: 400 } - ); + const sendWa = await res.json(); + if (sendWa.status !== "success") return NextResponse.json( - { - success: true, - message: "Kode Verifikasi Dikirim", - kodeId: createOtpId.id, - }, - { status: 200 } + { success: false, message: "Nomor Whatsapp Tidak Aktif" }, + { status: 400 } ); - } catch (error) { - backendLogger.log("Error Login", error); + + const createOtpId = await prisma.kodeOtp.create({ + data: { + nomor: nomor, + otp: codeOtp, + }, + }); + + if (!createOtpId) return NextResponse.json( - { success: false, message: error as Error }, - { status: 500 } + { success: false, message: "Gagal mengirim kode OTP" }, + { status: 400 } ); - } + + return NextResponse.json( + { + success: true, + message: "Kode verifikasi terkirim", + kodeId: createOtpId.id, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.log("Error Login", error); + return NextResponse.json( + { success: false, message: "Terjadi masalah saat login" , reason: error as Error }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); } - - return NextResponse.json( - { success: false, message: "Method Not Allowed" }, - { status: 405 } - ); } diff --git a/src/app_modules/auth/_lib/api_fetch_auth.ts b/src/app_modules/auth/_lib/api_fetch_auth.ts new file mode 100644 index 00000000..15882c76 --- /dev/null +++ b/src/app_modules/auth/_lib/api_fetch_auth.ts @@ -0,0 +1,13 @@ +export { apiFetchLogin }; + +const apiFetchLogin = async ({ nomor }: { nomor: string }) => { + const respone = await fetch("/api/auth/login", { + method: "POST", + body: JSON.stringify({ nomor: nomor }), + headers: { + "Content-Type": "application/json", + }, + }); + + return await respone.json().catch(() => null); +}; diff --git a/src/app_modules/auth/login/view.tsx b/src/app_modules/auth/login/view.tsx index 538b1280..f3b28d7f 100644 --- a/src/app_modules/auth/login/view.tsx +++ b/src/app_modules/auth/login/view.tsx @@ -17,6 +17,7 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; import { PhoneInput } from "react-international-phone"; import "react-international-phone/style.css"; +import { apiFetchLogin } from "../_lib/api_fetch_auth"; export default function Login({ version }: { version: string }) { const router = useRouter(); @@ -30,33 +31,20 @@ export default function Login({ version }: { version: string }) { try { setLoading(true); - const res = await fetch("/api/auth/login", { - method: "POST", - body: JSON.stringify({ nomor: nomor }), - headers: { - "Content-Type": "application/json", - }, - }); + const respone = await apiFetchLogin({ nomor: nomor }); - const result = await res.json(); - - if (res.status == 500) { - ComponentGlobal_NotifikasiGagal("Server Error"); - return; - } - - if (res.status === 200) { - localStorage.setItem("hipmi_auth_code_id", result.kodeId); - ComponentGlobal_NotifikasiBerhasil(result.message, 2000); + if (respone) { + localStorage.setItem("hipmi_auth_code_id", respone.kodeId); + ComponentGlobal_NotifikasiBerhasil(respone.message, 2000); router.push("/validasi", { scroll: false }); } else { - ComponentGlobal_NotifikasiPeringatan(result.message); + setLoading(false); + ComponentGlobal_NotifikasiPeringatan(respone.message); } } catch (error) { + setLoading(false); clientLogger.error("Error login:", error); ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan"); - } finally { - setLoading(false); } } diff --git a/src/middleware.ts b/src/middleware.ts index 31ad130c..aa572cb3 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -32,7 +32,7 @@ const middlewareConfig: MiddlewareConfig = { "/api/auth/*", "/api/origin-url", "/api/event/*", - "/api/master/*", + // "/api/master/*", // "/api/image/*", // "/api/user/*", // "/api/new/*", From c53ca6d35538d544527df9e0743896919af4da36 Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 4 Feb 2025 22:35:44 +0800 Subject: [PATCH 3/9] API Table Investasi Admin --- src/app/api/admin/investasi/[status]/route.ts | 164 ++++++++++ .../admin/investasi/sub-menu/reject/page.tsx | 4 +- .../admin/investasi/sub-menu/review/page.tsx | 4 +- .../admin/event/_view/view_table_review.tsx | 37 ++- .../admin/event/table_status/table_reject.tsx | 41 ++- .../_lib/api_fetch_admin_investasi.ts | 51 +++ .../investasi/_lib/api_fetch_count_status.ts | 22 -- .../admin/investasi/main/table_publish.tsx | 185 ++++++----- .../admin/investasi/main/table_reject.tsx | 294 ++++++++++-------- .../admin/investasi/main/table_review.tsx | 211 +++++++------ src/app_modules/admin/investasi/main/view.tsx | 9 +- src/middleware.ts | 1 + templates/ff.config.json | 82 +++++ templates/ff_bloc/bloc.tmpl | 16 + templates/ff_bloc/event.tmpl | 78 +++++ templates/ff_bloc/index.tmpl | 0 templates/ff_bloc/model.tmpl | 51 +++ templates/ff_bloc/page.tmpl | 57 ++++ templates/ff_bloc/provider.tmpl | 26 ++ templates/ff_bloc/screen.tmpl | 126 ++++++++ templates/ff_bloc/state.tmpl | 15 + templates/mutable/bloc.tmpl | 37 +++ templates/mutable/event.tmpl | 42 +++ templates/mutable/index.tmpl | 0 templates/mutable/model.tmpl | 47 +++ templates/mutable/page.tmpl | 23 ++ templates/mutable/provider.tmpl | 20 ++ templates/mutable/repository.tmpl | 11 + templates/mutable/screen.tmpl | 97 ++++++ templates/mutable/state.tmpl | 83 +++++ templates/navigate/navigate.tmpl | 33 ++ templates/simple/bloc.tmpl | 21 ++ templates/simple/event.tmpl | 34 ++ templates/simple/index.tmpl | 0 templates/simple/model.tmpl | 13 + templates/simple/page.tmpl | 23 ++ templates/simple/provider.tmpl | 20 ++ templates/simple/repository.tmpl | 11 + templates/simple/screen.tmpl | 84 +++++ templates/simple/state.tmpl | 42 +++ 40 files changed, 1737 insertions(+), 378 deletions(-) create mode 100644 src/app/api/admin/investasi/[status]/route.ts create mode 100644 src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts delete mode 100644 src/app_modules/admin/investasi/_lib/api_fetch_count_status.ts create mode 100644 templates/ff.config.json create mode 100644 templates/ff_bloc/bloc.tmpl create mode 100644 templates/ff_bloc/event.tmpl create mode 100644 templates/ff_bloc/index.tmpl create mode 100644 templates/ff_bloc/model.tmpl create mode 100644 templates/ff_bloc/page.tmpl create mode 100644 templates/ff_bloc/provider.tmpl create mode 100644 templates/ff_bloc/screen.tmpl create mode 100644 templates/ff_bloc/state.tmpl create mode 100644 templates/mutable/bloc.tmpl create mode 100644 templates/mutable/event.tmpl create mode 100644 templates/mutable/index.tmpl create mode 100644 templates/mutable/model.tmpl create mode 100644 templates/mutable/page.tmpl create mode 100644 templates/mutable/provider.tmpl create mode 100644 templates/mutable/repository.tmpl create mode 100644 templates/mutable/screen.tmpl create mode 100644 templates/mutable/state.tmpl create mode 100644 templates/navigate/navigate.tmpl create mode 100644 templates/simple/bloc.tmpl create mode 100644 templates/simple/event.tmpl create mode 100644 templates/simple/index.tmpl create mode 100644 templates/simple/model.tmpl create mode 100644 templates/simple/page.tmpl create mode 100644 templates/simple/provider.tmpl create mode 100644 templates/simple/repository.tmpl create mode 100644 templates/simple/screen.tmpl create mode 100644 templates/simple/state.tmpl diff --git a/src/app/api/admin/investasi/[status]/route.ts b/src/app/api/admin/investasi/[status]/route.ts new file mode 100644 index 00000000..04acca4f --- /dev/null +++ b/src/app/api/admin/investasi/[status]/route.ts @@ -0,0 +1,164 @@ +import { prisma } from "@/app/lib"; +import _ from "lodash"; +import moment from "moment"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request, { params }: { + params: { status: string } +} +) { + const method = request.method; + if (method !== "GET") { + return NextResponse.json({ + success: false, + message: "Method not allowed", + }, + { status: 405 } + ) + } + + const { status } = params; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10 + const skipData = Number(page) * takeData - takeData; + + console.log("Ini Status", status); + console.log("Ini Page", page) + + try { + let fixData; + const fixStatus = _.startCase(status); + + if (!page && !search) { + fixData = await prisma.investasi.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + active: true, + MasterStatusInvestasi: { + name: fixStatus + }, + }, + include: { + author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + MasterStatusInvestasi: true, + }, + }); + } else if (!page && search) { + fixData = await prisma.investasi.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + active: true, + MasterStatusInvestasi: { + name: fixStatus + }, + title: { + contains: search, + mode: "insensitive", + }, + }, + include: { + author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + MasterStatusInvestasi: true, + }, + }); + } else if (page && !search) { + + const data = await prisma.investasi.findMany({ + take: takeData, + skip: skipData, + orderBy: [ + { + countDown: "desc", + }, + ], + where: { + active: true, + MasterStatusInvestasi: { + name: fixStatus + } + + }, + include: { + MasterStatusInvestasi: true, + BeritaInvestasi: true, + DokumenInvestasi: true, + ProspektusInvestasi: true, + MasterPembagianDeviden: true, + MasterPencarianInvestor: true, + MasterPeriodeDeviden: true, + author: true, + Investasi_Invoice: { + where: { + statusInvoiceId: "2", + }, + }, + }, + }); + + const nCount = await prisma.investasi.count({ + where: { + active: true, + MasterStatusInvestasi: { + name: fixStatus + } + + }, + }); + + console.log("data >", data) + + fixData = { + data: data, + nPage: _.ceil(nCount / takeData), + }; + + } + + return NextResponse.json({ + success: true, + message: "Success", + data: fixData, + }, + { status: 200 } + ) + + } catch (error) { + console.log(error) + return NextResponse.json({ + success: false, + message: "Failed", + reason: (error as Error).message, + }, + { status: 500 } + ) + + } + + +} \ No newline at end of file diff --git a/src/app/dev/admin/investasi/sub-menu/reject/page.tsx b/src/app/dev/admin/investasi/sub-menu/reject/page.tsx index 9f4af9e0..9d2b186b 100644 --- a/src/app/dev/admin/investasi/sub-menu/reject/page.tsx +++ b/src/app/dev/admin/investasi/sub-menu/reject/page.tsx @@ -2,10 +2,10 @@ import { Admin_TableRejectInvestasi } from "@/app_modules/admin/investasi"; import { adminInvestasi_funGetAllReject } from "@/app_modules/admin/investasi/fun/get/get_all_reject"; export default async function Page() { - const dataInvestsi = await adminInvestasi_funGetAllReject({page: 1}); + // const dataInvestsi = await adminInvestasi_funGetAllReject({page: 1}); return ( <> - + ); } diff --git a/src/app/dev/admin/investasi/sub-menu/review/page.tsx b/src/app/dev/admin/investasi/sub-menu/review/page.tsx index 454397aa..0d493140 100644 --- a/src/app/dev/admin/investasi/sub-menu/review/page.tsx +++ b/src/app/dev/admin/investasi/sub-menu/review/page.tsx @@ -2,10 +2,10 @@ import { Admin_TableReviewInvestasi } from "@/app_modules/admin/investasi"; import { adminInvestasi_funGetAllReview } from "@/app_modules/admin/investasi/fun/get/get_all_review"; export default async function Page() { - const dataInvestsi = await adminInvestasi_funGetAllReview({ page: 1 }); + // const dataInvestsi = await adminInvestasi_funGetAllReview({ page: 1 }); return ( <> - + ); } diff --git a/src/app_modules/admin/event/_view/view_table_review.tsx b/src/app_modules/admin/event/_view/view_table_review.tsx index f8b4b54e..7f1dce9b 100644 --- a/src/app_modules/admin/event/_view/view_table_review.tsx +++ b/src/app_modules/admin/event/_view/view_table_review.tsx @@ -49,6 +49,7 @@ import adminNotifikasi_funCreateToUser from "../../notifikasi/fun/create/fun_cre import { adminEvent_funGetListReview } from "../fun"; import { AdminEvent_funEditStatusPublishById } from "../fun/edit/fun_edit_status_publish_by_id"; import { AdminEvent_funEditCatatanById } from "../fun/edit/fun_edit_status_reject_by_id"; +import { AdminColor } from "@/app_modules/_global/color/color_pallet"; export default function AdminEvent_ComponentTableReview() { const [data, setData] = useState(null); @@ -261,28 +262,28 @@ export default function AdminEvent_ComponentTableReview() { return data.map((e, i) => ( -
+
{e?.Author?.username}
-
+
{e.title}
-
+
{e.lokasi}
-
+
{e.EventMaster_TipeAcara.name}
-
+
{new Intl.DateTimeFormat("id-ID", { dateStyle: "full", @@ -297,7 +298,7 @@ export default function AdminEvent_ComponentTableReview() {
-
+
{new Intl.DateTimeFormat("id-ID", { dateStyle: "full", @@ -313,7 +314,7 @@ export default function AdminEvent_ComponentTableReview() { -
+
) : ( - + {isShowReload && (
@@ -416,35 +417,33 @@ export default function AdminEvent_ComponentTableReview() { horizontalSpacing={"md"} p={"md"} w={1500} - striped - highlightOnHover > -
Username
+
Username
-
Judul
+
Judul
-
Lokasi
+
Lokasi
-
Tipe Acara
+
Tipe Acara
-
Tanggal & Waktu Mulai
+
Tanggal & Waktu Mulai
-
Tanggal & Waktu Selesai
+
Tanggal & Waktu Selesai
-
Deskripsi
+
Deskripsi
-
Aksi
+
Aksi
diff --git a/src/app_modules/admin/event/table_status/table_reject.tsx b/src/app_modules/admin/event/table_status/table_reject.tsx index d3d52ae0..0678bfe9 100644 --- a/src/app_modules/admin/event/table_status/table_reject.tsx +++ b/src/app_modules/admin/event/table_status/table_reject.tsx @@ -137,20 +137,20 @@ function TableStatus() { return data.map((e, i) => ( -
{e?.Author?.username}
+
{e?.Author?.username}
-
{e.title}
+
{e.title}
-
{e.lokasi}
+
{e.lokasi}
-
{e.EventMaster_TipeAcara.name}
+
{e.EventMaster_TipeAcara.name}
-
+
{new Intl.DateTimeFormat("id-ID", { dateStyle: "full", @@ -165,7 +165,7 @@ function TableStatus() {
-
+
{new Intl.DateTimeFormat("id-ID", { dateStyle: "full", @@ -181,7 +181,7 @@ function TableStatus() { -
+
{" "} -
+
) : ( - + diff --git a/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts b/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts new file mode 100644 index 00000000..55a1ddab --- /dev/null +++ b/src/app_modules/admin/investasi/_lib/api_fetch_admin_investasi.ts @@ -0,0 +1,51 @@ +export { + apiGetAdminInvestasiCountDashboard, + apiGetAdminInvestasiByStatus, +} +const apiGetAdminInvestasiCountDashboard = async ({ name }: + { name: "Publish" | "Review" | "Reject" }) => { + + + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + + const response = await fetch(`/api/admin/investasi/dashboard/${name}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + + return await response.json().catch(() => null); +}; + +const apiGetAdminInvestasiByStatus = async ({ status, page, search }: { + status: "Publish" | "Review" | "Reject", + page: string, + search: string +}) => { + console.log("dgsdg") + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + console.log("Ini token", token) + console.log("Ini Page", page) + console.log("Ini Search", search) + + + const isPage = page ? `?page=${page}` : ""; + const isSearch = search ? `&search=${search}` : ""; + const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + console.log("Ini response", response) + return await response.json().catch(() => null); +} \ No newline at end of file diff --git a/src/app_modules/admin/investasi/_lib/api_fetch_count_status.ts b/src/app_modules/admin/investasi/_lib/api_fetch_count_status.ts deleted file mode 100644 index ed19bd40..00000000 --- a/src/app_modules/admin/investasi/_lib/api_fetch_count_status.ts +++ /dev/null @@ -1,22 +0,0 @@ -const apiGetInvestasiCountDashboard = async ({ name }: - { name: "Publish" | "Review" | "Reject" }) => { - - - const { token } = await fetch("/api/get-cookie").then((res) => res.json()); - if (!token) return await token.json().catch(() => null); - - - const response = await fetch(`/api/admin/investasi/dashboard/${name}`, { - method: "GET", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - - return await response.json().catch(() => null); -}; - -export default apiGetInvestasiCountDashboard; \ No newline at end of file diff --git a/src/app_modules/admin/investasi/main/table_publish.tsx b/src/app_modules/admin/investasi/main/table_publish.tsx index 0d7252f1..85a5f39b 100644 --- a/src/app_modules/admin/investasi/main/table_publish.tsx +++ b/src/app_modules/admin/investasi/main/table_publish.tsx @@ -25,6 +25,10 @@ import { adminInvestasi_funGetAllPublish } from "../fun/get/get_all_publish"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { MainColor } from "@/app_modules/_global/color"; import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { apiGetAdminInvestasiByStatus } from "../_lib/api_fetch_admin_investasi"; +import { useShallowEffect } from "@mantine/hooks"; +import { clientLogger } from "@/util/clientLogger"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; export default function Admin_TablePublishInvestasi({ dataInvestsi, @@ -50,83 +54,116 @@ function TableView({ listData }: { listData: any }) { const [isSearch, setSearch] = useState(""); const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); + const [origin, setOrigin] = useState(""); - async function onSearch(s: string) { - setSearch(s); + useShallowEffect(() => { + if (typeof window !== "undefined") { + setOrigin(window.location.origin); + } + }, []) + + useShallowEffect(() => { + const loadInitialData = async () => { + try { + const response = await apiGetAdminInvestasiByStatus({ + status: "Publish", + page: `${activePage}`, + search: isSearch, + }); + + if (response?.success && response?.data?.data) { + setData(response.data.data); + setNPage(response.data.nPage || 1); + } else { + console.error("Invalid data format received:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Error get data table publish", error); + setData([]); + } + }; + + loadInitialData(); + }, [activePage, isSearch]); + const onSearch = async (searchTerm: string) => { + setSearch(searchTerm); setActivePage(1); - const loadData = await adminInvestasi_funGetAllPublish({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminInvestasi_funGetAllPublish({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const onPageClick = (page: number) => { + setActivePage(page) } - const tableBody = data.map((e) => ( - - - - - - - - - - )); + const renderTableBody = () => { + if(!Array.isArray(data) || data.length === 0) { + return ( + + + + ); + } + return data.map((e, i) => ( + + + + + + + + + + )); + } + return ( <> @@ -164,8 +201,8 @@ function TableView({ listData }: { listData: any }) { /> */} - {_.isEmpty(data) ? ( - + {!data ? ( + ) : ( @@ -203,7 +240,7 @@ function TableView({ listData }: { listData: any }) { - {tableBody} + {renderTableBody()}
-
Username
+
Username
-
Judul
+
Judul
-
Lokasi
+
Lokasi
-
Tipe Acara
+
Tipe Acara
-
Tanggal & Waktu Mulai
+
Tanggal & Waktu Mulai
-
Tanggal & Waktu Selesai
+
Tanggal & Waktu Selesai
-
Cacatan
+
Cacatan
-
Deskripsi
+
Deskripsi
-
Aksi
+
Aksi
-
- {e.author.username} -
-
-
- {e.title} -
-
-
{_.toNumber(e.progress).toFixed(2)} %
-
-
- {new Intl.NumberFormat("id-ID", { - maximumFractionDigits: 10, - }).format(+e.sisaLembar)} -
-
-
- {new Intl.NumberFormat("id-ID", { - maximumFractionDigits: 10, - }).format(+e.totalLembar)} -
-
-
- {e.Investasi_Invoice.length} -
-
-
- -
-
+
+ Tidak ada data +
+
+
+ {e.author.username} +
+
+
+ {e.title} +
+
+
{_.toNumber(e.progress).toFixed(2)} %
+
+
+ {new Intl.NumberFormat("id-ID", { + maximumFractionDigits: 10, + }).format(+e.sisaLembar)} +
+
+
+ {new Intl.NumberFormat("id-ID", { + maximumFractionDigits: 10, + }).format(+e.totalLembar)} +
+
+
+ {e.Investasi_Invoice.length} +
+
+
+ +
+
diff --git a/src/app_modules/admin/investasi/main/table_reject.tsx b/src/app_modules/admin/investasi/main/table_reject.tsx index 9d81340c..b5d60ce4 100644 --- a/src/app_modules/admin/investasi/main/table_reject.tsx +++ b/src/app_modules/admin/investasi/main/table_reject.tsx @@ -31,162 +31,186 @@ import { RouterAdminInvestasi } from "@/app/lib/router_admin/router_admin_invest import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { MainColor } from "@/app_modules/_global/color"; import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { useShallowEffect } from "@mantine/hooks"; +import { clientLogger } from "@/util/clientLogger"; +import { apiGetAdminInvestasiByStatus } from "../_lib/api_fetch_admin_investasi"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function Admin_TableRejectInvestasi({ - dataInvestsi, -}: { - dataInvestsi: any[]; -}) { - const [investasi, setInvestasi] = useState(dataInvestsi); - const router = useRouter(); - +export default function Admin_TableRejectInvestasi() { return ( <> - + ); - const tableBody = investasi.map((e) => - e.MasterStatusInvestasi.id === "4" ? ( - - - - - {e.author.username} - - - {_.capitalize(e.title)} - {e.catatan} - -
- - - router.push(RouterAdminInvestasi_OLD.konfirmasi + `${e.id}`) - } - > - - - -
- - - ) : ( - "" - ) - ); + // const tableBody = investasi.map((e) => + // e.MasterStatusInvestasi.id === "4" ? ( + // + // + // + // + // {e.author.username} + // + // + // {_.capitalize(e.title)} + // {e.catatan} + // + //
+ // + // + // router.push(RouterAdminInvestasi_OLD.konfirmasi + `${e.id}`) + // } + // > + // + // + // + //
+ // + // + // ) : ( + // "" + // ) + // ); - return ( - <> - - router.push(RouterAdminInvestasi_OLD.main_investasi)} - > - - - - - - Reject - - - - - - - - - - - {tableBody} -
UsernameNama Proyek InvestasiCatatan -
Aksi
-
-
-
-
- - ); + // return ( + // <> + // + // router.push(RouterAdminInvestasi_OLD.main_investasi)} + // > + // + // + // + // + // + // Reject + // + // + // + // + // + // + // + // + // + // + // {tableBody} + //
UsernameNama Proyek InvestasiCatatan + //
Aksi
+ //
+ //
+ //
+ //
+ // + // ); } -function TableView({ listData }: { listData: any }) { +function TableView() { const router = useRouter(); - const [data, setData] = useState(listData.data); - const [nPage, setNPage] = useState(listData.nPage); + const [data, setData] = useState (null); + const [nPage, setNPage] = useState(1); const [activePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); - async function onSearch(s: string) { - setSearch(s); + + useShallowEffect(() => { + const loadInitialData = async () => { + try { + const response = await apiGetAdminInvestasiByStatus({ + status: "Reject", + page: `${activePage}`, + search: isSearch, + }); + + if (response?.success && response?.data.data) { + setData(response.data.data); + setNPage(response.data.nPage || 1); + } else { + console.error("Invalid data format recieved:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Error get data reject", error); + setData([]); + } + } + loadInitialData(); + }, [activePage, isSearch]); + const onSearch = async (searchTerm: string) => { + setSearch(searchTerm); setActivePage(1); - const loadData = await adminInvestasi_funGetAllReject({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminInvestasi_funGetAllReject({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + async function onPageClick(page: number) { + setActivePage(page); } - const tableBody = data.map((e) => ( - - -
- {e.author.username} -
- - -
- {e.title} -
- - -
- {e.catatan} -
- + const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ) + } + return data.map((e, i) => ( + + +
+ {e.author.username} +
+ + +
+ {e.title} +
+ + +
+ {e.catatan} +
+ + + +
+ +
+ + + )); + } - -
- -
- - - )); + return ( <> @@ -224,8 +248,8 @@ function TableView({ listData }: { listData: any }) { /> */} - {_.isEmpty(data) ? ( - + {!data ? ( + ) : ( @@ -253,7 +277,7 @@ function TableView({ listData }: { listData: any }) { - {tableBody} + {renderTableBody()}
diff --git a/src/app_modules/admin/investasi/main/table_review.tsx b/src/app_modules/admin/investasi/main/table_review.tsx index fc210299..6ee348ab 100644 --- a/src/app_modules/admin/investasi/main/table_review.tsx +++ b/src/app_modules/admin/investasi/main/table_review.tsx @@ -30,26 +30,25 @@ import ComponentAdminGlobal_TampilanRupiahDonasi from "../../_admin_global/tampi import { adminInvestasi_funGetAllReview } from "../fun/get/get_all_review"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { apiGetAdminInvestasiByStatus } from "../_lib/api_fetch_admin_investasi"; +import { clientLogger } from "@/util/clientLogger"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function Admin_TableReviewInvestasi({ - dataInvestsi, -}: { - dataInvestsi: any[]; -}) { +export default function Admin_TableReviewInvestasi() { return ( <> - + ); } -function TableView({ listData }: { listData: any }) { +function TableView() { const router = useRouter(); - const [data, setData] = useState(listData.data); - const [nPage, setNPage] = useState(listData.nPage); + const [data, setData] = useState(null); + const [nPage, setNPage] = useState(1); const [activePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); const [isLoading, setLoading] = useState(false); @@ -62,94 +61,108 @@ function TableView({ listData }: { listData: any }) { const [isLoadingReload, setLoadingReload] = useState(false); useShallowEffect(() => { - if (isAdminInvestasi_TriggerReview) { - setIsShowReload(false); - setIsAdminInvestasi_TriggerReview(false) - } - }, [isAdminInvestasi_TriggerReview]); + loadInitialData(); + }, [activePage, isSearch]); + const loadInitialData = async () => { + try { + const response = await apiGetAdminInvestasiByStatus({ + status: "Review", + page: `${activePage}`, + search: isSearch, + }); + if (response?.success && response?.data?.data) { + setData(response.data.data) + setNPage(response.data.nPage || 1) + } else { + console.error("Invalid data format received:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Error get data table review", error); + setData([]); + } + } + const onSearch = async (searchTerm: string) => { + setSearch(searchTerm); + setActivePage(1); + } + + const onPageClick = (page: number) => { + setActivePage(page); + } async function onLoadData() { - const loadData = await adminInvestasi_funGetAllReview({ page: 1 }); - setData(loadData.data as any); - setNPage(loadData.nPage); - setLoadingReload(false); + loadInitialData(); + setLoading(false); setIsShowReload(false); setIsAdminInvestasi_TriggerReview(false); } - async function onSearch(s: string) { - setSearch(s); - setActivePage(1); - const loadData = await adminInvestasi_funGetAllReview({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ) + } + return data.map((e, i) => ( + + +
+ {e.author.username} +
+ + +
+ {e.title} +
+ + +
+ {e.roi} % +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + )); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminInvestasi_funGetAllReview({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); - } - - const tableBody = data.map((e) => ( - - -
- {e.author.username} -
- - -
- {e.title} -
- - -
- {e.roi} % -
- - -
- -
- - -
- -
- - -
- -
- - - )); - return ( <> @@ -158,13 +171,13 @@ function TableView({ listData }: { listData: any }) { color={AdminColor.softBlue} component={ } - radius={"xl"} - placeholder="Cari nama proyek" - onChange={(val) => { - onSearch(val.currentTarget.value); - }} - /> + icon={} + radius={"xl"} + placeholder="Cari nama proyek" + onChange={(val) => { + onSearch(val.currentTarget.value); + }} + /> } /> {/* */} - {_.isEmpty(data) ? ( - + {!data ? ( + ) : ( {isShowReload && ( @@ -245,7 +258,7 @@ function TableView({ listData }: { listData: any }) { - {tableBody} + {renderTableBody()}
diff --git a/src/app_modules/admin/investasi/main/view.tsx b/src/app_modules/admin/investasi/main/view.tsx index c27312dc..ddeda2f3 100644 --- a/src/app_modules/admin/investasi/main/view.tsx +++ b/src/app_modules/admin/investasi/main/view.tsx @@ -50,7 +50,8 @@ import { clientLogger } from "@/util/clientLogger"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import global_limit from "@/app/lib/limit"; import { useShallowEffect } from "@mantine/hooks"; -import apiGetInvestasiCountDashboard from "../_lib/api_fetch_count_status"; +import { apiGetAdminInvestasiCountDashboard } from "../_lib/api_fetch_admin_investasi"; + export default function Admin_Investasi({ listInvestasi, @@ -88,7 +89,7 @@ export default function Admin_Investasi({ async function onLoadCountPublish() { try { - const response = await apiGetInvestasiCountDashboard({ + const response = await apiGetAdminInvestasiCountDashboard({ name: "Publish", }); @@ -103,7 +104,7 @@ export default function Admin_Investasi({ } async function onLoadCountReview() { try { - const response = await apiGetInvestasiCountDashboard({ + const response = await apiGetAdminInvestasiCountDashboard({ name: "Review", }); @@ -116,7 +117,7 @@ export default function Admin_Investasi({ } async function onLoadCountReject() { try { - const response = await apiGetInvestasiCountDashboard({ + const response = await apiGetAdminInvestasiCountDashboard({ name: "Reject", }); diff --git a/src/middleware.ts b/src/middleware.ts index 31ad130c..01c2a43d 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -43,6 +43,7 @@ const middlewareConfig: MiddlewareConfig = { // "/api/admin/voting/dashboard/*", // "/api/admin/job/dashboard/*", // "/api/admin/forum/dashboard/*", + // Akses awal diff --git a/templates/ff.config.json b/templates/ff.config.json new file mode 100644 index 00000000..ad05a6f5 --- /dev/null +++ b/templates/ff.config.json @@ -0,0 +1,82 @@ +{ + "name": "base", + "configs": [ + { + "name": "bloc", + "commands": [ + { + "name": "[FF] New Big Pack Bloc", + "templates": ["*"], + "key": "bigpack", + "files": [ + "bloc", + "event", + "index", + "model", + "page", + "provider", + "repository", + "screen", + "state" + ] + }, + { + "name": "[FF] New Small Pack Bloc", + "templates": ["*"], + "key": "smallpack", + "files": ["bloc", "event", "index", "page", "screen", "state"] + }, + { + "name": "[FF] New Bloc", + "templates": ["*"], + "files": ["bloc"] + }, + { + "name": "[FF] New Event", + "templates": ["*"], + "files": ["event"] + }, + { + "name": "[FF] New Model", + "templates": ["*"], + "files": ["model"] + }, + { + "name": "[FF] New Page", + "templates": ["*"], + "files": ["page"] + }, + { + "name": "[FF] New Provider", + "templates": ["*"], + "files": ["provider"] + }, + { + "name": "[FF] New Repository", + "templates": ["*"], + "files": ["repository"] + }, + { + "name": "[FF] New Screen", + "templates": ["*"], + "files": ["screen"] + }, + { + "name": "[FF] New State", + "templates": ["*"], + "files": ["state"] + }, + { + "name": "[FF] New Index", + "templates": ["*"], + "files": ["index"] + }, + { + "name": "[FF] New Navigate(Navme)", + "templates": ["navigate"], + "files": ["navigate"] + } + ] + } + ] +} diff --git a/templates/ff_bloc/bloc.tmpl b/templates/ff_bloc/bloc.tmpl new file mode 100644 index 00000000..f806fd48 --- /dev/null +++ b/templates/ff_bloc/bloc.tmpl @@ -0,0 +1,16 @@ +import 'package:ff_bloc/ff_bloc.dart'; + +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Bloc extends FFBloc<${upperName}Event, ${upperName}State> { + ${upperName}Bloc({ + required this.provider, + super.initialState = const ${upperName}State(), + }); + /// Use this for all requests to backend - you can mock it in tests + final ${upperName}Provider provider; + + @override + ${upperName}State onErrorState(Object error) => state.copy(error: error, isLoading: false); + +} diff --git a/templates/ff_bloc/event.tmpl b/templates/ff_bloc/event.tmpl new file mode 100644 index 00000000..7dcff332 --- /dev/null +++ b/templates/ff_bloc/event.tmpl @@ -0,0 +1,78 @@ +import 'dart:async'; + +import 'package:flutter/widgets.dart'; +import 'package:ff_bloc/ff_bloc.dart'; + +import 'package:${appName}${relative}/index.dart'; + +@immutable +abstract class ${upperName}Event implements FFBlocEvent<${upperName}State, ${upperName}Bloc> {} + +/// Initial Event with load data +class Load${upperName}Event extends ${upperName}Event { + Load${upperName}Event({required this.id}); + final String? id; + + static const String _name = 'Load${upperName}Event'; + + @override + String toString() => _name; + + @override + Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { + // set loading true for show loading + yield bloc.state.copyWithoutError(isLoading: true); + // fetch data + final result = await bloc.provider.fetchAsync(id); + // set data to state + yield bloc.state.copyWithoutError( + isLoading: false, + data: ${upperName}ViewModel(items: result), + ); + } +} + + +class Add${upperName}Event extends ${upperName}Event { + static const String _name = 'Add${upperName}Event'; + + @override + String toString() => _name; + + @override + Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { + yield bloc.state.copyWithoutError(isLoading: true); + final result = await bloc.provider.addMore(bloc.state.data?.items); + yield bloc.state.copyWithoutError( + isLoading: false, + data: ${upperName}ViewModel(items: result), + ); + } +} + +class ErrorYouAwesomeEvent extends YouAwesomeEvent { + static const String _name = 'ErrorYouAwesomeEvent'; + + @override + String toString() => _name; + + @override + Stream applyAsync({required YouAwesomeBloc bloc}) async* { + throw Exception('Test error'); + } +} + +class Clear${upperName}Event extends ${upperName}Event { + static const String _name = 'Clear${upperName}Event'; + + @override + String toString() => _name; + + @override + Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { + yield bloc.state.copyWithoutError(isLoading: true); + yield bloc.state.copyWithoutData( + isLoading: false, + ); + } +} diff --git a/templates/ff_bloc/index.tmpl b/templates/ff_bloc/index.tmpl new file mode 100644 index 00000000..e69de29b diff --git a/templates/ff_bloc/model.tmpl b/templates/ff_bloc/model.tmpl new file mode 100644 index 00000000..4b13e7cb --- /dev/null +++ b/templates/ff_bloc/model.tmpl @@ -0,0 +1,51 @@ +// ignore: depend_on_referenced_packages +import 'package:equatable/equatable.dart'; + +class ${upperName}Model extends Equatable { + const ${upperName}Model({ + required this.name, + }); + final String name; + + @override + List get props => [ name]; + + Map toMap() { + return { + 'name': name, + }; + } + + static ${upperName}Model? fromMap(Map? map) { + if (map == null) { + return null; + } + + return ${upperName}Model( + name: map['name']!.toString(), + ); + } + +} + +class ${upperName}ViewModel extends Equatable { + const ${upperName}ViewModel({ + // TODO(all): add all required constructor parameters + required this.items, + }); + + // TODO(all): declare your fields here + final List<${upperName}Model>? items; + + @override + List get props => [items /*TODO(all): List all fields here*/]; + + // TODO(all): implement copyWith + ${upperName}ViewModel copyWith({ + List<${upperName}Model>? items, + }) { + return ${upperName}ViewModel( + items: items ?? this.items, + ); + } +} diff --git a/templates/ff_bloc/page.tmpl b/templates/ff_bloc/page.tmpl new file mode 100644 index 00000000..d147a0fd --- /dev/null +++ b/templates/ff_bloc/page.tmpl @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:${appName}${relative}/index.dart'; + + +class ${upperName}Page extends StatefulWidget { + const ${upperName}Page({ + required this.bloc, + super.key + }); + static const String routeName = '/${privateName}'; + + final ${upperName}Bloc? bloc; + + @override + State<${upperName}Page> createState() => _${upperName}PageState(); +} + +class _${upperName}PageState extends State<${upperName}Page> { + + ${upperName}Bloc? _bloc; + ${upperName}Bloc get bloc { + // get it by DI in real code. + _bloc ??= widget.bloc ?? ${upperName}Bloc(); + return _bloc!; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: const Text('${upperName}'), + actions: [ + IconButton( + icon: const Icon(Icons.error), + onPressed: () { + bloc.add(ErrorYouAwesomeEvent()); + }, + ), + IconButton( + icon: const Icon(Icons.add), + onPressed: () { + bloc.add(Add${upperName}Event()); + }, + ), + IconButton( + icon: const Icon(Icons.clear), + onPressed: () { + bloc.add(Clear${upperName}Event()); + }, + ), + ], + ), + body: ${upperName}Screen(bloc: bloc), + ); + } +} diff --git a/templates/ff_bloc/provider.tmpl b/templates/ff_bloc/provider.tmpl new file mode 100644 index 00000000..23f68b26 --- /dev/null +++ b/templates/ff_bloc/provider.tmpl @@ -0,0 +1,26 @@ + +import 'dart:async'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Provider { + + Future?> fetchAsync(String? id) async { + // write logic here to send request to server + if (id == null) { + return null; + } + return [${upperName}Model(name: id)]; + } + + + Future?> addMore(List<${upperName}Model>? now) async { + // write logic here to send request to server + final result = [ + ...(now ?? <${upperName}Model>[]), + ${upperName}Model(name: now?.length.toString() ?? '0') + ]; + return result; + } + +} + diff --git a/templates/ff_bloc/screen.tmpl b/templates/ff_bloc/screen.tmpl new file mode 100644 index 00000000..7f78ad13 --- /dev/null +++ b/templates/ff_bloc/screen.tmpl @@ -0,0 +1,126 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:${appName}${relative}/index.dart'; + + +class ${upperName}Screen extends StatefulWidget { + const ${upperName}Screen({ + required this.bloc, + super.key, + }) ; + + @protected + final ${upperName}Bloc bloc; + + @override + State<${upperName}Screen> createState() { + return ${upperName}ScreenState(); + } +} + +class ${upperName}ScreenState extends State<${upperName}Screen> { + + @override + void initState() { + super.initState(); + // load data on init widget if bloc has not data + if (!widget.bloc.state.hasData) { + _load(); + } + } + + @override + void dispose() { + // dispose bloc if you use subscriptions in bloc + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BlocBuilder<${upperName}Bloc, ${upperName}State>( + bloc: widget.bloc, + builder: ( + BuildContext context, + ${upperName}State currentState, + ) { + // declaration of bloc states + return currentState.when( + onLoading: ()=>const CircularProgressIndicator(), + onEmpty: (data) => _Empty(), + onData: (data) => _BodyList(data: data), + onError: (e) => Center( + child: Column( + children: [ + Text(e.toString()), + TextButton( + onPressed: _load, + child: const Text('ReLoad'), + ) + ], + ), + ), + ); + }, + ); + } + + void _load() { + widget.bloc.add(Load${upperName}Event(id:'1')); + } + +} + + +class _BodyList extends StatefulWidget { + const _BodyList({required this.data}); + + final ${upperName}ViewModel data; + + @override + State<_BodyList> createState() => _BodyListState(); +} + +class _BodyListState extends State<_BodyList> { + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + + return CustomScrollView( + // primary: true, + slivers: [ + const SliverToBoxAdapter(child: Divider()), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + final item = widget.data.items![index]; + if (index == 0) { + return Text('Header $index, id = '+item.name); + } + return Text('Index = $index, id = '+item.name); + }, + childCount: widget.data.items!.length, + ))]); + } +} + + +class _Empty extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Column( + children: [ + Text('Empty'), + ], + ); + } +} \ No newline at end of file diff --git a/templates/ff_bloc/state.tmpl b/templates/ff_bloc/state.tmpl new file mode 100644 index 00000000..6bf34a03 --- /dev/null +++ b/templates/ff_bloc/state.tmpl @@ -0,0 +1,15 @@ +import 'package:ff_bloc/ff_bloc.dart'; + +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}State extends FFState<${upperName}State, ${upperName}ViewModel> { + const ${upperName}State({ + super.version = 0, + super.isLoading = false, + super.data, + super.error, + }); + + @override + StateCopyFactory<${upperName}State, ${upperName}ViewModel> getCopyFactory() => ${upperName}State.new; +} diff --git a/templates/mutable/bloc.tmpl b/templates/mutable/bloc.tmpl new file mode 100644 index 00000000..190adf5d --- /dev/null +++ b/templates/mutable/bloc.tmpl @@ -0,0 +1,37 @@ +import 'dart:async'; +import 'dart:developer' as developer; + +import 'package:bloc/bloc.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Bloc extends Bloc<${upperName}Event, ${upperName}State> { + // todo: check singleton for logic in project + // use GetIt for DI in projct + static final ${upperName}Bloc _${privateName}BlocSingleton = ${upperName}Bloc._internal(); + factory ${upperName}Bloc() { + return _${privateName}BlocSingleton; + } + + ${upperName}Bloc._internal(): super(Un${upperName}State(0)){ + on<${upperName}Event>((event, emit) { + return emit.forEach<${upperName}State>( + event.applyAsync(currentState: state, bloc: this), + onData: (state) => state, + onError: (error, stackTrace) { + developer.log('$error', name: '${upperName}Bloc', error: error, stackTrace: stackTrace); + return Error${upperName}State(0, error.toString()); + }, + ); + }); + } + + @override + Future close() async{ + // dispose objects + await super.close(); + } + + @override + ${upperName}State get initialState => Un${upperName}State(0); + +} diff --git a/templates/mutable/event.tmpl b/templates/mutable/event.tmpl new file mode 100644 index 00000000..cf45ca21 --- /dev/null +++ b/templates/mutable/event.tmpl @@ -0,0 +1,42 @@ +import 'dart:async'; +import 'dart:developer' as developer; + +import 'package:${appName}${relative}/index.dart'; +import 'package:meta/meta.dart'; + +@immutable +abstract class ${upperName}Event { + Stream<${upperName}State> applyAsync( + {${upperName}State currentState, ${upperName}Bloc bloc}); + final ${upperName}Repository _${privateName}Repository = ${upperName}Repository(); +} + +class Un${upperName}Event extends ${upperName}Event { + @override + Stream<${upperName}State> applyAsync({${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { + yield Un${upperName}State(0); + } +} + +class Load${upperName}Event extends ${upperName}Event { + + final bool isError; + @override + String toString() => 'Load${upperName}Event'; + + Load${upperName}Event(this.isError); + + @override + Stream<${upperName}State> applyAsync( + {${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { + try { + yield Un${upperName}State(0); + await Future.delayed(const Duration(seconds: 1)); + _${privateName}Repository.test(isError); + yield In${upperName}State(0, 'Hello world'); + } catch (_, stackTrace) { + developer.log('$_', name: 'Load${upperName}Event', error: _, stackTrace: stackTrace); + yield Error${upperName}State(0, _.toString()); + } + } +} diff --git a/templates/mutable/index.tmpl b/templates/mutable/index.tmpl new file mode 100644 index 00000000..e69de29b diff --git a/templates/mutable/model.tmpl b/templates/mutable/model.tmpl new file mode 100644 index 00000000..64cf5783 --- /dev/null +++ b/templates/mutable/model.tmpl @@ -0,0 +1,47 @@ +import 'package:equatable/equatable.dart'; + +/// generate by https://javiercbk.github.io/json_to_dart/ +class Autogenerated${upperName} { + final List<${upperName}Model> results; + + Autogenerated${upperName}({required this.results}); + + factory Autogenerated${upperName}.fromJson(Map json) { + var temp = []; + if (json['results'] != null) { + temp = <${upperName}Model>[]; + json['results'].forEach((v) { + temp.add(${upperName}Model.fromJson(v as Map)); + }); + } + return Autogenerated${upperName}(results: temp); + } + + Map toJson() { + final data = {}; + data['results'] = results.map((v) => v.toJson()).toList(); + return data; + } +} + +class ${upperName}Model extends Equatable { + final int id; + final String name; + + ${upperName}Model(this.id, this.name); + + @override + List get props => [id, name]; + + factory ${upperName}Model.fromJson(Map json) { + return ${upperName}Model(json['id'] as int, json['name'] as String); + } + + Map toJson() { + final data = {}; + data['id'] = id; + data['name'] = name; + return data; + } + +} diff --git a/templates/mutable/page.tmpl b/templates/mutable/page.tmpl new file mode 100644 index 00000000..5e152b8e --- /dev/null +++ b/templates/mutable/page.tmpl @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Page extends StatefulWidget { + static const String routeName = '/${privateName}'; + + @override + _${upperName}PageState createState() => _${upperName}PageState(); +} + +class _${upperName}PageState extends State<${upperName}Page> { + final _${privateName}Bloc = ${upperName}Bloc(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('${upperName}'), + ), + body: ${upperName}Screen(${privateName}Bloc: _${privateName}Bloc), + ); + } +} diff --git a/templates/mutable/provider.tmpl b/templates/mutable/provider.tmpl new file mode 100644 index 00000000..7fe9c15d --- /dev/null +++ b/templates/mutable/provider.tmpl @@ -0,0 +1,20 @@ +import 'dart:async'; + +class ${upperName}Provider { + Future loadAsync(String token) async { + /// write from keystore/keychain + await Future.delayed(Duration(seconds: 2)); + } + + Future saveAsync(String token) async { + /// write from keystore/keychain + await Future.delayed(Duration(seconds: 2)); + } + + void test(bool isError) { + if (isError == true){ + throw Exception('manual error'); + } + } +} + diff --git a/templates/mutable/repository.tmpl b/templates/mutable/repository.tmpl new file mode 100644 index 00000000..332f91dc --- /dev/null +++ b/templates/mutable/repository.tmpl @@ -0,0 +1,11 @@ +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Repository { + final ${upperName}Provider _${privateName}Provider = ${upperName}Provider(); + + ${upperName}Repository(); + + void test(bool isError) { + _${privateName}Provider.test(isError); + } +} \ No newline at end of file diff --git a/templates/mutable/screen.tmpl b/templates/mutable/screen.tmpl new file mode 100644 index 00000000..e126bf35 --- /dev/null +++ b/templates/mutable/screen.tmpl @@ -0,0 +1,97 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Screen extends StatefulWidget { + const ${upperName}Screen({ + required ${upperName}Bloc ${privateName}Bloc, + Key? key, + }) : _${privateName}Bloc = ${privateName}Bloc, + super(key: key); + + final ${upperName}Bloc _${privateName}Bloc; + + @override + ${upperName}ScreenState createState() { + return ${upperName}ScreenState(); + } +} + +class ${upperName}ScreenState extends State<${upperName}Screen> { + ${upperName}ScreenState(); + + @override + void initState() { + super.initState(); + _load(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BlocBuilder<${upperName}Bloc, ${upperName}State>( + bloc: widget._${privateName}Bloc, + builder: ( + BuildContext context, + ${upperName}State currentState, + ) { + if (currentState is Un${upperName}State) { + return Center( + child: CircularProgressIndicator(), + ); + } + if (currentState is Error${upperName}State) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(currentState.errorMessage), + Padding( + padding: const EdgeInsets.only(top: 32.0), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blue, + ), + child: Text('reload'), + onPressed: _load, + ), + ), + ], + )); + } + if (currentState is In${upperName}State) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(currentState.hello), + const Text('Flutter files: done'), + Padding( + padding: const EdgeInsets.only(top: 32.0), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + ), + child: Text('throw error'), + onPressed: () => _load(true), + ), + ), + ], + ), + ); + } + return Center( + child: CircularProgressIndicator(), + ); + + }); + } + + void _load([bool isError = false]) { + widget._${privateName}Bloc.add(Load${upperName}Event(isError)); + } +} diff --git a/templates/mutable/state.tmpl b/templates/mutable/state.tmpl new file mode 100644 index 00000000..52c7ea72 --- /dev/null +++ b/templates/mutable/state.tmpl @@ -0,0 +1,83 @@ +import 'package:equatable/equatable.dart'; + +abstract class ${upperName}State extends Equatable { + ${upperName}State(this.version); + + /// notify change state without deep clone state + final int version; + + /// Copy object for use in action + /// if need use deep clone + ${upperName}State getStateCopy(); + + ${upperName}State getNewVersion(); + + @override + List get props => [version]; +} + +/// UnInitialized +class Un${upperName}State extends ${upperName}State { + + Un${upperName}State(int version) : super(version); + + @override + String toString() => 'Un${upperName}State'; + + @override + Un${upperName}State getStateCopy() { + return Un${upperName}State(0); + } + + @override + Un${upperName}State getNewVersion() { + return Un${upperName}State(version+1); + } +} + +/// Initialized +class In${upperName}State extends ${upperName}State { + + In${upperName}State(int version, this.hello) : super(version); + + final String hello; + + @override + String toString() => 'In${upperName}State $hello'; + + @override + In${upperName}State getStateCopy() { + return In${upperName}State(version, hello); + } + + @override + In${upperName}State getNewVersion() { + return In${upperName}State(version+1, hello); + } + + @override + List get props => [version, hello]; +} + +class Error${upperName}State extends ${upperName}State { + Error${upperName}State(int version, this.errorMessage): super(version); + + final String errorMessage; + + @override + String toString() => 'Error${upperName}State'; + + @override + Error${upperName}State getStateCopy() { + return Error${upperName}State(version, errorMessage); + } + + @override + Error${upperName}State getNewVersion() { + return Error${upperName}State(version+1, + errorMessage); + } + + @override + List get props => [version, errorMessage]; +} diff --git a/templates/navigate/navigate.tmpl b/templates/navigate/navigate.tmpl new file mode 100644 index 00000000..57b6748b --- /dev/null +++ b/templates/navigate/navigate.tmpl @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:navme/navme.dart'; +import 'package:navme/helpers.dart'; + +import 'index.dart'; + +class ${upperName}Navigate { + // base path + static String path = '${privateName}'; + + // config for configurate Router + static RouteConfig routeConfig = RouteConfig( + state: (Uri? uri) => RouteState(uri: path.toUri()), + // condition for using this page + isThisPage: (RouteState state) { + if (state?.firstPath == path) { + return true; + } + return false; + }, + // settigs from url + settings: (RouteState state) { + return null; + }, + // get Page for Router + page: ({RouteState? state}) { + return MaterialPage( + key: const ValueKey('${upperName}Page'), + child: ${upperName}Page(), + name: '${upperName}Page'); + }, + ); +} diff --git a/templates/simple/bloc.tmpl b/templates/simple/bloc.tmpl new file mode 100644 index 00000000..3556967f --- /dev/null +++ b/templates/simple/bloc.tmpl @@ -0,0 +1,21 @@ +import 'dart:async'; +import 'dart:developer' as developer; + +import 'package:bloc/bloc.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Bloc extends Bloc<${upperName}Event, ${upperName}State> { + + ${upperName}Bloc(${upperName}State initialState) : super(initialState){ + on<${upperName}Event>((event, emit) { + return emit.forEach<${upperName}State>( + event.applyAsync(currentState: state, bloc: this), + onData: (state) => state, + onError: (error, stackTrace) { + developer.log('$error', name: '${upperName}Bloc', error: error, stackTrace: stackTrace); + return Error${upperName}State(error.toString()); + }, + ); + }); + } +} diff --git a/templates/simple/event.tmpl b/templates/simple/event.tmpl new file mode 100644 index 00000000..d21542a2 --- /dev/null +++ b/templates/simple/event.tmpl @@ -0,0 +1,34 @@ +import 'dart:async'; +import 'dart:developer' as developer; + +import 'package:${appName}${relative}/index.dart'; +import 'package:meta/meta.dart'; + +@immutable +abstract class ${upperName}Event { + Stream<${upperName}State> applyAsync( + {${upperName}State currentState, ${upperName}Bloc bloc}); +} + +class Un${upperName}Event extends ${upperName}Event { + @override + Stream<${upperName}State> applyAsync({${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { + yield Un${upperName}State(); + } +} + +class Load${upperName}Event extends ${upperName}Event { + + @override + Stream<${upperName}State> applyAsync( + {${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { + try { + yield Un${upperName}State(); + await Future.delayed(const Duration(seconds: 1)); + yield In${upperName}State('Hello world'); + } catch (_, stackTrace) { + developer.log('$_', name: 'Load${upperName}Event', error: _, stackTrace: stackTrace); + yield Error${upperName}State( _.toString()); + } + } +} diff --git a/templates/simple/index.tmpl b/templates/simple/index.tmpl new file mode 100644 index 00000000..e69de29b diff --git a/templates/simple/model.tmpl b/templates/simple/model.tmpl new file mode 100644 index 00000000..ede30505 --- /dev/null +++ b/templates/simple/model.tmpl @@ -0,0 +1,13 @@ +import 'package:equatable/equatable.dart'; + +/// use https://marketplace.visualstudio.com/items?itemName=BendixMa.dart-data-class-generator +class ${upperName}Model extends Equatable { + final int id; + final String name; + + ${upperName}Model(this.id, this.name); + + @override + List get props => [id, name]; + +} diff --git a/templates/simple/page.tmpl b/templates/simple/page.tmpl new file mode 100644 index 00000000..169680f2 --- /dev/null +++ b/templates/simple/page.tmpl @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Page extends StatefulWidget { + static const String routeName = '/${privateName}'; + + @override + _${upperName}PageState createState() => _${upperName}PageState(); +} + +class _${upperName}PageState extends State<${upperName}Page> { + final _${privateName}Bloc = ${upperName}Bloc(Un${upperName}State()); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('${upperName}'), + ), + body: ${upperName}Screen(${privateName}Bloc: _${privateName}Bloc), + ); + } +} diff --git a/templates/simple/provider.tmpl b/templates/simple/provider.tmpl new file mode 100644 index 00000000..7fe9c15d --- /dev/null +++ b/templates/simple/provider.tmpl @@ -0,0 +1,20 @@ +import 'dart:async'; + +class ${upperName}Provider { + Future loadAsync(String token) async { + /// write from keystore/keychain + await Future.delayed(Duration(seconds: 2)); + } + + Future saveAsync(String token) async { + /// write from keystore/keychain + await Future.delayed(Duration(seconds: 2)); + } + + void test(bool isError) { + if (isError == true){ + throw Exception('manual error'); + } + } +} + diff --git a/templates/simple/repository.tmpl b/templates/simple/repository.tmpl new file mode 100644 index 00000000..332f91dc --- /dev/null +++ b/templates/simple/repository.tmpl @@ -0,0 +1,11 @@ +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Repository { + final ${upperName}Provider _${privateName}Provider = ${upperName}Provider(); + + ${upperName}Repository(); + + void test(bool isError) { + _${privateName}Provider.test(isError); + } +} \ No newline at end of file diff --git a/templates/simple/screen.tmpl b/templates/simple/screen.tmpl new file mode 100644 index 00000000..dc592fec --- /dev/null +++ b/templates/simple/screen.tmpl @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:${appName}${relative}/index.dart'; + +class ${upperName}Screen extends StatefulWidget { + const ${upperName}Screen({ + required ${upperName}Bloc ${privateName}Bloc, + Key? key, + }) : _${privateName}Bloc = ${privateName}Bloc, + super(key: key); + + final ${upperName}Bloc _${privateName}Bloc; + + @override + ${upperName}ScreenState createState() { + return ${upperName}ScreenState(); + } +} + +class ${upperName}ScreenState extends State<${upperName}Screen> { + ${upperName}ScreenState(); + + @override + void initState() { + super.initState(); + _load(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BlocBuilder<${upperName}Bloc, ${upperName}State>( + bloc: widget._${privateName}Bloc, + builder: ( + BuildContext context, + ${upperName}State currentState, + ) { + if (currentState is Un${upperName}State) { + return Center( + child: CircularProgressIndicator(), + ); + } + if (currentState is Error${upperName}State) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(currentState.errorMessage ), + Padding( + padding: const EdgeInsets.only(top: 32.0), + child: RaisedButton( + color: Colors.blue, + child: Text('reload'), + onPressed: _load, + ), + ), + ], + )); + } + if (currentState is In${upperName}State) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(currentState.hello), + ], + ), + ); + } + return Center( + child: CircularProgressIndicator(), + ); + + }); + } + + void _load() { + widget._${privateName}Bloc.add(Load${upperName}Event()); + } +} diff --git a/templates/simple/state.tmpl b/templates/simple/state.tmpl new file mode 100644 index 00000000..be0c2ac0 --- /dev/null +++ b/templates/simple/state.tmpl @@ -0,0 +1,42 @@ +import 'package:equatable/equatable.dart'; + +abstract class ${upperName}State extends Equatable { + ${upperName}State(); + + @override + List get props => []; +} + +/// UnInitialized +class Un${upperName}State extends ${upperName}State { + + Un${upperName}State(); + + @override + String toString() => 'Un${upperName}State'; +} + +/// Initialized +class In${upperName}State extends ${upperName}State { + In${upperName}State(this.hello); + + final String hello; + + @override + String toString() => 'In${upperName}State $hello'; + + @override + List get props => [hello]; +} + +class Error${upperName}State extends ${upperName}State { + Error${upperName}State(this.errorMessage); + + final String errorMessage; + + @override + String toString() => 'Error${upperName}State'; + + @override + List get props => [errorMessage]; +} From 7c04d851343a78b1a0f289e1561b861db9ac4d3a Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 5 Feb 2025 10:35:33 +0800 Subject: [PATCH 4/9] fix API deskripsi: - api login , validasi, hapus code otp --- ...2026a78b8cb786880c7c733460d7dbe-audit.json | 15 +- ...c6075347623def466341a14f8ba4a12-audit.json | 15 +- logs/backend/combined-2025-01-21.log | 4 - logs/backend/combined-2025-01-22.log | 3 - logs/backend/combined-2025-02-04.log | 1 + logs/backend/combined-2025-02-05.log | 1 + logs/backend/error-2025-01-21.log | 0 logs/backend/error-2025-01-22.log | 3 - logs/backend/error-2025-02-04.log | 1 + logs/backend/error-2025-02-05.log | 1 + src/app/api/auth/check/[id]/route.ts | 30 ++ src/app/api/auth/check/route.ts | 24 -- src/app/api/auth/code/route.ts | 67 ++++ src/app/api/auth/validasi/route.ts | 98 +++--- src/app_modules/auth/_lib/api_fetch_auth.ts | 37 ++- src/app_modules/auth/register/view.tsx | 134 ++++---- src/app_modules/auth/validasi/view.tsx | 285 ++++++++++-------- .../component/detail/comp_box_sponsor.tsx | 23 +- 18 files changed, 442 insertions(+), 300 deletions(-) delete mode 100644 logs/backend/combined-2025-01-21.log delete mode 100644 logs/backend/combined-2025-01-22.log create mode 100644 logs/backend/combined-2025-02-05.log delete mode 100644 logs/backend/error-2025-01-21.log delete mode 100644 logs/backend/error-2025-01-22.log create mode 100644 logs/backend/error-2025-02-05.log create mode 100644 src/app/api/auth/check/[id]/route.ts delete mode 100644 src/app/api/auth/check/route.ts create mode 100644 src/app/api/auth/code/route.ts diff --git a/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json b/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json index 66eedd43..7f265053 100644 --- a/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json +++ b/logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json @@ -5,16 +5,6 @@ }, "auditLog": "logs/backend/.31d2357fa2026a78b8cb786880c7c733460d7dbe-audit.json", "files": [ - { - "date": 1737425815219, - "name": "logs/backend/combined-2025-01-21.log", - "hash": "b9cbc8d149568aaeb134725613e3cbf7e862bfe2acb7e6db56292abbf79e51a1" - }, - { - "date": 1737497241982, - "name": "logs/backend/combined-2025-01-22.log", - "hash": "574f8bfec27f059626b3174fe1911a733e84d38ac91be87f853456aae15b11a7" - }, { "date": 1737685849478, "name": "logs/backend/combined-2025-01-24.log", @@ -59,6 +49,11 @@ "date": 1738635038169, "name": "logs/backend/combined-2025-02-04.log", "hash": "b197eb2d58bbab3566e05fdb2bcc52ee608c4fe6ffb54fc958060c8dc4ff305f" + }, + { + "date": 1738709515069, + "name": "logs/backend/combined-2025-02-05.log", + "hash": "04d27d0d5708dfb4655dbb708eb49f663c063c8f571ea5aa4da9e5bee9daa0f3" } ], "hashType": "sha256" diff --git a/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json b/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json index 07566270..2ffc44e0 100644 --- a/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json +++ b/logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json @@ -5,16 +5,6 @@ }, "auditLog": "logs/backend/.5d9a990e0c6075347623def466341a14f8ba4a12-audit.json", "files": [ - { - "date": 1737425815214, - "name": "logs/backend/error-2025-01-21.log", - "hash": "d35389a53138894117f18cdd8210378c4ccfeea9921a52e42837102cad72c108" - }, - { - "date": 1737497241981, - "name": "logs/backend/error-2025-01-22.log", - "hash": "cb0bde065d94357687bece5102573a1876e3f00e1513ff9189e07f56cdadb82e" - }, { "date": 1737685849475, "name": "logs/backend/error-2025-01-24.log", @@ -59,6 +49,11 @@ "date": 1738635038164, "name": "logs/backend/error-2025-02-04.log", "hash": "7490b9f6c36fa2500bafa66c4aa590053c50234150ad9ad86ad9400f0ba76a43" + }, + { + "date": 1738709515065, + "name": "logs/backend/error-2025-02-05.log", + "hash": "b76580b2a8b76ee8941e0d913ff1b38d66ad7bd45f154ed371c913ff898e5dfd" } ], "hashType": "sha256" diff --git a/logs/backend/combined-2025-01-21.log b/logs/backend/combined-2025-01-21.log deleted file mode 100644 index f8447571..00000000 --- a/logs/backend/combined-2025-01-21.log +++ /dev/null @@ -1,4 +0,0 @@ -{"level":"info","message":"Server status code: 201","timestamp":"2025-01-21T05:44:04.245Z"} -{"level":"info","message":"Success upload donasi_bukti_transfer: {\"id\":\"cm661vcrb002a7r93gbyi7y0g\",\"name\":\"56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58.PNG\",\"path\":\"/cm0ur1yxw000056nsjlr6187p/2025/01/21/56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58.PNG\",\"mime\":\"image/png\",\"ext\":\".PNG\",\"desc\":null,\"size\":2531618,\"active\":true,\"createdAt\":\"2025-01-21T05:44:03.670Z\",\"updatedAt\":\"2025-01-21T05:44:03.671Z\",\"userId\":\"cm0ur1yxw000056nsjlr6187p\",\"dirId\":\"cm0yk1pmh000h10njhi6m8b8t\"}","timestamp":"2025-01-21T05:44:04.331Z"} -{"level":"info","message":"Server status code: 201","timestamp":"2025-01-21T05:53:55.644Z"} -{"level":"info","message":"Success upload event_sponsor: {\"id\":\"cm66281fn001rc9dcdf7m74ji\",\"name\":\"56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58-1.PNG\",\"path\":\"/cm0ur1yxw000056nsjlr6187p/2025/01/21/56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58-1.PNG\",\"mime\":\"image/png\",\"ext\":\".PNG\",\"desc\":null,\"size\":2531618,\"active\":true,\"createdAt\":\"2025-01-21T05:53:55.522Z\",\"updatedAt\":\"2025-01-21T05:53:55.523Z\",\"userId\":\"cm0ur1yxw000056nsjlr6187p\",\"dirId\":\"cm65zlbyf001udvmggnd6i0oh\"}","timestamp":"2025-01-21T05:53:55.647Z"} diff --git a/logs/backend/combined-2025-01-22.log b/logs/backend/combined-2025-01-22.log deleted file mode 100644 index 538b3c85..00000000 --- a/logs/backend/combined-2025-01-22.log +++ /dev/null @@ -1,3 +0,0 @@ -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:11:48.296Z"} -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:24:18.884Z"} -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:31:50.770Z"} diff --git a/logs/backend/combined-2025-02-04.log b/logs/backend/combined-2025-02-04.log index 95b71089..aacd117d 100644 --- a/logs/backend/combined-2025-02-04.log +++ b/logs/backend/combined-2025-02-04.log @@ -1 +1,2 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T03:16:37.809Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T06:54:35.085Z"} diff --git a/logs/backend/combined-2025-02-05.log b/logs/backend/combined-2025-02-05.log new file mode 100644 index 00000000..85961909 --- /dev/null +++ b/logs/backend/combined-2025-02-05.log @@ -0,0 +1 @@ +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:30:14.963Z"} diff --git a/logs/backend/error-2025-01-21.log b/logs/backend/error-2025-01-21.log deleted file mode 100644 index e69de29b..00000000 diff --git a/logs/backend/error-2025-01-22.log b/logs/backend/error-2025-01-22.log deleted file mode 100644 index 538b3c85..00000000 --- a/logs/backend/error-2025-01-22.log +++ /dev/null @@ -1,3 +0,0 @@ -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:11:48.296Z"} -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:24:18.884Z"} -{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","originalColumn":16,"originalLine":1069,"stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1217)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1084)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-01-21T22:31:50.770Z"} diff --git a/logs/backend/error-2025-02-04.log b/logs/backend/error-2025-02-04.log index 95b71089..aacd117d 100644 --- a/logs/backend/error-2025-02-04.log +++ b/logs/backend/error-2025-02-04.log @@ -1 +1,2 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T03:16:37.809Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-04T06:54:35.085Z"} diff --git a/logs/backend/error-2025-02-05.log b/logs/backend/error-2025-02-05.log new file mode 100644 index 00000000..85961909 --- /dev/null +++ b/logs/backend/error-2025-02-05.log @@ -0,0 +1 @@ +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:30:14.963Z"} diff --git a/src/app/api/auth/check/[id]/route.ts b/src/app/api/auth/check/[id]/route.ts new file mode 100644 index 00000000..4e073fb5 --- /dev/null +++ b/src/app/api/auth/check/[id]/route.ts @@ -0,0 +1,30 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextRequest, NextResponse } from "next/server"; +export const dynamic = "force-dynamic"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + if (request.method !== "GET") { + return NextResponse.json( + { success: false, message: "Method not allowed" }, + { status: 405 } + ); + } + + try { + const { id } = params; + const data = await prisma.kodeOtp.findFirst({ + where: { + id: id as string, + }, + }); + + return NextResponse.json(data, { status: 200 }); + } catch (error) { + backendLogger.error("Error get code otp", error); //(error); + return NextResponse.json(null, { status: 500 }); + } +} diff --git a/src/app/api/auth/check/route.ts b/src/app/api/auth/check/route.ts deleted file mode 100644 index b51a6f31..00000000 --- a/src/app/api/auth/check/route.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { prisma } from "@/app/lib"; -import { data } from "autoprefixer"; -import { NextRequest, NextResponse } from "next/server"; -export const dynamic = "force-dynamic"; - -export async function GET(request: NextRequest) { - const id = request.nextUrl.searchParams.get("id"); - // const { searchParams } = new URL(request.url); - // const id = searchParams.get("id"); - - try { - const data = await prisma.kodeOtp.findFirst({ - where: { - id: id as string, - }, - }); - - return NextResponse.json(data, { status: 200 }); - } catch (error) { - console.log(error); - } - - return NextResponse.json(null, { status: 500 }); -} diff --git a/src/app/api/auth/code/route.ts b/src/app/api/auth/code/route.ts new file mode 100644 index 00000000..9ecd35de --- /dev/null +++ b/src/app/api/auth/code/route.ts @@ -0,0 +1,67 @@ +import { prisma } from "@/app/lib"; +import { NextResponse } from "next/server"; + +export { DELETE }; +async function DELETE(request: Request) { + if (request.method !== "DELETE") { + return NextResponse.json( + { success: false, message: "Method not allowed" }, + { status: 405 } + ); + } + try { + // Ambil parameter nomor dari URL + const { searchParams } = new URL(request.url); + const nomor = searchParams.get("nomor"); + + // Validasi parameter nomor + if (!nomor) { + return NextResponse.json( + { + success: false, + message: "Parameter 'nomor' diperlukan", + }, + { status: 400 } + ); + } + + // Cek apakah data OTP dengan nomor tersebut ada + const existingOtp = await prisma.kodeOtp.findFirst({ + where: { nomor }, + }); + + if (!existingOtp) { + return NextResponse.json( + { + success: false, + message: "Data OTP tidak ditemukan", + }, + { status: 404 } + ); + } + + // Hapus data OTP + await prisma.kodeOtp.deleteMany({ + where: { nomor }, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil menghapus data OTP", + }, + { status: 200 } + ); + } catch (error) { + console.error("Error deleting OTP:", error); + return NextResponse.json( + { + success: false, + message: "Terjadi kesalahan saat menghapus data OTP", + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); + } +} diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index c8c2e9ea..c13633fd 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -4,58 +4,60 @@ import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { - if (req.method === "POST") { + if (req.method !== "POST") { + return NextResponse.json( + { success: false, message: "Method Not Allowed" }, + { status: 405 } + ); + } + + try { const { nomor } = await req.json(); + const dataUser = await prisma.user.findUnique({ + where: { + nomor: nomor, + }, + select: { + id: true, + nomor: true, + username: true, + active: true, + masterUserRoleId: true, + }, + }); - try { - const dataUser = await prisma.user.findUnique({ - where: { - nomor: nomor, - }, - select: { - id: true, - nomor: true, - username: true, - active: true, - masterUserRoleId: true, - }, - }); - - if (dataUser == null) - return NextResponse.json( - { success: false, message: "Nomor Belum Terdaftar" }, - { status: 404 } - ); - - const token = await sessionCreate({ - sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, - encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, - user: dataUser as any, - }); - + if (dataUser == null) return NextResponse.json( - { - success: true, - message: "Berhasil Login", - roleId: dataUser.masterUserRoleId, - active: dataUser.active, - }, + { success: false, message: "Nomor Belum Terdaftar" }, { status: 200 } ); - } catch (error) { - backendLogger.log("Error Validasi:", error); - return NextResponse.json( - { - success: false, - message: "Server Error", - reason: (error as Error).message, - }, - { status: 500 } - ); - } + + const token = await sessionCreate({ + sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + user: dataUser as any, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil Login", + roleId: dataUser.masterUserRoleId, + active: dataUser.active, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.log("API Error or Server Error", error); + return NextResponse.json( + { + success: false, + message: "API Error or Server Error", + reason: (error as Error).message, + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); } - return NextResponse.json( - { success: false, message: "Method Not Allowed" }, - { status: 405 } - ); } diff --git a/src/app_modules/auth/_lib/api_fetch_auth.ts b/src/app_modules/auth/_lib/api_fetch_auth.ts index 15882c76..ed7d9bc1 100644 --- a/src/app_modules/auth/_lib/api_fetch_auth.ts +++ b/src/app_modules/auth/_lib/api_fetch_auth.ts @@ -1,4 +1,9 @@ -export { apiFetchLogin }; +export { + apiFetchLogin, + apiGetCheckCodeOtp, + apiPostVerifikasiCodeOtp, + apiDeleteAktivasiKodeOtpByNomor, +}; const apiFetchLogin = async ({ nomor }: { nomor: string }) => { const respone = await fetch("/api/auth/login", { @@ -11,3 +16,33 @@ const apiFetchLogin = async ({ nomor }: { nomor: string }) => { return await respone.json().catch(() => null); }; + +const apiGetCheckCodeOtp = async ({ id }: { id: string }) => { + const respone = await fetch(`/api/auth/check/${id}`); + + return await respone.json().catch(() => null); +}; + +const apiPostVerifikasiCodeOtp = async ({ nomor }: { nomor: string }) => { + const respone = await fetch("/api/auth/validasi", { + method: "POST", + body: JSON.stringify({ nomor: nomor }), + headers: { + "Content-Type": "application/json", + }, + }); + + return await respone.json().catch(() => null); +}; + +const apiDeleteAktivasiKodeOtpByNomor = async ({ + nomor, +}: { + nomor: string; +}) => { + const respone = await fetch(`/api/auth/delete/${nomor}`, { + method: "DELETE", + }); + + return await respone.json().catch(() => null); +}; diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 37276b59..0aab82e8 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -5,7 +5,7 @@ import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_in import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui"; -import { Button, Stack, Text, TextInput, Title } from "@mantine/core"; +import { Button, Center, Stack, Text, TextInput, Title } from "@mantine/core"; import { useFocusTrap, useShallowEffect } from "@mantine/hooks"; import { IconUserCircle } from "@tabler/icons-react"; import _ from "lodash"; @@ -14,6 +14,8 @@ import { useState } from "react"; import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id"; import Register_SkeletonView from "./skeleton"; import { clientLogger } from "@/util/clientLogger"; +import { apiGetCheckCodeOtp } from "../_lib/api_fetch_auth"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; export default function Register() { const router = useRouter(); @@ -39,10 +41,16 @@ export default function Register() { kodeId: string; onSetData: any; }) { - const res = await fetch(`/api/auth/check?id=${kodeId}`); - const result = await res.json(); - - onSetData(result.nomor); + try { + const respone = await apiGetCheckCodeOtp({ id: kodeId }); + if (respone) { + onSetData(respone.nomor); + } + } catch (error) { + clientLogger.error("Error onCheckAuthCode:", error); + } + // const res = await fetch(`/api/auth/check?id=${kodeId}`); + // const result = await res.json(); } async function onRegistarsi() { @@ -102,71 +110,75 @@ export default function Register() { return ( <> - {nomor == "" ? ( - - ) : ( - - - REGISTRASI - + + + REGISTRASI + - + - + + - Anda akan terdaftar dengan nomor berikut{" "} - + Anda akan terdaftar dengan nomor + + {nomor == "" ? ( +
+ +
+ ) : ( + +{nomor} -
- 0 && value.length < 5 ? ( - - ) : _.values(value).includes(" ") ? ( - - - - - ) : isValue ? ( - - ) : ( - "" - ) + )} +
+ 0 && value.length < 5 ? ( + + ) : _.values(value).includes(" ") ? ( + + + + + ) : isValue ? ( + + ) : ( + "" + ) + } + onChange={(val) => { + val.currentTarget.value.length > 0 ? setIsValue(false) : ""; + setValue(val.currentTarget.value); + }} + /> + + - + > + DAFTAR +
- )} +
); diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index 65b603b9..ff2c31d8 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -10,8 +10,11 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_ import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui"; import { + ActionIcon, + Box, Button, Center, + Group, Loader, PinInput, Stack, @@ -26,6 +29,14 @@ import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_glo import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id"; import Validasi_SkeletonView from "./skeleton"; import { clientLogger } from "@/util/clientLogger"; +import { IconChevronLeft } from "@tabler/icons-react"; +import _ from "lodash"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { + apiDeleteAktivasiKodeOtpByNomor, + apiGetCheckCodeOtp, + apiPostVerifikasiCodeOtp, +} from "../_lib/api_fetch_auth"; export default function Validasi() { const router = useRouter(); @@ -61,20 +72,24 @@ export default function Validasi() { }, [triggerOtp]); async function onCheckAuthCode({ kodeId }: { kodeId: string }) { - const res = await fetch(`/api/auth/check?id=${kodeId}`); - const result = await res.json(); - - setData({ - nomor: result.nomor, - code: result.otp, - }); + try { + const respone = await apiGetCheckCodeOtp({ id: kodeId }); + if (respone) { + setData({ + nomor: respone.nomor, + code: respone.otp, + }); + } + } catch (error) { + clientLogger.error("Error onCheckAuthCode:", error); + } } useEffect(() => { counter > 0 && setTimeout(() => setCounter(counter - 1), 1000); }, [counter]); - async function onVerifikasi() { + async function onSubmitVerifikasi() { if (!inputCode) return ComponentGlobal_NotifikasiPeringatan("Lengkapi Kode"); if (data.code != inputCode) @@ -82,59 +97,77 @@ export default function Validasi() { try { setLoading(true); - const res = await fetch("/api/auth/validasi", { - method: "POST", - body: JSON.stringify({ - nomor: data.nomor, - }), - }); + const respone = await apiPostVerifikasiCodeOtp({ nomor: data.nomor }); - const result = await res.json(); + if (respone && respone.success == true) { + if (respone.roleId == "1") { + ComponentGlobal_NotifikasiBerhasil(respone.message); + localStorage.removeItem("hipmi_auth_code_id"); - if (res.status === 200 && result.roleId == "1") { - ComponentGlobal_NotifikasiBerhasil(result.message); - localStorage.removeItem("hipmi_auth_code_id"); - await auth_funDeleteAktivasiKodeOtpByNomor({ - nomor: data.nomor, - }); + router.push(RouterHome.main_home, { scroll: false }); + } else if (respone.roleId != "1") { + ComponentGlobal_NotifikasiBerhasil("Admin berhasil login"); + localStorage.removeItem("hipmi_auth_code_id"); - router.push(RouterHome.main_home, { scroll: false }); - return; - } + router.push(RouterAdminDashboard.splash_admin, { scroll: false }); + } - if (res.status === 200 && result.roleId != "1") { - ComponentGlobal_NotifikasiBerhasil("Admin Logged in"); - localStorage.removeItem("hipmi_auth_code_id"); - await auth_funDeleteAktivasiKodeOtpByNomor({ - nomor: data.nomor, - }); - - router.push(RouterAdminDashboard.splash_admin, { scroll: false }); - return; - } - - if (res.status === 404) { - setLoading(false); + try { + const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ + nomor: data.nomor, + }); + } catch (error) { + clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error); + } + } else if (respone && respone.success == false) { router.push("/register", { scroll: false }); - ComponentGlobal_NotifikasiBerhasil(result.message); - return; + ComponentGlobal_NotifikasiBerhasil(respone.message); } - if (res.status === 400) { - setLoading(false); - ComponentGlobal_NotifikasiPeringatan(result.message); - return; - } + // if (respone.status === 200 && result.roleId == "1") { + // ComponentGlobal_NotifikasiBerhasil(result.message); + // localStorage.removeItem("hipmi_auth_code_id"); + // await auth_funDeleteAktivasiKodeOtpByNomor({ + // nomor: data.nomor, + // }); - if (res.status == 500) { - setLoading(false); - ComponentGlobal_NotifikasiGagal(result.message); - return; - } + // router.push(RouterHome.main_home, { scroll: false }); + // return; + // } + + // if (respone.status === 200 && result.roleId != "1") { + // ComponentGlobal_NotifikasiBerhasil("Admin Logged in"); + // localStorage.removeItem("hipmi_auth_code_id"); + // await auth_funDeleteAktivasiKodeOtpByNomor({ + // nomor: data.nomor, + // }); + + // router.push(RouterAdminDashboard.splash_admin, { scroll: false }); + // return; + // } + + // if (respone.status === 404) { + // setLoading(false); + // router.push("/register", { scroll: false }); + // ComponentGlobal_NotifikasiBerhasil(result.message); + // return; + // } + + // if (respone.status === 400) { + // setLoading(false); + // ComponentGlobal_NotifikasiPeringatan(result.message); + // return; + // } + + // if (respone.status == 500) { + // setLoading(false); + // ComponentGlobal_NotifikasiGagal(result.message); + // return; + // } } catch (error) { setLoading(false); clientLogger.error("Error validasi:", error); - } + } } async function onBack() { @@ -176,8 +209,6 @@ export default function Validasi() { } } - // console.log(data.code); - return ( <> @@ -194,84 +225,88 @@ export default function Validasi() { */} - {data.nomor == "" && data.code == "" ? ( - - ) : ( - - - Verifikasi Kode OTP - - - - Masukan 4 digit kode otp - - Yang dikirim ke{" "} - - {" "} + + + Verifikasi Kode OTP + + + + + Masukan 4 digit kode otp + + Yang dikirim ke + {data && data.nomor !== "" ? ( + +{data.nomor} - - -
- { - setInputOtp(val); - }} - /> -
- - - - Tidak menerima kode ?{" "} - {counter > 0 ? ( - - {counter + "s"} - - ) : loadingResend ? ( - - ) : ( - { - onResendCode(); - }} - fw={"bold"} - > - Kirim ulang - - )} - - + ) : ( + + )} + +
+
+ { + setInputOtp(val); + }} + /> +
+ + + + Tidak menerima kode ?{" "} + {counter > 0 ? ( + + {counter + "s"} + + ) : loadingResend ? ( + + ) : ( + { + onResendCode(); + }} + fw={"bold"} + > + Kirim ulang + + )} + -
- )} + + + + {/* {data.nomor == "" && data.code == "" ? : ""} */}
diff --git a/src/app_modules/event/component/detail/comp_box_sponsor.tsx b/src/app_modules/event/component/detail/comp_box_sponsor.tsx index 9505d1f6..5777ed70 100644 --- a/src/app_modules/event/component/detail/comp_box_sponsor.tsx +++ b/src/app_modules/event/component/detail/comp_box_sponsor.tsx @@ -1,9 +1,10 @@ -import { RouterEvent } from '@/app/lib/router_hipmi/router_event'; -import { AccentColor, MainColor } from '@/app_modules/_global/color'; -import { ActionIcon, Flex, Loader, Paper, Text } from '@mantine/core'; -import { IconStar } from '@tabler/icons-react'; -import { useParams, useRouter } from 'next/navigation'; -import { useState } from 'react'; +import { RouterEvent } from "@/app/lib/router_hipmi/router_event"; +import { AccentColor, MainColor } from "@/app_modules/_global/color"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; +import { ActionIcon, Flex, Loader, Paper, Text } from "@mantine/core"; +import { IconStar } from "@tabler/icons-react"; +import { useParams, useRouter } from "next/navigation"; +import { useState } from "react"; function Event_ComponentBoxDaftarSponsor() { const router = useRouter(); @@ -20,11 +21,11 @@ function Event_ComponentBoxDaftarSponsor() { color: "white", }} onClick={() => { - setLoading(true); - router.push(RouterEvent.daftar_sponsor({ id: params.id }), { - scroll: false, - }); - // router.push(RouterInvestasi_OLD.detail_dokumen + investasiId, { scroll: false }); + // setLoading(true); + // router.push(RouterEvent.daftar_sponsor({ id: params.id }), { + // scroll: false, + // }); + ComponentGlobal_NotifikasiPeringatan("Fitur belum tersedia"); }} > From 331b5c9a846d0d75632897a7a37f9eca7dbd0181 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 5 Feb 2025 11:49:09 +0800 Subject: [PATCH 5/9] delete file tamplate --- logs/backend/combined-2025-02-05.log | 3 + logs/backend/error-2025-02-05.log | 3 + src/app/api/auth/code/route.ts | 6 +- src/app_modules/auth/_lib/api_fetch_auth.ts | 6 +- src/middleware.ts | 1 + templates/ff.config.json | 82 ------------- templates/ff_bloc/bloc.tmpl | 16 --- templates/ff_bloc/event.tmpl | 78 ------------ templates/ff_bloc/index.tmpl | 0 templates/ff_bloc/model.tmpl | 51 -------- templates/ff_bloc/page.tmpl | 57 --------- templates/ff_bloc/provider.tmpl | 26 ---- templates/ff_bloc/screen.tmpl | 126 -------------------- templates/ff_bloc/state.tmpl | 15 --- templates/mutable/bloc.tmpl | 37 ------ templates/mutable/event.tmpl | 42 ------- templates/mutable/index.tmpl | 0 templates/mutable/model.tmpl | 47 -------- templates/mutable/page.tmpl | 23 ---- templates/mutable/provider.tmpl | 20 ---- templates/mutable/repository.tmpl | 11 -- templates/mutable/screen.tmpl | 97 --------------- templates/mutable/state.tmpl | 83 ------------- templates/navigate/navigate.tmpl | 33 ----- templates/simple/bloc.tmpl | 21 ---- templates/simple/event.tmpl | 34 ------ templates/simple/index.tmpl | 0 templates/simple/model.tmpl | 13 -- templates/simple/page.tmpl | 23 ---- templates/simple/provider.tmpl | 20 ---- templates/simple/repository.tmpl | 11 -- templates/simple/screen.tmpl | 84 ------------- templates/simple/state.tmpl | 42 ------- {xhtml => x-example-show-pdf}/index.html | 0 x.sh | 1 - xcoba.sh | 14 --- 36 files changed, 16 insertions(+), 1110 deletions(-) delete mode 100644 templates/ff.config.json delete mode 100644 templates/ff_bloc/bloc.tmpl delete mode 100644 templates/ff_bloc/event.tmpl delete mode 100644 templates/ff_bloc/index.tmpl delete mode 100644 templates/ff_bloc/model.tmpl delete mode 100644 templates/ff_bloc/page.tmpl delete mode 100644 templates/ff_bloc/provider.tmpl delete mode 100644 templates/ff_bloc/screen.tmpl delete mode 100644 templates/ff_bloc/state.tmpl delete mode 100644 templates/mutable/bloc.tmpl delete mode 100644 templates/mutable/event.tmpl delete mode 100644 templates/mutable/index.tmpl delete mode 100644 templates/mutable/model.tmpl delete mode 100644 templates/mutable/page.tmpl delete mode 100644 templates/mutable/provider.tmpl delete mode 100644 templates/mutable/repository.tmpl delete mode 100644 templates/mutable/screen.tmpl delete mode 100644 templates/mutable/state.tmpl delete mode 100644 templates/navigate/navigate.tmpl delete mode 100644 templates/simple/bloc.tmpl delete mode 100644 templates/simple/event.tmpl delete mode 100644 templates/simple/index.tmpl delete mode 100644 templates/simple/model.tmpl delete mode 100644 templates/simple/page.tmpl delete mode 100644 templates/simple/provider.tmpl delete mode 100644 templates/simple/repository.tmpl delete mode 100644 templates/simple/screen.tmpl delete mode 100644 templates/simple/state.tmpl rename {xhtml => x-example-show-pdf}/index.html (100%) delete mode 100644 x.sh delete mode 100644 xcoba.sh diff --git a/logs/backend/combined-2025-02-05.log b/logs/backend/combined-2025-02-05.log index 85961909..44650842 100644 --- a/logs/backend/combined-2025-02-05.log +++ b/logs/backend/combined-2025-02-05.log @@ -1 +1,4 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:30:14.963Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:44:11.043Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T03:13:24.349Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-02-05T03:48:26.606Z"} diff --git a/logs/backend/error-2025-02-05.log b/logs/backend/error-2025-02-05.log index 85961909..44650842 100644 --- a/logs/backend/error-2025-02-05.log +++ b/logs/backend/error-2025-02-05.log @@ -1 +1,4 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:30:14.963Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:44:11.043Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T03:13:24.349Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-02-05T03:48:26.606Z"} diff --git a/src/app/api/auth/code/route.ts b/src/app/api/auth/code/route.ts index 9ecd35de..534eb1c6 100644 --- a/src/app/api/auth/code/route.ts +++ b/src/app/api/auth/code/route.ts @@ -11,8 +11,7 @@ async function DELETE(request: Request) { } try { // Ambil parameter nomor dari URL - const { searchParams } = new URL(request.url); - const nomor = searchParams.get("nomor"); + const { nomor } = await request.json(); // Validasi parameter nomor if (!nomor) { @@ -27,6 +26,9 @@ async function DELETE(request: Request) { // Cek apakah data OTP dengan nomor tersebut ada const existingOtp = await prisma.kodeOtp.findFirst({ + orderBy: { + createdAt: "desc", + }, where: { nomor }, }); diff --git a/src/app_modules/auth/_lib/api_fetch_auth.ts b/src/app_modules/auth/_lib/api_fetch_auth.ts index ed7d9bc1..f1c08e6b 100644 --- a/src/app_modules/auth/_lib/api_fetch_auth.ts +++ b/src/app_modules/auth/_lib/api_fetch_auth.ts @@ -40,8 +40,12 @@ const apiDeleteAktivasiKodeOtpByNomor = async ({ }: { nomor: string; }) => { - const respone = await fetch(`/api/auth/delete/${nomor}`, { + const respone = await fetch(`/api/auth/code`, { method: "DELETE", + body: JSON.stringify({nomor}), + headers: { + "Content-Type": "application/json", + } }); return await respone.json().catch(() => null); diff --git a/src/middleware.ts b/src/middleware.ts index 47f2f981..a68f2186 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -129,6 +129,7 @@ export const middleware = async (req: NextRequest) => { // ==================== Authentication: Login, Validasi, Registrasi ==================== // // Token verification const user = await verifyToken({ token, encodedKey }); + console.log("middlaware",user) // Handle login page access if (pathname === loginPath) { diff --git a/templates/ff.config.json b/templates/ff.config.json deleted file mode 100644 index ad05a6f5..00000000 --- a/templates/ff.config.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "name": "base", - "configs": [ - { - "name": "bloc", - "commands": [ - { - "name": "[FF] New Big Pack Bloc", - "templates": ["*"], - "key": "bigpack", - "files": [ - "bloc", - "event", - "index", - "model", - "page", - "provider", - "repository", - "screen", - "state" - ] - }, - { - "name": "[FF] New Small Pack Bloc", - "templates": ["*"], - "key": "smallpack", - "files": ["bloc", "event", "index", "page", "screen", "state"] - }, - { - "name": "[FF] New Bloc", - "templates": ["*"], - "files": ["bloc"] - }, - { - "name": "[FF] New Event", - "templates": ["*"], - "files": ["event"] - }, - { - "name": "[FF] New Model", - "templates": ["*"], - "files": ["model"] - }, - { - "name": "[FF] New Page", - "templates": ["*"], - "files": ["page"] - }, - { - "name": "[FF] New Provider", - "templates": ["*"], - "files": ["provider"] - }, - { - "name": "[FF] New Repository", - "templates": ["*"], - "files": ["repository"] - }, - { - "name": "[FF] New Screen", - "templates": ["*"], - "files": ["screen"] - }, - { - "name": "[FF] New State", - "templates": ["*"], - "files": ["state"] - }, - { - "name": "[FF] New Index", - "templates": ["*"], - "files": ["index"] - }, - { - "name": "[FF] New Navigate(Navme)", - "templates": ["navigate"], - "files": ["navigate"] - } - ] - } - ] -} diff --git a/templates/ff_bloc/bloc.tmpl b/templates/ff_bloc/bloc.tmpl deleted file mode 100644 index f806fd48..00000000 --- a/templates/ff_bloc/bloc.tmpl +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:ff_bloc/ff_bloc.dart'; - -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Bloc extends FFBloc<${upperName}Event, ${upperName}State> { - ${upperName}Bloc({ - required this.provider, - super.initialState = const ${upperName}State(), - }); - /// Use this for all requests to backend - you can mock it in tests - final ${upperName}Provider provider; - - @override - ${upperName}State onErrorState(Object error) => state.copy(error: error, isLoading: false); - -} diff --git a/templates/ff_bloc/event.tmpl b/templates/ff_bloc/event.tmpl deleted file mode 100644 index 7dcff332..00000000 --- a/templates/ff_bloc/event.tmpl +++ /dev/null @@ -1,78 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/widgets.dart'; -import 'package:ff_bloc/ff_bloc.dart'; - -import 'package:${appName}${relative}/index.dart'; - -@immutable -abstract class ${upperName}Event implements FFBlocEvent<${upperName}State, ${upperName}Bloc> {} - -/// Initial Event with load data -class Load${upperName}Event extends ${upperName}Event { - Load${upperName}Event({required this.id}); - final String? id; - - static const String _name = 'Load${upperName}Event'; - - @override - String toString() => _name; - - @override - Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { - // set loading true for show loading - yield bloc.state.copyWithoutError(isLoading: true); - // fetch data - final result = await bloc.provider.fetchAsync(id); - // set data to state - yield bloc.state.copyWithoutError( - isLoading: false, - data: ${upperName}ViewModel(items: result), - ); - } -} - - -class Add${upperName}Event extends ${upperName}Event { - static const String _name = 'Add${upperName}Event'; - - @override - String toString() => _name; - - @override - Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { - yield bloc.state.copyWithoutError(isLoading: true); - final result = await bloc.provider.addMore(bloc.state.data?.items); - yield bloc.state.copyWithoutError( - isLoading: false, - data: ${upperName}ViewModel(items: result), - ); - } -} - -class ErrorYouAwesomeEvent extends YouAwesomeEvent { - static const String _name = 'ErrorYouAwesomeEvent'; - - @override - String toString() => _name; - - @override - Stream applyAsync({required YouAwesomeBloc bloc}) async* { - throw Exception('Test error'); - } -} - -class Clear${upperName}Event extends ${upperName}Event { - static const String _name = 'Clear${upperName}Event'; - - @override - String toString() => _name; - - @override - Stream<${upperName}State> applyAsync({required ${upperName}Bloc bloc}) async* { - yield bloc.state.copyWithoutError(isLoading: true); - yield bloc.state.copyWithoutData( - isLoading: false, - ); - } -} diff --git a/templates/ff_bloc/index.tmpl b/templates/ff_bloc/index.tmpl deleted file mode 100644 index e69de29b..00000000 diff --git a/templates/ff_bloc/model.tmpl b/templates/ff_bloc/model.tmpl deleted file mode 100644 index 4b13e7cb..00000000 --- a/templates/ff_bloc/model.tmpl +++ /dev/null @@ -1,51 +0,0 @@ -// ignore: depend_on_referenced_packages -import 'package:equatable/equatable.dart'; - -class ${upperName}Model extends Equatable { - const ${upperName}Model({ - required this.name, - }); - final String name; - - @override - List get props => [ name]; - - Map toMap() { - return { - 'name': name, - }; - } - - static ${upperName}Model? fromMap(Map? map) { - if (map == null) { - return null; - } - - return ${upperName}Model( - name: map['name']!.toString(), - ); - } - -} - -class ${upperName}ViewModel extends Equatable { - const ${upperName}ViewModel({ - // TODO(all): add all required constructor parameters - required this.items, - }); - - // TODO(all): declare your fields here - final List<${upperName}Model>? items; - - @override - List get props => [items /*TODO(all): List all fields here*/]; - - // TODO(all): implement copyWith - ${upperName}ViewModel copyWith({ - List<${upperName}Model>? items, - }) { - return ${upperName}ViewModel( - items: items ?? this.items, - ); - } -} diff --git a/templates/ff_bloc/page.tmpl b/templates/ff_bloc/page.tmpl deleted file mode 100644 index d147a0fd..00000000 --- a/templates/ff_bloc/page.tmpl +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:${appName}${relative}/index.dart'; - - -class ${upperName}Page extends StatefulWidget { - const ${upperName}Page({ - required this.bloc, - super.key - }); - static const String routeName = '/${privateName}'; - - final ${upperName}Bloc? bloc; - - @override - State<${upperName}Page> createState() => _${upperName}PageState(); -} - -class _${upperName}PageState extends State<${upperName}Page> { - - ${upperName}Bloc? _bloc; - ${upperName}Bloc get bloc { - // get it by DI in real code. - _bloc ??= widget.bloc ?? ${upperName}Bloc(); - return _bloc!; - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - centerTitle: true, - title: const Text('${upperName}'), - actions: [ - IconButton( - icon: const Icon(Icons.error), - onPressed: () { - bloc.add(ErrorYouAwesomeEvent()); - }, - ), - IconButton( - icon: const Icon(Icons.add), - onPressed: () { - bloc.add(Add${upperName}Event()); - }, - ), - IconButton( - icon: const Icon(Icons.clear), - onPressed: () { - bloc.add(Clear${upperName}Event()); - }, - ), - ], - ), - body: ${upperName}Screen(bloc: bloc), - ); - } -} diff --git a/templates/ff_bloc/provider.tmpl b/templates/ff_bloc/provider.tmpl deleted file mode 100644 index 23f68b26..00000000 --- a/templates/ff_bloc/provider.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - -import 'dart:async'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Provider { - - Future?> fetchAsync(String? id) async { - // write logic here to send request to server - if (id == null) { - return null; - } - return [${upperName}Model(name: id)]; - } - - - Future?> addMore(List<${upperName}Model>? now) async { - // write logic here to send request to server - final result = [ - ...(now ?? <${upperName}Model>[]), - ${upperName}Model(name: now?.length.toString() ?? '0') - ]; - return result; - } - -} - diff --git a/templates/ff_bloc/screen.tmpl b/templates/ff_bloc/screen.tmpl deleted file mode 100644 index 7f78ad13..00000000 --- a/templates/ff_bloc/screen.tmpl +++ /dev/null @@ -1,126 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:${appName}${relative}/index.dart'; - - -class ${upperName}Screen extends StatefulWidget { - const ${upperName}Screen({ - required this.bloc, - super.key, - }) ; - - @protected - final ${upperName}Bloc bloc; - - @override - State<${upperName}Screen> createState() { - return ${upperName}ScreenState(); - } -} - -class ${upperName}ScreenState extends State<${upperName}Screen> { - - @override - void initState() { - super.initState(); - // load data on init widget if bloc has not data - if (!widget.bloc.state.hasData) { - _load(); - } - } - - @override - void dispose() { - // dispose bloc if you use subscriptions in bloc - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return BlocBuilder<${upperName}Bloc, ${upperName}State>( - bloc: widget.bloc, - builder: ( - BuildContext context, - ${upperName}State currentState, - ) { - // declaration of bloc states - return currentState.when( - onLoading: ()=>const CircularProgressIndicator(), - onEmpty: (data) => _Empty(), - onData: (data) => _BodyList(data: data), - onError: (e) => Center( - child: Column( - children: [ - Text(e.toString()), - TextButton( - onPressed: _load, - child: const Text('ReLoad'), - ) - ], - ), - ), - ); - }, - ); - } - - void _load() { - widget.bloc.add(Load${upperName}Event(id:'1')); - } - -} - - -class _BodyList extends StatefulWidget { - const _BodyList({required this.data}); - - final ${upperName}ViewModel data; - - @override - State<_BodyList> createState() => _BodyListState(); -} - -class _BodyListState extends State<_BodyList> { - - @override - void initState() { - super.initState(); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - - return CustomScrollView( - // primary: true, - slivers: [ - const SliverToBoxAdapter(child: Divider()), - SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - final item = widget.data.items![index]; - if (index == 0) { - return Text('Header $index, id = '+item.name); - } - return Text('Index = $index, id = '+item.name); - }, - childCount: widget.data.items!.length, - ))]); - } -} - - -class _Empty extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Column( - children: [ - Text('Empty'), - ], - ); - } -} \ No newline at end of file diff --git a/templates/ff_bloc/state.tmpl b/templates/ff_bloc/state.tmpl deleted file mode 100644 index 6bf34a03..00000000 --- a/templates/ff_bloc/state.tmpl +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:ff_bloc/ff_bloc.dart'; - -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}State extends FFState<${upperName}State, ${upperName}ViewModel> { - const ${upperName}State({ - super.version = 0, - super.isLoading = false, - super.data, - super.error, - }); - - @override - StateCopyFactory<${upperName}State, ${upperName}ViewModel> getCopyFactory() => ${upperName}State.new; -} diff --git a/templates/mutable/bloc.tmpl b/templates/mutable/bloc.tmpl deleted file mode 100644 index 190adf5d..00000000 --- a/templates/mutable/bloc.tmpl +++ /dev/null @@ -1,37 +0,0 @@ -import 'dart:async'; -import 'dart:developer' as developer; - -import 'package:bloc/bloc.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Bloc extends Bloc<${upperName}Event, ${upperName}State> { - // todo: check singleton for logic in project - // use GetIt for DI in projct - static final ${upperName}Bloc _${privateName}BlocSingleton = ${upperName}Bloc._internal(); - factory ${upperName}Bloc() { - return _${privateName}BlocSingleton; - } - - ${upperName}Bloc._internal(): super(Un${upperName}State(0)){ - on<${upperName}Event>((event, emit) { - return emit.forEach<${upperName}State>( - event.applyAsync(currentState: state, bloc: this), - onData: (state) => state, - onError: (error, stackTrace) { - developer.log('$error', name: '${upperName}Bloc', error: error, stackTrace: stackTrace); - return Error${upperName}State(0, error.toString()); - }, - ); - }); - } - - @override - Future close() async{ - // dispose objects - await super.close(); - } - - @override - ${upperName}State get initialState => Un${upperName}State(0); - -} diff --git a/templates/mutable/event.tmpl b/templates/mutable/event.tmpl deleted file mode 100644 index cf45ca21..00000000 --- a/templates/mutable/event.tmpl +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:async'; -import 'dart:developer' as developer; - -import 'package:${appName}${relative}/index.dart'; -import 'package:meta/meta.dart'; - -@immutable -abstract class ${upperName}Event { - Stream<${upperName}State> applyAsync( - {${upperName}State currentState, ${upperName}Bloc bloc}); - final ${upperName}Repository _${privateName}Repository = ${upperName}Repository(); -} - -class Un${upperName}Event extends ${upperName}Event { - @override - Stream<${upperName}State> applyAsync({${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { - yield Un${upperName}State(0); - } -} - -class Load${upperName}Event extends ${upperName}Event { - - final bool isError; - @override - String toString() => 'Load${upperName}Event'; - - Load${upperName}Event(this.isError); - - @override - Stream<${upperName}State> applyAsync( - {${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { - try { - yield Un${upperName}State(0); - await Future.delayed(const Duration(seconds: 1)); - _${privateName}Repository.test(isError); - yield In${upperName}State(0, 'Hello world'); - } catch (_, stackTrace) { - developer.log('$_', name: 'Load${upperName}Event', error: _, stackTrace: stackTrace); - yield Error${upperName}State(0, _.toString()); - } - } -} diff --git a/templates/mutable/index.tmpl b/templates/mutable/index.tmpl deleted file mode 100644 index e69de29b..00000000 diff --git a/templates/mutable/model.tmpl b/templates/mutable/model.tmpl deleted file mode 100644 index 64cf5783..00000000 --- a/templates/mutable/model.tmpl +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:equatable/equatable.dart'; - -/// generate by https://javiercbk.github.io/json_to_dart/ -class Autogenerated${upperName} { - final List<${upperName}Model> results; - - Autogenerated${upperName}({required this.results}); - - factory Autogenerated${upperName}.fromJson(Map json) { - var temp = []; - if (json['results'] != null) { - temp = <${upperName}Model>[]; - json['results'].forEach((v) { - temp.add(${upperName}Model.fromJson(v as Map)); - }); - } - return Autogenerated${upperName}(results: temp); - } - - Map toJson() { - final data = {}; - data['results'] = results.map((v) => v.toJson()).toList(); - return data; - } -} - -class ${upperName}Model extends Equatable { - final int id; - final String name; - - ${upperName}Model(this.id, this.name); - - @override - List get props => [id, name]; - - factory ${upperName}Model.fromJson(Map json) { - return ${upperName}Model(json['id'] as int, json['name'] as String); - } - - Map toJson() { - final data = {}; - data['id'] = id; - data['name'] = name; - return data; - } - -} diff --git a/templates/mutable/page.tmpl b/templates/mutable/page.tmpl deleted file mode 100644 index 5e152b8e..00000000 --- a/templates/mutable/page.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Page extends StatefulWidget { - static const String routeName = '/${privateName}'; - - @override - _${upperName}PageState createState() => _${upperName}PageState(); -} - -class _${upperName}PageState extends State<${upperName}Page> { - final _${privateName}Bloc = ${upperName}Bloc(); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('${upperName}'), - ), - body: ${upperName}Screen(${privateName}Bloc: _${privateName}Bloc), - ); - } -} diff --git a/templates/mutable/provider.tmpl b/templates/mutable/provider.tmpl deleted file mode 100644 index 7fe9c15d..00000000 --- a/templates/mutable/provider.tmpl +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:async'; - -class ${upperName}Provider { - Future loadAsync(String token) async { - /// write from keystore/keychain - await Future.delayed(Duration(seconds: 2)); - } - - Future saveAsync(String token) async { - /// write from keystore/keychain - await Future.delayed(Duration(seconds: 2)); - } - - void test(bool isError) { - if (isError == true){ - throw Exception('manual error'); - } - } -} - diff --git a/templates/mutable/repository.tmpl b/templates/mutable/repository.tmpl deleted file mode 100644 index 332f91dc..00000000 --- a/templates/mutable/repository.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Repository { - final ${upperName}Provider _${privateName}Provider = ${upperName}Provider(); - - ${upperName}Repository(); - - void test(bool isError) { - _${privateName}Provider.test(isError); - } -} \ No newline at end of file diff --git a/templates/mutable/screen.tmpl b/templates/mutable/screen.tmpl deleted file mode 100644 index e126bf35..00000000 --- a/templates/mutable/screen.tmpl +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Screen extends StatefulWidget { - const ${upperName}Screen({ - required ${upperName}Bloc ${privateName}Bloc, - Key? key, - }) : _${privateName}Bloc = ${privateName}Bloc, - super(key: key); - - final ${upperName}Bloc _${privateName}Bloc; - - @override - ${upperName}ScreenState createState() { - return ${upperName}ScreenState(); - } -} - -class ${upperName}ScreenState extends State<${upperName}Screen> { - ${upperName}ScreenState(); - - @override - void initState() { - super.initState(); - _load(); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return BlocBuilder<${upperName}Bloc, ${upperName}State>( - bloc: widget._${privateName}Bloc, - builder: ( - BuildContext context, - ${upperName}State currentState, - ) { - if (currentState is Un${upperName}State) { - return Center( - child: CircularProgressIndicator(), - ); - } - if (currentState is Error${upperName}State) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(currentState.errorMessage), - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Colors.blue, - ), - child: Text('reload'), - onPressed: _load, - ), - ), - ], - )); - } - if (currentState is In${upperName}State) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(currentState.hello), - const Text('Flutter files: done'), - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Colors.red, - ), - child: Text('throw error'), - onPressed: () => _load(true), - ), - ), - ], - ), - ); - } - return Center( - child: CircularProgressIndicator(), - ); - - }); - } - - void _load([bool isError = false]) { - widget._${privateName}Bloc.add(Load${upperName}Event(isError)); - } -} diff --git a/templates/mutable/state.tmpl b/templates/mutable/state.tmpl deleted file mode 100644 index 52c7ea72..00000000 --- a/templates/mutable/state.tmpl +++ /dev/null @@ -1,83 +0,0 @@ -import 'package:equatable/equatable.dart'; - -abstract class ${upperName}State extends Equatable { - ${upperName}State(this.version); - - /// notify change state without deep clone state - final int version; - - /// Copy object for use in action - /// if need use deep clone - ${upperName}State getStateCopy(); - - ${upperName}State getNewVersion(); - - @override - List get props => [version]; -} - -/// UnInitialized -class Un${upperName}State extends ${upperName}State { - - Un${upperName}State(int version) : super(version); - - @override - String toString() => 'Un${upperName}State'; - - @override - Un${upperName}State getStateCopy() { - return Un${upperName}State(0); - } - - @override - Un${upperName}State getNewVersion() { - return Un${upperName}State(version+1); - } -} - -/// Initialized -class In${upperName}State extends ${upperName}State { - - In${upperName}State(int version, this.hello) : super(version); - - final String hello; - - @override - String toString() => 'In${upperName}State $hello'; - - @override - In${upperName}State getStateCopy() { - return In${upperName}State(version, hello); - } - - @override - In${upperName}State getNewVersion() { - return In${upperName}State(version+1, hello); - } - - @override - List get props => [version, hello]; -} - -class Error${upperName}State extends ${upperName}State { - Error${upperName}State(int version, this.errorMessage): super(version); - - final String errorMessage; - - @override - String toString() => 'Error${upperName}State'; - - @override - Error${upperName}State getStateCopy() { - return Error${upperName}State(version, errorMessage); - } - - @override - Error${upperName}State getNewVersion() { - return Error${upperName}State(version+1, - errorMessage); - } - - @override - List get props => [version, errorMessage]; -} diff --git a/templates/navigate/navigate.tmpl b/templates/navigate/navigate.tmpl deleted file mode 100644 index 57b6748b..00000000 --- a/templates/navigate/navigate.tmpl +++ /dev/null @@ -1,33 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:navme/navme.dart'; -import 'package:navme/helpers.dart'; - -import 'index.dart'; - -class ${upperName}Navigate { - // base path - static String path = '${privateName}'; - - // config for configurate Router - static RouteConfig routeConfig = RouteConfig( - state: (Uri? uri) => RouteState(uri: path.toUri()), - // condition for using this page - isThisPage: (RouteState state) { - if (state?.firstPath == path) { - return true; - } - return false; - }, - // settigs from url - settings: (RouteState state) { - return null; - }, - // get Page for Router - page: ({RouteState? state}) { - return MaterialPage( - key: const ValueKey('${upperName}Page'), - child: ${upperName}Page(), - name: '${upperName}Page'); - }, - ); -} diff --git a/templates/simple/bloc.tmpl b/templates/simple/bloc.tmpl deleted file mode 100644 index 3556967f..00000000 --- a/templates/simple/bloc.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -import 'dart:async'; -import 'dart:developer' as developer; - -import 'package:bloc/bloc.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Bloc extends Bloc<${upperName}Event, ${upperName}State> { - - ${upperName}Bloc(${upperName}State initialState) : super(initialState){ - on<${upperName}Event>((event, emit) { - return emit.forEach<${upperName}State>( - event.applyAsync(currentState: state, bloc: this), - onData: (state) => state, - onError: (error, stackTrace) { - developer.log('$error', name: '${upperName}Bloc', error: error, stackTrace: stackTrace); - return Error${upperName}State(error.toString()); - }, - ); - }); - } -} diff --git a/templates/simple/event.tmpl b/templates/simple/event.tmpl deleted file mode 100644 index d21542a2..00000000 --- a/templates/simple/event.tmpl +++ /dev/null @@ -1,34 +0,0 @@ -import 'dart:async'; -import 'dart:developer' as developer; - -import 'package:${appName}${relative}/index.dart'; -import 'package:meta/meta.dart'; - -@immutable -abstract class ${upperName}Event { - Stream<${upperName}State> applyAsync( - {${upperName}State currentState, ${upperName}Bloc bloc}); -} - -class Un${upperName}Event extends ${upperName}Event { - @override - Stream<${upperName}State> applyAsync({${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { - yield Un${upperName}State(); - } -} - -class Load${upperName}Event extends ${upperName}Event { - - @override - Stream<${upperName}State> applyAsync( - {${upperName}State? currentState, ${upperName}Bloc? bloc}) async* { - try { - yield Un${upperName}State(); - await Future.delayed(const Duration(seconds: 1)); - yield In${upperName}State('Hello world'); - } catch (_, stackTrace) { - developer.log('$_', name: 'Load${upperName}Event', error: _, stackTrace: stackTrace); - yield Error${upperName}State( _.toString()); - } - } -} diff --git a/templates/simple/index.tmpl b/templates/simple/index.tmpl deleted file mode 100644 index e69de29b..00000000 diff --git a/templates/simple/model.tmpl b/templates/simple/model.tmpl deleted file mode 100644 index ede30505..00000000 --- a/templates/simple/model.tmpl +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:equatable/equatable.dart'; - -/// use https://marketplace.visualstudio.com/items?itemName=BendixMa.dart-data-class-generator -class ${upperName}Model extends Equatable { - final int id; - final String name; - - ${upperName}Model(this.id, this.name); - - @override - List get props => [id, name]; - -} diff --git a/templates/simple/page.tmpl b/templates/simple/page.tmpl deleted file mode 100644 index 169680f2..00000000 --- a/templates/simple/page.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Page extends StatefulWidget { - static const String routeName = '/${privateName}'; - - @override - _${upperName}PageState createState() => _${upperName}PageState(); -} - -class _${upperName}PageState extends State<${upperName}Page> { - final _${privateName}Bloc = ${upperName}Bloc(Un${upperName}State()); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('${upperName}'), - ), - body: ${upperName}Screen(${privateName}Bloc: _${privateName}Bloc), - ); - } -} diff --git a/templates/simple/provider.tmpl b/templates/simple/provider.tmpl deleted file mode 100644 index 7fe9c15d..00000000 --- a/templates/simple/provider.tmpl +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:async'; - -class ${upperName}Provider { - Future loadAsync(String token) async { - /// write from keystore/keychain - await Future.delayed(Duration(seconds: 2)); - } - - Future saveAsync(String token) async { - /// write from keystore/keychain - await Future.delayed(Duration(seconds: 2)); - } - - void test(bool isError) { - if (isError == true){ - throw Exception('manual error'); - } - } -} - diff --git a/templates/simple/repository.tmpl b/templates/simple/repository.tmpl deleted file mode 100644 index 332f91dc..00000000 --- a/templates/simple/repository.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Repository { - final ${upperName}Provider _${privateName}Provider = ${upperName}Provider(); - - ${upperName}Repository(); - - void test(bool isError) { - _${privateName}Provider.test(isError); - } -} \ No newline at end of file diff --git a/templates/simple/screen.tmpl b/templates/simple/screen.tmpl deleted file mode 100644 index dc592fec..00000000 --- a/templates/simple/screen.tmpl +++ /dev/null @@ -1,84 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:${appName}${relative}/index.dart'; - -class ${upperName}Screen extends StatefulWidget { - const ${upperName}Screen({ - required ${upperName}Bloc ${privateName}Bloc, - Key? key, - }) : _${privateName}Bloc = ${privateName}Bloc, - super(key: key); - - final ${upperName}Bloc _${privateName}Bloc; - - @override - ${upperName}ScreenState createState() { - return ${upperName}ScreenState(); - } -} - -class ${upperName}ScreenState extends State<${upperName}Screen> { - ${upperName}ScreenState(); - - @override - void initState() { - super.initState(); - _load(); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return BlocBuilder<${upperName}Bloc, ${upperName}State>( - bloc: widget._${privateName}Bloc, - builder: ( - BuildContext context, - ${upperName}State currentState, - ) { - if (currentState is Un${upperName}State) { - return Center( - child: CircularProgressIndicator(), - ); - } - if (currentState is Error${upperName}State) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(currentState.errorMessage ), - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: RaisedButton( - color: Colors.blue, - child: Text('reload'), - onPressed: _load, - ), - ), - ], - )); - } - if (currentState is In${upperName}State) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(currentState.hello), - ], - ), - ); - } - return Center( - child: CircularProgressIndicator(), - ); - - }); - } - - void _load() { - widget._${privateName}Bloc.add(Load${upperName}Event()); - } -} diff --git a/templates/simple/state.tmpl b/templates/simple/state.tmpl deleted file mode 100644 index be0c2ac0..00000000 --- a/templates/simple/state.tmpl +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:equatable/equatable.dart'; - -abstract class ${upperName}State extends Equatable { - ${upperName}State(); - - @override - List get props => []; -} - -/// UnInitialized -class Un${upperName}State extends ${upperName}State { - - Un${upperName}State(); - - @override - String toString() => 'Un${upperName}State'; -} - -/// Initialized -class In${upperName}State extends ${upperName}State { - In${upperName}State(this.hello); - - final String hello; - - @override - String toString() => 'In${upperName}State $hello'; - - @override - List get props => [hello]; -} - -class Error${upperName}State extends ${upperName}State { - Error${upperName}State(this.errorMessage); - - final String errorMessage; - - @override - String toString() => 'Error${upperName}State'; - - @override - List get props => [errorMessage]; -} diff --git a/xhtml/index.html b/x-example-show-pdf/index.html similarity index 100% rename from xhtml/index.html rename to x-example-show-pdf/index.html diff --git a/x.sh b/x.sh deleted file mode 100644 index 7eb36730..00000000 --- a/x.sh +++ /dev/null @@ -1 +0,0 @@ -# Test sh \ No newline at end of file diff --git a/xcoba.sh b/xcoba.sh deleted file mode 100644 index 47e2a998..00000000 --- a/xcoba.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -ffmpeg -f avfoundation \ --i "1:0" \ --s 1280x720 \ --framerate 30 \ --c:v libx264 \ --preset ultrafast \ --tune zerolatency \ --b:v 3000k \ --c:a aac \ --b:a 192k \ --vf "format=uyvy422" \ --f flv "rtmp://192.168.1.243:1935/live/bagas" \ --probesize 10M \ No newline at end of file From 6dc4e7afc3ba494a795384818d8366cb5d933547 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 5 Feb 2025 15:07:18 +0800 Subject: [PATCH 6/9] fix middleware --- logs/backend/combined-2025-02-05.log | 19 ++ logs/backend/error-2025-02-05.log | 18 ++ src/app/api/auth/code/{ => [id]}/route.ts | 41 +-- src/app/api/user-validate/route.ts | 4 +- src/app/api/validation/route.ts | 3 +- src/app_modules/auth/_lib/api_fetch_auth.ts | 13 +- src/app_modules/auth/validasi/view.tsx | 86 ++---- src/middleware.ts | 204 +++++++------- src/middleware.v2.back.txt | 284 ++++++++++++++++++++ src/middleware.v3.back.txt | 244 +++++++++++++++++ 10 files changed, 713 insertions(+), 203 deletions(-) rename src/app/api/auth/code/{ => [id]}/route.ts (53%) create mode 100644 src/middleware.v2.back.txt create mode 100644 src/middleware.v3.back.txt diff --git a/logs/backend/combined-2025-02-05.log b/logs/backend/combined-2025-02-05.log index 44650842..b799e57a 100644 --- a/logs/backend/combined-2025-02-05.log +++ b/logs/backend/combined-2025-02-05.log @@ -2,3 +2,22 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:44:11.043Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T03:13:24.349Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-02-05T03:48:26.606Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T04:24:29.510Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T05:56:01.792Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:33.579Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:38.069Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:39.386Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:40.316Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:41.037Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:41.842Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.615Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.784Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.982Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:43.131Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:43.278Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.025Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.028Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.029Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} +{"id":"c65237f0-e0cf-4961-9454-2405c4f4fe05","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T06:41:30.785Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} diff --git a/logs/backend/error-2025-02-05.log b/logs/backend/error-2025-02-05.log index 44650842..b845dbdd 100644 --- a/logs/backend/error-2025-02-05.log +++ b/logs/backend/error-2025-02-05.log @@ -2,3 +2,21 @@ {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T02:44:11.043Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T03:13:24.349Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at new eS (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:26724)\n at e_ (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27574)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32507)\n at get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32603)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39714)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:33303)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36)\n at run (node:async_hooks:64:22)","timestamp":"2025-02-05T03:48:26.606Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T04:24:29.510Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.deleteMany()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T05:56:01.792Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:33.579Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:38.069Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:39.386Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:40.316Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:41.037Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:41.842Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.615Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.784Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:42.982Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:43.131Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:24:43.278Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.025Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.028Z"} +{"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.029Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} +{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} diff --git a/src/app/api/auth/code/route.ts b/src/app/api/auth/code/[id]/route.ts similarity index 53% rename from src/app/api/auth/code/route.ts rename to src/app/api/auth/code/[id]/route.ts index 534eb1c6..b2193ed3 100644 --- a/src/app/api/auth/code/route.ts +++ b/src/app/api/auth/code/[id]/route.ts @@ -1,8 +1,12 @@ import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export { DELETE }; -async function DELETE(request: Request) { +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { if (request.method !== "DELETE") { return NextResponse.json( { success: false, message: "Method not allowed" }, @@ -10,41 +14,24 @@ async function DELETE(request: Request) { ); } try { - // Ambil parameter nomor dari URL - const { nomor } = await request.json(); + // Ambil parameter id dari URL + const { id } = params; - // Validasi parameter nomor - if (!nomor) { + if (!id) { return NextResponse.json( { success: false, - message: "Parameter 'nomor' diperlukan", + message: "Parameter 'id' diperlukan", }, { status: 400 } ); } - // Cek apakah data OTP dengan nomor tersebut ada - const existingOtp = await prisma.kodeOtp.findFirst({ - orderBy: { - createdAt: "desc", - }, - where: { nomor }, - }); - - if (!existingOtp) { - return NextResponse.json( - { - success: false, - message: "Data OTP tidak ditemukan", - }, - { status: 404 } - ); - } - // Hapus data OTP - await prisma.kodeOtp.deleteMany({ - where: { nomor }, + await prisma.kodeOtp.delete({ + where: { + id: id, + }, }); return NextResponse.json( @@ -55,7 +42,7 @@ async function DELETE(request: Request) { { status: 200 } ); } catch (error) { - console.error("Error deleting OTP:", error); + backendLogger.error("Error deleting OTP:", error); return NextResponse.json( { success: false, diff --git a/src/app/api/user-validate/route.ts b/src/app/api/user-validate/route.ts index 0b5c8cf3..8b881bb3 100644 --- a/src/app/api/user-validate/route.ts +++ b/src/app/api/user-validate/route.ts @@ -32,7 +32,6 @@ export async function GET(req: NextRequest) { }); // Disconnect after successful query - await prisma.$disconnect(); return NextResponse.json({ success: true, @@ -41,7 +40,6 @@ export async function GET(req: NextRequest) { }); } catch (error) { // Ensure connection is closed even if error occurs - await prisma.$disconnect(); console.error("Error in user validation:", error); return NextResponse.json( @@ -51,5 +49,7 @@ export async function GET(req: NextRequest) { }, { status: 500 } ); + } finally { + await prisma.$disconnect(); } } diff --git a/src/app/api/validation/route.ts b/src/app/api/validation/route.ts index ba9c6587..c9a8b258 100644 --- a/src/app/api/validation/route.ts +++ b/src/app/api/validation/route.ts @@ -1,10 +1,9 @@ - import { NextResponse } from "next/server"; - export async function GET(req: Request) { const auth = req.headers.get("Authorization"); const token = auth?.split(" ")[1]; + console.log("TOKEN>", token); if (!token) return NextResponse.json({ success: false }, { status: 401 }); return NextResponse.json({ success: true }); diff --git a/src/app_modules/auth/_lib/api_fetch_auth.ts b/src/app_modules/auth/_lib/api_fetch_auth.ts index f1c08e6b..bf7d7876 100644 --- a/src/app_modules/auth/_lib/api_fetch_auth.ts +++ b/src/app_modules/auth/_lib/api_fetch_auth.ts @@ -35,18 +35,15 @@ const apiPostVerifikasiCodeOtp = async ({ nomor }: { nomor: string }) => { return await respone.json().catch(() => null); }; -const apiDeleteAktivasiKodeOtpByNomor = async ({ - nomor, -}: { - nomor: string; -}) => { - const respone = await fetch(`/api/auth/code`, { +const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => { + const respone = await fetch(`/api/auth/code/${id}`, { method: "DELETE", - body: JSON.stringify({nomor}), headers: { "Content-Type": "application/json", - } + }, }); + console.log("respone delete", await respone.json()); + return await respone.json().catch(() => null); }; diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index ff2c31d8..31bad0f3 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -1,7 +1,6 @@ "use client"; import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin"; -import { RouterHome } from "@/app/lib/router_hipmi/router_home"; import { AccentColor, MainColor, @@ -26,12 +25,9 @@ import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global"; -import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id"; -import Validasi_SkeletonView from "./skeleton"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { clientLogger } from "@/util/clientLogger"; import { IconChevronLeft } from "@tabler/icons-react"; -import _ from "lodash"; -import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { apiDeleteAktivasiKodeOtpByNomor, apiGetCheckCodeOtp, @@ -46,6 +42,7 @@ export default function Validasi() { const [counter, setCounter] = useState(60); const [loadingResend, setLoadingResend] = useState(false); const [triggerOtp, setTriggerOtp] = useState(false); + const [idCode, setIdCode] = useState(""); const [data, setData] = useState({ nomor: "", @@ -74,7 +71,9 @@ export default function Validasi() { async function onCheckAuthCode({ kodeId }: { kodeId: string }) { try { const respone = await apiGetCheckCodeOtp({ id: kodeId }); + if (respone) { + setIdCode(kodeId); setData({ nomor: respone.nomor, code: respone.otp, @@ -101,21 +100,21 @@ export default function Validasi() { if (respone && respone.success == true) { if (respone.roleId == "1") { + router.push("/login", { scroll: false }); ComponentGlobal_NotifikasiBerhasil(respone.message); - localStorage.removeItem("hipmi_auth_code_id"); - - router.push(RouterHome.main_home, { scroll: false }); } else if (respone.roleId != "1") { - ComponentGlobal_NotifikasiBerhasil("Admin berhasil login"); - localStorage.removeItem("hipmi_auth_code_id"); - router.push(RouterAdminDashboard.splash_admin, { scroll: false }); + ComponentGlobal_NotifikasiBerhasil("Admin berhasil login"); } try { const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ - nomor: data.nomor, + id: idCode, }); + + if (responeDelete) { + localStorage.removeItem("hipmi_auth_code_id"); + } } catch (error) { clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error); } @@ -123,47 +122,6 @@ export default function Validasi() { router.push("/register", { scroll: false }); ComponentGlobal_NotifikasiBerhasil(respone.message); } - - // if (respone.status === 200 && result.roleId == "1") { - // ComponentGlobal_NotifikasiBerhasil(result.message); - // localStorage.removeItem("hipmi_auth_code_id"); - // await auth_funDeleteAktivasiKodeOtpByNomor({ - // nomor: data.nomor, - // }); - - // router.push(RouterHome.main_home, { scroll: false }); - // return; - // } - - // if (respone.status === 200 && result.roleId != "1") { - // ComponentGlobal_NotifikasiBerhasil("Admin Logged in"); - // localStorage.removeItem("hipmi_auth_code_id"); - // await auth_funDeleteAktivasiKodeOtpByNomor({ - // nomor: data.nomor, - // }); - - // router.push(RouterAdminDashboard.splash_admin, { scroll: false }); - // return; - // } - - // if (respone.status === 404) { - // setLoading(false); - // router.push("/register", { scroll: false }); - // ComponentGlobal_NotifikasiBerhasil(result.message); - // return; - // } - - // if (respone.status === 400) { - // setLoading(false); - // ComponentGlobal_NotifikasiPeringatan(result.message); - // return; - // } - - // if (respone.status == 500) { - // setLoading(false); - // ComponentGlobal_NotifikasiGagal(result.message); - // return; - // } } catch (error) { setLoading(false); clientLogger.error("Error validasi:", error); @@ -171,9 +129,19 @@ export default function Validasi() { } async function onBack() { - localStorage.removeItem("hipmi_auth_code_id"); - await auth_funDeleteAktivasiKodeOtpByNomor({ nomor: data.nomor }); - router.back(); + try { + router.back(); + 111; + const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ + id: idCode, + }); + + if (responeDelete) { + localStorage.removeItem("hipmi_auth_code_id"); + } + } catch (error) { + clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error); + } } async function onResendCode() { @@ -213,7 +181,7 @@ export default function Validasi() { <> - {/* onBack()}> - */} + - Verifikasi Kode OTP + Verifikasi Kode OTP {data.code} diff --git a/src/middleware.ts b/src/middleware.ts index a68f2186..1b09e728 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -43,8 +43,6 @@ const middlewareConfig: MiddlewareConfig = { // "/api/admin/voting/dashboard/*", // "/api/admin/job/dashboard/*", // "/api/admin/forum/dashboard/*", - - // Akses awal "/api/get-cookie", @@ -78,135 +76,143 @@ export const middleware = async (req: NextRequest) => { apiPath, encodedKey, loginPath, - // validasiPath, - // registarasiPath, publicRoutes, sessionKey, validationApiRoute, userPath, } = middlewareConfig; + const { pathname } = req.nextUrl; - // CORS handling + // Handle CORS const corsResponse = handleCors(req); if (corsResponse) { - return setCorsHeaders(corsResponse); + return corsResponse; } - // Skip authentication for public routes - const isPublicRoute = [ - ...publicRoutes, - loginPath, - // validasiPath, - // registarasiPath, - ].some((route) => { - const pattern = route.replace(/\*/g, ".*"); - return new RegExp(`^${pattern}$`).test(pathname); - }); - - // Always protect validation endpoint - if (pathname === validationApiRoute) { - const reqToken = req.headers.get("Authorization")?.split(" ")[1]; - if (!reqToken) { - return setCorsHeaders(unauthorizedResponse()); - } - } - - if ( - isPublicRoute && - pathname !== loginPath - // && - // pathname !== validasiPath && - // pathname !== registarasiPath - ) { + // Check if route is public + const isPublicRoute = isRoutePublic(pathname, publicRoutes, loginPath); + if (isPublicRoute && pathname !== loginPath) { return setCorsHeaders(NextResponse.next()); } - const token = - req.cookies.get(sessionKey)?.value || - req.headers.get("Authorization")?.split(" ")[1]; + // Get token from cookies or Authorization header + const token = getToken(req, sessionKey); - // ==================== Authentication: Login, Validasi, Registrasi ==================== // - // Token verification + // Verify token and get user data const user = await verifyToken({ token, encodedKey }); - console.log("middlaware",user) + console.log("USER >>", user?.username); // Handle login page access if (pathname === loginPath) { if (user) { - return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); + const response = NextResponse.redirect(new URL(userPath, req.url)); + // Preserve token in cookie when redirecting + if (token) { + response.cookies.set(sessionKey, token, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + } + return setCorsHeaders(response); } return setCorsHeaders(NextResponse.next()); } - // // Handle validation page access - // if (pathname === validasiPath) { - // if (user) { - // return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); - // } - // return setCorsHeaders(NextResponse.next()); - // } - - // // Handle register page access - // if (pathname === registarasiPath) { - // if (user) { - // return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); - // } - // return setCorsHeaders(NextResponse.next()); - // } - - // Handle protected routes + // Redirect to login if no user found if (!user) { - return setCorsHeaders(NextResponse.redirect(new URL(loginPath, req.url))); + const response = NextResponse.redirect(new URL(loginPath, req.url)); + // Clear invalid token + response.cookies.delete(sessionKey); + return setCorsHeaders(response); } - // ==================== Authentication: Login, Validasi, Registrasi ==================== // + // Handle /dev routes that require active status if (pathname.startsWith("/dev")) { - const userValidate = await fetch(new URL("/api/user-validate", req.url), { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - }); - - const userValidateJson = await userValidate.json(); - - if (!userValidateJson.data.active) { - return setCorsHeaders( - NextResponse.redirect(new URL("/waiting-room", req.url)) - ); - } - } - - // Handle authenticated API requests - if (pathname.startsWith(apiPath)) { - const reqToken = req.headers.get("Authorization")?.split(" ")[1]; - if (!reqToken) { - return setCorsHeaders(unauthorizedResponse()); - } - - // Validate user access with external API - const validationResponse = await fetch( - new URL(validationApiRoute, req.url), - { + try { + const userValidate = await fetch(new URL("/api/user-validate", req.url), { headers: { "Content-Type": "application/json", - Authorization: `Bearer ${reqToken}`, + Authorization: `Bearer ${token}`, }, - } - ); + }); - if (!validationResponse.ok) { + if (!userValidate.ok) { + throw new Error("Failed to validate user"); + } + + const userValidateJson = await userValidate.json(); + + if (!userValidateJson.data.active) { + return setCorsHeaders( + NextResponse.redirect(new URL("/waiting-room", req.url)) + ); + } + } catch (error) { + console.error("Error validating user:", error); + return setCorsHeaders(unauthorizedResponse()); + } + } + + // Handle API requests + if (pathname.startsWith(apiPath)) { + if (!token) { return setCorsHeaders(unauthorizedResponse()); } - const dataJson = await validationResponse.json(); + try { + const validationResponse = await fetch( + new URL(validationApiRoute, req.url), + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ); + + if (!validationResponse.ok) { + throw new Error("Failed to validate API request"); + } + } catch (error) { + console.error("Error validating API request:", error); + return setCorsHeaders(unauthorizedResponse()); + } } - // Proceed with the request - return setCorsHeaders(NextResponse.next()); + const response = NextResponse.next(); + // Ensure token is preserved in cookie + if (token) { + response.cookies.set(sessionKey, token, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + } + return setCorsHeaders(response); }; +function isRoutePublic( + pathname: string, + publicRoutes: string[], + loginPath: string +): boolean { + return [...publicRoutes, loginPath].some((route) => { + const pattern = route.replace(/\*/g, ".*"); + return new RegExp(`^${pattern}$`).test(pathname); + }); +} + +function getToken(req: NextRequest, sessionKey: string): string | undefined { + return ( + req.cookies.get(sessionKey)?.value || + req.headers.get("Authorization")?.split(" ")[1] + ); +} + function unauthorizedResponse(): NextResponse { return new NextResponse(JSON.stringify({ error: "Unauthorized" }), { status: 401, @@ -251,16 +257,6 @@ async function verifyToken({ }): Promise | null> { if (!token) return null; - return await decrypt({ token, encodedKey }); -} - -async function decrypt({ - token, - encodedKey, -}: { - token: string; - encodedKey: string; -}): Promise | null> { try { const enc = new TextEncoder().encode(encodedKey); const { payload } = await jwtVerify(token, enc, { @@ -268,7 +264,7 @@ async function decrypt({ }); return (payload.user as Record) || null; } catch (error) { - console.error("Gagal verifikasi session", error); + console.error("Token verification failed:", error); return null; } } @@ -276,5 +272,3 @@ async function decrypt({ export const config = { matcher: ["/((?!_next|static|favicon.ico|manifest).*)"], }; - -// wibu:0.2.82 diff --git a/src/middleware.v2.back.txt b/src/middleware.v2.back.txt new file mode 100644 index 00000000..7b7aea01 --- /dev/null +++ b/src/middleware.v2.back.txt @@ -0,0 +1,284 @@ +import { NextRequest, NextResponse } from "next/server"; +import { jwtVerify } from "jose"; +import { apies, pages } from "./lib/routes"; + +type MiddlewareConfig = { + apiPath: string; + loginPath: string; + // validasiPath: string; + // registarasiPath: string; + userPath: string; + publicRoutes: string[]; + encodedKey: string; + sessionKey: string; + validationApiRoute: string; + log: boolean; +}; + +const middlewareConfig: MiddlewareConfig = { + apiPath: "/api", + loginPath: "/login", + // validasiPath: "/validasi", + // registarasiPath: "/register", + userPath: "/dev/home", + publicRoutes: [ + // API + "/", + "/api/voting/*", + "/api/collaboration/*", + "/api/notifikasi/*", + "/api/logs/*", + "/api/job/*", + "/api/auth/*", + "/api/origin-url", + "/api/event/*", + // "/api/master/*", + // "/api/image/*", + // "/api/user/*", + // "/api/new/*", + // ADMIN API + // "/api/admin/event/*", + // "/api/admin/investasi/*", + // "/api/admin/donasi/dashboard/*", + // "/api/admin/voting/dashboard/*", + // "/api/admin/job/dashboard/*", + // "/api/admin/forum/dashboard/*", + + // Akses awal + "/api/get-cookie", + "/api/user/activation", + "/api/user-validate", + + // PAGE + "/login", + "/register", + "/validasi", + "/splash", + "/job-vacancy", + "/preview-image", + "/auth/login", + "/auth/api/login", + "/waiting-room", + "/zCoba/*", + + // ASSETS + "/aset/global/main_background.png", + "/aset/logo/logo-hipmi.png", + ], + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, + validationApiRoute: "/api/validation", + log: false, +}; + +export const middleware = async (req: NextRequest) => { + const { + apiPath, + encodedKey, + loginPath, + // validasiPath, + // registarasiPath, + publicRoutes, + sessionKey, + validationApiRoute, + userPath, + } = middlewareConfig; + const { pathname } = req.nextUrl; + + // CORS handling + const corsResponse = handleCors(req); + if (corsResponse) { + return setCorsHeaders(corsResponse); + } + + // Skip authentication for public routes + const isPublicRoute = [ + ...publicRoutes, + loginPath, + // validasiPath, + // registarasiPath, + ].some((route) => { + const pattern = route.replace(/\*/g, ".*"); + return new RegExp(`^${pattern}$`).test(pathname); + }); + + // Always protect validation endpoint + if (pathname === validationApiRoute) { + const reqToken = req.headers.get("Authorization")?.split(" ")[1]; + if (!reqToken) { + return setCorsHeaders(unauthorizedResponse()); + } + } + + if ( + isPublicRoute && + pathname !== loginPath + // && + // pathname !== validasiPath && + // pathname !== registarasiPath + ) { + return setCorsHeaders(NextResponse.next()); + } + + const token = + req.cookies.get(sessionKey)?.value || + req.headers.get("Authorization")?.split(" ")[1]; + + // ==================== Authentication: Login, Validasi, Registrasi ==================== // + // Token verification + const user = await verifyToken({ token, encodedKey }); + console.log("middlaware console:", user); + + // Handle login page access + if (pathname === loginPath) { + console.log("cek pathname >>", pathname); + if (user) { + console.log("sudah login, cek user >>", user); + return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); + } + return setCorsHeaders(NextResponse.next()); + } + + if (!user) { + return setCorsHeaders(NextResponse.redirect(new URL(loginPath, req.url))); + } + + // // Handle validation page access + // if (pathname === validasiPath) { + // if (user) { + // return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); + // } + // return setCorsHeaders(NextResponse.next()); + // } + + // // Handle register page access + // if (pathname === registarasiPath) { + // if (user) { + // return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url))); + // } + // return setCorsHeaders(NextResponse.next()); + // } + + // Handle protected routes + // if (!user) { + // return setCorsHeaders(NextResponse.redirect(new URL(loginPath, req.url))); + // } + // ==================== Authentication: Login, Validasi, Registrasi ==================== // + + if (pathname.startsWith("/dev")) { + const userValidate = await fetch(new URL("/api/user-validate", req.url), { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + const userValidateJson = await userValidate.json(); + + if (!userValidateJson.data.active) { + return setCorsHeaders( + NextResponse.redirect(new URL("/waiting-room", req.url)) + ); + } + } + + // Handle authenticated API requests + if (pathname.startsWith(apiPath)) { + const reqToken = req.headers.get("Authorization")?.split(" ")[1]; + if (!reqToken) { + return setCorsHeaders(unauthorizedResponse()); + } + + // Validate user access with external API + const validationResponse = await fetch( + new URL(validationApiRoute, req.url), + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${reqToken}`, + }, + } + ); + + if (!validationResponse.ok) { + return setCorsHeaders(unauthorizedResponse()); + } + + const dataJson = await validationResponse.json(); + } + + // Proceed with the request + return setCorsHeaders(NextResponse.next()); +}; + +function unauthorizedResponse(): NextResponse { + return new NextResponse(JSON.stringify({ error: "Unauthorized" }), { + status: 401, + headers: { "Content-Type": "application/json" }, + }); +} + +function setCorsHeaders(res: NextResponse): NextResponse { + res.headers.set("Access-Control-Allow-Origin", "*"); + res.headers.set( + "Access-Control-Allow-Methods", + "GET, POST, PUT, DELETE, OPTIONS" + ); + res.headers.set( + "Access-Control-Allow-Headers", + "Content-Type, Authorization" + ); + return res; +} + +function handleCors(req: NextRequest): NextResponse | null { + if (req.method === "OPTIONS") { + return new NextResponse(null, { + status: 204, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization", + "Access-Control-Max-Age": "86400", + }, + }); + } + return null; +} + +async function verifyToken({ + token, + encodedKey, +}: { + token: string | undefined; + encodedKey: string; +}): Promise | null> { + if (!token) return null; + + return await decrypt({ token, encodedKey }); +} + +async function decrypt({ + token, + encodedKey, +}: { + token: string; + encodedKey: string; +}): Promise | null> { + try { + const enc = new TextEncoder().encode(encodedKey); + const { payload } = await jwtVerify(token, enc, { + algorithms: ["HS256"], + }); + return (payload.user as Record) || null; + } catch (error) { + console.error("Gagal verifikasi session", error); + return null; + } +} + +export const config = { + matcher: ["/((?!_next|static|favicon.ico|manifest).*)"], +}; + +// wibu:0.2.82 diff --git a/src/middleware.v3.back.txt b/src/middleware.v3.back.txt new file mode 100644 index 00000000..5f86f614 --- /dev/null +++ b/src/middleware.v3.back.txt @@ -0,0 +1,244 @@ +import { NextRequest, NextResponse } from "next/server"; +import { jwtVerify } from "jose"; + +type MiddlewareConfig = { + apiPath: string; + loginPath: string; + userPath: string; + publicRoutes: string[]; + encodedKey: string; + sessionKey: string; + validationApiRoute: string; + log: boolean; +}; + +const middlewareConfig: MiddlewareConfig = { + apiPath: "/api", + loginPath: "/login", + userPath: "/dev/home", + publicRoutes: [ + "/", + "/api/voting/*", + "/api/collaboration/*", + "/api/notifikasi/*", + "/api/logs/*", + "/api/job/*", + "/api/auth/*", + "/api/origin-url", + "/api/event/*", + "/api/get-cookie", + "/api/user/activation", + "/api/user-validate", + "/login", + "/register", + "/validasi", + "/splash", + "/job-vacancy", + "/preview-image", + "/auth/login", + "/auth/api/login", + "/waiting-room", + "/zCoba/*", + "/aset/global/main_background.png", + "/aset/logo/logo-hipmi.png", + ], + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, + validationApiRoute: "/api/validation", + log: false, +}; + +export const middleware = async (req: NextRequest) => { + const { + apiPath, + encodedKey, + loginPath, + publicRoutes, + sessionKey, + validationApiRoute, + userPath, + } = middlewareConfig; + + const { pathname } = req.nextUrl; + + // Handle CORS + const corsResponse = handleCors(req); + if (corsResponse) { + return corsResponse; + } + + // Check if route is public + const isPublicRoute = isRoutePublic(pathname, publicRoutes, loginPath); + if (isPublicRoute && pathname !== loginPath) { + return setCorsHeaders(NextResponse.next()); + } + + // Get token from cookies or Authorization header + const token = getToken(req, sessionKey); + + // Verify token and get user data + const user = await verifyToken({ token, encodedKey }); + + // Handle login page access + if (pathname === loginPath) { + if (user) { + const response = NextResponse.redirect(new URL(userPath, req.url)); + // Preserve token in cookie when redirecting + if (token) { + response.cookies.set(sessionKey, token, { + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + sameSite: 'lax', + path: '/' + }); + } + return setCorsHeaders(response); + } + return setCorsHeaders(NextResponse.next()); + } + + // Redirect to login if no user found + if (!user) { + const response = NextResponse.redirect(new URL(loginPath, req.url)); + // Clear invalid token + response.cookies.delete(sessionKey); + return setCorsHeaders(response); + } + + // Handle /dev routes that require active status + if (pathname.startsWith("/dev")) { + try { + const userValidate = await fetch(new URL("/api/user-validate", req.url), { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + if (!userValidate.ok) { + throw new Error('Failed to validate user'); + } + + const userValidateJson = await userValidate.json(); + + if (!userValidateJson.data.active) { + return setCorsHeaders( + NextResponse.redirect(new URL("/waiting-room", req.url)) + ); + } + } catch (error) { + console.error('Error validating user:', error); + return setCorsHeaders(unauthorizedResponse()); + } + } + + // Handle API requests + if (pathname.startsWith(apiPath)) { + if (!token) { + return setCorsHeaders(unauthorizedResponse()); + } + + try { + const validationResponse = await fetch( + new URL(validationApiRoute, req.url), + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ); + + if (!validationResponse.ok) { + throw new Error('Failed to validate API request'); + } + } catch (error) { + console.error('Error validating API request:', error); + return setCorsHeaders(unauthorizedResponse()); + } + } + + const response = NextResponse.next(); + // Ensure token is preserved in cookie + if (token) { + response.cookies.set(sessionKey, token, { + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + sameSite: 'lax', + path: '/' + }); + } + return setCorsHeaders(response); +}; + +function isRoutePublic(pathname: string, publicRoutes: string[], loginPath: string): boolean { + return [...publicRoutes, loginPath].some((route) => { + const pattern = route.replace(/\*/g, ".*"); + return new RegExp(`^${pattern}$`).test(pathname); + }); +} + +function getToken(req: NextRequest, sessionKey: string): string | undefined { + return req.cookies.get(sessionKey)?.value || + req.headers.get("Authorization")?.split(" ")[1]; +} + +function unauthorizedResponse(): NextResponse { + return new NextResponse(JSON.stringify({ error: "Unauthorized" }), { + status: 401, + headers: { "Content-Type": "application/json" }, + }); +} + +function setCorsHeaders(res: NextResponse): NextResponse { + res.headers.set("Access-Control-Allow-Origin", "*"); + res.headers.set( + "Access-Control-Allow-Methods", + "GET, POST, PUT, DELETE, OPTIONS" + ); + res.headers.set( + "Access-Control-Allow-Headers", + "Content-Type, Authorization" + ); + return res; +} + +function handleCors(req: NextRequest): NextResponse | null { + if (req.method === "OPTIONS") { + return new NextResponse(null, { + status: 204, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization", + "Access-Control-Max-Age": "86400", + }, + }); + } + return null; +} + +async function verifyToken({ + token, + encodedKey, +}: { + token: string | undefined; + encodedKey: string; +}): Promise | null> { + if (!token) return null; + + try { + const enc = new TextEncoder().encode(encodedKey); + const { payload } = await jwtVerify(token, enc, { + algorithms: ["HS256"], + }); + return (payload.user as Record) || null; + } catch (error) { + console.error("Token verification failed:", error); + return null; + } +} + +export const config = { + matcher: ["/((?!_next|static|favicon.ico|manifest).*)"], +}; \ No newline at end of file From d7252b9fb375d47400771e3f2d6ea47587a117c9 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 5 Feb 2025 15:34:06 +0800 Subject: [PATCH 7/9] fix folder deskripsi: - ganti nama folder (user) ke (auth) - hapus folder auth --- logs/backend/combined-2025-02-05.log | 1 + logs/backend/error-2025-02-05.log | 1 + src/app/{auth => (auth)}/_lib/decrypt.ts | 0 src/app/{auth => (auth)}/_lib/encrypt.ts | 0 .../{auth => (auth)}/_lib/session_create.ts | 0 src/app/{(user) => (auth)}/login/page.tsx | 0 src/app/{(user) => (auth)}/register/page.tsx | 0 src/app/{(user) => (auth)}/splash/page.tsx | 0 src/app/{(user) => (auth)}/validasi/page.tsx | 0 .../{(user) => (auth)}/waiting-room/page.tsx | 0 src/app/api/auth/register/route.ts | 2 +- src/app/api/auth/validasi/route.ts | 2 +- src/app/api/user-validate/route.ts | 2 +- src/app/api/user/get-cookies/route.ts | 2 +- src/app/api/user/route.ts | 2 +- src/app/auth/api/login/route.ts | 25 ------------ src/app/auth/api/logout/route.ts | 8 ---- src/app/auth/login/page.tsx | 39 ------------------- .../fun/get/fun_get_user_id_by_token.ts | 2 +- src/app_modules/auth/register/view.tsx | 18 +++------ src/app_modules/auth/validasi/view.tsx | 28 +++++++------ 21 files changed, 30 insertions(+), 102 deletions(-) rename src/app/{auth => (auth)}/_lib/decrypt.ts (100%) rename src/app/{auth => (auth)}/_lib/encrypt.ts (100%) rename src/app/{auth => (auth)}/_lib/session_create.ts (100%) rename src/app/{(user) => (auth)}/login/page.tsx (100%) rename src/app/{(user) => (auth)}/register/page.tsx (100%) rename src/app/{(user) => (auth)}/splash/page.tsx (100%) rename src/app/{(user) => (auth)}/validasi/page.tsx (100%) rename src/app/{(user) => (auth)}/waiting-room/page.tsx (100%) delete mode 100644 src/app/auth/api/login/route.ts delete mode 100644 src/app/auth/api/logout/route.ts delete mode 100644 src/app/auth/login/page.tsx diff --git a/logs/backend/combined-2025-02-05.log b/logs/backend/combined-2025-02-05.log index b799e57a..7d880846 100644 --- a/logs/backend/combined-2025-02-05.log +++ b/logs/backend/combined-2025-02-05.log @@ -21,3 +21,4 @@ {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} {"id":"c65237f0-e0cf-4961-9454-2405c4f4fe05","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T06:41:30.785Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} diff --git a/logs/backend/error-2025-02-05.log b/logs/backend/error-2025-02-05.log index b845dbdd..c2b2edfd 100644 --- a/logs/backend/error-2025-02-05.log +++ b/logs/backend/error-2025-02-05.log @@ -20,3 +20,4 @@ {"clientVersion":"6.3.0","code":"P2025","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.","meta":{"cause":"Record to delete does not exist.","modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nAn operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:25:00.029Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} diff --git a/src/app/auth/_lib/decrypt.ts b/src/app/(auth)/_lib/decrypt.ts similarity index 100% rename from src/app/auth/_lib/decrypt.ts rename to src/app/(auth)/_lib/decrypt.ts diff --git a/src/app/auth/_lib/encrypt.ts b/src/app/(auth)/_lib/encrypt.ts similarity index 100% rename from src/app/auth/_lib/encrypt.ts rename to src/app/(auth)/_lib/encrypt.ts diff --git a/src/app/auth/_lib/session_create.ts b/src/app/(auth)/_lib/session_create.ts similarity index 100% rename from src/app/auth/_lib/session_create.ts rename to src/app/(auth)/_lib/session_create.ts diff --git a/src/app/(user)/login/page.tsx b/src/app/(auth)/login/page.tsx similarity index 100% rename from src/app/(user)/login/page.tsx rename to src/app/(auth)/login/page.tsx diff --git a/src/app/(user)/register/page.tsx b/src/app/(auth)/register/page.tsx similarity index 100% rename from src/app/(user)/register/page.tsx rename to src/app/(auth)/register/page.tsx diff --git a/src/app/(user)/splash/page.tsx b/src/app/(auth)/splash/page.tsx similarity index 100% rename from src/app/(user)/splash/page.tsx rename to src/app/(auth)/splash/page.tsx diff --git a/src/app/(user)/validasi/page.tsx b/src/app/(auth)/validasi/page.tsx similarity index 100% rename from src/app/(user)/validasi/page.tsx rename to src/app/(auth)/validasi/page.tsx diff --git a/src/app/(user)/waiting-room/page.tsx b/src/app/(auth)/waiting-room/page.tsx similarity index 100% rename from src/app/(user)/waiting-room/page.tsx rename to src/app/(auth)/waiting-room/page.tsx diff --git a/src/app/api/auth/register/route.ts b/src/app/api/auth/register/route.ts index 53f83014..7a4ddb85 100644 --- a/src/app/api/auth/register/route.ts +++ b/src/app/api/auth/register/route.ts @@ -1,4 +1,4 @@ -import { sessionCreate } from "@/app/auth/_lib/session_create"; +import { sessionCreate } from "@/app/(auth)/_lib/session_create"; import prisma from "@/app/lib/prisma"; import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index c13633fd..d485c054 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -1,4 +1,4 @@ -import { sessionCreate } from "@/app/auth/_lib/session_create"; +import { sessionCreate } from "@/app/(auth)/_lib/session_create"; import prisma from "@/app/lib/prisma"; import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; diff --git a/src/app/api/user-validate/route.ts b/src/app/api/user-validate/route.ts index 8b881bb3..505c65ae 100644 --- a/src/app/api/user-validate/route.ts +++ b/src/app/api/user-validate/route.ts @@ -1,4 +1,4 @@ -import { decrypt } from "@/app/auth/_lib/decrypt"; +import { decrypt } from "@/app/(auth)/_lib/decrypt"; import { prisma } from "@/app/lib"; import { cookies } from "next/headers"; import { NextRequest, NextResponse } from "next/server"; diff --git a/src/app/api/user/get-cookies/route.ts b/src/app/api/user/get-cookies/route.ts index f59b5fe8..812242cb 100644 --- a/src/app/api/user/get-cookies/route.ts +++ b/src/app/api/user/get-cookies/route.ts @@ -1,4 +1,4 @@ -import { decrypt } from "@/app/auth/_lib/decrypt"; +import { decrypt } from "@/app/(auth)/_lib/decrypt"; import _ from "lodash"; import { cookies } from "next/headers"; import { NextResponse } from "next/server"; diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 1ae5f208..06f4d909 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -1,5 +1,5 @@ -import { decrypt } from "@/app/auth/_lib/decrypt"; +import { decrypt } from "@/app/(auth)/_lib/decrypt"; import _ from "lodash"; import { cookies } from "next/headers"; import { NextResponse } from "next/server"; diff --git a/src/app/auth/api/login/route.ts b/src/app/auth/api/login/route.ts deleted file mode 100644 index eb59a9f0..00000000 --- a/src/app/auth/api/login/route.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { prisma } from "@/app/lib"; -import { sessionCreate } from "../../_lib/session_create"; -import { NextResponse } from "next/server"; - -export async function POST(req: Request) { - const user = await prisma.user.findUnique({ - where: { - nomor: "6281339158911", - }, - select: { - id: true, - nomor: true, - }, - }); - - if (!user) return NextResponse.json({ success: false }, { status: 404 }); - - const token = await sessionCreate({ - sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, - encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, - user: user as any, - }); - - return NextResponse.json({ success: true, token }); -} diff --git a/src/app/auth/api/logout/route.ts b/src/app/auth/api/logout/route.ts deleted file mode 100644 index 25aab3db..00000000 --- a/src/app/auth/api/logout/route.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { cookies } from "next/headers"; -import { NextResponse } from "next/server"; - -export async function GET() { - const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); - - return NextResponse.json({ success: true, message: "Logout Berhasil" }); -} diff --git a/src/app/auth/login/page.tsx b/src/app/auth/login/page.tsx deleted file mode 100644 index 7fe848b8..00000000 --- a/src/app/auth/login/page.tsx +++ /dev/null @@ -1,39 +0,0 @@ -"use client"; -import { Button } from "@mantine/core"; -import { useState } from "react"; - -export default function Page() { - const [loading, setLoading] = useState(false); - - - async function login() { - setLoading(true); - try { - const res = await fetch("/auth/api/login", { - method: "POST", - }); - - const dataText = await res.text(); - - if (!res.ok) { - console.error(dataText); - throw new Error(res.statusText); - } - - const dataJson = JSON.parse(dataText); - console.log(dataJson); - // window.location.replace("/dev/home"); - } catch (error) { - console.error(error); - } finally { - setLoading(false); - } - } - return ( - <> - - - ); -} diff --git a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts index cfbdb1e2..3164efdf 100644 --- a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts +++ b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts @@ -1,7 +1,7 @@ "use server"; import { cookies } from "next/headers"; -import { decrypt } from "../../../../app/auth/_lib/decrypt"; +import { decrypt } from "../../../../app/(auth)/_lib/decrypt"; export async function funGetUserIdByToken() { const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!; diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 0aab82e8..6c38ec7c 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -24,33 +24,27 @@ export default function Register() { const [isValue, setIsValue] = useState(false); const focusTrapRef = useFocusTrap(); const [loading, setLoading] = useState(false); + const [idCode, setIdCode] = useState(""); useShallowEffect(() => { const kodeId = localStorage.getItem("hipmi_auth_code_id"); if (kodeId != null) { - onCheckAuthCode({ kodeId: kodeId as string, onSetData: setNomor }); + onCheckAuthCode({ kodeId: kodeId as string }); } else { console.log("code id not found"); } - }, [setNomor]); + }, []); - async function onCheckAuthCode({ - kodeId, - onSetData, - }: { - kodeId: string; - onSetData: any; - }) { + async function onCheckAuthCode({ kodeId }: { kodeId: string }) { try { const respone = await apiGetCheckCodeOtp({ id: kodeId }); if (respone) { - onSetData(respone.nomor); + setIdCode(kodeId); + setNomor(respone.nomor); } } catch (error) { clientLogger.error("Error onCheckAuthCode:", error); } - // const res = await fetch(`/api/auth/check?id=${kodeId}`); - // const result = await res.json(); } async function onRegistarsi() { diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index 31bad0f3..5d611a4b 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -181,18 +181,22 @@ export default function Validasi() { <> - - onBack()}> - - - + {data && data.nomor !== "" ? ( + + onBack()}> + + + + ) : ( + "" + )} From 61f8e03c73da4ecce4a5ddc22ec0ebd66930fafa Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 <bagasbanuna02@gmail.com> Date: Wed, 5 Feb 2025 17:48:45 +0800 Subject: [PATCH 8/9] fix registrasi deskripsi: - fix registrasi dan middleware --- logs/backend/combined-2025-02-05.log | 2 + logs/backend/error-2025-02-05.log | 1 + src/app/api/auth/register/route.ts | 85 +++++++++------- src/app/api/auth/resend/route.ts | 101 ++++++++++---------- src/app/api/auth/validasi/route.ts | 2 +- src/app/api/validation/route.ts | 2 +- src/app_modules/auth/_lib/api_fetch_auth.ts | 28 +++++- src/app_modules/auth/register/view.tsx | 62 +++++------- src/app_modules/auth/validasi/view.tsx | 88 ++++++++--------- src/middleware.ts | 1 - 10 files changed, 199 insertions(+), 173 deletions(-) diff --git a/logs/backend/combined-2025-02-05.log b/logs/backend/combined-2025-02-05.log index 7d880846..1c99acf3 100644 --- a/logs/backend/combined-2025-02-05.log +++ b/logs/backend/combined-2025-02-05.log @@ -22,3 +22,5 @@ {"id":"c65237f0-e0cf-4961-9454-2405c4f4fe05","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T06:41:30.785Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} +{"id":"64e3a991-7e44-407c-94b4-1693dc8a4417","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T09:14:22.961Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T09:43:37.753Z"} diff --git a/logs/backend/error-2025-02-05.log b/logs/backend/error-2025-02-05.log index c2b2edfd..b26e7137 100644 --- a/logs/backend/error-2025-02-05.log +++ b/logs/backend/error-2025-02-05.log @@ -21,3 +21,4 @@ {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at <anonymous> (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} +{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T09:43:37.753Z"} diff --git a/src/app/api/auth/register/route.ts b/src/app/api/auth/register/route.ts index 7a4ddb85..41f11fd4 100644 --- a/src/app/api/auth/register/route.ts +++ b/src/app/api/auth/register/route.ts @@ -4,8 +4,16 @@ import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; export async function POST(req: Request) { - if (req.method === "POST") { + if (req.method !== "POST") { + return NextResponse.json( + { success: false, message: "Method Not Allowed" }, + { status: 405 } + ); + } + + try { const { data } = await req.json(); + console.log("data api register", data); const cekUsername = await prisma.user.findUnique({ where: { @@ -13,46 +21,51 @@ export async function POST(req: Request) { }, }); - try { - if (cekUsername) - return NextResponse.json( - { success: false, message: "Username sudah digunakan" }, - { status: 400 } - ); - - const createUser = await prisma.user.create({ - data: { - username: data.username, - nomor: data.nomor, - active: false, - }, + if (cekUsername) + return NextResponse.json({ + success: false, + message: "Username sudah digunakan", }); - const token = await sessionCreate({ - sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, - encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, - user: createUser as any, - }); + const createUser = await prisma.user.create({ + data: { + username: data.username, + nomor: data.nomor, + active: false, + }, + }); + if (!createUser) return NextResponse.json( - { success: true, message: "Berhasil Login", data: createUser }, - { status: 200 } - ); - } catch (error) { - backendLogger.log("Error registrasi:", error); - return NextResponse.json( - { - success: false, - message: "Server Error", - reason: (error as Error).message, - }, + { success: false, message: "Gagal Registrasi" }, { status: 500 } ); - } - } - return NextResponse.json( - { success: false, message: "Method Not Allowed" }, - { status: 405 } - ); + const token = await sessionCreate({ + sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + user: createUser as any, + }); + + return NextResponse.json( + { + success: true, + message: "Registrasi Berhasil, Anda Sedang Login", + // data: createUser, + }, + { status: 201 } + ); + } catch (error) { + backendLogger.error("Error registrasi:", error); + return NextResponse.json( + { + success: false, + message: "Maaf, Terjadi Keselahan", + reason: (error as Error).message, + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); + } } diff --git a/src/app/api/auth/resend/route.ts b/src/app/api/auth/resend/route.ts index 3e02b0ef..b77a7a97 100644 --- a/src/app/api/auth/resend/route.ts +++ b/src/app/api/auth/resend/route.ts @@ -1,69 +1,72 @@ 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) { - if (req.method === "POST") { + if (req.method !== "POST") { + return NextResponse.json( + { success: false, message: "Method Not Allowed" }, + { status: 405 } + ); + } + + try { const codeOtp = randomOTP(); const body = await req.json(); const { nomor } = body; - try { - const res = await fetch( - `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. + const res = await fetch( + `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. \n >> Kode OTP anda: ${codeOtp}. ` - ); - - 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, - otp: codeOtp, - }, - }); - - if (!createOtpId) - return NextResponse.json( - { - success: false, - message: "Gagal Membuat Kode OTP", - }, - { status: 400 } - ); - - return NextResponse.json( - { - success: true, - message: "Kode Verifikasi Dikirim", - kodeId: createOtpId.id, - }, - { status: 200 } - ); - } catch (error) { - console.log(error); + ); + const sendWa = await res.json(); + if (sendWa.status !== "success") return NextResponse.json( { success: false, - message: "Server Whatsapp Error !!", + message: "Nomor Whatsapp Tidak Aktif", }, - { status: 500 } + { status: 400 } ); - } + + const createOtpId = await prisma.kodeOtp.create({ + data: { + nomor: nomor, + otp: codeOtp, + }, + }); + + if (!createOtpId) + return NextResponse.json( + { + success: false, + message: "Gagal Membuat Kode OTP", + }, + { status: 400 } + ); + + return NextResponse.json( + { + success: true, + message: "Kode Verifikasi Dikirim", + kodeId: createOtpId.id, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.error(" Error Resend OTP", error); + return NextResponse.json( + { + success: false, + message: "Server Whatsapp Error !!", + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); } - return NextResponse.json( - { success: false, message: "Method Not Allowed" }, - { status: 405 } - ); } diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index d485c054..c9f9814e 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -52,7 +52,7 @@ export async function POST(req: Request) { return NextResponse.json( { success: false, - message: "API Error or Server Error", + message: "Maaf, Terjadi Keselahan", reason: (error as Error).message, }, { status: 500 } diff --git a/src/app/api/validation/route.ts b/src/app/api/validation/route.ts index c9a8b258..ddf3d1cc 100644 --- a/src/app/api/validation/route.ts +++ b/src/app/api/validation/route.ts @@ -3,7 +3,7 @@ import { NextResponse } from "next/server"; export async function GET(req: Request) { const auth = req.headers.get("Authorization"); const token = auth?.split(" ")[1]; - console.log("TOKEN>", token); + if (!token) return NextResponse.json({ success: false }, { status: 401 }); return NextResponse.json({ success: true }); diff --git a/src/app_modules/auth/_lib/api_fetch_auth.ts b/src/app_modules/auth/_lib/api_fetch_auth.ts index bf7d7876..0bd42e65 100644 --- a/src/app_modules/auth/_lib/api_fetch_auth.ts +++ b/src/app_modules/auth/_lib/api_fetch_auth.ts @@ -3,6 +3,7 @@ export { apiGetCheckCodeOtp, apiPostVerifikasiCodeOtp, apiDeleteAktivasiKodeOtpByNomor, + apiFetchRegister, }; const apiFetchLogin = async ({ nomor }: { nomor: string }) => { @@ -43,7 +44,30 @@ const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => { }, }); - console.log("respone delete", await respone.json()); - return await respone.json().catch(() => null); }; + +const apiFetchRegister = async ({ + nomor, + username, +}: { + nomor: string; + username: string; +}) => { + const data = { + username: username, + nomor: nomor, + }; + const respone = await fetch("/api/auth/register", { + method: "POST", + body: JSON.stringify({ data }), + headers: { + "Content-Type": "application/json", + }, + }); + + const result = await respone.json(); + + return result; + // return await respone.json().catch(() => null); +}; diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 6c38ec7c..4b56e8c0 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -14,8 +14,13 @@ import { useState } from "react"; import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id"; import Register_SkeletonView from "./skeleton"; import { clientLogger } from "@/util/clientLogger"; -import { apiGetCheckCodeOtp } from "../_lib/api_fetch_auth"; +import { + apiDeleteAktivasiKodeOtpByNomor, + apiFetchRegister, + apiGetCheckCodeOtp, +} from "../_lib/api_fetch_auth"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global"; export default function Register() { const router = useRouter(); @@ -48,52 +53,28 @@ export default function Register() { } async function onRegistarsi() { - const data = { - username: value, - nomor: nomor, - }; - try { setLoading(true); - const res = await fetch("/api/auth/register", { - method: "POST", - body: JSON.stringify({ - data, - }), - headers: { - "Content-Type": "application/json", - }, - }); - - const result = await res.json(); - - if (res.status === 200) { - ComponentGlobal_NotifikasiBerhasil(result.message); - localStorage.removeItem("hipmi_auth_code_id"); - await auth_funDeleteAktivasiKodeOtpByNomor({ - nomor: data.nomor, - }); + const respone = await apiFetchRegister({ nomor: nomor, username: value }); + if (respone.success) { router.push("/waiting-room", { scroll: false }); - return; - } + ComponentGlobal_NotifikasiBerhasil(respone.message); - if (res.status === 400) { - setLoading(false); - ComponentGlobal_NotifikasiPeringatan(result.message); - return; - } + try { + const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ + id: idCode, + }); - if (res.status === 405) { + if (responeDelete) { + localStorage.removeItem("hipmi_auth_code_id"); + } + } catch (error) { + clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error); + } + } else { setLoading(false); - ComponentGlobal_NotifikasiPeringatan(result.message); - return; - } - - if (res.status === 500) { - setLoading(false); - ComponentGlobal_NotifikasiPeringatan(result.message); - return; + ComponentGlobal_NotifikasiPeringatan(respone.message); } } catch (error) { setLoading(false); @@ -156,6 +137,7 @@ export default function Register() { value.length < 5 || _.values(value).includes(" ") } + style={{ transition: "0.5s" }} loading={loading ? true : false} loaderPosition="center" radius={"md"} diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index 5d611a4b..5c966d58 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -131,7 +131,6 @@ export default function Validasi() { async function onBack() { try { router.back(); - 111; const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ id: idCode, }); @@ -165,13 +164,12 @@ export default function Validasi() { setTriggerOtp(true); setCounter(60); setLoadingResend(false); - // router.push("/validasi", { scroll: false }); } else { setLoadingResend(false); ComponentGlobal_NotifikasiPeringatan(result.message); } } catch (error) { - console.error(error); + clientLogger.error(" Error onResend", error); setLoadingResend(false); ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan"); } @@ -181,26 +179,26 @@ export default function Validasi() { <> <UIGlobal_LayoutDefault> <Stack h={"100vh"}> - {data && data.nomor !== "" ? ( - <Box - pt={"md"} - px={"md"} - style={{ - position: "sticky", - top: 0, - }} - > - <ActionIcon variant="transparent" onClick={() => onBack()}> + <Box + pt={"md"} + px={"md"} + style={{ + position: "sticky", + top: 0, + }} + > + <ActionIcon variant="transparent" onClick={() => onBack()}> + {data && data.nomor !== "" ? ( <IconChevronLeft color="white" /> - </ActionIcon> - </Box> - ) : ( - "" - )} + ) : ( + "" + )} + </ActionIcon> + </Box> <Stack align="center" justify="center" h={"100vh"} spacing={50}> <Title order={2} color={MainColor.yellow}> - Verifikasi Kode OTP {data.code} + Verifikasi Kode OTP @@ -232,31 +230,40 @@ export default function Validasi() { - - Tidak menerima kode ?{" "} - {counter > 0 ? ( - - {counter + "s"} - - ) : loadingResend ? ( - + + + Tidak menerima kode ?{" "} + + {data && data.nomor !== "" ? ( + counter > 0 ? ( + + {counter + "s"} + + ) : loadingResend ? ( + + ) : ( + { + onResendCode(); + }} + fw={"bold"} + > + Kirim ulang + + ) ) : ( - { - onResendCode(); - }} - fw={"bold"} - > - Kirim ulang - + )} - + - - {/* {data.nomor == "" && data.code == "" ? : ""} */} diff --git a/src/middleware.ts b/src/middleware.ts index 1b09e728..03d761e4 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -101,7 +101,6 @@ export const middleware = async (req: NextRequest) => { // Verify token and get user data const user = await verifyToken({ token, encodedKey }); - console.log("USER >>", user?.username); // Handle login page access if (pathname === loginPath) { From ad653c996b63bb81f8e8d812cf3fd187a2484e9c Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 5 Feb 2025 17:51:21 +0800 Subject: [PATCH 9/9] API ADMIN DASHBOARD DONASI --- src/app/api/admin/donasi/[status]/route.ts | 152 +++++++++ .../admin/donasi/sub-menu/publish/page.tsx | 8 +- .../dev/admin/donasi/sub-menu/reject/page.tsx | 4 +- .../dev/admin/donasi/sub-menu/review/page.tsx | 4 +- .../admin/investasi/sub-menu/publish/page.tsx | 4 +- .../donasi/lib/api_fetch_admin_donasi.ts | 44 ++- src/app_modules/admin/donasi/main/index.tsx | 11 +- .../admin/donasi/sub_menu/table_publish.tsx | 270 +++++++++------- .../admin/donasi/sub_menu/table_reject.tsx | 271 +++++++++------- .../admin/donasi/sub_menu/table_review.tsx | 304 ++++++++++-------- .../admin/investasi/main/table_publish.tsx | 14 +- src/middleware.ts | 2 +- 12 files changed, 679 insertions(+), 409 deletions(-) create mode 100644 src/app/api/admin/donasi/[status]/route.ts diff --git a/src/app/api/admin/donasi/[status]/route.ts b/src/app/api/admin/donasi/[status]/route.ts new file mode 100644 index 00000000..b8cc0bfe --- /dev/null +++ b/src/app/api/admin/donasi/[status]/route.ts @@ -0,0 +1,152 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { data } from "autoprefixer"; +import _, { take } from "lodash"; +import moment from "moment"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request, + { params }: { params: { status: string } }) { + const method = request.method; + if (method !== "GET") { + return NextResponse.json({ + succes: false, + message: "Method not allowed" + }, + { status: 405 } + ); + } + + const { status } = params; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + try { + let fixData; + const fixStatus = _.startCase(status); + + + if (!page && !search) { + fixData = await prisma.donasi.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + active: true, + DonasiMaster_Status: { + name: fixStatus + } + }, + include: { + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true + } + } + } + }, + DonasiMaster_Status: true, + DonasiMaster_Ketegori: true, + DonasiMaster_Durasi: true + } + }) + } else if (!page && search) { + fixData = await prisma.donasi.findMany({ + orderBy: { + updatedAt: "desc" + }, + where: { + active: true, + DonasiMaster_Status: { + name: fixStatus + }, + title: { + contains: search, + mode: "insensitive" + } + }, + include: { + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true + } + } + } + }, + DonasiMaster_Status: true, + DonasiMaster_Ketegori: true, + DonasiMaster_Durasi: true + } + }) + } else if (page && !search) { + const data = await prisma.donasi.findMany({ + take: takeData, + skip: skipData, + orderBy: [ + { + publishTime: "desc" + } + ], + where: { + active: true, + DonasiMaster_Status: { + name: fixStatus + } + }, + include: { + Author: true, + imageDonasi: true, + DonasiMaster_Status: true, + DonasiMaster_Ketegori: true, + DonasiMaster_Durasi: true + } + }) + + const nCount = await prisma.donasi.count({ + where: { + active: true, + DonasiMaster_Status: { + name: fixStatus + }, + } + }) + + console.log("data >", data) + fixData = { + data: data, + nCount: _.ceil(nCount / takeData) + } + } + + return NextResponse.json({ + success: true, + message: "Success", + data: fixData + }, + { status: 200 } + ) + + } catch (error) { + backendLogger.error("Error geta data table donasi event dashboard>>", error) + return NextResponse.json({ + success: false, + message: "Failed get data table donasi dashboard", + reason: (error as Error).message + }, + { status: 500 } + ); + } finally { + await prisma.$disconnect(); + } +} \ No newline at end of file diff --git a/src/app/dev/admin/donasi/sub-menu/publish/page.tsx b/src/app/dev/admin/donasi/sub-menu/publish/page.tsx index a0171588..a38784c8 100644 --- a/src/app/dev/admin/donasi/sub-menu/publish/page.tsx +++ b/src/app/dev/admin/donasi/sub-menu/publish/page.tsx @@ -2,11 +2,11 @@ import { AdminDonasi_TablePublish } from "@/app_modules/admin/donasi"; import adminDonasi_getListPublish from "@/app_modules/admin/donasi/fun/get/get_list_publish"; export default async function Page() { - const listPublish = await adminDonasi_getListPublish({ - page: 1, - }); + // const listPublish = await adminDonasi_getListPublish({ + // page: 1, + // }); // console.log(listPublish) return<> - + } \ No newline at end of file diff --git a/src/app/dev/admin/donasi/sub-menu/reject/page.tsx b/src/app/dev/admin/donasi/sub-menu/reject/page.tsx index 76c38ec8..8c1228c4 100644 --- a/src/app/dev/admin/donasi/sub-menu/reject/page.tsx +++ b/src/app/dev/admin/donasi/sub-menu/reject/page.tsx @@ -2,11 +2,11 @@ import { AdminDonasi_TableReject } from "@/app_modules/admin/donasi"; import adminDonasi_getListReject from "@/app_modules/admin/donasi/fun/get/get_list_reject"; export default async function Page() { - const dataReject = await adminDonasi_getListReject({ page: 1 }); + // const dataReject = await adminDonasi_getListReject({ page: 1 }); // console.log(dataReject) return ( <> - + ); } diff --git a/src/app/dev/admin/donasi/sub-menu/review/page.tsx b/src/app/dev/admin/donasi/sub-menu/review/page.tsx index 6e25d7fe..987917a5 100644 --- a/src/app/dev/admin/donasi/sub-menu/review/page.tsx +++ b/src/app/dev/admin/donasi/sub-menu/review/page.tsx @@ -2,7 +2,7 @@ import { AdminDonasi_TableReview } from "@/app_modules/admin/donasi"; import adminDonasi_getListReview from "@/app_modules/admin/donasi/fun/get/get_list_review"; export default async function Page() { - const listReview = await adminDonasi_getListReview({page: 1}); + // const listReview = await adminDonasi_getListReview({page: 1}); // console.log(listReview); - return ; + return ; } diff --git a/src/app/dev/admin/investasi/sub-menu/publish/page.tsx b/src/app/dev/admin/investasi/sub-menu/publish/page.tsx index 02de99d3..f37e97d2 100644 --- a/src/app/dev/admin/investasi/sub-menu/publish/page.tsx +++ b/src/app/dev/admin/investasi/sub-menu/publish/page.tsx @@ -2,11 +2,11 @@ import { Admin_TablePublishInvestasi } from "@/app_modules/admin/investasi"; import { adminInvestasi_funGetAllPublish } from "@/app_modules/admin/investasi/fun/get/get_all_publish"; export default async function Page() { - const listInvestasi = await adminInvestasi_funGetAllPublish({page: 1}); + // const listInvestasi = await adminInvestasi_funGetAllPublish({page: 1}); return ( <> - + ); } diff --git a/src/app_modules/admin/donasi/lib/api_fetch_admin_donasi.ts b/src/app_modules/admin/donasi/lib/api_fetch_admin_donasi.ts index be1e50e4..348d7f3f 100644 --- a/src/app_modules/admin/donasi/lib/api_fetch_admin_donasi.ts +++ b/src/app_modules/admin/donasi/lib/api_fetch_admin_donasi.ts @@ -1,12 +1,13 @@ export { - apiGetDonasiStatusCountDashboard, - apiGetDonasiKategoriCountDashboard + apiGetAdminDonasiStatusCountDashboard, + apiGetAdminDonasiKategoriCountDashboard, + apiGetAdminDonasiByStatus }; -const apiGetDonasiStatusCountDashboard = async ({ name }: +const apiGetAdminDonasiStatusCountDashboard = async ({ name }: { name: "Publish" | "Review" | "Reject" }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); - + const response = await fetch(`/api/admin/donasi/dashboard/${name}`, { method: "GET", headers: { @@ -19,7 +20,7 @@ const apiGetDonasiStatusCountDashboard = async ({ name }: return await response.json().catch(() => null); }; -const apiGetDonasiKategoriCountDashboard = async () => { +const apiGetAdminDonasiKategoriCountDashboard = async () => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); @@ -33,4 +34,35 @@ const apiGetDonasiKategoriCountDashboard = async () => { } }); return await response.json().catch(() => null); -} \ No newline at end of file +} + +const apiGetAdminDonasiByStatus = async ({ + status, + page, + search }: { + status: "Publish" | "Review" | "Reject", + page: string; + search: string; + }) => { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + console.log("Ini token", token) + console.log("Ini Page", page) + console.log("Ini search", search) + const isPage = page ? `?page=${page}` : ""; + const isSearch = search ? `&search=${search}` : ""; + const response = await fetch( + `/api/admin/donasi/${status}${isPage}${isSearch}`, + { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}` + } + } + ) + console.log("Ini response", response) + return await response.json().catch(() => null); +} diff --git a/src/app_modules/admin/donasi/main/index.tsx b/src/app_modules/admin/donasi/main/index.tsx index 27f17de1..ed1b7cef 100644 --- a/src/app_modules/admin/donasi/main/index.tsx +++ b/src/app_modules/admin/donasi/main/index.tsx @@ -25,7 +25,8 @@ import { clientLogger } from "@/util/clientLogger"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import global_limit from "@/app/lib/limit"; import { useShallowEffect } from "@mantine/hooks"; -import { apiGetDonasiKategoriCountDashboard, apiGetDonasiStatusCountDashboard } from "../lib/api_fetch_admin_donasi"; +import { apiGetAdminDonasiKategoriCountDashboard, apiGetAdminDonasiStatusCountDashboard } from "../lib/api_fetch_admin_donasi"; + export default function AdminDonasi_Main({ // countPublish, @@ -62,7 +63,7 @@ export default function AdminDonasi_Main({ } async function onLoadCountPublish() { try { - const response = await apiGetDonasiStatusCountDashboard({ + const response = await apiGetAdminDonasiStatusCountDashboard({ name: "Publish", }) @@ -75,7 +76,7 @@ export default function AdminDonasi_Main({ } async function onLoadCountReview() { try { - const response = await apiGetDonasiStatusCountDashboard({ + const response = await apiGetAdminDonasiStatusCountDashboard({ name: "Review", }) if (response) { @@ -87,7 +88,7 @@ export default function AdminDonasi_Main({ } async function onLoadCountReject() { try { - const response = await apiGetDonasiStatusCountDashboard({ + const response = await apiGetAdminDonasiStatusCountDashboard({ name: "Reject", }) if (response) { @@ -99,7 +100,7 @@ export default function AdminDonasi_Main({ } async function onLoadCountKategori() { try { - const response = await apiGetDonasiKategoriCountDashboard() + const response = await apiGetAdminDonasiKategoriCountDashboard() if (response) { setCountKategori(response.data); } diff --git a/src/app_modules/admin/donasi/sub_menu/table_publish.tsx b/src/app_modules/admin/donasi/sub_menu/table_publish.tsx index 21c053cb..a44e72a5 100644 --- a/src/app_modules/admin/donasi/sub_menu/table_publish.tsx +++ b/src/app_modules/admin/donasi/sub_menu/table_publish.tsx @@ -12,6 +12,7 @@ import { ScrollArea, Stack, Table, + Text, TextInput, Title } from "@mantine/core"; @@ -23,94 +24,120 @@ import adminDonasi_getListPublish from "../fun/get/get_list_publish"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { AccentColor, MainColor } from "@/app_modules/_global/color"; import { AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { useShallowEffect } from "@mantine/hooks"; +import { clientLogger } from "@/util/clientLogger"; +import { apiGetAdminDonasiByStatus } from "../lib/api_fetch_admin_donasi"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function AdminDonasi_TablePublish({ - listPublish, -}: { - listPublish: any; -}) { +export default function AdminDonasi_TablePublish() { return ( <> - + ); } -function TableStatus({ listPublish }: { listPublish: any }) { +function TableStatus() { const router = useRouter(); const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); - const [data, setData] = useState(listPublish.data); - const [isNPage, setNPage] = useState(listPublish.nPage); + const [data, setData] = useState(null); + const [isNPage, setNPage] = useState(1); const [isActivePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); - async function onSearch(s: string) { - setSearch(s); - const loadData = await adminDonasi_getListPublish({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + useShallowEffect(() => { + const loadInitialData = async () => { + try { + const response = await apiGetAdminDonasiByStatus({ + status: "Publish", + page: `${isActivePage}`, + search: isSearch + }) + + if (response?.success && response?.data.data) { + setData(response.data.data); + setNPage(response.data.nPage || 1); + } else { + console.error("Invalid data format recieved:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Invalid data format recieved:", error); + setData([]); + } + } + loadInitialData(); + }, [isActivePage, isSearch]) + + const onSearch = (searchTerm: string) => { + setSearch(searchTerm); + setActivePage(1); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminDonasi_getListPublish({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const onPageClick = (page: number) => { + setActivePage(page); + } + const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ) + } + return data.map((e, i) => ( + + +
{e.title}
+ + +
+ +
+ + +
+ +
+ + +
{e.DonasiMaster_Ketegori.name}
+ + +
{e.DonasiMaster_Durasi.name} hari
+ + +
+ +
+ + + )); } - const TableRows = data.map((e, i) => ( - - -
{e.title}
- - -
- -
- - -
- -
- - -
{e.DonasiMaster_Ketegori.name}
- - -
{e.DonasiMaster_Durasi.name} hari
- - -
- -
- - - )); return ( <> @@ -121,13 +148,13 @@ function TableStatus({ listPublish }: { listPublish: any }) { color={AdminColor.softBlue} component={ } - radius={"xl"} - placeholder="Masukan judul" - onChange={(val) => { - onSearch(val.currentTarget.value); - }} - /> + icon={} + radius={"xl"} + placeholder="Masukan judul" + onChange={(val) => { + onSearch(val.currentTarget.value); + }} + /> } /> {/* */} - - - - - - - - - - - - - - {TableRows} -
-
Judul
-
-
Target
-
-
Terkumpul
-
-
Ketegori
-
-
Durasi
-
-
Aksi
-
-
- {/* + {!data ? ( + + ) : ( + + + + + + + + + + + + + + {renderTableBody()} +
+
Judul
+
+
Target
+
+
Terkumpul
+
+
Ketegori
+
+
Durasi
+
+
Aksi
+
+
+ {/* */} -
- { - onPageClick(val); - }} - /> -
-
+
+ { + onPageClick(val); + }} + /> +
+
+ )} +
); diff --git a/src/app_modules/admin/donasi/sub_menu/table_reject.tsx b/src/app_modules/admin/donasi/sub_menu/table_reject.tsx index a71bfd1e..0b5eaa08 100644 --- a/src/app_modules/admin/donasi/sub_menu/table_reject.tsx +++ b/src/app_modules/admin/donasi/sub_menu/table_reject.tsx @@ -18,7 +18,7 @@ import { TextInput, Title } from "@mantine/core"; -import { useDisclosure } from "@mantine/hooks"; +import { useDisclosure, useShallowEffect } from "@mantine/hooks"; import { IconEyeEdit, IconSearch } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -26,90 +26,118 @@ import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate"; import adminDonasi_getListReject from "../fun/get/get_list_reject"; import { IconEyeCheck } from "@tabler/icons-react"; +import { clientLogger } from "@/util/clientLogger"; +import { apiGetAdminDonasiByStatus } from "../lib/api_fetch_admin_donasi"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function AdminDonasi_TableReject({ - dataReject, -}: { - dataReject: any; -}) { +export default function AdminDonasi_TableReject() { return ( <> - + ); } -function TableStatus({ dataReject }: { dataReject: any }) { +function TableStatus() { const router = useRouter(); const [opened, { open, close }] = useDisclosure(false); const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); - const [data, setData] = useState(dataReject.data); - const [isNPage, setNPage] = useState(dataReject.nPage); + const [data, setData] = useState(null); + const [isNPage, setNPage] = useState(1); const [isActivePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); - async function onSearch(s: string) { - setSearch(s); - const loadData = await adminDonasi_getListReject({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + + useShallowEffect(() => { + const loadInitialData = async () => { + try { + const response = await apiGetAdminDonasiByStatus({ + status: "Reject", + page: `${isActivePage}`, + search: isSearch + }) + + if (response?.success && response?.data.data) { + setData(response.data.data); + setNPage(response.data.nPage || 1); + } else { + console.error("Invalid data format recieved:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Invalid data format recieved:", error); + setData([]); + } + } + loadInitialData(); + }, [isActivePage, isSearch]) + + + const onSearch = (searchTerm: string) => { + setSearch(searchTerm); + setActivePage(1); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminDonasi_getListReject({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const onPageClick = (page: number) => { + setActivePage(page); } - const TableRows = data.map((e, i) => ( - - -
{e?.Author?.username}
- - -
{e?.title}
- - -
- -
- - -
{e?.DonasiMaster_Ketegori.name}
- - -
{e?.DonasiMaster_Durasi.name} hari
- - -
- -
+ const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ) + } + return data.map((e, i) => ( + + +
{e?.Author?.username}
+ + +
{e?.title}
+ + +
+ +
+ + +
{e?.DonasiMaster_Ketegori.name}
+ + +
{e?.DonasiMaster_Durasi.name} hari
+ + +
+ +
+ + {/* */} + + + )); + } - {/* */} - - - )); return ( <> @@ -120,13 +148,13 @@ function TableStatus({ dataReject }: { dataReject: any }) { color={AdminColor.softBlue} component={ } - radius={"xl"} - placeholder="Masukan judul" - onChange={(val) => { - onSearch(val.currentTarget.value); - }} - /> + icon={} + radius={"xl"} + placeholder="Masukan judul" + onChange={(val) => { + onSearch(val.currentTarget.value); + }} + /> } /> {/* */} - - - - - - - - - - - - - - {TableRows} -
-
Username
-
-
Judul
-
-
Target
-
-
Ketegori
-
-
Durasi
-
-
Alasan
-
-
- {/* - */} -
- { - onPageClick(val); - }} - /> -
-
-
+ {!data ? ( + + ) : ( - {data.map((e, i) => ( + + + + + + + + + + + + + + + {renderTableBody()} +
+
Username
+
+
Judul
+
+
Target
+
+
Ketegori
+
+
Durasi
+
+
Alasan
+
+
+ {/* + */} +
+ { + onPageClick(val); + }} + /> +
+
+ )} +
+ {/* {data.map((e, i) => ( {i} - ))} + ))} */} ); } diff --git a/src/app_modules/admin/donasi/sub_menu/table_review.tsx b/src/app_modules/admin/donasi/sub_menu/table_review.tsx index f4c0f5be..c2325dec 100644 --- a/src/app_modules/admin/donasi/sub_menu/table_review.tsx +++ b/src/app_modules/admin/donasi/sub_menu/table_review.tsx @@ -16,6 +16,7 @@ import { ScrollArea, Stack, Table, + Text, TextInput, Title, } from "@mantine/core"; @@ -28,28 +29,28 @@ import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamp import adminDonasi_getListReview from "../fun/get/get_list_review"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; import { AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { apiGetAdminDonasiByStatus } from "../lib/api_fetch_admin_donasi"; +import { error } from "console"; +import { clientLogger } from "@/util/clientLogger"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function AdminDonasi_TableReview({ - listReview, -}: { - listReview: MODEL_DONASI[]; -}) { +export default function AdminDonasi_TableReview() { return ( <> - + ); } -function TableStatus({ listReview }: { listReview: any }) { +function TableStatus() { const router = useRouter(); const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); - const [data, setData] = useState(listReview.data); - const [isNPage, setNPage] = useState(listReview.nPage); + const [data, setData] = useState(null); + const [isNPage, setNPage] = useState(1); const [isActivePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); @@ -61,80 +62,100 @@ function TableStatus({ listReview }: { listReview: any }) { const [isLoadingReload, setLoadingReload] = useState(false); useShallowEffect(() => { - if (isAdminDonasi_TriggerReview) { - setIsShowReload(true); + loadInitialData(); + }, [isActivePage, isSearch]); + + const loadInitialData = async () => { + try { + const response = await apiGetAdminDonasiByStatus({ + status: "Review", + page: `${isActivePage}`, + search: isSearch + }) + console.log("IniData", response) + + if (response?.success && response?.data?.data) { + setData(response.data.data); + setNPage(response.data.nPage || 1); + } else { + console.error("Invalid data format received:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Error get data table publish", error); + setData([]); } - }, [isAdminDonasi_TriggerReview, setIsShowReload]); - + } async function onLoadData() { - const loadData = await adminDonasi_getListReview({ page: 1 }); - - setData(loadData.data as any); - setNPage(loadData.nPage); + loadInitialData(); setLoadingReload(false); setIsShowReload(false); setIsAdminDonasi_TriggerReview(false); } - async function onSearch(s: string) { - setSearch(s); - const loadData = await adminDonasi_getListReview({ - page: 1, - search: s, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const onSearch = async (searchTerm: string) => { + setSearch(searchTerm); + setActivePage(1); } - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminDonasi_getListReview({ - search: isSearch, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const onPageClick = (page: number) => { + setActivePage(page); + } + + const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ) + } + + return data.map((e, i) => ( + + +
{e?.Author?.username}
+ + +
{e?.title}
+ + +
+ +
+ + +
{e?.DonasiMaster_Ketegori.name}
+ + +
{e?.DonasiMaster_Durasi.name} hari
+ + +
+ +
+ + + )); } - const TableRows = data.map((e, i) => ( - - -
{e?.Author?.username}
- - -
{e?.title}
- - -
- -
- - -
{e?.DonasiMaster_Ketegori.name}
- - -
{e?.DonasiMaster_Durasi.name} hari
- - -
- -
- - - )); return ( <> @@ -142,7 +163,7 @@ function TableStatus({ listReview }: { listReview: any }) { {/*
{JSON.stringify(listUser, null, 2)}
*/} } @@ -170,74 +191,77 @@ function TableStatus({ listReview }: { listReview: any }) { }} /> */} + {!data ? ( + + ) : ( + + {isShowReload && ( + +
+ +
+
+ )} + + + + + + + + + + + + + {renderTableBody()} +
+
Username
+
+
Judul
+
+
Target
+
+
Ketegori
+
+
Durasi
+
+
Aksi
+
+
+
+ { + onPageClick(val); + }} + /> +
+
+ )} - - {isShowReload && ( - -
- -
-
- )} - - - - - - - - - - - - - {TableRows} -
-
Username
-
-
Judul
-
-
Target
-
-
Ketegori
-
-
Durasi
-
-
Aksi
-
-
-
- { - onPageClick(val); - }} - /> -
-
); diff --git a/src/app_modules/admin/investasi/main/table_publish.tsx b/src/app_modules/admin/investasi/main/table_publish.tsx index 85a5f39b..dd0c4dbd 100644 --- a/src/app_modules/admin/investasi/main/table_publish.tsx +++ b/src/app_modules/admin/investasi/main/table_publish.tsx @@ -30,26 +30,22 @@ import { useShallowEffect } from "@mantine/hooks"; import { clientLogger } from "@/util/clientLogger"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export default function Admin_TablePublishInvestasi({ - dataInvestsi, -}: { - dataInvestsi: MODEL_INVESTASI[]; -}) { +export default function Admin_TablePublishInvestasi() { return ( <> - + {/*
{JSON.stringify(listPublish, null, 2)}
*/}
); } -function TableView({ listData }: { listData: any }) { +function TableView() { const router = useRouter(); - const [data, setData] = useState(listData.data); - const [nPage, setNPage] = useState(listData.nPage); + const [data, setData] = useState(null); + const [nPage, setNPage] = useState(1); const [activePage, setActivePage] = useState(1); const [isSearch, setSearch] = useState(""); const [isLoading, setLoading] = useState(false); diff --git a/src/middleware.ts b/src/middleware.ts index 01c2a43d..18382d73 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -39,7 +39,7 @@ const middlewareConfig: MiddlewareConfig = { // ADMIN API // "/api/admin/event/*", // "/api/admin/investasi/*", - // "/api/admin/donasi/dashboard/*", + "/api/admin/donasi/*", // "/api/admin/voting/dashboard/*", // "/api/admin/job/dashboard/*", // "/api/admin/forum/dashboard/*",