diff --git a/src/app/dev/admin/developer/loading.tsx b/src/app/dev/admin/developer/loading.tsx new file mode 100644 index 00000000..96547f3a --- /dev/null +++ b/src/app/dev/admin/developer/loading.tsx @@ -0,0 +1,9 @@ +import ComponentAdminGlobal_LoadingPage from "@/app_modules/admin/component/loading_admin_page"; + +export default async function Page() { + return ( + <> + + > + ); +} diff --git a/src/app/dev/admin/developer/page.tsx b/src/app/dev/admin/developer/page.tsx new file mode 100644 index 00000000..c69ae063 --- /dev/null +++ b/src/app/dev/admin/developer/page.tsx @@ -0,0 +1,15 @@ +import AdminDeveloper from "@/app_modules/admin/developer"; +import adminDeveloper_funGetListAllAdmin from "@/app_modules/admin/developer/fun/get/fun_get_list_all_admin"; +import adminDeveloper_funGetListAllUser from "@/app_modules/admin/developer/fun/get/fun_get_list_all_user"; +import _ from "lodash"; + +export default async function Page() { + const listUser = await adminDeveloper_funGetListAllUser(); + const listAdmin = await adminDeveloper_funGetListAllAdmin(); + + return ( + <> + + > + ); +} diff --git a/src/app/dev/auth/login/layout.tsx b/src/app/dev/auth/login/layout.tsx deleted file mode 100644 index 79a8e50e..00000000 --- a/src/app/dev/auth/login/layout.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { LayoutLogin } from "@/app_modules/auth"; -import React from "react"; - -export default async function Layout({ - children, -}: { - children: React.ReactNode; -}) { - return ( - <> - {children} - > - ); -} diff --git a/src/app/lib/router_admin/router_admin_developer.ts b/src/app/lib/router_admin/router_admin_developer.ts new file mode 100644 index 00000000..28c01626 --- /dev/null +++ b/src/app/lib/router_admin/router_admin_developer.ts @@ -0,0 +1,3 @@ +export const RouterAdminDeveloper = { + main: "/dev/admin/developer", +}; diff --git a/src/app_modules/admin/component/logout.tsx b/src/app_modules/admin/component/logout.tsx index 02e875f7..40caa8c6 100644 --- a/src/app_modules/admin/component/logout.tsx +++ b/src/app_modules/admin/component/logout.tsx @@ -1,7 +1,15 @@ "use client"; import { myConsole } from "@/app/fun/my_console"; import { ApiHipmi } from "@/app/lib/api"; -import { ActionIcon, Button, Group, Modal, Stack, Title } from "@mantine/core"; +import { + ActionIcon, + Button, + Group, + Loader, + Modal, + Stack, + Title, +} from "@mantine/core"; import { useRouter } from "next/navigation"; import { useAtom } from "jotai"; import { IconLogout } from "@tabler/icons-react"; @@ -16,6 +24,7 @@ import { useState } from "react"; export default function Admin_Logout() { const router = useRouter(); const [opened, { toggle }] = useDisclosure(false); + const [loading, setLoading] = useState(false); const [kodeId, setKodeId] = useAtom(gs_kodeId); const [loadingLogout, setLoadingLogout] = useState(false); @@ -34,15 +43,26 @@ export default function Admin_Logout() { return ( <> - + Anda yakin ingin keluar ? - + { + toggle(); + setLoading(false); + }} + radius={50} + > Batal - + {loading ? ( + + ) : ( + { + toggle(); + setLoading(true); + }} + /> + )} {/* Logout diff --git a/src/app_modules/admin/developer/fun/edit/fun_edit_user_akses_by_id.ts b/src/app_modules/admin/developer/fun/edit/fun_edit_user_akses_by_id.ts new file mode 100644 index 00000000..db032e37 --- /dev/null +++ b/src/app_modules/admin/developer/fun/edit/fun_edit_user_akses_by_id.ts @@ -0,0 +1,23 @@ +"use server"; + +import prisma from "@/app/lib/prisma"; +import { RouterAdminDeveloper } from "@/app/lib/router_admin/router_admin_developer"; +import { revalidatePath } from "next/cache"; + +export default async function adminDeveloper_funEditUserAksesById( + userId: string, + roleId: string +) { + const updt = await prisma.user.update({ + where: { + id: userId, + }, + data: { + masterUserRoleId: roleId, + }, + }); + + if (!updt) return { status: 400, message: "Gagal Update Akses" }; + revalidatePath(RouterAdminDeveloper.main); + return { status: 200, message: "Berhasil Update Akses" }; +} diff --git a/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts b/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts new file mode 100644 index 00000000..7cf6d885 --- /dev/null +++ b/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts @@ -0,0 +1,15 @@ +"use server" + +import prisma from "@/app/lib/prisma" + +export default async function adminDeveloper_funGetListAllAdmin() { + const data = await prisma.user.findMany({ + orderBy: { + updatedAt: "asc", + }, + where: { + masterUserRoleId: "2", + }, + }); + return data; +} \ No newline at end of file diff --git a/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts b/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts new file mode 100644 index 00000000..3de50a19 --- /dev/null +++ b/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts @@ -0,0 +1,15 @@ +"use server"; + +import prisma from "@/app/lib/prisma"; + +export default async function adminDeveloper_funGetListAllUser() { + const data = await prisma.user.findMany({ + orderBy: { + updatedAt: "asc", + }, + where: { + masterUserRoleId: "1", + }, + }); + return data; +} diff --git a/src/app_modules/admin/developer/index.tsx b/src/app_modules/admin/developer/index.tsx new file mode 100644 index 00000000..c2d49ac5 --- /dev/null +++ b/src/app_modules/admin/developer/index.tsx @@ -0,0 +1,232 @@ +"use client"; + +import { + Box, + Button, + Center, + Group, + Paper, + ScrollArea, + SimpleGrid, + Stack, + Table, + TextInput, + Title, +} from "@mantine/core"; +import ComponentAdminGlobal_HeaderTamplate from "../component/header_tamplate"; +import { MODEL_USER } from "@/app_modules/home/model/interface"; +import _ from "lodash"; +import { IconSearch } from "@tabler/icons-react"; +import { useState } from "react"; +import adminDeveloper_funEditUserAksesById from "./fun/edit/fun_edit_user_akses_by_id"; +import adminDeveloper_funGetListAllAdmin from "./fun/get/fun_get_list_all_admin"; +import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil"; +import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal"; +import adminDeveloper_funGetListAllUser from "./fun/get/fun_get_list_all_user"; + +export default function AdminDeveloper({ + listUser, + listAdmin, +}: { + listUser: MODEL_USER[]; + listAdmin: MODEL_USER[]; +}) { + const [dataUser, setDataUser] = useState(listUser); + const [dataAdmin, setDataAdmin] = useState(listAdmin); + + return ( + <> + + + + + + + + > + ); +} + +function TableAdmin({ + dataAdmin, + setDataAdmin, + setDataUser, +}: { + dataAdmin: MODEL_USER[]; + setDataAdmin: any; + setDataUser: any; +}) { + async function onAccess(id: string) { + await adminDeveloper_funEditUserAksesById(id, "1").then(async (res) => { + if (res.status === 200) { + await adminDeveloper_funGetListAllUser().then((val) => { + setDataUser(val); + }); + await adminDeveloper_funGetListAllAdmin().then((val) => { + setDataAdmin(val); + }); + ComponentGlobal_NotifikasiBerhasil(res.message); + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } + }); + } + + const tableBody = dataAdmin.map((e) => ( + + + {e.username} + + + {e.nomor} + + + + onAccess(e.id)}> + Delete Access + + + + + )); + + return ( + <> + + + Table Admin + } + radius={"xl"} + placeholder="Masukan username" + /> + + + + + + + Username + + + Nomor + + + Aksi + + + + {tableBody} + + + + > + ); +} + +function TableUser({ + dataUser, + setDataUser, + setDataAdmin, +}: { + dataUser: MODEL_USER[]; + setDataUser: any; + setDataAdmin: any; +}) { + async function onAccess(id: string) { + await adminDeveloper_funEditUserAksesById(id, "2").then(async (res) => { + if (res.status === 200) { + await adminDeveloper_funGetListAllUser().then((val) => { + setDataUser(val); + }); + await adminDeveloper_funGetListAllAdmin().then((val) => { + setDataAdmin(val); + }); + ComponentGlobal_NotifikasiBerhasil(res.message); + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } + }); + } + + const tableBody = dataUser.map((e) => ( + + + {e.username} + + + {e.nomor} + + + + onAccess(e.id)}> + Admin Access + + + + + )); + + return ( + <> + + + Table User + } + radius={"xl"} + placeholder="Masukan username" + /> + + + + + + + Username + + + Nomor + + + Aksi + + + + {tableBody} + + + + > + ); +} diff --git a/src/app_modules/admin/list_page.tsx b/src/app_modules/admin/list_page.tsx index cf051ac8..d7304746 100644 --- a/src/app_modules/admin/list_page.tsx +++ b/src/app_modules/admin/list_page.tsx @@ -1,3 +1,4 @@ +import { RouterAdminDeveloper } from "@/app/lib/router_admin/router_admin_developer"; import { RouterAdminEvent } from "@/app/lib/router_admin/router_admin_event"; import { RouterAdminForum } from "@/app/lib/router_admin/router_admin_forum"; import { RouterAdminJob } from "@/app/lib/router_admin/router_admin_job"; @@ -174,7 +175,7 @@ export const listAdminPage = [ { id: 99, name: "Developer", - path: RouterAdminDashboard.main_admin, + path: RouterAdminDeveloper.main, icon: , child: [], }, diff --git a/src/app_modules/admin/splash/splash.tsx b/src/app_modules/admin/splash/splash.tsx index 19f513f4..9fd04119 100644 --- a/src/app_modules/admin/splash/splash.tsx +++ b/src/app_modules/admin/splash/splash.tsx @@ -14,7 +14,7 @@ export default function SplashDashboardAdmin() { useShallowEffect(() => { setTimeout(() => { router.push(RouterAdminDashboard.main_admin); - setActive(0); + setActive(1); }, 2000); }, []); return ( diff --git a/src/app_modules/auth/login/view.tsx b/src/app_modules/auth/login/view.tsx index 485b71dc..a8dfc89f 100644 --- a/src/app_modules/auth/login/view.tsx +++ b/src/app_modules/auth/login/view.tsx @@ -79,67 +79,48 @@ export default function Login() { return ( <> - - - - - - - Selamat Datang di HIPMI App - - Silahkan masukan nomor telepon anda untuk masuk ! - - - - {/* - - - +62 - - - - { - setNomor(62 + val.target.value); - }} + + + + + - - */} + + + Selamat Datang di HIPMI App + + Silahkan masukan nomor telepon anda untuk masuk ! + + - { - setPhone(val); - }} - /> + { + setPhone(val); + }} + /> - { - onLogin(); - }} - loading={loading ? true : false} - loaderPosition="center" - > - LOGIN - - - + { + onLogin(); + }} + loading={loading ? true : false} + loaderPosition="center" + > + LOGIN + + + + > ); }