From 0a16dbe20ae96f6066fa52b115af60ca5116f033 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Thu, 12 Jun 2025 20:23:22 +0700 Subject: [PATCH] fix:role menu --- app/(admin)/settings/page.tsx | 7 +- components/form/login.tsx | 11 +- components/form/settings/profile.tsx | 16 +- components/layout/sidebar/sidebar-mobile.tsx | 285 ++++++++++++++++-- components/layout/sidebar/sidebar.tsx | 289 ++++++++++++++++++- components/table/article-table.tsx | 25 +- 6 files changed, 571 insertions(+), 62 deletions(-) diff --git a/app/(admin)/settings/page.tsx b/app/(admin)/settings/page.tsx index 9f6d307..69d900d 100644 --- a/app/(admin)/settings/page.tsx +++ b/app/(admin)/settings/page.tsx @@ -2,18 +2,21 @@ import PasswordForm from "@/components/form/settings/password"; import ProfileForm from "@/components/form/settings/profile"; import { close, loading } from "@/config/swal"; -import { getProfile } from "@/services/master-user"; +import { getDetailMasterUsers, getProfile } from "@/services/master-user"; import { Tab, Tabs } from "@heroui/react"; +import Cookies from "js-cookie"; import { useEffect, useState } from "react"; export default function Settings() { const [profile, setProfile] = useState(); + const uid = Cookies.get("uie"); useEffect(() => { initFetch(); }, []); const initFetch = async () => { loading(); - const profile = await getProfile(); + const profile = await getDetailMasterUsers(String(uid)); + // const profile = await getProfile(); setProfile(profile?.data?.data); close(); }; diff --git a/components/form/login.tsx b/components/form/login.tsx index 12dfd58..45834b2 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -139,10 +139,7 @@ export default function Login() { // Cookies.set("username", profile?.data?.data?.username, { // expires: 1, // }); - // Cookies.set("urie", profile?.data?.data?.roleId, { - // expires: 1, - // }); - // Cookies.set("roleName", profile?.data?.data?.roleName, { + // Cookies.set("urie", profile?.data?.data?.userRoleId, { // expires: 1, // }); // Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { @@ -151,9 +148,9 @@ export default function Login() { // Cookies.set("ulne", profile?.data?.data?.userLevelId, { // expires: 1, // }); - // Cookies.set("urce", profile?.data?.data?.roleCode, { - // expires: 1, - // }); + // // Cookies.set("urce", profile?.data?.data?.roleCode, { + // // expires: 1, + // // }); // Cookies.set("email", profile?.data?.data?.email, { // expires: 1, // }); diff --git a/components/form/settings/profile.tsx b/components/form/settings/profile.tsx index d5ceb13..b3b6a48 100644 --- a/components/form/settings/profile.tsx +++ b/components/form/settings/profile.tsx @@ -26,18 +26,10 @@ const formSchema = z.object({ .min(2, { message: "Harus diisi", }), - nrp: z.string().min(1, { - message: "Harus diisi", - }), - address: z.string().min(1, { - message: "Harus diisi", - }), - gender: z.string().min(1, { - message: "Harus diisi", - }), - phoneNumber: z.string().min(1, { - message: "Harus diisi", - }), + nrp: z.string().optional(), + address: z.string().optional(), + gender: z.string().optional(), + phoneNumber: z.string().optional(), }); export default function ProfileForm(props: { diff --git a/components/layout/sidebar/sidebar-mobile.tsx b/components/layout/sidebar/sidebar-mobile.tsx index 7b9e3cd..32de173 100644 --- a/components/layout/sidebar/sidebar-mobile.tsx +++ b/components/layout/sidebar/sidebar-mobile.tsx @@ -59,7 +59,7 @@ interface SidebarProps { updateSidebarData: (newData: boolean) => void; } -const sidebarOtherRole = [ +const sidebarLevel3 = [ { id: 1, name: "Dashboard", @@ -134,7 +134,7 @@ const sidebarOtherRole = [ }, ]; -const sideBarDummyData = [ +const sidebarLevel2 = [ { id: 1, name: "Dashboard", @@ -263,6 +263,197 @@ const sideBarDummyData = [ statusName: "Active", childModule: null, }, + + { + id: 5, + name: "Master", + moduleId: 652, + moduleName: "Dashboard", + isGroup: true, + modulePathUrl: "/admin/basic", + parentId: -1, + icon: "table", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + + { + id: 11, + name: "Master Static Page", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/static-page", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 8, + name: "Master User", + moduleId: 654, + moduleName: "Form Vertical", + modulePathUrl: "/admin/master-user", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 23, + name: "Master User Level", + moduleId: 656, + moduleName: "Form Validation", + modulePathUrl: "/admin/user-level", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, +]; + +const sidebarLevel1 = [ + { + id: 1, + name: "Dashboard", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/dashboard", + isGroup: true, + parentId: -1, + icon: "dashboard", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 2, + name: "Dashboard", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/dashboard", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 3, + name: "Apps", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/basic", + isGroup: true, + parentId: -1, + icon: "table", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 4, + name: "Artikel", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/article", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 30, + name: "Kategori", + moduleId: 654, + moduleName: "Master", + modulePathUrl: "/admin/master-category", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 6, + name: "Majalah", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/magazine", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 33, + name: "Advertise", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/advertise", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 34, + name: "Kritik & Saran", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/feedbacks", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 35, + name: "Komentar", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/comment", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + // { // id: 4, // name: "E-Magazine", @@ -388,6 +579,7 @@ const SidebarMobile: React.FC = ({ updateSidebarData }) => { const username = Cookies.get("username"); const isAuthenticated = Cookies.get("is_authenticated"); const roles = Cookies.get("ulie"); + const rolesId = Cookies.get("urie"); useEffect(() => { if (!token) { @@ -451,8 +643,8 @@ const SidebarMobile: React.FC = ({ updateSidebarData }) => { - {roles?.includes("mabes") || username?.includes("mabes") - ? sideBarDummyData?.map((list: any, index: number) => + {rolesId === "1" + ? sidebarLevel1?.map((list: any, index: number) => list.isGroup ? (

= ({ updateSidebarData }) => { ) : list.childMenu?.length < 1 ? ( isOpen ? ( - {/*

*/}
= ({ updateSidebarData }) => { /> ) ) - : sidebarOtherRole?.map((list: any, index: number) => + : rolesId === "2" + ? sidebarLevel2?.map((list: any, index: number) => list.isGroup ? (

= ({ updateSidebarData }) => { ) : list.childMenu?.length < 1 ? ( isOpen ? ( - {/*

*/}
= ({ updateSidebarData }) => { placement="right" delay={0} closeDelay={0} + key={list.name} + > + +
+ {list.icon} {isOpen && list.name} +
+ + + ) + ) : ( + ( + + )), + ]} + /> + ) + ) + : sidebarLevel3?.map((list: any, index: number) => + list.isGroup ? ( +

+ {isOpen ? list.name : "..."} +

+ ) : list.childMenu?.length < 1 ? ( + isOpen ? ( + +
+ {list.icon} {isOpen && list.name} +
+ + ) : ( +
void; } -const sidebarOtherRole = [ +const sidebarLevel3 = [ { id: 1, name: "Dashboard", @@ -135,7 +135,197 @@ const sidebarOtherRole = [ }, ]; -const sideBarDummyData = [ +const sidebarLevel2 = [ + { + id: 1, + name: "Dashboard", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/dashboard", + isGroup: true, + parentId: -1, + icon: "dashboard", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 2, + name: "Dashboard", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/dashboard", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 3, + name: "Apps", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/basic", + isGroup: true, + parentId: -1, + icon: "table", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 4, + name: "Artikel", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/article", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 30, + name: "Kategori", + moduleId: 654, + moduleName: "Master", + modulePathUrl: "/admin/master-category", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 6, + name: "Majalah", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/magazine", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 33, + name: "Advertise", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/advertise", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 34, + name: "Kritik & Saran", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/feedbacks", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 35, + name: "Komentar", + moduleId: 652, + moduleName: "Apps", + modulePathUrl: "/admin/comment", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + + { + id: 5, + name: "Master", + moduleId: 652, + moduleName: "Dashboard", + isGroup: true, + modulePathUrl: "/admin/basic", + parentId: -1, + icon: "table", + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + + { + id: 11, + name: "Master Static Page", + moduleId: 652, + moduleName: "Dashboard", + modulePathUrl: "/admin/static-page", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 8, + name: "Master User", + moduleId: 654, + moduleName: "Form Vertical", + modulePathUrl: "/admin/master-user", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, + { + id: 23, + name: "Master User Level", + moduleId: 656, + moduleName: "Form Validation", + modulePathUrl: "/admin/user-level", + parentId: -1, + icon: , + position: 1, + statusId: 1, + childMenu: [], + statusName: "Active", + childModule: null, + }, +]; + +const sidebarLevel1 = [ { id: 1, name: "Dashboard", @@ -390,6 +580,7 @@ const Sidebar: React.FC = ({ updateSidebarData }) => { const username = Cookies.get("username"); const isAuthenticated = Cookies.get("is_authenticated"); const roles = Cookies.get("ulie"); + const rolesId = Cookies.get("urie"); useEffect(() => { if (!token) { @@ -415,7 +606,7 @@ const Sidebar: React.FC = ({ updateSidebarData }) => { }`} >
@@ -453,8 +644,8 @@ const Sidebar: React.FC = ({ updateSidebarData }) => {
- {roles?.includes("mabes") || username?.includes("mabes") - ? sideBarDummyData?.map((list: any, index: number) => + {rolesId === "1" + ? sidebarLevel1?.map((list: any, index: number) => list.isGroup ? (

= ({ updateSidebarData }) => { /> ) ) - : sidebarOtherRole?.map((list: any, index: number) => + : rolesId === "2" + ? sidebarLevel2?.map((list: any, index: number) => + list.isGroup ? ( +

+ {isOpen ? list.name : "..."} +

+ ) : list.childMenu?.length < 1 ? ( + isOpen ? ( + + {/*
*/} +
+ {list.icon} {isOpen && list.name} +
+ + ) : ( + + +
+ {list.icon} {isOpen && list.name} +
+ +
+ ) + ) : ( + ( + + )), + ]} + /> + ) + ) + : sidebarLevel3?.map((list: any, index: number) => list.isGroup ? (

= ({ updateSidebarData }) => { placement="right" delay={0} closeDelay={0} + key={list.id} >

= ({ updateSidebarData }) => {
@@ -651,13 +918,13 @@ const Sidebar: React.FC = ({ updateSidebarData }) => { )} {isOpen ? (
- +
- + {textEllipsis(String(username), 18)} onLogout()} > Logout @@ -677,7 +944,7 @@ const Sidebar: React.FC = ({ updateSidebarData }) => { } gap-2 items-center text-zinc-600 dark:text-zinc-400 hover:font-semibold hover:text-zinc-700 dark:hover:text-zinc-300`} onClick={toggleSidebar} > - + )} diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index 6f6864d..62500b9 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -63,7 +63,7 @@ import makeAnimated from "react-select/animated"; const columns = [ { name: "No", uid: "no" }, { name: "Judul", uid: "title" }, - { name: "Banner", uid: "isBanner" }, + // { name: "Banner", uid: "isBanner" }, { name: "Kategori", uid: "category" }, { name: "Tanggal Unggah", uid: "createdAt" }, { name: "Kreator", uid: "createdByName" }, @@ -96,6 +96,7 @@ export default function ArticleTable() { const username = Cookies.get("username"); const userId = Cookies.get("uie"); const animatedComponents = makeAnimated(); + const roleId = Cookies.get("urie"); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); @@ -339,13 +340,13 @@ export default function ArticleTable() { - {(username?.includes("mabes") || + {((roleId && Number(roleId) < 3) || Number(userId) === article.createdById) && ( @@ -353,14 +354,14 @@ export default function ArticleTable() { )} - handleBanner(article?.id, !article?.isBanner) } - className={username?.includes("mabes") ? "" : "hidden"} + className={roleId && Number(roleId) < 3 ? "" : "hidden"} > - {username?.includes("mabes") && ( + {roleId && Number(roleId) < 3 && ( <> {article?.isBanner @@ -368,18 +369,18 @@ export default function ArticleTable() { : "Jadikan Banner"} )} - + */} handleDelete(article.id)} className={ - username?.includes("mabes") || + (roleId && Number(roleId) < 3) || Number(userId) === article.createdById ? "" : "hidden" } > - {(username?.includes("mabes") || + {((roleId && Number(roleId) < 3) || Number(userId) === article.createdById) && ( <> {" "} @@ -517,7 +518,7 @@ export default function ArticleTable() { // }} />
- {username?.includes("mabes") && ( + {roleId && Number(roleId) < 3 && (

Author

@@ -636,7 +637,9 @@ export default function ArticleTable() { }} > {(column) => ( {column.name}