Fix admin

Deskripsi:
- Ganti status developer jadi super admin
This commit is contained in:
2025-01-04 11:48:22 +08:00
parent d4c4bee2f2
commit c3a05fd6b2
9 changed files with 189 additions and 109 deletions

View File

@@ -1,19 +1,12 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { funGlobal_checkActivationUseById } from "@/app_modules/_global/fun/get/fun_check_activation_use_by_id";
import WaitingRoom_View from "@/app_modules/waiting_room/view"; import WaitingRoom_View from "@/app_modules/waiting_room/view";
export default async function Page() { export default async function Page() {
const userLoginId = await funGetUserIdByToken(); const userLoginId = await funGetUserIdByToken();
const activationUser = await funGlobal_checkActivationUseById({
userId: userLoginId as string,
});
return ( return (
<> <>
<WaitingRoom_View <WaitingRoom_View userLoginId={userLoginId as string} />
activationUser={activationUser as boolean}
userLoginId={userLoginId as string}
/>
</> </>
); );
} }

View File

@@ -0,0 +1,53 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
try {
let fixData
const userLoginId = await funGetUserIdByToken();
if (userLoginId == null) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data, user id tidak ada",
},
{ status: 500 }
);
}
const activationUser = await prisma.user.findFirst({
where: {
id: userLoginId,
},
select: {
active: true,
},
});
fixData = activationUser?.active
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan data",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get activation user: ", error);
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,9 +1,16 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(req: Request) { export async function GET(req: Request) {
const auth = req.headers.get("Authorization"); const auth = req.headers.get("Authorization");
const token = auth?.split(" ")[1]; const token = auth?.split(" ")[1];
if (!token) return NextResponse.json({ success: false }, { status: 401 });
return NextResponse.json({ success: true });
console.log("validasi atas", token);
if (!token) return NextResponse.json({ success: false }, { status: 401 });
console.log("validasi bawah", token);
return NextResponse.json({ success: true });
} }

View File

@@ -0,0 +1,9 @@
export const apiGetCookiesUser = async () => {
const response = await fetch(`/api/user/get`);
return await response.json().catch(() => null);
};
export const apiGetACtivationUser = async () => {
const response = await fetch(`/api/user/activation`);
return await response.json().catch(() => null);
};

View File

