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 { 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}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
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";
|
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 });
|
||||||
}
|
}
|
||||||
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 (
|
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"}
|
||||||
|
|||||||
@@ -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: [],
|
||||||
|
|||||||
@@ -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,48 +17,67 @@ 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) {
|
||||||
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
|
try {
|
||||||
if (res.status === 200) {
|
setUserId(id);
|
||||||
const value = await adminUserAccess_getListUser({
|
setIsLoadingAccess(true);
|
||||||
page: 1,
|
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
|
||||||
search: isSearch,
|
if (res.status === 200) {
|
||||||
});
|
const value = await adminUserAccess_getListUser({
|
||||||
setData(value.data as any);
|
page: 1,
|
||||||
setNPage(value.nPage);
|
search: isSearch,
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
});
|
||||||
} else {
|
setData(value.data as any);
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
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) {
|
async function onDelete(id: string) {
|
||||||
await adminUserAccess_funEditAccess(id, false).then(async (res) => {
|
try {
|
||||||
if (res.status === 200) {
|
setUserId(id);
|
||||||
const value = await adminUserAccess_getListUser({
|
setIsLoadingDelete(true);
|
||||||
page: 1,
|
await adminUserAccess_funEditAccess(id, false).then(async (res) => {
|
||||||
search: isSearch,
|
if (res.status === 200) {
|
||||||
});
|
const value = await adminUserAccess_getListUser({
|
||||||
setData(value.data as any);
|
page: 1,
|
||||||
setNPage(value.nPage);
|
search: isSearch,
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
});
|
||||||
} else {
|
setData(value.data as any);
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
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) {
|
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
|
||||||
|
|||||||
@@ -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,71 +39,61 @@ 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>
|
||||||
|
{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}>
|
{/* <Button
|
||||||
<Title order={3} c={"white"}>
|
color="red"
|
||||||
Anda telah berhasil mendaftar,
|
loaderPosition="center"
|
||||||
</Title>
|
loading={loading}
|
||||||
<Title order={3} c={"white"}>
|
radius={"xl"}
|
||||||
Mohon menunggu konfirmansi Admin !
|
onClick={() => onClickLogout()}
|
||||||
</Title>
|
>
|
||||||
</Stack>
|
Keluar
|
||||||
|
</Button> */}
|
||||||
<Button
|
</Stack>
|
||||||
color="red"
|
)}
|
||||||
loaderPosition="center"
|
</ComponentGlobal_CardStyles>
|
||||||
loading={loading}
|
</Stack>
|
||||||
radius={"xl"}
|
|
||||||
onClick={() => onClickLogout()}
|
|
||||||
>
|
|
||||||
Keluar
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Center>
|
|
||||||
</UIGlobal_LayoutDefault>
|
</UIGlobal_LayoutDefault>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user