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. 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.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) ## [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", "name": "hipmi",
"version": "1.2.48", "version": "1.2.49",
"private": true, "private": true,
"prisma": { "prisma": {
"seed": "bun prisma/seed.ts" "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

@@ -29,88 +29,62 @@ export async function GET(request: Request,
const fixStatus = _.startCase(status); const fixStatus = _.startCase(status);
if (!page && !search) { if (!page) {
fixData = await prisma.donasi.findMany({ const data = await prisma.donasi.findMany({
orderBy: { orderBy: {
updatedAt: "desc", createdAt: "desc",
}, },
where: { where: {
active: true,
DonasiMaster_Status: { DonasiMaster_Status: {
name: fixStatus name: fixStatus,
}
}, },
include: {
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true
}
}
}
},
DonasiMaster_Status: true,
DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true
}
})
} else if (!page && search) {
fixData = await prisma.donasi.findMany({
orderBy: {
updatedAt: "desc"
},
where: {
active: true, active: true,
DonasiMaster_Status: {
name: fixStatus
},
title: { title: {
contains: search, contains: search ? search : "",
mode: "insensitive" mode: "insensitive",
} },
}, },
include: {
Author: {
select: { select: {
id: true, id: true,
username: true, title: true,
Profile: { target: true,
select: { authorId: true,
name: true terkumpul: true,
} imageDonasi: true,
}
}
},
DonasiMaster_Status: true,
DonasiMaster_Ketegori: true, DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true DonasiMaster_Durasi: true,
} imageId: true,
},
}) })
} else if (page && !search) { } else {
const data = await prisma.donasi.findMany({ const data = await prisma.donasi.findMany({
take: takeData, take: takeData,
skip: skipData, skip: skipData,
orderBy: [ orderBy: {
{ createdAt: "desc",
publishTime: "desc"
}
],
where: {
active: true,
DonasiMaster_Status: {
name: fixStatus
}
}, },
include: { where: {
Author: true, 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, imageDonasi: true,
DonasiMaster_Status: true,
DonasiMaster_Ketegori: true, DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true DonasiMaster_Durasi: true,
} imageId: true,
},
}) })
const nCount = await prisma.donasi.count({ const nCount = await prisma.donasi.count({
@@ -122,7 +96,7 @@ export async function GET(request: Request,
} }
}) })
console.log("data >", data)
fixData = { fixData = {
data: data, data: data,
nCount: _.ceil(nCount / takeData) 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 takeData = 10
const skipData = Number(page) * takeData - takeData; const skipData = Number(page) * takeData - takeData;
console.log("Ini Status", status);
console.log("Ini Page", page)
try { try {
let fixData; let fixData;
const fixStatus = _.startCase(status); const fixStatus = _.startCase(status);
if (!page && !search) {
fixData = await prisma.investasi.findMany({ if (!page) {
orderBy: { const data = await prisma.investasi.findMany({
updatedAt: "desc",
},
where: {
active: true,
MasterStatusInvestasi: {
name: fixStatus
},
},
include: {
author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
MasterStatusInvestasi: true,
},
});
} else if (!page && search) {
fixData = await prisma.investasi.findMany({
orderBy: { orderBy: {
updatedAt: "desc", updatedAt: "desc",
}, },
@@ -68,41 +40,40 @@ export async function GET(request: Request, { params }: {
name: fixStatus name: fixStatus
}, },
title: { title: {
contains: search, contains: search ? search : "",
mode: "insensitive", mode: "insensitive"
}, }
}, },
include: { include: {
author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
MasterStatusInvestasi: true, MasterStatusInvestasi: true,
BeritaInvestasi: true,
DokumenInvestasi: true,
ProspektusInvestasi: true,
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
author: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "2",
},
},
}, },
}); });
} else if (page && !search) { } else {
const data = await prisma.investasi.findMany({ const data = await prisma.investasi.findMany({
take: takeData, orderBy: {
skip: skipData, updatedAt: "desc",
orderBy: [
{
countDown: "desc",
}, },
],
where: { where: {
active: true, active: true,
MasterStatusInvestasi: { MasterStatusInvestasi: {
name: fixStatus name: fixStatus
},
title: {
contains: search ? search : "",
mode: "insensitive"
} }
}, },
include: { include: {
MasterStatusInvestasi: true, MasterStatusInvestasi: true,
@@ -131,8 +102,6 @@ export async function GET(request: Request, { params }: {
}, },
}); });
console.log("data >", data)
fixData = { fixData = {
data: data, data: data,
nPage: _.ceil(nCount / takeData), nPage: _.ceil(nCount / takeData),

View File

@@ -31,7 +31,7 @@ export async function GET(request: Request, { params }: {
const fixStatus = _.startCase(status); const fixStatus = _.startCase(status);
if (!page) { if (!page) {
fixData = await prisma.job.findMany({ const data = await prisma.job.findMany({
orderBy: { orderBy: {
updatedAt: "desc" updatedAt: "desc"
}, },
@@ -53,7 +53,7 @@ export async function GET(request: Request, { params }: {
}) })
} else { } else {
fixData = await prisma.job.findMany({ const data = await prisma.job.findMany({
take: takeData, take: takeData,
skip: skipData, skip: skipData,
orderBy: { orderBy: {
@@ -87,7 +87,7 @@ export async function GET(request: Request, { params }: {
}) })
fixData = { fixData = {
data: fixData, data: data,
nPage: _.ceil(nCount / takeData) 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 { searchParams } = new URL(request.url);
const search = searchParams.get("search"); const search = searchParams.get("search");
const page = searchParams.get("page"); const page = searchParams.get("page");
const takeData = 1; const takeData = 15;
const skipData = Number(page) * takeData - takeData; const skipData = Number(page) * takeData - takeData;
if (!page) { 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"; import adminColab_countIsReject from "@/app_modules/admin/colab/fun/count/count_reject";
export default async function Page() { export default async function Page() {
const countPublish = await adminColab_countIsPublish(); // const countPublish = await adminColab_countIsPublish();
const countRoom = await adminColab_countGroupChat(); // const countRoom = await adminColab_countGroupChat();
const countReject = await adminColab_countIsReject() // const countReject = await adminColab_countIsReject()
return ( return (
<> <>
<AdminColab_Dashboard <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"; import adminDonasi_getMasterKategori from "@/app_modules/admin/donasi/fun/master/get_list_kategori";
export default async function Page() { export default async function Page() {
// const listKategori = await adminDonasi_getMasterKategori();
return ( 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"; import adminDonasi_getListPublish from "@/app_modules/admin/donasi/fun/get/get_list_publish";
export default async function Page() { export default async function Page() {
// const listPublish = await adminDonasi_getListPublish({
// page: 1,
// });
// console.log(listPublish)
return<> return<>
<AdminDonasi_TablePublish /> <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"; import adminDonasi_getListReject from "@/app_modules/admin/donasi/fun/get/get_list_reject";
export default async function Page() { export default async function Page() {
// const dataReject = await adminDonasi_getListReject({ page: 1 });
// console.log(dataReject)
return ( return (
<> <>
<AdminDonasi_TableReject /> <AdminDonasi_TableReject />

View File

@@ -1,8 +1,6 @@
import { AdminDonasi_TableReview } from "@/app_modules/admin/donasi"; 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() { export default async function Page() {
// const listReview = await adminDonasi_getListReview({page: 1});
// console.log(listReview);
return <AdminDonasi_TableReview />; return <AdminDonasi_TableReview />;
} }

View File

@@ -1,8 +1,6 @@
import { Admin_TablePublishInvestasi } from "@/app_modules/admin/investasi"; 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() { export default async function Page() {
// const listInvestasi = await adminInvestasi_funGetAllPublish({page: 1});
return ( return (
<> <>

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"; import { adminInvestasi_funGetAllReject } from "@/app_modules/admin/investasi/fun/get/get_all_reject";
export default async function Page() { export default async function Page() {
// const dataInvestsi = await adminInvestasi_funGetAllReject({page: 1});
return ( return (
<> <>
<Admin_TableRejectInvestasi /> <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"; import { adminInvestasi_funGetAllReview } from "@/app_modules/admin/investasi/fun/get/get_all_review";
export default async function Page() { export default async function Page() {
// const dataInvestsi = await adminInvestasi_funGetAllReview({ page: 1 });
return ( return (
<> <>
<Admin_TableReviewInvestasi /> <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"; import { AdminJob_getListTableByStatusId } from "@/app_modules/admin/job/fun/get/get_list_table_by_status_id";
export default async function Page() { export default async function Page() {
const listReject = await adminJob_getListReject({ page: 1 });
return ( return (
<> <>
<AdminJob_TableReject dataReject={listReject} /> <AdminJob_TableReject />
</> </>
); );
} }

View File

@@ -1,13 +1,10 @@
import EditProfile from "@/app_modules/katalog/profile/edit/view"; 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 } }) { export default async function Page() {
let profileId = params.id;
const dataProfile = await Profile_getOneProfileAndUserById(profileId);
return ( 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 ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
import { IconAlertTriangle, IconMessage2, IconUpload } from "@tabler/icons-react"; import { IconAlertTriangle, IconMessage2, IconUpload } from "@tabler/icons-react";
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet"; 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({ export default function AdminColab_Dashboard() {
countPublish, const [countPublish, setCountPublish] = useState<number | null>(null);
countRoom, const [countRoom, setCountRoom] = useState<number | null>(null);
countReject, const [countReject, setCountReject] = useState<number | null>(null);
}: {
countPublish: number;
countRoom: number;
countReject: number;
}) {
const router = useRouter(); 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 = [ const listStatus = [
{ {
id: 1, id: 1,
name: "Publish", name: "Publish",
jumlah: countPublish, jumlah: countPublish
== null ? (
<CustomSkeleton height={40} width={40} />
) : countPublish ? (
countPublish
) : (
"-"
)
,
color: "green", color: "green",
icon: <IconUpload size={18} color="#4CAF4F" /> icon: <IconUpload size={18} color="#4CAF4F" />
}, },
{ {
id: 2, id: 2,
name: "Group Chat", name: "Group Chat",
jumlah: countRoom, jumlah: countRoom
== null ? (
<CustomSkeleton height={40} width={40} />
) : countRoom ? (
countRoom
) : (
"-"
)
,
color: "orange", color: "orange",
icon: <IconMessage2 size={18} color="#FF9800" /> icon: <IconMessage2 size={18} color="#FF9800" />
}, },
{ {
id: 3, id: 3,
name: "Reject", name: "Reject",
jumlah: countReject, jumlah: countReject
== null ? (
<CustomSkeleton height={40} width={40} />
) : countReject ? (
countReject
) : (
"-"
)
,
color: "red", color: "red",
icon: <IconAlertTriangle size={18} color="#FF4B4C" /> 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()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); 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 isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : ""; const isSearch = search ? `&search=${search}` : "";
const response = await fetch( const response = await fetch(
@@ -64,14 +62,14 @@ const apiGetAdminDonasiByStatus = async ({
} }
} }
) )
console.log("Ini response", response)
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminDonasiKategori = async () => { const apiGetAdminDonasiKategori = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
console.log("ini token", token)
const response = await fetch(`/api/admin/donasi/kategori`, { const response = await fetch(`/api/admin/donasi/kategori`, {
method: "GET", method: "GET",
headers: { headers: {

View File

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

View File

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

View File

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

View File

@@ -28,12 +28,10 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
page: string, page: string,
search: string search: string
}) => { }) => {
console.log("dgsdg")
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); 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 isPage = page ? `?page=${page}` : "";
@@ -46,6 +44,6 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
}) })
console.log("Ini response", response)
return await response.json().catch(() => null); 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_DetailData } from "../_component/detail_data_investasi";
import { ComponentAdminInvestasi_DetailGambar } from "../_component/detail_gambar_investasi"; import { ComponentAdminInvestasi_DetailGambar } from "../_component/detail_gambar_investasi";
import { ComponentAdminInvestasi_UIDetailFile } from "../_component/ui_detail_file"; 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 }) { export function AdminInvestasi_DetailReject({ data }: { data: MODEL_INVESTASI }) {
return ( return (
@@ -28,15 +29,15 @@ export function AdminInvestasi_DetailReject({ data }: { data: MODEL_INVESTASI })
{ maxWidth: "36rem", cols: 1, spacing: "sm" }, { maxWidth: "36rem", cols: 1, spacing: "sm" },
]} ]}
> >
<Paper withBorder p={"lg"}> <Paper bg={AdminColor.softBlue} p={"lg"}>
<Stack> <Stack>
<Title order={3} c={"red"}> <Title order={3} c={"red"}>
#{" "} #{" "}
<Text span inherit c={"black"}> <Text span inherit c={AdminColor.white}>
Alasan penolakan Alasan penolakan
</Text> </Text>
</Title> </Title>
<Text>{data.catatan}</Text> <Text c={AdminColor.white}>{data.catatan}</Text>
</Stack> </Stack>
</Paper> </Paper>
</SimpleGrid> </SimpleGrid>

View File

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

View File

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

View File

@@ -15,102 +15,218 @@ import { Button } from "@mantine/core";
import _ from "lodash"; import _ from "lodash";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; 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 { 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({ export function Profile_ComponentCreateNewProfile({
value, value,
filePP, filePP,
fileBG, fileBG,
}: { }: ProfileComponentProps) {
value: MODEL_PROFILE;
filePP: File;
fileBG: File;
}) {
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
async function onSubmit() { const validateData = (): string | null => {
const newData = { if (_.values(value).some((val) => !val)) {
name: value.name, return "Lengkapi Data";
email: value.email, }
alamat: value.alamat, if (!emailRegex.test(value.email)) {
jenisKelamin: value.jenisKelamin, return "Format email salah";
}
if (!filePP) {
return "Lengkapi foto profile";
}
if (!fileBG) {
return "Lengkapi background profile";
}
return null;
}; };
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"
);
try {
setLoading(true);
const uploadImages = async (): Promise<{
photoId: string;
backgroundId: string;
} | null> => {
const uploadPhoto = await funGlobal_UploadToStorage({ const uploadPhoto = await funGlobal_UploadToStorage({
file: filePP, file: filePP!,
dirId: DIRECTORY_ID.profile_foto, dirId: DIRECTORY_ID.profile_foto,
}); });
if (!uploadPhoto.success) { if (!uploadPhoto.success) {
setLoading(false); throw new Error("Gagal upload foto profile");
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
} }
const uploadBackground = await funGlobal_UploadToStorage({ const uploadBackground = await funGlobal_UploadToStorage({
file: fileBG, file: fileBG!,
dirId: DIRECTORY_ID.profile_background, dirId: DIRECTORY_ID.profile_background,
}); });
if (!uploadBackground.success) { if (!uploadBackground.success) {
setLoading(false); throw new Error("Gagal upload background profile");
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); }
return {
photoId: uploadPhoto.data.id,
backgroundId: uploadBackground.data.id,
};
};
const handleSubmit = async () => {
try {
const validationError = validateData();
if (validationError) {
ComponentGlobal_NotifikasiPeringatan(validationError);
return; return;
} }
const create = await funCreateNewProfile({ setLoading(true);
data: newData as any,
imageId: uploadPhoto.data.id,
imageBackgroundId: uploadBackground.data.id,
});
if (create.status === 201) { const uploadedImages = await uploadImages();
if (!uploadedImages) {
return;
}
const profileData: CreateProfileData = {
name: value.name,
email: value.email,
alamat: value.alamat,
jenisKelamin: value.jenisKelamin,
imageId: uploadedImages.photoId,
imageBackgroundId: uploadedImages.backgroundId,
};
const response = await apiCreateProfile({ data: profileData as any});
if (response.success) {
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000); ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
router.replace(RouterHome.main_home, { scroll: false }); router.replace(RouterHome.main_home, { scroll: false });
} } else {
ComponentGlobal_NotifikasiPeringatan(response.message);
if (create.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiGagal(create.message);
}
if (create.status === 500) {
setLoading(false);
ComponentGlobal_NotifikasiGagal(create.message);
} }
} catch (error) { } catch (error) {
setLoading(false);
clientLogger.error("Error create new profile:", error); 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 ( return (
<> <>
<Button <Button
loading={loading ? true : false} loading={loading}
loaderPosition="center" loaderPosition="center"
mt={"md"} mt={"md"}
radius={50} radius={50}
bg={MainColor.yellow} bg={MainColor.yellow}
color="yellow" color="yellow"
onClick={() => { onClick={() => {
onSubmit(); // onSubmit();
handleSubmit();
}} }}
style={{ style={{
border: `2px solid ${AccentColor.yellow}`, 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_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { clientLogger } from "@/util/clientLogger"; 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 _ from "lodash";
import { useRouter } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import { emailRegex } from "../../component/regular_expressions"; 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"; import { MODEL_PROFILE } from "../model/interface";
export default function EditProfile({ data }: { data: MODEL_PROFILE }) { export default function EditProfile() {
const router = useRouter(); const router = useRouter();
const params = useParams<{ id: string }>();
const profileId = params.id;
//Get data profile //Get data profile
const [dataProfile, setDataProfile] = useState(data); const [data, setData] = useState<MODEL_PROFILE | null>(null);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
async function onUpdate() { useShallowEffect(() => {
const body = dataProfile; 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) // console.log(body)
if (_.values(body).includes("")) if (_.values(data).includes(""))
return ComponentGlobal_NotifikasiPeringatan("Lengkapi data"); return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
if (!body.email.match(emailRegex)) if (!data?.email.match(emailRegex))
return ComponentGlobal_NotifikasiPeringatan("Format email salah"); return ComponentGlobal_NotifikasiPeringatan("Format email salah");
try { try {
setLoading(true); setLoading(true);
const res = await Profile_funEditById(body); const respone = await apiUpdateProfile({ data: data });
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(res.message); if (respone && respone.success == true) {
ComponentGlobal_NotifikasiBerhasil(respone.message);
router.back(); router.back();
} else { } else {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message); ComponentGlobal_NotifikasiGagal(respone.message);
} }
} catch (error) { } catch (error) {
setLoading(false); setLoading(false);
clientLogger.error("Error update foto profile", error); clientLogger.error("Error client update profile", error);
} }
} }
if (!dataProfile) if (!data) return <Profile_SkeletonViewEdit />;
return (
<>
<Loader />
</>
);
return ( return (
<> <>
@@ -108,16 +125,16 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
placeholder="nama" placeholder="nama"
maxLength={50} maxLength={50}
error={ error={
dataProfile?.name === "" ? ( data?.name === "" ? (
<ComponentGlobal_ErrorInput text="Masukan nama" /> <ComponentGlobal_ErrorInput text="Masukan nama" />
) : ( ) : (
"" ""
) )
} }
value={dataProfile?.name} value={data?.name}
onChange={(val) => { onChange={(val) => {
setDataProfile({ setData({
...dataProfile, ...data,
name: val.target.value, name: val.target.value,
}); });
}} }}
@@ -136,19 +153,18 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
label="Email" label="Email"
placeholder="email" placeholder="email"
error={ error={
dataProfile?.email === "" ? ( data?.email === "" ? (
<ComponentGlobal_ErrorInput text="Masukan email " /> <ComponentGlobal_ErrorInput text="Masukan email " />
) : dataProfile?.email?.length > 0 && ) : data?.email?.length > 0 && !data?.email.match(emailRegex) ? (
!dataProfile?.email.match(emailRegex) ? (
<ComponentGlobal_ErrorInput text="Invalid email" /> <ComponentGlobal_ErrorInput text="Invalid email" />
) : ( ) : (
"" ""
) )
} }
value={dataProfile?.email} value={data?.email}
onChange={(val) => { onChange={(val) => {
setDataProfile({ setData({
...dataProfile, ...data,
email: val.target.value, email: val.target.value,
}); });
}} }}
@@ -166,18 +182,18 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
withAsterisk withAsterisk
label="Alamat" label="Alamat"
placeholder="alamat" placeholder="alamat"
value={dataProfile.alamat} value={data.alamat}
maxLength={100} maxLength={100}
error={ error={
dataProfile?.alamat === "" ? ( data?.alamat === "" ? (
<ComponentGlobal_ErrorInput text="Masukan alamat " /> <ComponentGlobal_ErrorInput text="Masukan alamat " />
) : ( ) : (
"" ""
) )
} }
onChange={(val) => { onChange={(val) => {
setDataProfile({ setData({
...dataProfile, ...data,
alamat: val.target.value, alamat: val.target.value,
}); });
}} }}
@@ -194,14 +210,14 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
}} }}
withAsterisk withAsterisk
label="Jenis Kelamin" label="Jenis Kelamin"
value={dataProfile?.jenisKelamin} value={data?.jenisKelamin}
data={[ data={[
{ value: "Laki-laki", label: "Laki-laki" }, { value: "Laki-laki", label: "Laki-laki" },
{ value: "Perempuan", label: "Perempuan" }, { value: "Perempuan", label: "Perempuan" },
]} ]}
onChange={(val: any) => { onChange={(val: any) => {
setDataProfile({ setData({
...dataProfile, ...data,
jenisKelamin: val, jenisKelamin: val,
}); });
}} }}
@@ -213,14 +229,13 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
bg={MainColor.yellow} bg={MainColor.yellow}
color="yellow" color="yellow"
c={"black"} c={"black"}
loading={loading ? true : false} loading={loading}
loaderPosition="center" loaderPosition="center"
onClick={() => onUpdate()} onClick={() => onUpdate()}
> >
Update Update
</Button> </Button>
</Stack> </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 { useState } from "react";
import { userSearch_getAllUser } from "../fun/get/get_all_user"; import { userSearch_getAllUser } from "../fun/get/get_all_user";
import { apiGetUserSearch } from "./api_fetch_user_search"; import { apiGetUserSearch } from "./api_fetch_user_search";
import { UserSearch_SkeletonView } from "./skeleton_view";
export function UserSearch_UiView() { export function UserSearch_UiView() {
const [data, setData] = useState<MODEL_USER[]>([]); const [data, setData] = useState<MODEL_USER[]>([]);
@@ -107,15 +108,15 @@ export function UserSearch_UiView() {
onChange={(val) => handleSearch(val.target.value)} onChange={(val) => handleSearch(val.target.value)}
// disabled={isLoading} // disabled={isLoading}
/> />
{!data && isLoading ? ( {!data.length && isLoading ? (
<CustomSkeleton height={40} width={"100%"} /> <UserSearch_SkeletonView />
) : ( ) : (
<Box> <Box>
{_.isEmpty(data) ? ( {_.isEmpty(data) ? (
<ComponentGlobal_IsEmptyData text="Pengguna tidak ditemukan" /> <ComponentGlobal_IsEmptyData text="Pengguna tidak ditemukan" />
) : ( ) : (
<ScrollOnly <ScrollOnly
height="5vh" height="84vh"
renderLoading={() => ( renderLoading={() => (
<Center mt={"lg"}> <Center mt={"lg"}>
<Loader color={"yellow"} /> <Loader color={"yellow"} />
@@ -170,61 +171,12 @@ function CardView({ data }: { data: MODEL_USER }) {
<Group position="right" align="center" h={"100%"}> <Group position="right" align="center" h={"100%"}>
<Center> <Center>
<ActionIcon variant="transparent"> <ActionIcon variant="transparent">
{/* PAKE LOADING */}
{/* {loading ? (
<ComponentGlobal_Loader />
) : (
<IconChevronRight color="white" />
)} */}
{/* GA PAKE LOADING */}
<IconChevronRight color="white" /> <IconChevronRight color="white" />
</ActionIcon> </ActionIcon>
</Center> </Center>
</Group> </Group>
</Grid.Col> </Grid.Col>
</Grid> </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/*", // "/api/new/*",
// ADMIN API // ADMIN API
// "/api/admin/event/*", // "/api/admin/event/*",
// "/api/admin/investasi/*", "/api/admin/investasi/*",
// "/api/admin/donasi/*", // "/api/admin/donasi/*",
// "/api/admin/voting/dashboard/*", // "/api/admin/voting/dashboard/*",
// "/api/admin/job/dashboard/*",
// "/api/admin/forum/dashboard/*",
// "/api/admin/job/*", // "/api/admin/job/*",
// "/api/admin/forum/*",
// "/api/admin/collaboration/*",
// Akses awal // Akses awal
"/api/get-cookie", "/api/get-cookie",