@@ -44,7 +44,7 @@ export default function AdminDeveloper({
return ( return (
<> <>
<Stack> <Stack>
<ComponentAdminGlobal_HeaderTamplate name="Developer" /> <ComponentAdminGlobal_HeaderTamplate name="Super Admin" />
<SimpleGrid cols={2} spacing={50}> <SimpleGrid cols={2} spacing={50}>
{/* <TableAdmin {/* <TableAdmin
dataAdmin={dataAdmin} dataAdmin={dataAdmin}
@@ -148,7 +148,7 @@ function NewTableUser({
p={"xs"} p={"xs"}
style={{ borderRadius: "6px" }} style={{ borderRadius: "6px" }}
> >
<Title order={4}>Table User NEW</Title> <Title order={4}>Table User</Title>
<TextInput <TextInput
icon={<IconSearch size={20} />} icon={<IconSearch size={20} />}
radius={"xl"} radius={"xl"}

View File

@@ -297,10 +297,10 @@ export const newListAdminPage = [
child: [], child: [],
}, },
// Developer // Developer | Super Admin
{ {
id: "Developer", id: "Super Admin",
name: "Developer", name: "Super Admin",
path: RouterAdminDeveloper.main, path: RouterAdminDeveloper.main,
icon: <IconDashboard />, icon: <IconDashboard />,
child: [], child: [],

View File

@@ -1,6 +1,9 @@
"use client"; "use client";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { MODEL_USER } from "@/app_modules/home/model/interface"; import { MODEL_USER } from "@/app_modules/home/model/interface";
import { clientLogger } from "@/util/clientLogger";
import { import {
Button, Button,
Center, Center,
@@ -14,19 +17,23 @@ import {
Title, Title,
} from "@mantine/core"; } from "@mantine/core";
import { IconSearch } from "@tabler/icons-react"; import { IconSearch } from "@tabler/icons-react";
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
import { useState } from "react"; import { useState } from "react";
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
import adminUserAccess_getListUser from "../fun/get/get_list_all_user"; import adminUserAccess_getListUser from "../fun/get/get_list_all_user";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
export default function AdminUserAccess_View({ listUser }: { listUser: any }) { export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
const [data, setData] = useState<MODEL_USER[]>(listUser.data); const [data, setData] = useState<MODEL_USER[]>(listUser.data);
const [isActivePage, setActivePage] = useState(1); const [isActivePage, setActivePage] = useState(1);
const [isNPage, setNPage] = useState(listUser.nPage); const [isNPage, setNPage] = useState(listUser.nPage);
const [isSearch, setSearch] = useState(""); const [isSearch, setSearch] = useState("");
const [isLoadingAccess, setIsLoadingAccess] = useState(false);
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
const [userId, setUserId] = useState("");
async function onAccess(id: string) { async function onAccess(id: string) {
try {
setUserId(id);
setIsLoadingAccess(true);
await adminUserAccess_funEditAccess(id, true).then(async (res) => { await adminUserAccess_funEditAccess(id, true).then(async (res) => {
if (res.status === 200) { if (res.status === 200) {
const value = await adminUserAccess_getListUser({ const value = await adminUserAccess_getListUser({
@@ -40,9 +47,18 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
ComponentGlobal_NotifikasiGagal(res.message); ComponentGlobal_NotifikasiGagal(res.message);
} }
}); });
} catch (error) {
clientLogger.error("Error grand access", error);
} finally {
setIsLoadingAccess(false);
setUserId("");
}
} }
async function onDelAccess(id: string) { async function onDelete(id: string) {
try {
setUserId(id);
setIsLoadingDelete(true);
await adminUserAccess_funEditAccess(id, false).then(async (res) => { await adminUserAccess_funEditAccess(id, false).then(async (res) => {
if (res.status === 200) { if (res.status === 200) {
const value = await adminUserAccess_getListUser({ const value = await adminUserAccess_getListUser({
@@ -56,6 +72,12 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
ComponentGlobal_NotifikasiGagal(res.message); ComponentGlobal_NotifikasiGagal(res.message);
} }
}); });
} catch (error) {
clientLogger.error("Error delete access", error);
} finally {
setIsLoadingDelete(false);
setUserId("");
}
} }
async function onSearch(s: any) { async function onSearch(s: any) {
@@ -91,22 +113,26 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
{e.active === false ? ( {e.active === false ? (
<Center> <Center>
<Button <Button
loaderPosition="center"
loading={isLoadingAccess && userId === e.id}
radius={"xl"} radius={"xl"}
color="Green" color="Green"
onClick={() => { onClick={() => {
onAccess(e.id); onAccess(e.id);
}} }}
> >
Give Access Grand Access
</Button> </Button>
</Center> </Center>
) : ( ) : (
<Center> <Center>
<Button <Button
loaderPosition="center"
loading={isLoadingDelete && userId === e.id}
radius={"xl"} radius={"xl"}
color="red" color="red"
onClick={() => { onClick={() => {
onDelAccess(e.id); onDelete(e.id);
}} }}
> >
Delete Access Delete Access

View File

@@ -14,13 +14,15 @@ import {
import { useShallowEffect } from "@mantine/hooks"; import { useShallowEffect } from "@mantine/hooks";
import { redirect, useRouter } from "next/navigation"; import { redirect, useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import { ComponentGlobal_CardStyles } from "../_global/component";
import { apiGetACtivationUser } from "../_global/lib/api_user";
import { clientLogger } from "@/util/clientLogger";
import _ from "lodash";
export default function WaitingRoom_View({ export default function WaitingRoom_View({
activationUser,
userLoginId, userLoginId,
}: { }: {
activationUser: boolean; userLoginId?: string;
userLoginId: string;
}) { }) {
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
@@ -37,61 +39,49 @@ export default function WaitingRoom_View({
} }
} }
useShallowEffect(() => { const [data, setData] = useState<boolean | null>(null);
if (activationUser == true) {
return redirect("/");
}
}, [activationUser]);
const listhHuruf = [ useShallowEffect(() => {
{ onLoadData();
huruf: "H", }, []);
},
{ async function onLoadData() {
huruf: "I", try {
}, const respone = await apiGetACtivationUser();
{ if (respone) {
huruf: "P", console.log(respone.data);
}, setData(respone.data);
{ }
huruf: "M", } catch (error) {
}, clientLogger.error("Error get cookies user", error);
{ }
huruf: "I", }
},
];
const customLOader = (
<Center>
<Group>
{listhHuruf.map((e, i) => (
<Center key={i} h={"100%"}>
<Skeleton height={50} circle radius={"100%"} />
<Text sx={{ position: "absolute" }} c={"gray.5"} fw={"bold"}>
{e.huruf}
</Text>
</Center>
))}
</Group>
</Center>
);
return ( return (
<> <>
<UIGlobal_LayoutDefault> <UIGlobal_LayoutDefault>
<Center h={"100vh"}> <Stack justify="cneter" h={"90vh"} mt={"xl"}>
<Stack align="center" spacing={50}> <ComponentGlobal_CardStyles>
{/* {customLOader} */} {_.isNull(data) ? (
<Stack>
<Stack align="center" spacing={5}> {Array.from(new Array(4)).map((e, i) => (
<Title order={3} c={"white"}> <Skeleton key={i} h={20} w={"100%"} />
Anda telah berhasil mendaftar, ))}
</Title> </Stack>
<Title order={3} c={"white"}> ) : (
Mohon menunggu konfirmansi Admin ! <Stack align="center">
</Title> <Stack align="center" spacing={5} fs={"italic"}>
<Text fw={"bold"} c={"white"} align="center">
Permohonan akses Anda sedang dalam proses verifikasi oleh
admin.
</Text>
<Text fw={"bold"} c={"white"} align="center">
Harap tunggu, Anda akan menerima pemberitahuan melalui
Whatsapp setelah disetujui.
</Text>
</Stack> </Stack>
<Button {/* <Button
color="red" color="red"
loaderPosition="center" loaderPosition="center"
loading={loading} loading={loading}
@@ -99,9 +89,11 @@ export default function WaitingRoom_View({
onClick={() => onClickLogout()} onClick={() => onClickLogout()}
> >
Keluar Keluar
</Button> </Button> */}
</Stack>
)}
</ComponentGlobal_CardStyles>
</Stack> </Stack>
</Center>
</UIGlobal_LayoutDefault> </UIGlobal_LayoutDefault>
</> </>
); );