From 0b40accc49fa98459dcb2884f1ccf98740933ad5 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Tue, 11 Feb 2025 13:53:55 +0700 Subject: [PATCH] feat:executive create user form --- .../management-user/internal/create/page.tsx | 4 + components/partials/auth/login-form.tsx | 105 ++++++++++++++---- lib/menus.ts | 35 +++++- 3 files changed, 120 insertions(+), 24 deletions(-) diff --git a/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx b/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx index c89159eb..34b6b2d5 100644 --- a/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx @@ -232,6 +232,10 @@ export default function CreateUserForm() { id: "ADM-ID", name: "Admin", }, + { + id: "EXE-ID", + name: "Eksekutif", + }, { id: "APP-ID", name: "Approver", diff --git a/components/partials/auth/login-form.tsx b/components/partials/auth/login-form.tsx index 16a4595c..7df97dcf 100644 --- a/components/partials/auth/login-form.tsx +++ b/components/partials/auth/login-form.tsx @@ -21,7 +21,9 @@ import { useTranslations } from "next-intl"; // Schema validasi menggunakan zod const schema = z.object({ username: z.string().min(1, { message: "Judul diperlukan" }), - password: z.string().min(4, { message: "Password must be at least 4 characters." }), + password: z + .string() + .min(4, { message: "Password must be at least 4 characters." }), }); // Tipe untuk form values @@ -37,7 +39,9 @@ const LoginForm = () => { const t = useTranslations("LandingPage"); const togglePasswordType = () => { - setPasswordType((prevType) => (prevType === "password" ? "text" : "password")); + setPasswordType((prevType) => + prevType === "password" ? "text" : "password" + ); }; const { @@ -86,18 +90,29 @@ const LoginForm = () => { const profile = await getProfile(access_token); console.log("PROFILE : ", profile?.data?.data); - if (profile?.data?.data?.isInternational == true || profile?.data?.data?.isActive == false || profile?.data?.data?.isDelete == true) { + if ( + profile?.data?.data?.isInternational == true || + profile?.data?.data?.isActive == false || + profile?.data?.data?.isDelete == true + ) { Object.keys(Cookies.get()).forEach((cookieName) => { Cookies.remove(cookieName); }); - warning("Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri", "/auth/login"); + warning( + "Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri", + "/auth/login" + ); } else { Cookies.set("home_path", profile?.data?.data?.homePath, { expires: 1, }); - Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { - expires: 1, - }); + Cookies.set( + "profile_picture", + profile?.data?.data?.profilePictureUrl, + { + expires: 1, + } + ); Cookies.set("state", profile?.data?.data?.userLevel?.name, { expires: 1, }); @@ -113,12 +128,20 @@ const LoginForm = () => { setCookiesEncrypt("ulie", profile?.data?.data?.userLevel?.id, { expires: 1, }); - setCookiesEncrypt("uplie", profile?.data?.data?.userLevel?.parentLevelId, { - expires: 1, - }); - setCookiesEncrypt("ulne", profile?.data?.data?.userLevel?.levelNumber, { - expires: 1, - }); + setCookiesEncrypt( + "uplie", + profile?.data?.data?.userLevel?.parentLevelId, + { + expires: 1, + } + ); + setCookiesEncrypt( + "ulne", + profile?.data?.data?.userLevel?.levelNumber, + { + expires: 1, + } + ); setCookiesEncrypt("ufne", profile?.data?.data?.fullname, { expires: 1, }); @@ -128,7 +151,7 @@ const LoginForm = () => { setCookiesEncrypt("uinse", profile?.data?.data?.instituteId, { expires: 1, }); - + console.log("ssaddd", profile?.data?.data?.roleId); if ( Number(profile?.data?.data?.roleId) == 2 || Number(profile?.data?.data?.roleId) == 3 || @@ -136,9 +159,19 @@ const LoginForm = () => { Number(profile?.data?.data?.roleId) == 9 || Number(profile?.data?.data?.roleId) == 10 || Number(profile?.data?.data?.roleId) == 11 || - Number(profile?.data?.data?.roleId) == 12 + Number(profile?.data?.data?.roleId) == 12 || + Number(profile?.data?.data?.roleId) == 18 ) { - if (profile?.data?.data?.userLevel?.id == 761 || profile?.data?.data?.userLevel?.parentLevelId == 761) { + if (profile?.data?.data?.roleId === 18) { + window.location.href = "/in/dashboard/executive"; + // router.push('/admin/dashboard'); + Cookies.set("status", "login", { + expires: 1, + }); + } else if ( + profile?.data?.data?.userLevel?.id == 761 || + profile?.data?.data?.userLevel?.parentLevelId == 761 + ) { window.location.href = "/in/welcome"; Cookies.set("status", "login", { expires: 1, @@ -182,7 +215,11 @@ const LoginForm = () => { "border-destructive": errors.username, })} /> - {errors.username?.message &&
{errors.username.message}
} + {errors.username?.message && ( +
+ {errors.username.message} +
+ )}
@@ -190,12 +227,33 @@ const LoginForm = () => { {t("password")}
- -
- {passwordType === "password" ? : } + +
+ {passwordType === "password" ? ( + + ) : ( + + )}
- {errors.password?.message &&
{errors.password.message}
} + {errors.password?.message && ( +
+ {errors.password.message} +
+ )}
@@ -203,7 +261,10 @@ const LoginForm = () => {
- + {t("forgotPass")}
diff --git a/lib/menus.ts b/lib/menus.ts index c40a7468..ed6bce18 100644 --- a/lib/menus.ts +++ b/lib/menus.ts @@ -1607,7 +1607,10 @@ export function getMenuList(pathname: string, t: any): Group[] { ], }, ]; - } else if ((Number(roleId) == 3 || Number(roleId) == 4) && Number(levelNumber) == 2) { + } else if ( + (Number(roleId) == 3 || Number(roleId) == 4) && + Number(levelNumber) == 2 + ) { if (Number(userLevelId) != 761) { menusSelected = [ { @@ -1955,7 +1958,10 @@ export function getMenuList(pathname: string, t: any): Group[] { }, ]; } - } else if ((Number(roleId) == 3 || Number(roleId) == 4) && Number(levelNumber) == 3) { + } else if ( + (Number(roleId) == 3 || Number(roleId) == 4) && + Number(levelNumber) == 3 + ) { if (Number(userParentLevelId) != 761) { menusSelected = [ { @@ -3188,6 +3194,31 @@ export function getMenuList(pathname: string, t: any): Group[] { }, ]; } + } else if (Number(roleId) === 18) { + menusSelected = [ + { + groupLabel: t("apps"), + id: "dashboard", + menus: [ + { + id: "dashboard", + href: "/dashboard", + label: t("dashboard"), + active: pathname.includes("/dashboard"), + icon: "material-symbols:dashboard", + submenus: [ + { + href: "/dashboard/executive", + label: "Executive", + active: pathname === "/dashboard/executive", + icon: "heroicons:arrow-trending-up", + children: [], + }, + ], + }, + ], + }, + ]; } return menusSelected;