Merge pull request #292 from bipproduction/join
fix server action to API
This commit is contained in:
9
.env.build
Normal file
9
.env.build
Normal file
@@ -0,0 +1,9 @@
|
||||
DATABASE_URL="postgresql://bip:Production_123@localhost:5433/hipmi_build?schema=public"
|
||||
WIBU_PWD="QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZlghvftyguhijknhbgvcfytguu8okjnhbgvfty7u8oilkjnhgvtygu7u8ojilnkhbgvhujnkhghvjhukjnhb"
|
||||
Client_KEY="SB-Mid-client-9NDTxltqdZrEB9m-"
|
||||
Server_KEY="SB-Mid-server-NyltU-U7fLVQd1nv1LWBKylr"
|
||||
MAPBOX_TOKEN="pk.eyJ1IjoibWFsaWtrdXJvc2FraSIsImEiOiJjbHppZHh2enYwZnQ3MmlyMWc2Y2RlMzZoIn0.XssvJvq_iniclf8UhvXaIg"
|
||||
WS_APIKEY="eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoiY20wdXIxeXh3MDAwMDU2bnNqbHI2MTg3cCIsIm5hbWUiOiJiYWdhcyIsImVtYWlsIjoiYmFnYXNAZ21haWwuY29tIiwiQXBpS2V5IjpbeyJpZCI6ImNtMHVyMXl5MzAwMDI1Nm5zazNia2xyc28iLCJuYW1lIjoiZGVmYXVsdCJ9XX0sImlhdCI6MTcyNTk1NjMyMSwiZXhwIjo0ODgxNzE2MzIxfQ.9D3YszZA_ljrkTKMcgo03u7PL5mo9OaoM41rbUrOsz8"
|
||||
NEXT_PUBLIC_WIBU_REALTIME_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp5aml4c2J1c2diYnR2am9namhvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjY3Mzk1NDUsImV4cCI6MjA0MjMxNTU0NX0.jHNW5Pwhj-KXUQOMqzILaAz62k3xlKEL5XKE4xoR7Xc"
|
||||
NEXT_PUBLIC_BASE_TOKEN_KEY="QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZlghvftyguhijknhbgvcfytguu8okjnhbgvfty7u8oilkjnhgvtygu7u8ojilnkhbgvhujnkhghvjhukjnhb"
|
||||
NEXT_PUBLIC_BASE_SESSION_KEY="hipmi-key"
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.2.50](https://github.com/bipproduction/hipmi/compare/v1.2.49...v1.2.50) (2025-02-10)
|
||||
|
||||
## [1.2.49](https://github.com/bipproduction/hipmi/compare/v1.2.48...v1.2.49) (2025-02-07)
|
||||
|
||||
## [1.2.48](https://github.com/bipproduction/hipmi/compare/v1.2.47...v1.2.48) (2025-02-07)
|
||||
|
||||
3
build.wibu
Normal file
3
build.wibu
Normal file
@@ -0,0 +1,3 @@
|
||||
bun --env-file=.env.build prisma db push
|
||||
bun --env-file=.env.build prisma db seed
|
||||
bun --env-file=.env.build run build
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.2.49",
|
||||
"version": "1.2.50",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
22
src/app/(auth)/_lib/decrypt.back.txt
Normal file
22
src/app/(auth)/_lib/decrypt.back.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
import { jwtVerify } from "jose";
|
||||
|
||||
export async function decrypt({
|
||||
token,
|
||||
encodedKey,
|
||||
}: {
|
||||
token: string;
|
||||
encodedKey: string;
|
||||
}): Promise<Record<string, any> | null> {
|
||||
try {
|
||||
const enc = new TextEncoder().encode(encodedKey);
|
||||
const { payload } = await jwtVerify(token, enc, {
|
||||
algorithms: ["HS256"],
|
||||
});
|
||||
return (payload.user as Record<string, any>) || null;
|
||||
} catch (error) {
|
||||
console.error("Gagal verifikasi session", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// wibu:0.2.82
|
||||
@@ -7,16 +7,43 @@ export async function decrypt({
|
||||
token: string;
|
||||
encodedKey: string;
|
||||
}): Promise<Record<string, any> | null> {
|
||||
if (!token || !encodedKey) {
|
||||
console.error("Missing required parameters:", {
|
||||
hasToken: !!token,
|
||||
hasEncodedKey: !!encodedKey,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const enc = new TextEncoder().encode(encodedKey);
|
||||
const { payload } = await jwtVerify(token, enc, {
|
||||
algorithms: ["HS256"],
|
||||
});
|
||||
return (payload.user as Record<string, any>) || null;
|
||||
|
||||
if (!payload || !payload.user) {
|
||||
console.error("Invalid payload structure:", {
|
||||
hasPayload: !!payload,
|
||||
hasUser: payload ? !!payload.user : false,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
// Logging untuk debug
|
||||
// console.log("Decrypt successful:", {
|
||||
// payloadExists: !!payload,
|
||||
// userExists: !!payload.user,
|
||||
// tokenPreview: token.substring(0, 10) + "...",
|
||||
// });
|
||||
|
||||
return payload.user as Record<string, any>;
|
||||
} catch (error) {
|
||||
console.error("Gagal verifikasi session", error);
|
||||
console.error("Token verification failed:", {
|
||||
error,
|
||||
tokenLength: token?.length,
|
||||
errorName: error instanceof Error ? error.name : "Unknown error",
|
||||
errorMessage: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// wibu:0.2.82
|
||||
|
||||
9
src/app/(auth)/invalid-user/page.tsx
Normal file
9
src/app/(auth)/invalid-user/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { InvalidUser } from "@/app_modules/auth";
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<>
|
||||
<InvalidUser />
|
||||
</>
|
||||
);
|
||||
}
|
||||
133
src/app/api/admin/forum/komentar/route.ts
Normal file
133
src/app/api/admin/forum/komentar/route.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { count } from 'console';
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
import _ from 'lodash';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed"
|
||||
},
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
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 page", page)
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.forum_ReportKomentar.findMany({
|
||||
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
},
|
||||
where: {
|
||||
Forum_Komentar: {
|
||||
isActive: true,
|
||||
komentar: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
deskripsi: true,
|
||||
ForumMaster_KategoriReport: true,
|
||||
User: {
|
||||
select: {
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
},
|
||||
})
|
||||
} else {
|
||||
const data = await prisma.forum_ReportKomentar.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Forum_Komentar: {
|
||||
isActive: true,
|
||||
komentar: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
deskripsi: true,
|
||||
ForumMaster_KategoriReport: true,
|
||||
User: {
|
||||
select: {
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
const nCount = await prisma.forum_ReportKomentar.count({
|
||||
where: {
|
||||
Forum_Komentar: {
|
||||
isActive: true,
|
||||
komentar: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nCount: _.ceil(nCount / takeData)
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data forum komentar",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data forum komentar", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get data forum komentar",
|
||||
reason: (error as Error).message
|
||||
},
|
||||
)
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
150
src/app/api/admin/forum/posting/route.ts
Normal file
150
src/app/api/admin/forum/posting/route.ts
Normal file
@@ -0,0 +1,150 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request,
|
||||
{ postingId }: { postingId: string }) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
},
|
||||
{ status: 405 }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.forum_ReportPosting.findMany({
|
||||
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
forum_PostingId: postingId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
deskripsi: true,
|
||||
createdAt: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ForumMaster_KategoriReport: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const data = await prisma.forum_ReportPosting.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Forum_Posting: {
|
||||
isActive: true,
|
||||
diskusi: {
|
||||
contains: search ? search : '',
|
||||
mode: "insensitive"
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
deskripsi: true,
|
||||
forumMaster_KategoriReportId: true,
|
||||
ForumMaster_KategoriReport: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
},
|
||||
},
|
||||
|
||||
forum_PostingId: true,
|
||||
Forum_Posting: {
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
ForumMaster_StatusPosting: {
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
}
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
userId: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const nCount = await prisma.forum_ReportPosting.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nCount: _.ceil(nCount / takeData)
|
||||
}
|
||||
}
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data forum posting",
|
||||
data: fixData
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data forum posting >>", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get data forum posting",
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,40 @@ export async function GET(request: Request) {
|
||||
let fixData;
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.forum_Posting.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
diskusi: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
Forum_ReportPosting: true,
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
ForumMaster_StatusPosting: true,
|
||||
},
|
||||
});
|
||||
|
||||
} else {
|
||||
const data = await prisma.forum_Posting.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
@@ -73,7 +107,6 @@ export async function GET(request: Request) {
|
||||
data: data,
|
||||
nCount: _.ceil(nCount / takeData)
|
||||
}
|
||||
|
||||
}
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
@@ -91,5 +124,7 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
} finally {
|
||||
await prisma.$disconnect()
|
||||
}
|
||||
}
|
||||
@@ -3,42 +3,46 @@ import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
if (request.method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
},
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.voting.count({
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
{ status: 405 }
|
||||
)
|
||||
}
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.voting.count({
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
}
|
||||
})
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'Success get data voting dashboard',
|
||||
data: fixData
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error('Error get data voting dashboard >>', error);
|
||||
NextResponse.json({
|
||||
success: false,
|
||||
message: 'Error get data voting dashboard',
|
||||
reason: (error as Error).message
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data voting dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data voting dashboard >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get data voting dashboard",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,39 @@
|
||||
import { decrypt } from "@/app/(auth)/_lib/decrypt";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { 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");
|
||||
|
||||
// const delToken = await prisma.userSession.delete({
|
||||
// where: {
|
||||
// userId: id as string,
|
||||
// },
|
||||
// });
|
||||
export async function GET() {
|
||||
const sessionKey = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!; // Gunakan environment variable yang tidak diekspos ke client-side
|
||||
if (!sessionKey) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Session key tidak ditemukan" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Logout Berhasil" },
|
||||
{ status: 200 }
|
||||
);
|
||||
const cookieStore = cookies();
|
||||
const sessionCookie = cookieStore.get(sessionKey);
|
||||
|
||||
if (!sessionCookie) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Session tidak ditemukan" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
cookieStore.delete(sessionKey);
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Logout berhasil" },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Gagal menghapus cookie:", error);
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal melakukan logout" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ export async function POST(req: Request) {
|
||||
|
||||
try {
|
||||
const { data } = await req.json();
|
||||
console.log("data api register", data);
|
||||
|
||||
const cekUsername = await prisma.user.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -38,7 +38,14 @@ export async function POST(req: Request) {
|
||||
user: dataUser as any,
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
if (!token) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal membuat session" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
// Buat response dengan token dalam cookie
|
||||
const response = NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil Login",
|
||||
@@ -47,6 +54,16 @@ export async function POST(req: Request) {
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
// Set cookie dengan token yang sudah dipastikan tidak null
|
||||
response.cookies.set(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, token, {
|
||||
path: "/",
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
maxAge: 30 * 24 * 60 * 60, // 30 hari dalam detik (1 bulan)
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
backendLogger.log("API Error or Server Error", error);
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -21,13 +21,11 @@ export async function GET(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil mendapatkan data", data: res },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error Get Master Bank >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -37,5 +35,7 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
41
src/app/api/master/bidang-bisnis/route.ts
Normal file
41
src/app/api/master/bidang-bisnis/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (request.method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.masterBidangBisnis.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error Get Master Bidang Bisnis >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Get Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
53
src/app/api/portofolio/[id]/route.ts
Normal file
53
src/app/api/portofolio/[id]/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { POST };
|
||||
|
||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
if (request.method !== "POST") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
},
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
|
||||
// const createPortofolio = await prisma.portofolio.create({
|
||||
// data: {
|
||||
// profileId: id,
|
||||
// id_Portofolio: "Porto" + Date.now().toString(),
|
||||
// namaBisnis: data.namaBisnis,
|
||||
// deskripsi: data.deskripsi,
|
||||
// tlpn: data.tlpn,
|
||||
// alamatKantor: data.alamatKantor,
|
||||
// masterBidangBisnisId: data.masterBidangBisnisId,
|
||||
// logoId: data.fileId,
|
||||
// },
|
||||
// });
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
id,
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Post Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@ import { AdminForum_TablePublish } from "@/app_modules/admin/forum";
|
||||
import { adminForum_getListPosting } from "@/app_modules/admin/forum/fun/get/get_list_publish";
|
||||
|
||||
export default async function Page() {
|
||||
const listPublish = await adminForum_getListPosting({page: 1});
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminForum_TablePublish listPublish={listPublish as any} />
|
||||
<AdminForum_TablePublish />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import adminForum_funGetAllReportKomentar from "@/app_modules/admin/forum/fun/get/get_all_report_komentar";
|
||||
import AdminForum_TableReportKomentar from "@/app_modules/admin/forum/sub_menu/table_report_komentar";
|
||||
|
||||
export default async function Page() {
|
||||
const listData = await adminForum_funGetAllReportKomentar({ page: 1 });
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminForum_TableReportKomentar listData={listData} />
|
||||
<AdminForum_TableReportKomentar />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { funGlobal_getUserById } from "@/app_modules/_global/fun/get/fun_get_user_by_id";
|
||||
import { CheckCookies_UiView } from "@/app_modules/check_cookies";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
// const userLoginId = await funGetUserIdByToken();
|
||||
// const dataUser = await funGlobal_getUserById({ userId: userLoginId });
|
||||
|
||||
// if (dataUser?.masterUserRoleId === "1") {
|
||||
// return redirect(RouterHome.main_home);
|
||||
// }
|
||||
|
||||
// if (dataUser?.masterUserRoleId !== "1") {
|
||||
// return redirect(RouterAdminDashboard.splash_admin);
|
||||
// }
|
||||
|
||||
// return <CheckCookies_UiView />;
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
import { CreatePortofolio } from "@/app_modules/katalog/portofolio";
|
||||
import { Portofolio_getMasterBidangBisnis } from "@/app_modules/katalog/portofolio/fun/master/get_bidang_bisnis";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const profileId = params.id;
|
||||
const bidangBisnis = await Portofolio_getMasterBidangBisnis();
|
||||
export default async function Page() {
|
||||
// const profileId = params.id;
|
||||
// const bidangBisnis = await Portofolio_getMasterBidangBisnis();
|
||||
|
||||
return (
|
||||
<>
|
||||
<CreatePortofolio
|
||||
bidangBisnis={bidangBisnis as any}
|
||||
profileId={profileId}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { apiGetMasterBank };
|
||||
export { apiGetMasterBank, apiGetMasterBidangBisnis };
|
||||
|
||||
const apiGetMasterBank = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
@@ -12,8 +12,22 @@ const apiGetMasterBank = async () => {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetMasterBidangBisnis = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const respone = await fetch(`/api/master/bidang-bisnis`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
export {
|
||||
apiGetAdminForumPublishCountDasboard,
|
||||
apiGetAdminCountForumReportPosting ,
|
||||
apiGetAdminCountForumReportKomentar,
|
||||
apiGetAdminForumReportPosting,
|
||||
apiGetAdminForumReportKomentar
|
||||
apiGetAdminForumReportKomentar,
|
||||
apiGetAdminForumPublish
|
||||
}
|
||||
|
||||
const apiGetAdminForumPublishCountDasboard = async () => {
|
||||
@@ -21,7 +24,7 @@ const apiGetAdminForumPublishCountDasboard = async () => {
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
const apiGetAdminForumReportPosting = async () => {
|
||||
const apiGetAdminCountForumReportPosting = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
@@ -35,10 +38,11 @@ const apiGetAdminForumReportPosting = async () => {
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
const apiGetAdminForumReportKomentar = async () => {
|
||||
const apiGetAdminCountForumReportKomentar = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
@@ -52,5 +56,56 @@ const apiGetAdminForumReportKomentar = async () => {
|
||||
},
|
||||
})
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const apiGetAdminForumReportPosting = async () => {
|
||||
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/forum/posting`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const apiGetAdminForumReportKomentar = async({ page } : { page?: string}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isPage = page ? `?page=${page}` : "";
|
||||
const response = await fetch(`/api/admin/forum/komentar${isPage}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const apiGetAdminForumPublish = async ({ page }: { page?: string }) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isPage = page ? `?page=${page}` : "";
|
||||
const response = await fetch(`/api/admin/forum/publish${isPage}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import global_limit from "@/app/lib/limit";
|
||||
import { apiGetAdminForumPublishCountDasboard } from "../lib/api_fetch_admin_forum";
|
||||
import { apiGetAdminCountForumReportKomentar, apiGetAdminCountForumReportPosting, apiGetAdminForumPublishCountDasboard } from "../lib/api_fetch_admin_forum";
|
||||
import { useState } from "react";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
@@ -63,7 +63,7 @@ function ForumMain() {
|
||||
|
||||
async function onLoadCountReportPosting() {
|
||||
try {
|
||||
const response = await apiGetAdminForumPublishCountDasboard()
|
||||
const response = await apiGetAdminCountForumReportPosting()
|
||||
if (response) {
|
||||
setCountLaporanPosting(response.data)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ function ForumMain() {
|
||||
|
||||
async function onLoadCountReportKomentar() {
|
||||
try {
|
||||
const response = await apiGetAdminForumPublishCountDasboard()
|
||||
const response = await apiGetAdminCountForumReportKomentar()
|
||||
if (response) {
|
||||
setCountLaporanKomentar(response.data)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
"use client";
|
||||
|
||||
|
||||
import { RouterAdminForum } from "@/app/lib/router_admin/router_admin_forum";
|
||||
import { RouterForum } from "@/app/lib/router_hipmi/router_forum";
|
||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import { MODEL_FORUM_POSTING } from "@/app_modules/forum/model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Group,
|
||||
Modal,
|
||||
Pagination,
|
||||
Paper,
|
||||
ScrollArea,
|
||||
@@ -18,154 +19,170 @@ import {
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
TextInput,
|
||||
Title,
|
||||
TextInput
|
||||
} from "@mantine/core";
|
||||
import { IconMessageCircle, IconSearch } from "@tabler/icons-react";
|
||||
import { IconFlag3 } from "@tabler/icons-react";
|
||||
import { IconEyeCheck, IconTrash } from "@tabler/icons-react";
|
||||
import _, { isEmpty } from "lodash";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconFlag3, IconMessageCircle, IconSearch } from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { adminForum_funDeletePostingById } from "../fun/delete/fun_delete_posting_by_id";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { adminForum_getListPosting } from "../fun/get/get_list_publish";
|
||||
import adminJob_getListPublish from "@/app_modules/admin/job/fun/get/get_list_publish";
|
||||
import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete";
|
||||
import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data";
|
||||
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete";
|
||||
import { apiGetAdminForumPublish } from "../lib/api_fetch_admin_forum";
|
||||
|
||||
export default function AdminForum_TablePosting({
|
||||
listPublish,
|
||||
}: {
|
||||
listPublish: any;
|
||||
}) {
|
||||
|
||||
export default function AdminForum_TablePosting() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
|
||||
<TablePublish listPublish={listPublish} />
|
||||
<TablePublish />
|
||||
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TablePublish({ listPublish }: { listPublish: any }) {
|
||||
|
||||
function TablePublish() {
|
||||
const router = useRouter();
|
||||
const [data, setData] = useState<MODEL_FORUM_POSTING[]>(listPublish.data);
|
||||
const [nPage, setNPage] = useState(listPublish.nPage);
|
||||
const [data, setData] = useState<MODEL_FORUM_POSTING[] | null>(null);
|
||||
const [nPage, setNPage] = useState<number>(1);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [isSearch, setSearch] = useState("");
|
||||
|
||||
async function onSearch(s: string) {
|
||||
setSearch(s);
|
||||
setActivePage(1);
|
||||
const loadData = await adminForum_getListPosting({
|
||||
page: 1,
|
||||
search: s,
|
||||
});
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
}
|
||||
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
const loadData = await adminForum_getListPosting({
|
||||
search: isSearch,
|
||||
page: p,
|
||||
});
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
useShallowEffect(() => {
|
||||
const loadInitialData = async () => {
|
||||
try {
|
||||
const response = await apiGetAdminForumPublish({
|
||||
page: `${activePage}`
|
||||
})
|
||||
|
||||
|
||||
if (response?.success && response?.data.data) {
|
||||
setData(response.data.data);
|
||||
setNPage(response.data.nCount || 1);
|
||||
} else {
|
||||
console.error("Invalid data format recieved:", response);
|
||||
setData([]);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Invlid data format recieved:", error);
|
||||
setData([]);
|
||||
}
|
||||
}
|
||||
loadInitialData();
|
||||
}, [activePage, isSearch]);
|
||||
|
||||
const onSearch = (searchTerm: string) => {
|
||||
setSearch(searchTerm);
|
||||
setActivePage(1);
|
||||
}
|
||||
|
||||
async function onLoadData() {
|
||||
const loadData = await adminForum_getListPosting({
|
||||
page: 1,
|
||||
});
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
const loadData = await apiGetAdminForumPublish({
|
||||
page: `${activePage}`
|
||||
});
|
||||
setData(loadData.data.data);
|
||||
setNPage(loadData.data.nPage);
|
||||
}
|
||||
|
||||
const TableRows = data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.Author?.username}</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={100}>
|
||||
<Badge
|
||||
color={
|
||||
(e?.ForumMaster_StatusPosting?.id as any) === 1 ? "green" : "red"
|
||||
}
|
||||
>
|
||||
{e?.ForumMaster_StatusPosting?.status}
|
||||
</Badge>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Box w={400}>
|
||||
<Spoiler
|
||||
// w={400}
|
||||
maxHeight={60}
|
||||
hideLabel="sembunyikan"
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: e?.diskusi,
|
||||
const onPageClick = (page: number) => {
|
||||
setActivePage(page);
|
||||
}
|
||||
|
||||
|
||||
const renderTableBody = () => {
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return (
|
||||
<tr>
|
||||
<td colSpan={12}>
|
||||
<Center>
|
||||
<Text color="gray">Tidak ada data</Text>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
return data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.Author?.username}</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={100}>
|
||||
<Badge
|
||||
color={
|
||||
(e?.ForumMaster_StatusPosting?.id as any) === 1 ? "green" : "red"
|
||||
}
|
||||
>
|
||||
{e?.ForumMaster_StatusPosting?.status}
|
||||
</Badge>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Box w={400}>
|
||||
<Spoiler
|
||||
// w={400}
|
||||
c={AdminColor.white}
|
||||
maxHeight={60}
|
||||
hideLabel="sembunyikan"
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: e?.diskusi,
|
||||
}}
|
||||
/>
|
||||
</Spoiler>
|
||||
</Box>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text c={AdminColor.white}>
|
||||
{new Intl.DateTimeFormat("id-ID", { dateStyle: "medium" }).format(
|
||||
new Date(e?.createdAt)
|
||||
)}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text c={AdminColor.white} fw={"bold"} fz={"lg"}>
|
||||
{e?.Forum_Komentar.length}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text
|
||||
c={e?.Forum_ReportPosting?.length >= 3 ? "red" : AdminColor.white}
|
||||
fw={"bold"}
|
||||
fz={"lg"}
|
||||
>
|
||||
{e?.Forum_ReportPosting.length}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Stack align="center" spacing={"xs"}>
|
||||
<ButtonAction postingId={e?.id} />
|
||||
<ComponentAdminForum_ButtonDeletePosting
|
||||
postingId={e?.id}
|
||||
onSuccesDelete={(val) => {
|
||||
if (val) {
|
||||
onLoadData();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Spoiler>
|
||||
</Box>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text c={AdminColor.white}>
|
||||
{new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
|
||||
e.createdAt
|
||||
)}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text c={AdminColor.white} fw={"bold"} fz={"lg"}>
|
||||
{e?.Forum_Komentar.length}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text
|
||||
c={e?.Forum_ReportPosting?.length >= 3 ? "red" : "black"}
|
||||
fw={"bold"}
|
||||
fz={"lg"}
|
||||
>
|
||||
{e?.Forum_ReportPosting.length}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Stack align="center" spacing={"xs"}>
|
||||
<ButtonAction postingId={e?.id} />
|
||||
<ComponentAdminForum_ButtonDeletePosting
|
||||
postingId={e?.id}
|
||||
onSuccesDelete={(val) => {
|
||||
if (val) {
|
||||
onLoadData();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Stack>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
</Stack>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -175,36 +192,37 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{/* <Group
|
||||
position="apart"
|
||||
bg={"green.4"}
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title order={4} c={"white"}>
|
||||
Posting
|
||||
</Title>
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Group> */}
|
||||
|
||||
{isEmpty(data) ? (
|
||||
<ComponentAdminGlobal_IsEmptyData />
|
||||
position="apart"
|
||||
bg={"green.4"}
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title order={4} c={"white"}>
|
||||
Posting
|
||||
</Title>
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Group> */}
|
||||
|
||||
|
||||
{!data ? (
|
||||
<CustomSkeleton height={"80vh"} width={"100%"} />
|
||||
) : (
|
||||
<Paper p={"md"} bg={AdminColor.softBlue} h={"80vh"}>
|
||||
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
|
||||
@@ -214,7 +232,8 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
||||
p={"md"}
|
||||
w={"100%"}
|
||||
h={"100%"}
|
||||
|
||||
|
||||
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -241,7 +260,7 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>{TableRows}</tbody>
|
||||
<tbody>{renderTableBody()}</tbody>
|
||||
</Table>
|
||||
</ScrollArea>
|
||||
<Center mt={"xl"}>
|
||||
@@ -260,11 +279,13 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function ButtonAction({ postingId }: { postingId: string }) {
|
||||
const router = useRouter();
|
||||
const [loadingKomentar, setLoadingKomentar] = useState(false);
|
||||
const [loadingReport, setLoadingReport] = useState(false);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
@@ -299,11 +320,13 @@ function ButtonAction({ postingId }: { postingId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// function ButtonDeletePosting({ postingId }: { postingId: string }) {
|
||||
// const [opened, { open, close }] = useDisclosure(false);
|
||||
// const [loadingDel, setLoadingDel] = useState(false);
|
||||
// const [loadingDel2, setLoadingDel2] = useState(false);
|
||||
|
||||
|
||||
// async function onDelete() {
|
||||
// await adminForum_funDeletePostingById(postingId).then((res) => {
|
||||
// if (res.status === 200) {
|
||||
@@ -371,3 +394,6 @@ function ButtonAction({ postingId }: { postingId: string }) {
|
||||
// </>
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
"use client";
|
||||
|
||||
|
||||
import { RouterAdminForum } from "@/app/lib/router_admin/router_admin_forum";
|
||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import {
|
||||
MODEL_FORUM_REPORT_KOMENTAR
|
||||
} from "@/app_modules/forum/model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Group,
|
||||
Pagination,
|
||||
Paper,
|
||||
ScrollArea,
|
||||
@@ -17,143 +20,159 @@ import {
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
TextInput,
|
||||
Title
|
||||
TextInput
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconFlag3, IconSearch } from "@tabler/icons-react";
|
||||
import { isEmpty } from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data";
|
||||
import adminForum_funGetAllReportKomentar from "../fun/get/get_all_report_komentar";
|
||||
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { apiGetAdminForumReportKomentar } from "../lib/api_fetch_admin_forum";
|
||||
|
||||
export default function AdminForum_TableReportKomentar({
|
||||
listData,
|
||||
}: {
|
||||
listData: any;
|
||||
}) {
|
||||
|
||||
export default function AdminForum_TableReportKomentar() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
|
||||
<TableView listData={listData} />
|
||||
<TableView />
|
||||
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TableView({ listData }: { listData: any }) {
|
||||
|
||||
function TableView() {
|
||||
const router = useRouter();
|
||||
const [data, setData] = useState<MODEL_FORUM_REPORT_KOMENTAR[]>(
|
||||
listData.data
|
||||
);
|
||||
const [nPage, setNPage] = useState(listData.nPage);
|
||||
const [data, setData] = useState<MODEL_FORUM_REPORT_KOMENTAR[] | null>(null);
|
||||
const [nPage, setNPage] = useState<number>(1);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [isSearch, setSearch] = useState("");
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadData({
|
||||
onLoad(val) {
|
||||
setData(val.data as any);
|
||||
setNPage(val.nPage);
|
||||
setActivePage(1);
|
||||
},
|
||||
});
|
||||
}, [setData, setNPage]);
|
||||
const loadInitialData = async () => {
|
||||
try {
|
||||
const response = await apiGetAdminForumReportKomentar({
|
||||
page: `${activePage}`
|
||||
})
|
||||
if (response?.success && response?.data.data) {
|
||||
setData(response.data.data);
|
||||
setNPage(response.data.nCount || 1)
|
||||
} else {
|
||||
console.error("Invalid data format recieved", response)
|
||||
setData([])
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Invalid data format recieved", error)
|
||||
setData([])
|
||||
}
|
||||
}
|
||||
loadInitialData();
|
||||
}, [activePage, isSearch]);
|
||||
|
||||
async function onLoadData({ onLoad }: { onLoad: (val: any) => void }) {
|
||||
const loadData = await adminForum_funGetAllReportKomentar({ page: 1 });
|
||||
onLoad(loadData);
|
||||
|
||||
// setData(loadData.data as any);
|
||||
// setNPage(loadData.nPage);
|
||||
}
|
||||
// async function onLoadData({ onLoad }: { onLoad: (val: any) => void }) {
|
||||
// const loadData = await apiGetAdminForumReportKomentar(
|
||||
// { page: `${activePage}` });
|
||||
// onLoad(loadData);
|
||||
|
||||
async function onSearch(s: string) {
|
||||
setSearch(s);
|
||||
|
||||
// setData(loadData.data.data);
|
||||
// setNPage(loadData.data.nPage);
|
||||
// }
|
||||
|
||||
|
||||
const onSearch = (searchTerm: string) => {
|
||||
setSearch(searchTerm);
|
||||
setActivePage(1);
|
||||
const loadData = await adminForum_funGetAllReportKomentar({
|
||||
page: 1,
|
||||
search: s,
|
||||
});
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
}
|
||||
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
const loadData = await adminForum_funGetAllReportKomentar({
|
||||
search: isSearch,
|
||||
page: p,
|
||||
});
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
|
||||
const onPageClick = (page: number) => {
|
||||
setActivePage(page);
|
||||
}
|
||||
|
||||
const TableRows = data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.User.username}</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
{e?.forumMaster_KategoriReportId === null ? (
|
||||
<Text c={AdminColor.white}>Lainnya</Text>
|
||||
) : (
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.ForumMaster_KategoriReport.title}</Text>
|
||||
)}
|
||||
</Center>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<Box w={400}>
|
||||
<Spoiler
|
||||
// w={400}
|
||||
maxHeight={60}
|
||||
hideLabel="sembunyikan"
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: e?.Forum_Komentar.komentar,
|
||||
}}
|
||||
/>
|
||||
</Spoiler>
|
||||
</Box>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text>
|
||||
{new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
|
||||
e.createdAt
|
||||
const renderTableBody = () => {
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return (
|
||||
<tr>
|
||||
<td colSpan={12}>
|
||||
<Center>
|
||||
<Text color="gray">Tidak ada data</Text>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
return data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.User?.Profile?.name}</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
{e?.forumMaster_KategoriReportId === null ? (
|
||||
<Text c={AdminColor.white}>Lainnya</Text>
|
||||
) : (
|
||||
<Text c={AdminColor.white} lineClamp={1}>{e?.ForumMaster_KategoriReport?.title}</Text>
|
||||
)}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
</Center>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<Box w={400}>
|
||||
<Spoiler
|
||||
c={AdminColor.white}
|
||||
// w={400}
|
||||
maxHeight={60}
|
||||
hideLabel="sembunyikan"
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: e?.deskripsi,
|
||||
}}
|
||||
/>
|
||||
</Spoiler>
|
||||
</Box>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<Center w={150} >
|
||||
<Text c={AdminColor.white}>
|
||||
{new Intl.DateTimeFormat("id-ID", { dateStyle: "medium" }).format(
|
||||
new Date(e?.createdAt)
|
||||
)}
|
||||
</Text>
|
||||
</Center>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<Stack align="center" spacing={"xs"}>
|
||||
{/* <ButtonAction postingId={e?.id} /> */}
|
||||
<ButtonLihatReportLainnya komentarId={e?.forum_KomentarId} />
|
||||
{/* <ComponentAdminForum_ButtonDeletePosting
|
||||
postingId={e?.Forum_Komentar.forum_PostingId}
|
||||
onSuccesDelete={(val) => {
|
||||
if (val) {
|
||||
onLoadData();
|
||||
}
|
||||
}}
|
||||
/> */}
|
||||
</Stack>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
}
|
||||
|
||||
<td>
|
||||
<Stack align="center" spacing={"xs"}>
|
||||
{/* <ButtonAction postingId={e?.id} /> */}
|
||||
<ButtonLihatReportLainnya komentarId={e?.forum_KomentarId} />
|
||||
{/* <ComponentAdminForum_ButtonDeletePosting
|
||||
postingId={e?.Forum_Komentar.forum_PostingId}
|
||||
onSuccesDelete={(val) => {
|
||||
if (val) {
|
||||
onLoadData();
|
||||
}
|
||||
}}
|
||||
/> */}
|
||||
</Stack>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -163,36 +182,37 @@ function TableView({ listData }: { listData: any }) {
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{/* <Group
|
||||
position="apart"
|
||||
bg={"yellow.4"}
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title order={4} c={"white"}>
|
||||
Report Komentar
|
||||
</Title>
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Group> */}
|
||||
position="apart"
|
||||
bg={"yellow.4"}
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title order={4} c={"white"}>
|
||||
Report Komentar
|
||||
</Title>
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Cari postingan"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Group> */}
|
||||
|
||||
{isEmpty(data) ? (
|
||||
<ComponentAdminGlobal_IsEmptyData />
|
||||
|
||||
{!data ? (
|
||||
<CustomSkeleton height={"80vh"} width={"100%"} />
|
||||
) : (
|
||||
<Paper p={"md"} bg={AdminColor.softBlue} h={"80vh"}>
|
||||
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
|
||||
@@ -202,33 +222,39 @@ function TableView({ listData }: { listData: any }) {
|
||||
p={"md"}
|
||||
w={"100%"}
|
||||
h={"100%"}
|
||||
|
||||
|
||||
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<Center c={AdminColor.white}>Pelapor</Center>
|
||||
</th>
|
||||
|
||||
|
||||
|
||||
<th>
|
||||
<Center c={AdminColor.white}>Jenis Laporan</Center>
|
||||
</th>
|
||||
|
||||
|
||||
<th>
|
||||
<Text c={AdminColor.white}>Komentar</Text>
|
||||
</th>
|
||||
|
||||
|
||||
<th>
|
||||
<Center c={AdminColor.white}>Tanggal Report</Center>
|
||||
</th>
|
||||
|
||||
|
||||
<th>
|
||||
<Center c={AdminColor.white}>Aksi</Center>
|
||||
</th>
|
||||
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>{TableRows}</tbody>
|
||||
<tbody>{renderTableBody()}</tbody>
|
||||
</Table>
|
||||
</ScrollArea>
|
||||
<Center mt={"xl"}>
|
||||
@@ -247,6 +273,7 @@ function TableView({ listData }: { listData: any }) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function ButtonLihatReportLainnya({ komentarId }: { komentarId: string }) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -269,3 +296,6 @@ function ButtonLihatReportLainnya({ komentarId }: { komentarId: string }) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -86,12 +86,12 @@ function TableView({ listData }: { listData: any }) {
|
||||
const TableRows = data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Center c={AdminColor.white} w={200}>
|
||||
<Text lineClamp={1}>{e?.User.username}</Text>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center w={200}>
|
||||
<Center c={AdminColor.white} w={200}>
|
||||
{e?.forumMaster_KategoriReportId === null ? (
|
||||
<Text>Lainnya</Text>
|
||||
) : (
|
||||
@@ -139,7 +139,7 @@ function TableView({ listData }: { listData: any }) {
|
||||
|
||||
<td>
|
||||
<Center w={150}>
|
||||
<Text>
|
||||
<Text c={AdminColor.white}>
|
||||
{new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
|
||||
e.createdAt
|
||||
)}
|
||||
|
||||
@@ -3,6 +3,7 @@ import Login from "./login/view";
|
||||
import Validasi from "./validasi/view";
|
||||
import Register from "./register/view";
|
||||
import Component_ButtonLogout from "./logout/view";
|
||||
import InvalidUser from "./invalid_user/view";
|
||||
|
||||
export {
|
||||
SplashScreen,
|
||||
@@ -10,4 +11,5 @@ export {
|
||||
Validasi,
|
||||
Register,
|
||||
Component_ButtonLogout as Logout,
|
||||
InvalidUser,
|
||||
};
|
||||
|
||||
46
src/app_modules/auth/invalid_user/view.tsx
Normal file
46
src/app_modules/auth/invalid_user/view.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
|
||||
import { Button, Stack, Text, Title } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function InvalidUser() {
|
||||
const router = useRouter();
|
||||
const deleteCookie = async () => {
|
||||
const sessionKey = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!;
|
||||
if (!sessionKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await fetch("/api/auth/logout", {
|
||||
method: "GET",
|
||||
});
|
||||
router.push("/login");
|
||||
} catch (error) {
|
||||
console.error("Gagal menghapus cookie:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutDefault>
|
||||
<Stack align="center" justify="center" spacing="md" h={"100vh"}>
|
||||
<Title order={2} c={MainColor.white}>
|
||||
{" "}
|
||||
Invalid User
|
||||
</Title>
|
||||
<Button
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
deleteCookie();
|
||||
}}
|
||||
>
|
||||
Logout
|
||||
</Button>
|
||||
</Stack>
|
||||
</UIGlobal_LayoutDefault>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { CheckCookies_UiLayout } from "./layout_cek_cookies";
|
||||
import { CheckCookies_UiView } from "./ui_check_cookies";
|
||||
|
||||
export { CheckCookies_UiView };
|
||||
export { CheckCookies_UiLayout };
|
||||
@@ -1,48 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { redirect, useRouter } from "next/navigation";
|
||||
import { MODEL_USER } from "../home/model/interface";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
|
||||
export function CheckCookies_UiLayout({
|
||||
children,
|
||||
dataUser,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
dataUser: MODEL_USER;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
// if (dataUser.active == false){
|
||||
// router.push(RouterHome.home_user_non_active, { scroll: false });
|
||||
// return children
|
||||
// }
|
||||
|
||||
|
||||
// useShallowEffect(() => {
|
||||
// onCheckCookies();
|
||||
// }, []);
|
||||
|
||||
// async function onCheckCookies() {
|
||||
// const cek = await fetch("/api/check-cookies");
|
||||
|
||||
// const result = await cek.json();
|
||||
|
||||
// if (result.success === false) {
|
||||
// router.push(RouterAuth.login, { scroll: false });
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (dataUser.masterUserRoleId === "1") {
|
||||
// router.push(RouterHome.main_home, { scroll: false });
|
||||
// }
|
||||
|
||||
// if (dataUser.masterUserRoleId !== "1") {
|
||||
// router.push(RouterAdminDashboard.splash_admin, { scroll: false });
|
||||
// }
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { Button, Center } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { UIGlobal_LayoutDefault } from "../_global/ui";
|
||||
|
||||
export function CheckCookies_UiView() {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutDefault>
|
||||
<Center h={"80vh"}>
|
||||
<Button radius={"xl"} onClick={() => router.push(RouterAuth.login)}>
|
||||
Kembali ke Halaman Login
|
||||
</Button>
|
||||
</Center>
|
||||
</UIGlobal_LayoutDefault>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -61,6 +61,7 @@ export interface MODEL_FORUM_REPORT_POSTING {
|
||||
}
|
||||
|
||||
export interface MODEL_FORUM_REPORT_KOMENTAR {
|
||||
komentar: string | TrustedHTML;
|
||||
id: string;
|
||||
isActive: boolean;
|
||||
createdAt: Date;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export {
|
||||
apiCreatePortofolio,
|
||||
};
|
||||
|
||||
const apiCreatePortofolio = async ({ data }: { data: any }) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const res = await fetch(`/api/portofolio`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ data }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await res.json().catch(() => null);
|
||||
};
|
||||
@@ -15,6 +15,21 @@ import { clientLogger } from "@/util/clientLogger";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import funCreatePortofolio from "../../fun/fun_create_portofolio";
|
||||
import { apiCreatePortofolio } from "../api_fetch_portofolio";
|
||||
|
||||
interface ICreatePortofolio {
|
||||
namaBisnis: string;
|
||||
masterBidangBisnisId: string;
|
||||
alamatKantor: string;
|
||||
tlpn: string;
|
||||
deskripsi: string;
|
||||
fileId: string;
|
||||
facebook: string;
|
||||
twitter: string;
|
||||
instagram: string;
|
||||
tiktok: string;
|
||||
youtube: string;
|
||||
}
|
||||
|
||||
export function Portofolio_ComponentButtonSelanjutnya({
|
||||
profileId,
|
||||
@@ -31,15 +46,7 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit() {
|
||||
const porto = {
|
||||
namaBisnis: dataPortofolio.namaBisnis,
|
||||
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
|
||||
alamatKantor: dataPortofolio.alamatKantor,
|
||||
tlpn: dataPortofolio.tlpn,
|
||||
deskripsi: dataPortofolio.deskripsi,
|
||||
};
|
||||
|
||||
if (_.values(porto).includes("")) {
|
||||
if (_.values(dataPortofolio).includes("")) {
|
||||
ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
return;
|
||||
}
|
||||
@@ -65,6 +72,29 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
|
||||
const fileId = uploadFile.data.id;
|
||||
|
||||
const newData: ICreatePortofolio = {
|
||||
namaBisnis: dataPortofolio.namaBisnis,
|
||||
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
|
||||
alamatKantor: dataPortofolio.alamatKantor,
|
||||
tlpn: dataPortofolio.tlpn,
|
||||
deskripsi: dataPortofolio.deskripsi,
|
||||
facebook: dataMedsos.facebook,
|
||||
twitter: dataMedsos.twitter,
|
||||
instagram: dataMedsos.instagram,
|
||||
tiktok: dataMedsos.tiktok,
|
||||
youtube: dataMedsos.youtube,
|
||||
fileId: fileId,
|
||||
};
|
||||
|
||||
// const responeCreated = await apiCreatePortofolio({
|
||||
// data: newData,
|
||||
// });
|
||||
|
||||
// if (responeCreated.success) {
|
||||
// ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan");
|
||||
// router.replace(RouterMap.create + responeCreated.id, { scroll: false });
|
||||
// }
|
||||
|
||||
const res = await funCreatePortofolio({
|
||||
profileId: profileId,
|
||||
data: dataPortofolio as any,
|
||||
|
||||
@@ -35,14 +35,16 @@ import { useState } from "react";
|
||||
import { PhoneInput } from "react-international-phone";
|
||||
import "react-international-phone/style.css";
|
||||
import { Portofolio_ComponentButtonSelanjutnya } from "../component";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetMasterBidangBisnis } from "@/app_modules/_global/lib/api_master";
|
||||
import { MODEL_PORTOFOLIO_BIDANG_BISNIS } from "../model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function CreatePortofolio() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const profileId = params.id;
|
||||
|
||||
export default function CreatePortofolio({
|
||||
bidangBisnis,
|
||||
profileId,
|
||||
}: {
|
||||
bidangBisnis: BIDANG_BISNIS_OLD;
|
||||
profileId: any;
|
||||
}) {
|
||||
const [dataPortofolio, setDataPortofolio] = useState({
|
||||
namaBisnis: "",
|
||||
masterBidangBisnisId: "",
|
||||
@@ -62,6 +64,25 @@ export default function CreatePortofolio({
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [img, setImg] = useState<any | null>(null);
|
||||
const [imageId, setImageId] = useState("");
|
||||
const [listBidangBisnis, setListBidangBisnis] = useState<
|
||||
MODEL_PORTOFOLIO_BIDANG_BISNIS[] | null
|
||||
>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadMaster();
|
||||
}, []);
|
||||
|
||||
async function onLoadMaster() {
|
||||
try {
|
||||
const respone = await apiGetMasterBidangBisnis();
|
||||
|
||||
if (respone.success) {
|
||||
setListBidangBisnis(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error on load master bidang bisnis", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -91,6 +112,7 @@ export default function CreatePortofolio({
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Select
|
||||
styles={{
|
||||
label: {
|
||||
@@ -108,8 +130,10 @@ export default function CreatePortofolio({
|
||||
}}
|
||||
withAsterisk
|
||||
label="Bidang Bisnis"
|
||||
placeholder="Pilih salah satu bidang bisnis"
|
||||
data={_.map(bidangBisnis as any).map((e: any) => ({
|
||||
placeholder={
|
||||
listBidangBisnis ? "Pilih bidang bisnis" : "Loading..."
|
||||
}
|
||||
data={_.map(listBidangBisnis as any).map((e: any) => ({
|
||||
value: e.id,
|
||||
label: e.name,
|
||||
}))}
|
||||
@@ -420,7 +444,7 @@ export default function CreatePortofolio({
|
||||
dataPortofolio={dataPortofolio as any}
|
||||
dataMedsos={dataMedsos}
|
||||
profileId={profileId}
|
||||
//
|
||||
//
|
||||
file={file as File}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { jwtVerify } from "jose";
|
||||
import { apies, pages } from "./lib/routes";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
type MiddlewareConfig = {
|
||||
apiPath: string;
|
||||
@@ -32,18 +31,9 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
"/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/*",
|
||||
// "/api/admin/voting/dashboard/*",
|
||||
// "/api/admin/job/*",
|
||||
// "/api/admin/forum/*",
|
||||
// "/api/admin/collaboration/*",
|
||||
// >> buat dibawah sini <<
|
||||
|
||||
// Akses awal
|
||||
"/api/get-cookie",
|
||||
@@ -55,6 +45,7 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
"/register",
|
||||
"/validasi",
|
||||
"/splash",
|
||||
"/invalid-user",
|
||||
"/job-vacancy",
|
||||
"/preview-image",
|
||||
"/auth/login",
|
||||
@@ -110,7 +101,7 @@ export const middleware = async (req: NextRequest) => {
|
||||
// Preserve token in cookie when redirecting
|
||||
if (token) {
|
||||
response.cookies.set(sessionKey, token, {
|
||||
httpOnly: true,
|
||||
// httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
@@ -145,6 +136,12 @@ export const middleware = async (req: NextRequest) => {
|
||||
|
||||
const userValidateJson = await userValidate.json();
|
||||
|
||||
if (userValidateJson.success == true && userValidateJson.data == null) {
|
||||
return setCorsHeaders(
|
||||
NextResponse.redirect(new URL("/invalid-user", req.url))
|
||||
);
|
||||
}
|
||||
|
||||
if (!userValidateJson.data.active) {
|
||||
return setCorsHeaders(
|
||||
NextResponse.redirect(new URL("/waiting-room", req.url))
|
||||
@@ -186,7 +183,7 @@ export const middleware = async (req: NextRequest) => {
|
||||
// Ensure token is preserved in cookie
|
||||
if (token) {
|
||||
response.cookies.set(sessionKey, token, {
|
||||
httpOnly: true,
|
||||
// httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
|
||||
Reference in New Issue
Block a user