Merge pull request #54 from bipproduction/developer/create
Developer/create
This commit is contained in:
@@ -43,23 +43,23 @@ export async function GET(req: Request) {
|
||||
});
|
||||
}
|
||||
|
||||
// for (let i of userSeeder) {
|
||||
// await prisma.user.upsert({
|
||||
// where: {
|
||||
// nomor: i.nomor,
|
||||
// },
|
||||
// create: {
|
||||
// nomor: i.nomor,
|
||||
// username: i.name,
|
||||
// masterUserRoleId: i.masterUserRoleId,
|
||||
// },
|
||||
// update: {
|
||||
// nomor: i.nomor,
|
||||
// username: i.name,
|
||||
// masterUserRoleId: i.masterUserRoleId,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
for (let i of userSeeder) {
|
||||
await prisma.user.upsert({
|
||||
where: {
|
||||
nomor: i.nomor,
|
||||
},
|
||||
create: {
|
||||
nomor: i.nomor,
|
||||
username: i.name,
|
||||
masterUserRoleId: i.masterUserRoleId,
|
||||
},
|
||||
update: {
|
||||
nomor: i.nomor,
|
||||
username: i.name,
|
||||
masterUserRoleId: i.masterUserRoleId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
for (let i of bidangBisnis) {
|
||||
await prisma.masterBidangBisnis.upsert({
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { AdminLayout } from "@/app_modules/admin/main_dashboard";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { user_getOneById } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import React from "react";
|
||||
|
||||
export default async function Layout({
|
||||
@@ -6,9 +8,13 @@ export default async function Layout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const userId = await User_getUserId()
|
||||
const dataUser = await user_getOneById(userId)
|
||||
const userRole = dataUser?.masterUserRoleId
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminLayout>{children}</AdminLayout>
|
||||
<AdminLayout userRole={userRole as any}>{children}</AdminLayout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { user_getOneById } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import { redirect } from "next/navigation";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
|
||||
export default async function Page() {
|
||||
const userId = await User_getUserId();
|
||||
const dataUser = await user_getOneById(userId);
|
||||
|
||||
if (dataUser?.masterUserRoleId === "2" || dataUser?.masterUserRoleId === "3")
|
||||
return redirect(RouterAdminDashboard.splash_admin);
|
||||
// await new Promise((a, b) => {
|
||||
// setTimeout(a, 4000);
|
||||
// });
|
||||
|
||||
@@ -7,29 +7,30 @@ import { useAtom } from "jotai";
|
||||
import { IconLogout } from "@tabler/icons-react";
|
||||
import { Warna } from "@/app/lib/warna";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { gs_nomor, gs_otp } from "@/app_modules/auth/state/state";
|
||||
import { gs_kodeId, gs_nomor, gs_otp } from "@/app_modules/auth/state/state";
|
||||
import { auth_Logout } from "@/app_modules/auth/fun/fun_logout";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function Admin_Logout() {
|
||||
const router = useRouter();
|
||||
const [nomor, setnomor] = useAtom(gs_nomor);
|
||||
const [code, setCode] = useAtom(gs_otp);
|
||||
|
||||
const [opened, { toggle }] = useDisclosure(false);
|
||||
|
||||
const onLogout = async () => {
|
||||
router.push("/dev/auth/login");
|
||||
const [kodeId, setKodeId] = useAtom(gs_kodeId);
|
||||
const [loadingLogout, setLoadingLogout] = useState(false);
|
||||
|
||||
// await fetch(ApiHipmi.logout)
|
||||
// .then((res) => res.json())
|
||||
// .then((val) => {
|
||||
// if (val.status == 200) {
|
||||
// setnomor(null);
|
||||
// setCode(null);
|
||||
|
||||
// router.push("/dev/auth/login");
|
||||
// }
|
||||
// });
|
||||
};
|
||||
async function onClickLogout() {
|
||||
await auth_Logout(kodeId).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setLoadingLogout(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setKodeId("");
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -42,10 +43,12 @@ export default function Admin_Logout() {
|
||||
</Button>
|
||||
<Button
|
||||
compact
|
||||
loaderPosition="center"
|
||||
loading={loadingLogout ? true : false}
|
||||
radius={50}
|
||||
bg={Warna.merah}
|
||||
color="red"
|
||||
onClick={() => onLogout()}
|
||||
onClick={() => onClickLogout()}
|
||||
>
|
||||
Keluar
|
||||
</Button>
|
||||
|
||||
@@ -24,8 +24,10 @@ import React, { useState } from "react";
|
||||
import ComponentGlobal_HeaderTamplate from "../component_global/header_tamplate";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import {
|
||||
IconCheck,
|
||||
IconCircleDot,
|
||||
IconCircleDotFilled,
|
||||
IconDashboard,
|
||||
IconHome,
|
||||
IconLetterH,
|
||||
IconLogout,
|
||||
@@ -47,10 +49,16 @@ import _ from "lodash";
|
||||
import { listAdminPage } from "./list_page";
|
||||
import { RouterAdminVote } from "@/app/lib/router_admin/router_admin_vote";
|
||||
import { RouterAdminJob } from "@/app/lib/router_admin/router_admin_job";
|
||||
import { gs_kodeId } from "../auth/state/state";
|
||||
import { auth_Logout } from "../auth/fun/fun_logout";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "../component_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "../component_global/notif_global/notifikasi_peringatan";
|
||||
|
||||
export default function AdminLayout({
|
||||
userRole,
|
||||
children,
|
||||
}: {
|
||||
userRole: string;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const theme = useMantineTheme();
|
||||
@@ -59,6 +67,21 @@ export default function AdminLayout({
|
||||
const [active, setActive] = useAtom(gs_admin_hotMenu);
|
||||
const [activeChild, setActiveChild] = useAtom(gs_admin_subMenu);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [kodeId, setKodeId] = useAtom(gs_kodeId);
|
||||
|
||||
async function onClickLogout() {
|
||||
// await auth_Logout(kodeId).then((res) => {
|
||||
// ComponentGlobal_NotifikasiBerhasil("Berhasil Logout");
|
||||
// });
|
||||
await auth_Logout(kodeId).then((res) => {
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setKodeId("");
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const navbarItems = listAdminPage.map((e, i) => (
|
||||
<Box key={e.id}>
|
||||
@@ -117,6 +140,79 @@ export default function AdminLayout({
|
||||
</Box>
|
||||
));
|
||||
|
||||
const bukanDeveloper = listAdminPage.slice(0, -1);
|
||||
const notAdminDev = bukanDeveloper.map((e) => (
|
||||
<Box key={e.id}>
|
||||
<NavLink
|
||||
sx={{
|
||||
":hover": {
|
||||
backgroundColor: "transparent",
|
||||
},
|
||||
}}
|
||||
fw={active === e.id ? "bold" : "normal"}
|
||||
icon={
|
||||
// active === e.id ? loading ? <Loader size={10} /> : e.icon : e.icon
|
||||
e.icon
|
||||
}
|
||||
label={<Text size={"sm"}>{e.name}</Text>}
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
setActive(e.id);
|
||||
setActiveChild(null);
|
||||
e.path === "" ? router.push(e.child[0].path) : router.push(e.path);
|
||||
e.path === "" ? setActiveChild(e.child[0].id) : "";
|
||||
}}
|
||||
>
|
||||
{_.isEmpty(e.child) ? (
|
||||
""
|
||||
) : (
|
||||
<Box>
|
||||
{e.child.map((v, ii) => (
|
||||
<Box key={v.id}>
|
||||
<NavLink
|
||||
sx={{
|
||||
":hover": {
|
||||
backgroundColor: "transparent",
|
||||
},
|
||||
}}
|
||||
fw={activeChild === v.id ? "bold" : "normal"}
|
||||
label={<Text>{v.name}</Text>}
|
||||
icon={
|
||||
activeChild === v.id ? (
|
||||
<IconCircleDotFilled size={10} />
|
||||
) : (
|
||||
<IconCircleDot size={10} />
|
||||
)
|
||||
}
|
||||
onClick={() => {
|
||||
setActive(e.id);
|
||||
setActiveChild(v.id);
|
||||
router.push(v.path);
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
</NavLink>
|
||||
</Box>
|
||||
));
|
||||
|
||||
const navbarAdmin = (
|
||||
<Box>
|
||||
<NavLink
|
||||
c="orange"
|
||||
icon={<IconDashboard />}
|
||||
label="Developer"
|
||||
sx={{
|
||||
":hover": {
|
||||
backgroundColor: "transparent",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<AppShell
|
||||
@@ -132,7 +228,12 @@ export default function AdminLayout({
|
||||
p="xs"
|
||||
bg={"gray.2"}
|
||||
>
|
||||
{navbarItems}
|
||||
<Navbar.Section>
|
||||
<Stack>
|
||||
{userRole === "3" ? navbarItems : notAdminDev}
|
||||
{/* <NavLink icon={<IconCheck />} label="Create Admin" /> */}
|
||||
</Stack>
|
||||
</Navbar.Section>
|
||||
</Navbar>
|
||||
</MediaQuery>
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
RouterAdminDonasi,
|
||||
RouterAdminInvestasi,
|
||||
} from "@/app/lib/router_hipmi/router_admin";
|
||||
import { IconBriefcase, IconMessages } from "@tabler/icons-react";
|
||||
import { IconBriefcase, IconDashboard, IconMessages } from "@tabler/icons-react";
|
||||
import {
|
||||
IconHeartHandshake,
|
||||
IconHome,
|
||||
@@ -171,4 +171,11 @@ export const listAdminPage = [
|
||||
// },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 99,
|
||||
name: "Developer",
|
||||
path: RouterAdminDashboard.main_admin,
|
||||
icon: <IconDashboard />,
|
||||
child: [],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -5,6 +5,7 @@ import { randomOTP } from "./rondom_otp";
|
||||
|
||||
export async function auth_funLogin(nomor: string) {
|
||||
const codeOtp = randomOTP();
|
||||
console.log(nomor)
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
|
||||
@@ -21,6 +21,6 @@ export async function auth_Logout(kodeId: string) {
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal Hapus Kode OTP Id"};
|
||||
revalidatePath("/dev/katalog")
|
||||
// revalidatePath("/dev/katalog")
|
||||
return { status: 200, message: "Logout Berhasil" };
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export async function auth_funValidasi(nomor: string) {
|
||||
id: true,
|
||||
nomor: true,
|
||||
username: true,
|
||||
masterUserRoleId: true
|
||||
},
|
||||
});
|
||||
|
||||
@@ -42,5 +43,7 @@ export async function auth_funValidasi(nomor: string) {
|
||||
revalidatePath(RouterHome.main_home);
|
||||
}
|
||||
|
||||
return { status: 200, message: "Nomor Terverivikasi" };
|
||||
|
||||
|
||||
return { status: 200, message: "Nomor Terverivikasi", role: cek.masterUserRoleId };
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ export default function Login() {
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Nomor maximal 13 digit");
|
||||
|
||||
const nomorHp = phone.substring(1);
|
||||
// console.log(nomorHp)
|
||||
|
||||
await auth_funLogin(nomorHp).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setKodeId(res.kodeOtpId);
|
||||
router.push(RouterAuth.validasi + res.kodeOtpId);
|
||||
@@ -130,7 +132,6 @@ export default function Login() {
|
||||
color={"teal"}
|
||||
onClick={() => {
|
||||
onLogin();
|
||||
setLoading(true);
|
||||
}}
|
||||
loading={loading ? true : false}
|
||||
loaderPosition="center"
|
||||
|
||||
@@ -35,6 +35,7 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_glob
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { auth_funEditAktivasiKodeOtpById } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
|
||||
export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
const router = useRouter();
|
||||
@@ -85,8 +86,12 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
if (res.status === 200) {
|
||||
await auth_funEditAktivasiKodeOtpById(dataOtp.id).then((val) => {
|
||||
if (val.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterHome.main_home);
|
||||
if (res.role === "1") {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterHome.main_home);
|
||||
} else {
|
||||
router.push(RouterAdminDashboard.splash_admin)
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(val.message);
|
||||
}
|
||||
@@ -183,7 +188,7 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
color={"teal"}
|
||||
onClick={() => {
|
||||
onVerifikasi();
|
||||
setLoading(true)
|
||||
setLoading(true);
|
||||
}}
|
||||
>
|
||||
<Text>VERIFIKASI</Text>
|
||||
|
||||
@@ -10,6 +10,7 @@ export async function user_getOneById(userId: string) {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
masterUserRoleId: true,
|
||||
Profile: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { Logout } from "@/app_modules/auth";
|
||||
import { ActionIcon, AppShell, Group, Header, Text } from "@mantine/core";
|
||||
import {
|
||||
ActionIcon,
|
||||
AppShell,
|
||||
Group,
|
||||
Header,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import {
|
||||
IconUserSearch,
|
||||
IconAward,
|
||||
@@ -9,11 +16,14 @@ import {
|
||||
IconArrowLeft,
|
||||
IconPencilPlus,
|
||||
IconChevronLeft,
|
||||
IconDashboard,
|
||||
} from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import ComponentKatalog_HeaderTamplate from "../component/header_tamplate";
|
||||
import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { title } from "process";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
|
||||
export default function KatalogLayout({
|
||||
children,
|
||||
@@ -27,12 +37,34 @@ export default function KatalogLayout({
|
||||
<>
|
||||
<AppShell
|
||||
header={
|
||||
<ComponentKatalog_HeaderTamplate
|
||||
title="Katalog"
|
||||
bg={"black"}
|
||||
titleColor="white"
|
||||
// route={RouterHome.main_home}
|
||||
/>
|
||||
// <ComponentKatalog_HeaderTamplate
|
||||
// title="Katalog"
|
||||
// bg={"black"}
|
||||
// titleColor="white"
|
||||
// // route={RouterHome.main_home}
|
||||
// />
|
||||
<Header height={50} sx={{ borderStyle: "none" }} bg={"black"}>
|
||||
<Group h={50} position="apart" px={"md"}>
|
||||
<ActionIcon
|
||||
variant="transparent"
|
||||
onClick={() => {
|
||||
router.back();
|
||||
}}
|
||||
>
|
||||
<IconChevronLeft />
|
||||
</ActionIcon>
|
||||
<Title order={5} c={"white"}>
|
||||
Katalog
|
||||
</Title>
|
||||
<ActionIcon variant="transparent" disabled></ActionIcon>
|
||||
{/* <ActionIcon
|
||||
variant="transparent"
|
||||
onClick={() => router.push(RouterAdminDashboard.splash_admin)}
|
||||
>
|
||||
<IconDashboard />
|
||||
</ActionIcon> */}
|
||||
</Group>
|
||||
</Header>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[
|
||||
{
|
||||
"name": "Banuna",
|
||||
"name": "banuna",
|
||||
"nomor": "6282340374412",
|
||||
"masterUserRoleId": "1"
|
||||
"masterUserRoleId": "3"
|
||||
},
|
||||
{
|
||||
"name": "Firman",
|
||||
"name": "firman",
|
||||
"nomor": "6281339158911",
|
||||
"masterUserRoleId": "1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user