Fix admin
Deskripsi: - Ganti status developer jadi super admin
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
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";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
const activationUser = await funGlobal_checkActivationUseById({
|
||||
userId: userLoginId as string,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<WaitingRoom_View
|
||||
activationUser={activationUser as boolean}
|
||||
userLoginId={userLoginId as string}
|
||||
/>
|
||||
<WaitingRoom_View userLoginId={userLoginId as string} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
53
src/app/api/user/activation/route.ts
Normal file
53
src/app/api/user/activation/route.ts
Normal 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const auth = req.headers.get("Authorization");
|
||||
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 });
|
||||
}
|
||||
9
src/app_modules/_global/lib/api_user.ts
Normal file
9
src/app_modules/_global/lib/api_user.ts
Normal 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);
|
||||
};
|
||||
@@ -44,7 +44,7 @@ export default function AdminDeveloper({
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Developer" />
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Super Admin" />
|
||||
<SimpleGrid cols={2} spacing={50}>
|
||||
{/* <TableAdmin
|
||||
dataAdmin={dataAdmin}
|
||||
@@ -148,7 +148,7 @@ function NewTableUser({
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title order={4}>Table User NEW</Title>
|
||||
<Title order={4}>Table User</Title>
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
|
||||
@@ -297,10 +297,10 @@ export const newListAdminPage = [
|
||||
child: [],
|
||||
},
|
||||
|
||||
// Developer
|
||||
// Developer | Super Admin
|
||||
{
|
||||
id: "Developer",
|
||||
name: "Developer",
|
||||
id: "Super Admin",
|
||||
name: "Super Admin",
|
||||
path: RouterAdminDeveloper.main,
|
||||
icon: <IconDashboard />,
|
||||
child: [],
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"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 { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
Button,
|
||||
Center,
|
||||
@@ -14,48 +17,67 @@ import {
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { IconSearch } from "@tabler/icons-react";
|
||||
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
||||
import { useState } from "react";
|
||||
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
||||
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 }) {
|
||||
const [data, setData] = useState<MODEL_USER[]>(listUser.data);
|
||||
const [isActivePage, setActivePage] = useState(1);
|
||||
const [isNPage, setNPage] = useState(listUser.nPage);
|
||||
const [isSearch, setSearch] = useState("");
|
||||
const [isLoadingAccess, setIsLoadingAccess] = useState(false);
|
||||
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
||||
const [userId, setUserId] = useState("");
|
||||
|
||||
async function onAccess(id: string) {
|
||||
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
const value = await adminUserAccess_getListUser({
|
||||
page: 1,
|
||||
search: isSearch,
|
||||
});
|
||||
setData(value.data as any);
|
||||
setNPage(value.nPage);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
try {
|
||||
setUserId(id);
|
||||
setIsLoadingAccess(true);
|
||||
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
const value = await adminUserAccess_getListUser({
|
||||
page: 1,
|
||||
search: isSearch,
|
||||
});
|
||||
setData(value.data as any);
|
||||
setNPage(value.nPage);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
clientLogger.error("Error grand access", error);
|
||||
} finally {
|
||||
setIsLoadingAccess(false);
|
||||
setUserId("");
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelAccess(id: string) {
|
||||
await adminUserAccess_funEditAccess(id, false).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
const value = await adminUserAccess_getListUser({
|
||||
page: 1,
|
||||
search: isSearch,
|
||||
});
|
||||
setData(value.data as any);
|
||||
setNPage(value.nPage);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
async function onDelete(id: string) {
|
||||
try {
|
||||
setUserId(id);
|
||||
setIsLoadingDelete(true);
|
||||
await adminUserAccess_funEditAccess(id, false).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
const value = await adminUserAccess_getListUser({
|
||||
page: 1,
|
||||
search: isSearch,
|
||||
});
|
||||
setData(value.data as any);
|
||||
setNPage(value.nPage);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
clientLogger.error("Error delete access", error);
|
||||
} finally {
|
||||
setIsLoadingDelete(false);
|
||||
setUserId("");
|
||||
}
|
||||
}
|
||||
|
||||
async function onSearch(s: any) {
|
||||
@@ -91,22 +113,26 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
||||
{e.active === false ? (
|
||||
<Center>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingAccess && userId === e.id}
|
||||
radius={"xl"}
|
||||
color="Green"
|
||||
onClick={() => {
|
||||
onAccess(e.id);
|
||||
}}
|
||||
>
|
||||
Give Access
|
||||
Grand Access
|
||||
</Button>
|
||||
</Center>
|
||||
) : (
|
||||
<Center>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingDelete && userId === e.id}
|
||||
radius={"xl"}
|
||||
color="red"
|
||||
onClick={() => {
|
||||
onDelAccess(e.id);
|
||||
onDelete(e.id);
|
||||
}}
|
||||
>
|
||||
Delete Access
|
||||
|
||||
@@ -14,13 +14,15 @@ import {
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { redirect, useRouter } from "next/navigation";
|
||||
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({
|
||||
activationUser,
|
||||
userLoginId,
|
||||
}: {
|
||||
activationUser: boolean;
|
||||
userLoginId: string;
|
||||
userLoginId?: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -37,71 +39,61 @@ export default function WaitingRoom_View({
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (activationUser == true) {
|
||||
return redirect("/");
|
||||
}
|
||||
}, [activationUser]);
|
||||
const [data, setData] = useState<boolean | null>(null);
|
||||
|
||||
const listhHuruf = [
|
||||
{
|
||||
huruf: "H",
|
||||
},
|
||||
{
|
||||
huruf: "I",
|
||||
},
|
||||
{
|
||||
huruf: "P",
|
||||
},
|
||||
{
|
||||
huruf: "M",
|
||||
},
|
||||
{
|
||||
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>
|
||||
);
|
||||
useShallowEffect(() => {
|
||||
onLoadData();
|
||||
}, []);
|
||||
|
||||
async function onLoadData() {
|
||||
try {
|
||||
const respone = await apiGetACtivationUser();
|
||||
if (respone) {
|
||||
console.log(respone.data);
|
||||
setData(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get cookies user", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutDefault>
|
||||
<Center h={"100vh"}>
|
||||
<Stack align="center" spacing={50}>
|
||||
{/* {customLOader} */}
|
||||
<Stack justify="cneter" h={"90vh"} mt={"xl"}>
|
||||
<ComponentGlobal_CardStyles>
|
||||
{_.isNull(data) ? (
|
||||
<Stack>
|
||||
{Array.from(new Array(4)).map((e, i) => (
|
||||
<Skeleton key={i} h={20} w={"100%"} />
|
||||
))}
|
||||
</Stack>
|
||||
) : (
|
||||
<Stack align="center">
|
||||
<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 align="center" spacing={5}>
|
||||
<Title order={3} c={"white"}>
|
||||
Anda telah berhasil mendaftar,
|
||||
</Title>
|
||||
<Title order={3} c={"white"}>
|
||||
Mohon menunggu konfirmansi Admin !
|
||||
</Title>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
color="red"
|
||||
loaderPosition="center"
|
||||
loading={loading}
|
||||
radius={"xl"}
|
||||
onClick={() => onClickLogout()}
|
||||
>
|
||||
Keluar
|
||||
</Button>
|
||||
</Stack>
|
||||
</Center>
|
||||
{/* <Button
|
||||
color="red"
|
||||
loaderPosition="center"
|
||||
loading={loading}
|
||||
radius={"xl"}
|
||||
onClick={() => onClickLogout()}
|
||||
>
|
||||
Keluar
|
||||
</Button> */}
|
||||
</Stack>
|
||||
)}
|
||||
</ComponentGlobal_CardStyles>
|
||||
</Stack>
|
||||
</UIGlobal_LayoutDefault>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user