Merge pull request #288 from bipproduction/join

Fix api user & admin
This commit is contained in:
Bagasbanuna02
2025-02-07 17:38:46 +08:00
committed by GitHub
39 changed files with 923 additions and 366 deletions

View File

@@ -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.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)
## [1.2.47](https://github.com/bipproduction/hipmi/compare/v1.2.46...v1.2.47) (2025-02-03)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.2.48",
"version": "1.2.49",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -0,0 +1,65 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: {
params: { name: string }
}) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
const { name } = params;
try {
let fixData;
const fixStatus = _.startCase(name);
if (fixStatus === "Publish") {
fixData = await prisma.projectCollaboration.count({
where: {
isActive: true,
},
});
} else if (fixStatus === "Reject") {
fixData = await prisma.projectCollaboration.count({
where: {
isReject: true,
},
});
} else if (fixStatus === "Room") {
fixData = await prisma.projectCollaboration_RoomChat.count({
where: {
isActive: true,
},
});
}
return NextResponse.json({
success: true,
message: `Success Get Data ${fixStatus}`,
data: fixData,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get count group chat", error);
return NextResponse.json({
success: false,
message: "Error get data count group chat ",
reason: (error as Error).message
},
{ status: 500 }
)
} finally {
await prisma.$disconnect
}
}

View File

@@ -27,90 +27,64 @@ export async function GET(request: Request,
try {
let fixData;
const fixStatus = _.startCase(status);
if (!page && !search) {
fixData = await prisma.donasi.findMany({
if (!page) {
const data = await prisma.donasi.findMany({
orderBy: {
updatedAt: "desc",
createdAt: "desc",
},
where: {
active: true,
DonasiMaster_Status: {
name: fixStatus
}
},
include: {
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true
}
}
}
name: fixStatus,
},
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
}
}
}
contains: search ? search : "",
mode: "insensitive",
},
DonasiMaster_Status: true,
},
select: {
id: true,
title: true,
target: true,
authorId: true,
terkumpul: true,
imageDonasi: true,
DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true
}
DonasiMaster_Durasi: true,
imageId: true,
},
})
} else if (page && !search) {
} else {
const data = await prisma.donasi.findMany({
take: takeData,
skip: skipData,
orderBy: [
{
publishTime: "desc"
}
],
where: {
active: true,
DonasiMaster_Status: {
name: fixStatus
}
orderBy: {
createdAt: "desc",
},
include: {
Author: true,
where: {
DonasiMaster_Status: {
name: fixStatus,
},
active: true,
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
title: true,
target: true,
authorId: true,
terkumpul: true,
imageDonasi: true,
DonasiMaster_Status: true,
DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true
}
DonasiMaster_Durasi: true,
imageId: true,
},
})
const nCount = await prisma.donasi.count({
@@ -122,7 +96,7 @@ export async function GET(request: Request,
}
})
console.log("data >", data)
fixData = {
data: data,
nCount: _.ceil(nCount / takeData)

View File

@@ -0,0 +1,95 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
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",
},
{ 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) {
const data = await prisma.forum_Posting.findMany({
take: takeData,
skip: skipData,
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,
},
});
const nCount = await prisma.forum_Posting.count({
where: {
isActive: true,
diskusi: {
contains: search ? search : "",
mode: "insensitive",
},
},
});
fixData = {
data: data,
nCount: _.ceil(nCount / takeData)
}
}
return NextResponse.json({
success: true,
message: "Success get data table forum",
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get data table forum", error)
return NextResponse.json({
success: false,
message: "Error get data table forum",
reason: (error as Error)
},
{ status: 500 }
)
}
}

View File

@@ -24,41 +24,13 @@ export async function GET(request: Request, { params }: {
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({
if (!page) {
const data = await prisma.investasi.findMany({
orderBy: {
updatedAt: "desc",
},
@@ -68,41 +40,40 @@ export async function GET(request: Request, { params }: {
name: fixStatus
},
title: {
contains: search,
mode: "insensitive",
},
contains: search ? search : "",
mode: "insensitive"
}
},
include: {
author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
MasterStatusInvestasi: true,
BeritaInvestasi: true,
DokumenInvestasi: true,
ProspektusInvestasi: true,
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
author: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "2",
},
},
MasterStatusInvestasi: true,
},
});
} else if (page && !search) {
} else {
const data = await prisma.investasi.findMany({
take: takeData,
skip: skipData,
orderBy: [
{
countDown: "desc",
},
],
orderBy: {
updatedAt: "desc",
},
where: {
active: true,
MasterStatusInvestasi: {
name: fixStatus
},
title: {
contains: search ? search : "",
mode: "insensitive"
}
},
include: {
MasterStatusInvestasi: true,
@@ -131,8 +102,6 @@ export async function GET(request: Request, { params }: {
},
});
console.log("data >", data)
fixData = {
data: data,
nPage: _.ceil(nCount / takeData),

View File

@@ -31,7 +31,7 @@ export async function GET(request: Request, { params }: {
const fixStatus = _.startCase(status);
if (!page) {
fixData = await prisma.job.findMany({
const data = await prisma.job.findMany({
orderBy: {
updatedAt: "desc"
},
@@ -53,7 +53,7 @@ export async function GET(request: Request, { params }: {
})
} else {
fixData = await prisma.job.findMany({
const data = await prisma.job.findMany({
take: takeData,
skip: skipData,
orderBy: {
@@ -87,7 +87,7 @@ export async function GET(request: Request, { params }: {
})
fixData = {
data: fixData,
data: data,
nPage: _.ceil(nCount / takeData)
}
}

View File

@@ -0,0 +1,111 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { GET, PUT };
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 {
let fixData;
const { id } = params;
fixData = await prisma.profile.findFirst({
where: {
id: id,
},
include: {
User: true,
},
});
return NextResponse.json(
{
success: true,
message: "Success get profile",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get profile", error);
return NextResponse.json(
{
success: false,
message: "Error get profile",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}
async function PUT(request: Request) {
if (request.method !== "PUT") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try {
const body = await request.json();
const { data } = body;
const cekEmail = await prisma.profile.findUnique({
where: {
email: data.email,
},
});
if (cekEmail && cekEmail.id != data.id)
return NextResponse.json(
{ success: false, message: "Email sudah digunakan" },
{ status: 400 }
);
const updateData = await prisma.profile.update({
where: {
id: data.id,
},
data: {
name: data.name,
email: data.email,
alamat: data.alamat,
jenisKelamin: data.jenisKelamin,
},
});
if (!updateData) {
return NextResponse.json(
{ success: false, message: "Gagal update" },
{
status: 400,
}
);
}
return NextResponse.json(
{ success: true, message: "Berhasil edit profile" },
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error edit profile", error);
return NextResponse.json(
{
success: false,
message: "Error edit profile",
reason: (error as Error).message,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -0,0 +1,82 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { POST };
async function POST(request: Request) {
if (request.method !== "POST") {
return NextResponse.json(
{
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
try {
const { data } = await request.json();
const userLoginId = await funGetUserIdByToken();
if (!userLoginId) {
backendLogger.error("User tidak terautentikasi");
return NextResponse.json(
{
success: false,
message: "User tidak terautentikasi",
},
{ status: 400 }
); // Validasi user login
}
const existingEmail = await prisma.profile.findUnique({
where: {
email: data.email,
},
});
if (existingEmail) {
return NextResponse.json(
{
success: false,
message: "Email telah digunakan",
},
{ status: 409 }
);
}
const createProfile = await prisma.profile.create({
data: {
userId: userLoginId,
name: data.name,
email: data.email,
alamat: data.alamat,
jenisKelamin: data.jenisKelamin,
imageId: data.imageId,
imageBackgroundId: data.imageBackgroundId,
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil membuat profile",
data: createProfile,
},
{ status: 201 }
);
} catch (error) {
backendLogger.error("Error create profile", error);
return NextResponse.json(
{
success: false,
message: "Gagal membuat profile",
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -30,7 +30,7 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page");
const takeData = 1;
const takeData = 15;
const skipData = Number(page) * takeData - takeData;
if (!page) {

View File

@@ -4,16 +4,13 @@ import adminColab_countIsPublish from "@/app_modules/admin/colab/fun/count/count
import adminColab_countIsReject from "@/app_modules/admin/colab/fun/count/count_reject";
export default async function Page() {
const countPublish = await adminColab_countIsPublish();
const countRoom = await adminColab_countGroupChat();
const countReject = await adminColab_countIsReject()
// const countPublish = await adminColab_countIsPublish();
// const countRoom = await adminColab_countGroupChat();
// const countReject = await adminColab_countIsReject()
return (
<>
<AdminColab_Dashboard
countPublish={countPublish}
countRoom={countRoom}
countReject={countReject}
/>
</>
);

View File

@@ -2,7 +2,6 @@ import { AdminDonasi_TableKategori } from "@/app_modules/admin/donasi";
import adminDonasi_getMasterKategori from "@/app_modules/admin/donasi/fun/master/get_list_kategori";
export default async function Page() {
// const listKategori = await adminDonasi_getMasterKategori();
return (
<>

View File

@@ -2,10 +2,7 @@ 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,
// });
// console.log(listPublish)
return<>
<AdminDonasi_TablePublish />
</>

View File

@@ -2,8 +2,7 @@ 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 });
// console.log(dataReject)
return (
<>
<AdminDonasi_TableReject />

View File

@@ -1,8 +1,6 @@
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});
// console.log(listReview);
return <AdminDonasi_TableReview />;
}

View File

@@ -1,9 +1,7 @@
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});
return (
<>
<Admin_TablePublishInvestasi />

View File

@@ -2,7 +2,7 @@ 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});
return (
<>
<Admin_TableRejectInvestasi />

View File

@@ -2,7 +2,6 @@ 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 });
return (
<>
<Admin_TableReviewInvestasi />

View File

@@ -3,11 +3,11 @@ import adminJob_getListReject from "@/app_modules/admin/job/fun/get/get_list_rej
import { AdminJob_getListTableByStatusId } from "@/app_modules/admin/job/fun/get/get_list_table_by_status_id";
export default async function Page() {
const listReject = await adminJob_getListReject({ page: 1 });
return (
<>
<AdminJob_TableReject dataReject={listReject} />
<AdminJob_TableReject />
</>
);
}

View File

@@ -1,13 +1,10 @@
import EditProfile from "@/app_modules/katalog/profile/edit/view";
import { Profile_getOneProfileAndUserById } from "@/app_modules/katalog/profile/fun/get/get_one_user_profile";
export default async function Page({ params }: { params: { id: string } }) {
let profileId = params.id;
const dataProfile = await Profile_getOneProfileAndUserById(profileId);
export default async function Page() {
return (
<>
<EditProfile data={dataProfile as any} />
<EditProfile />
</>
);
}

View File

@@ -5,37 +5,122 @@ import { useRouter } from "next/navigation";
import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
import { IconAlertTriangle, IconMessage2, IconUpload } from "@tabler/icons-react";
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
import { useState } from "react";
import { clientLogger } from "@/util/clientLogger";
import { apiGetAdminCollaborationStatusCountDashboard } from "../lib/api_fetch_admin_collaboration";
import global_limit from "@/app/lib/limit";
import { useShallowEffect } from "@mantine/hooks";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function AdminColab_Dashboard({
countPublish,
countRoom,
countReject,
}: {
countPublish: number;
countRoom: number;
countReject: number;
}) {
export default function AdminColab_Dashboard() {
const [countPublish, setCountPublish] = useState<number | null>(null);
const [countRoom, setCountRoom] = useState<number | null>(null);
const [countReject, setCountReject] = useState<number | null>(null);
const router = useRouter();
useShallowEffect(() => {
handlerLoadData()
}, []);
async function handlerLoadData() {
try {
const listLoadData = [
global_limit(() => onLoadCountPublish()),
global_limit(() => onLoadCountRoom()),
global_limit(() => onLoadCountReject()),
]
const result = await Promise.all(listLoadData);
} catch (error) {
clientLogger.error("Error handler load data", error)
}
}
async function onLoadCountPublish() {
try {
const response = await apiGetAdminCollaborationStatusCountDashboard({
name: "Publish",
})
if (response) {
setCountPublish(response.data);
}
} catch (error) {
clientLogger.error("Error get count publish", error);
}
}
async function onLoadCountRoom() {
try {
const response = await apiGetAdminCollaborationStatusCountDashboard(
{
name: "Room",
}
)
if (response) {
setCountRoom(response.data);
}
} catch (error) {
clientLogger.error("Error get count room", error);
}
}
async function onLoadCountReject() {
try {
const response = await apiGetAdminCollaborationStatusCountDashboard({
name: "Reject",
})
if (response) {
setCountReject(response.data);
}
} catch (error) {
clientLogger.error("Error get count reject", error);
}
}
const listStatus = [
{
id: 1,
name: "Publish",
jumlah: countPublish,
jumlah: countPublish
== null ? (
<CustomSkeleton height={40} width={40} />
) : countPublish ? (
countPublish
) : (
"-"
)
,
color: "green",
icon: <IconUpload size={18} color="#4CAF4F" />
},
{
id: 2,
name: "Group Chat",
jumlah: countRoom,
jumlah: countRoom
== null ? (
<CustomSkeleton height={40} width={40} />
) : countRoom ? (
countRoom
) : (
"-"
)
,
color: "orange",
icon: <IconMessage2 size={18} color="#FF9800" />
},
{
id: 3,
name: "Reject",
jumlah: countReject,
jumlah: countReject
== null ? (
<CustomSkeleton height={40} width={40} />
) : countReject ? (
countReject
) : (
"-"
)
,
color: "red",
icon: <IconAlertTriangle size={18} color="#FF4B4C" />
},
@@ -84,3 +169,7 @@ export default function AdminColab_Dashboard({
</>
);
}
function apiGetAdminCollaborationStatuCountDashboard(arg0: { name: string; }) {
throw new Error("Function not implemented.");
}

View File

@@ -0,0 +1,25 @@
export {
apiGetAdminCollaborationStatusCountDashboard,
}
const apiGetAdminCollaborationStatusCountDashboard = async ({
name
}: {
name: "Publish" | "Reject" | "Room";
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
// console.log("Ini Token", token);
const response = await fetch(`/api/admin/collaboration/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
// console.log("Ini Response", await response.json());
return await response.json().catch(() => null);
}

View File

@@ -48,9 +48,7 @@ const apiGetAdminDonasiByStatus = async ({
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(
@@ -64,14 +62,14 @@ const apiGetAdminDonasiByStatus = async ({
}
}
)
console.log("Ini response", response)
return await response.json().catch(() => null);
}
const apiGetAdminDonasiKategori = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
console.log("ini token", token)
const response = await fetch(`/api/admin/donasi/kategori`, {
method: "GET",
headers: {

View File

@@ -73,7 +73,7 @@ function TableView() {
try {
const response = await apiGetAdminDonasiKategori();
if (response) {
console.log("ini response", response)
setData(response.data)
}
} catch (error) {
@@ -96,7 +96,7 @@ function TableView() {
}
async function onChangeStatus() {
// console.log(updateStatus.kategoriId, updateStatus.isActive);
const del = await adminDonasi_funDeleteKategori({
kategoriId: updateStatus.kategoriId,
isActive: updateStatus.isActive as any,

View File

@@ -72,7 +72,7 @@ function TableStatus() {
page: `${isActivePage}`,
search: isSearch
})
console.log("IniData", response)
if (response?.success && response?.data?.data) {
setData(response.data.data);

View File

@@ -162,11 +162,11 @@ export default function AdminEvent_ComponentTableReview() {
});
if (response?.success && response?.data?.data) {
console.log("review >>", response.data.data);
setData(response.data.data);
setNPage(response.data.nPage || 1);
} else {
console.error("Invalid data format received:", response);
setData([]);
}
} catch (error) {
@@ -227,7 +227,7 @@ export default function AdminEvent_ComponentTableReview() {
});
if (response?.success && response?.data?.data) {
console.log("review >>", response.data.data);
setData(response.data.data);
setNPage(response.data.nPage || 1);
} else {

View File

@@ -28,12 +28,10 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
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}` : "";
@@ -46,6 +44,6 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
Authorization: `Bearer ${token}`,
},
})
console.log("Ini response", response)
return await response.json().catch(() => null);
}

View File

@@ -13,6 +13,7 @@ import { ComponentAdminInvestasi_DetailDataAuthor } from "../_component/detail_d
import { ComponentAdminInvestasi_DetailData } from "../_component/detail_data_investasi";
import { ComponentAdminInvestasi_DetailGambar } from "../_component/detail_gambar_investasi";
import { ComponentAdminInvestasi_UIDetailFile } from "../_component/ui_detail_file";
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
export function AdminInvestasi_DetailReject({ data }: { data: MODEL_INVESTASI }) {
return (
@@ -28,15 +29,15 @@ export function AdminInvestasi_DetailReject({ data }: { data: MODEL_INVESTASI })
{ maxWidth: "36rem", cols: 1, spacing: "sm" },
]}
>
<Paper withBorder p={"lg"}>
<Paper bg={AdminColor.softBlue} p={"lg"}>
<Stack>
<Title order={3} c={"red"}>
#{" "}
<Text span inherit c={"black"}>
<Text span inherit c={AdminColor.white}>
Alasan penolakan
</Text>
</Title>
<Text>{data.catatan}</Text>
<Text c={AdminColor.white}>{data.catatan}</Text>
</Stack>
</Paper>
</SimpleGrid>

View File

@@ -35,11 +35,7 @@ import { apiGetAdminJobByStatus } from "../../lib/api_fetch_admin_job";
import { clientLogger } from "@/util/clientLogger";
import { useShallowEffect } from "@mantine/hooks";
export default function AdminJob_TableReject({
dataReject,
}: {
dataReject: any;
}) {
export default function AdminJob_TableReject() {
return (
<>
<Stack>

View File

@@ -85,7 +85,7 @@ export default function HomeViewNew() {
<ActionIcon radius={"xl"} variant={"transparent"}>
<IconUserSearch color={MainColor.white} />
</ActionIcon>
) : dataUser && dataUser?.profile === undefined ? (
) : dataUser?.profile === undefined ? (
<ActionIcon
radius={"xl"}
variant={"transparent"}
@@ -112,7 +112,7 @@ export default function HomeViewNew() {
<ActionIcon radius={"xl"} variant={"transparent"}>
<IconBell color={MainColor.white} />
</ActionIcon>
) : dataUser && dataUser?.profile === undefined ? (
) : dataUser?.profile === undefined ? (
<ActionIcon
radius={"xl"}
variant={"transparent"}

View File

@@ -15,102 +15,218 @@ import { Button } from "@mantine/core";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import funCreateNewProfile from "../../fun/fun_create_profile";
import { apiCreateProfile } from "../../lib/api_fetch_profile";
import { MODEL_PROFILE } from "../../model/interface";
import funCreateNewProfile from "../../fun/fun_create_profile";
interface CreateProfileData {
name: string;
email: string;
alamat: string;
jenisKelamin: string;
imageId: string;
imageBackgroundId: string;
}
interface ProfileComponentProps {
value: MODEL_PROFILE;
filePP: File | null;
fileBG: File | null;
}
export function Profile_ComponentCreateNewProfile({
value,
filePP,
fileBG,
}: {
value: MODEL_PROFILE;
filePP: File;
fileBG: File;
}) {
}: ProfileComponentProps) {
const router = useRouter();
const [loading, setLoading] = useState(false);
async function onSubmit() {
const newData = {
name: value.name,
email: value.email,
alamat: value.alamat,
jenisKelamin: value.jenisKelamin,
const validateData = (): string | null => {
if (_.values(value).some((val) => !val)) {
return "Lengkapi Data";
}
if (!emailRegex.test(value.email)) {
return "Format email salah";
}
if (!filePP) {
return "Lengkapi foto profile";
}
if (!fileBG) {
return "Lengkapi background profile";
}
return null;
};
const uploadImages = async (): Promise<{
photoId: string;
backgroundId: string;
} | null> => {
const uploadPhoto = await funGlobal_UploadToStorage({
file: filePP!,
dirId: DIRECTORY_ID.profile_foto,
});
if (!uploadPhoto.success) {
throw new Error("Gagal upload foto profile");
}
const uploadBackground = await funGlobal_UploadToStorage({
file: fileBG!,
dirId: DIRECTORY_ID.profile_background,
});
if (!uploadBackground.success) {
throw new Error("Gagal upload background profile");
}
return {
photoId: uploadPhoto.data.id,
backgroundId: uploadBackground.data.id,
};
if (_.values(newData).includes(""))
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
if (!newData.email.match(emailRegex))
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
};
if (filePP == null)
return ComponentGlobal_NotifikasiPeringatan("Lengkapi foto profile");
if (fileBG == null)
return ComponentGlobal_NotifikasiPeringatan(
"Lengkapi background profile"
);
const handleSubmit = async () => {
try {
const validationError = validateData();
if (validationError) {
ComponentGlobal_NotifikasiPeringatan(validationError);
return;
}
setLoading(true);
const uploadPhoto = await funGlobal_UploadToStorage({
file: filePP,
dirId: DIRECTORY_ID.profile_foto,
});
if (!uploadPhoto.success) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
const uploadedImages = await uploadImages();
if (!uploadedImages) {
return;
}
const uploadBackground = await funGlobal_UploadToStorage({
file: fileBG,
dirId: DIRECTORY_ID.profile_background,
});
const profileData: CreateProfileData = {
name: value.name,
email: value.email,
alamat: value.alamat,
jenisKelamin: value.jenisKelamin,
imageId: uploadedImages.photoId,
imageBackgroundId: uploadedImages.backgroundId,
};
if (!uploadBackground.success) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
}
const response = await apiCreateProfile({ data: profileData as any});
const create = await funCreateNewProfile({
data: newData as any,
imageId: uploadPhoto.data.id,
imageBackgroundId: uploadBackground.data.id,
});
if (create.status === 201) {
if (response.success) {
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
router.replace(RouterHome.main_home, { scroll: false });
}
if (create.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiGagal(create.message);
}
if (create.status === 500) {
setLoading(false);
ComponentGlobal_NotifikasiGagal(create.message);
} else {
ComponentGlobal_NotifikasiPeringatan(response.message);
}
} catch (error) {
setLoading(false);
clientLogger.error("Error create new profile:", error);
ComponentGlobal_NotifikasiGagal(
error instanceof Error
? error.message
: "Terjadi kesalahan saat membuat profile"
);
} finally {
setLoading(false);
}
}
};
// async function onSubmit() {
// if (_.values(value).includes(""))
// return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
// if (!value.email.match(emailRegex))
// return ComponentGlobal_NotifikasiPeringatan("Format email salah");
// if (filePP == null)
// return ComponentGlobal_NotifikasiPeringatan("Lengkapi foto profile");
// if (fileBG == null)
// return ComponentGlobal_NotifikasiPeringatan(
// "Lengkapi background profile"
// );
// try {
// setLoading(true);
// const uploadPhoto = await funGlobal_UploadToStorage({
// file: filePP,
// dirId: DIRECTORY_ID.profile_foto,
// });
// if (!uploadPhoto.success) {
// setLoading(false);
// ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
// return;
// }
// const uploadBackground = await funGlobal_UploadToStorage({
// file: fileBG,
// dirId: DIRECTORY_ID.profile_background,
// });
// if (!uploadBackground.success) {
// setLoading(false);
// ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
// return;
// }
// const newData: CreateProfileData = {
// name: value.name,
// email: value.email,
// alamat: value.alamat,
// jenisKelamin: value.jenisKelamin,
// imageId: uploadPhoto.data.id,
// imageBackgroundId: uploadBackground.data.id,
// };
// const respone = await apiCreateProfile({
// data: newData as any,
// });
// if (respone && respone.success) {
// console.log(respone.data);
// ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
// router.replace(RouterHome.main_home, { scroll: false });
// } else {
// setLoading(false);
// ComponentGlobal_NotifikasiPeringatan(respone.message);
// }
// // const create = await funCreateNewProfile({
// // data: fixData as any,
// // imageId: uploadPhoto.data.id,
// // imageBackgroundId: uploadBackground.data.id,
// // });
// // if (create.status === 201) {
// // ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
// // router.replace(RouterHome.main_home, { scroll: false });
// // }
// // if (create.status === 400) {
// // setLoading(false);
// // ComponentGlobal_NotifikasiGagal(create.message);
// // }
// // if (create.status === 500) {
// // setLoading(false);
// // ComponentGlobal_NotifikasiGagal(create.message);
// // }
// } catch (error) {
// setLoading(false);
// clientLogger.error("Error create new profile:", error);
// }
// }
return (
<>
<Button
loading={loading ? true : false}
loading={loading}
loaderPosition="center"
mt={"md"}
radius={50}
bg={MainColor.yellow}
color="yellow"
onClick={() => {
onSubmit();
// onSubmit();
handleSubmit();
}}
style={{
border: `2px solid ${AccentColor.yellow}`,

View File

@@ -0,0 +1,17 @@
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { Stack } from "@mantine/core";
export { Profile_SkeletonViewEdit };
function Profile_SkeletonViewEdit() {
return (
<>
<Stack spacing={"xl"}>
{Array.from({ length: 4 }).map((_, i) => (
<CustomSkeleton key={i} height={50} width={"100%"} />
))}
<CustomSkeleton height={50} width={"100%"} radius={"xl"} />
</Stack>
</>
);
}

View File

@@ -6,52 +6,69 @@ import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/noti
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { clientLogger } from "@/util/clientLogger";
import { Button, Loader, Select, Stack, TextInput } from "@mantine/core";
import { Button, Select, Stack, TextInput } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import { emailRegex } from "../../component/regular_expressions";
import { Profile_funEditById } from "../fun/update/fun_edit_profile_by_id";
import { Profile_SkeletonViewEdit } from "../_component/skeleton_view";
import {
apiGetOneProfileById,
apiUpdateProfile,
} from "../lib/api_fetch_profile";
import { MODEL_PROFILE } from "../model/interface";
export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
export default function EditProfile() {
const router = useRouter();
const params = useParams<{ id: string }>();
const profileId = params.id;
//Get data profile
const [dataProfile, setDataProfile] = useState(data);
const [data, setData] = useState<MODEL_PROFILE | null>(null);
const [loading, setLoading] = useState(false);
async function onUpdate() {
const body = dataProfile;
useShallowEffect(() => {
onLoadData();
}, []);
async function onLoadData() {
try {
const respone = await apiGetOneProfileById({ id: profileId });
if (respone) {
setData(respone.data);
}
} catch (error) {
clientLogger.error("Error get data profile", error);
}
}
async function onUpdate() {
// console.log(body)
if (_.values(body).includes(""))
if (_.values(data).includes(""))
return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
if (!body.email.match(emailRegex))
if (!data?.email.match(emailRegex))
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
try {
setLoading(true);
const res = await Profile_funEditById(body);
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(res.message);
const respone = await apiUpdateProfile({ data: data });
if (respone && respone.success == true) {
ComponentGlobal_NotifikasiBerhasil(respone.message);
router.back();
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
ComponentGlobal_NotifikasiGagal(respone.message);
}
} catch (error) {
setLoading(false);
clientLogger.error("Error update foto profile", error);
clientLogger.error("Error client update profile", error);
}
}
if (!dataProfile)
return (
<>
<Loader />
</>
);
if (!data) return <Profile_SkeletonViewEdit />;
return (
<>
@@ -108,16 +125,16 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
placeholder="nama"
maxLength={50}
error={
dataProfile?.name === "" ? (
data?.name === "" ? (
<ComponentGlobal_ErrorInput text="Masukan nama" />
) : (
""
)
}
value={dataProfile?.name}
value={data?.name}
onChange={(val) => {
setDataProfile({
...dataProfile,
setData({
...data,
name: val.target.value,
});
}}
@@ -136,19 +153,18 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
label="Email"
placeholder="email"
error={
dataProfile?.email === "" ? (
data?.email === "" ? (
<ComponentGlobal_ErrorInput text="Masukan email " />
) : dataProfile?.email?.length > 0 &&
!dataProfile?.email.match(emailRegex) ? (
) : data?.email?.length > 0 && !data?.email.match(emailRegex) ? (
<ComponentGlobal_ErrorInput text="Invalid email" />
) : (
""
)
}
value={dataProfile?.email}
value={data?.email}
onChange={(val) => {
setDataProfile({
...dataProfile,
setData({
...data,
email: val.target.value,
});
}}
@@ -166,18 +182,18 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
withAsterisk
label="Alamat"
placeholder="alamat"
value={dataProfile.alamat}
value={data.alamat}
maxLength={100}
error={
dataProfile?.alamat === "" ? (
data?.alamat === "" ? (
<ComponentGlobal_ErrorInput text="Masukan alamat " />
) : (
""
)
}
onChange={(val) => {
setDataProfile({
...dataProfile,
setData({
...data,
alamat: val.target.value,
});
}}
@@ -194,14 +210,14 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
}}
withAsterisk
label="Jenis Kelamin"
value={dataProfile?.jenisKelamin}
value={data?.jenisKelamin}
data={[
{ value: "Laki-laki", label: "Laki-laki" },
{ value: "Perempuan", label: "Perempuan" },
]}
onChange={(val: any) => {
setDataProfile({
...dataProfile,
setData({
...data,
jenisKelamin: val,
});
}}
@@ -213,14 +229,13 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
bg={MainColor.yellow}
color="yellow"
c={"black"}
loading={loading ? true : false}
loading={loading}
loaderPosition="center"
onClick={() => onUpdate()}
>
Update
</Button>
</Stack>
</>
);
}

View File

@@ -1,16 +0,0 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function Profile_getOneProfileAndUserById(profileId: string) {
const data = await prisma.profile.findFirst({
where: {
id: profileId,
},
include: {
User: true,
},
});
// console.log(data)
return data;
}

View File

@@ -0,0 +1,57 @@
import { MODEL_PROFILE } from "../model/interface";
export { apiUpdateProfile, apiGetOneProfileById, apiCreateProfile };
const apiCreateProfile = async ({ data }: { data: MODEL_PROFILE }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const res = await fetch(`/api/profile`, {
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);
}
const apiGetOneProfileById = async ({ id }: { id: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const res = await fetch(`/api/profile/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await res.json().catch(() => null);
};
const apiUpdateProfile = async ({ data }: { data: MODEL_PROFILE }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const res = await fetch(`/api/profile/${data.id}`, {
method: "PUT",
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);
};

View File

@@ -0,0 +1,27 @@
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { Grid, Group, Stack } from "@mantine/core";
export function UserSearch_SkeletonView() {
return (
<>
<Stack>
{Array.from({ length: 2 }).map((e, i) => (
<Grid key={i}>
<Grid.Col span={2}>
<CustomSkeleton height={40} width={40} circle />
</Grid.Col>
<Grid.Col span={"auto"}>
<Stack>
<CustomSkeleton width={"80%"} height={20} />
<CustomSkeleton width={"40%"} height={15} />
</Stack>
</Grid.Col>
<Grid.Col span={2}>
<CustomSkeleton height={40} width={40} circle />
</Grid.Col>
</Grid>
))}
</Stack>
</>
);
}

View File

@@ -25,6 +25,7 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import { userSearch_getAllUser } from "../fun/get/get_all_user";
import { apiGetUserSearch } from "./api_fetch_user_search";
import { UserSearch_SkeletonView } from "./skeleton_view";
export function UserSearch_UiView() {
const [data, setData] = useState<MODEL_USER[]>([]);
@@ -107,15 +108,15 @@ export function UserSearch_UiView() {
onChange={(val) => handleSearch(val.target.value)}
// disabled={isLoading}
/>
{!data && isLoading ? (
<CustomSkeleton height={40} width={"100%"} />
{!data.length && isLoading ? (
<UserSearch_SkeletonView />
) : (
<Box >
<Box>
{_.isEmpty(data) ? (
<ComponentGlobal_IsEmptyData text="Pengguna tidak ditemukan" />
) : (
<ScrollOnly
height="5vh"
height="84vh"
renderLoading={() => (
<Center mt={"lg"}>
<Loader color={"yellow"} />
@@ -170,61 +171,12 @@ function CardView({ data }: { data: MODEL_USER }) {
<Group position="right" align="center" h={"100%"}>
<Center>
<ActionIcon variant="transparent">
{/* PAKE LOADING */}
{/* {loading ? (
<ComponentGlobal_Loader />
) : (
<IconChevronRight color="white" />
)} */}
{/* GA PAKE LOADING */}
<IconChevronRight color="white" />
</ActionIcon>
</Center>
</Group>
</Grid.Col>
</Grid>
{/* <Stack
spacing={"xs"}
c="white"
py={"xs"}
onClick={() => {
setLoading(true);
router.push(RouterProfile.katalogOLD + `${data?.Profile?.id}`);
}}
>
<Group position="apart" grow>
<Group position="left" bg={"blue"}>
<ComponentGlobal_LoaderAvatar
fileId={data.Profile.imageId as any}
imageSize="100"
/>
<Stack spacing={0}>
<Text fw={"bold"} lineClamp={1}>
{data?.Profile.name}d sdasd sdas
</Text>
<Text fz={"sm"} fs={"italic"}>
+{data?.nomor}
</Text>
</Stack>
</Group>
<Group position="right">
<Center>
<ActionIcon variant="transparent">
{loading ? (
<ComponentGlobal_Loader />
) : (
<IconChevronRight color="white" />
)}
</ActionIcon>
</Center>
</Group>
</Group>
</Stack> */}
</>
);
}

View File

@@ -38,12 +38,12 @@ const middlewareConfig: MiddlewareConfig = {
// "/api/new/*",
// ADMIN API
// "/api/admin/event/*",
// "/api/admin/investasi/*",
"/api/admin/investasi/*",
// "/api/admin/donasi/*",
// "/api/admin/voting/dashboard/*",
// "/api/admin/job/dashboard/*",
// "/api/admin/forum/dashboard/*",
// "/api/admin/job/*",
// "/api/admin/forum/*",
// "/api/admin/collaboration/*",
// Akses awal
"/api/get-cookie",