fix: sidebar

This commit is contained in:
Sabda Yagra 2025-10-07 12:10:34 +07:00
parent 8ff369e34a
commit 0077e22717
3 changed files with 265 additions and 182 deletions

View File

@ -15,7 +15,6 @@ import {
useReactTable,
} from "@tanstack/react-table";
import { Button } from "@/components/ui/button";
import {
Table,
TableBody,
@ -46,7 +45,9 @@ import {
import { Checkbox } from "@/components/ui/checkbox";
import { close, loading } from "@/config/swal";
import { Link, useRouter } from "@/i18n/routing";
import { AdministrationUserList } from "@/service/service/management-user/management-user";
import { getAllUsers } from "@/service/management-user/management-user";
// ✅ Import service baru dari Swagger
const UserInternalTable = () => {
const router = useRouter();
@ -69,11 +70,11 @@ const UserInternalTable = () => {
pageSize: Number(showData),
});
const [search, setSearch] = React.useState("");
const [categoryFilter, setCategoryFilter] = React.useState<number[]>([]);
const [statusFilter, setStatusFilter] = React.useState<number[]>([]);
const [page, setPage] = React.useState(1);
const [totalPage, setTotalPage] = React.useState(1);
const table = useReactTable({
data: dataTable,
columns,
@ -131,31 +132,41 @@ const UserInternalTable = () => {
});
}, [page, showData]);
// === 🔥 Implementasi service getAllUsers dari Swagger ===
async function fetchData() {
try {
loading();
const res = await AdministrationUserList(
String(levelId),
page - 1,
search,
showData,
"1",
statusFilter?.sort().join(",")
);
const data = res?.data?.data;
const contentData = data?.content ?? [];
const res = await getAllUsers({
count: 1,
limit: Number(showData),
nextPage: page + 1,
page: page,
previousPage: page - 1,
sort: "desc",
sortBy: "id",
totalPage: 10,
});
const data = res?.data;
const contentData = Array.isArray(data)
? data
: data?.content || data?.items || [];
// Tambahkan nomor urut
contentData.forEach((item: any, index: number) => {
item.no = (page - 1) * Number(showData) + index + 1;
});
console.log("contentData : ", contentData);
console.log("📦 contentData:", contentData);
setDataTable(contentData);
setTotalData(data?.totalElements ?? 0);
setTotalPage(data?.totalPages ?? 0);
setTotalData(data?.totalElements ?? contentData.length ?? 0);
setTotalPage(data?.totalPages ?? 1);
close();
} catch (error) {
console.error("Error fetching tasks:", error);
console.error("❌ Error fetching users:", error);
close();
}
}
@ -336,6 +347,8 @@ const UserInternalTable = () => {
</Popover>
</div>
</div>
{/* === TABLE === */}
<Table className="overflow-hidden">
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
@ -377,6 +390,7 @@ const UserInternalTable = () => {
)}
</TableBody>
</Table>
<TablePagination
table={table}
totalData={totalData}

View File

@ -31,7 +31,7 @@ export type Group = {
};
export function getMenuList(pathname: string, t: any): Group[] {
const roleId = getCookiesDecrypt("urie");
const roleId = Number(getCookiesDecrypt("urie"));
const levelNumber = getCookiesDecrypt("ulne");
const userLevelId = getCookiesDecrypt("ulie");
const userParentLevelId = getCookiesDecrypt("uplie");
@ -55,49 +55,72 @@ export function getMenuList(pathname: string, t: any): Group[] {
},
],
},
{
groupLabel: "Content Management",
id: "content",
menus: [
{
id: "content",
href: "/admin/content/image",
label: "Content",
active: pathname.includes("/content"),
icon: "line-md:youtube",
submenus: [
{
href: "/admin/content/image",
label: "Image",
active: pathname.includes("/content/image"),
icon: "ic:outline-image",
children: [],
},
{
href: "/admin/content/audio-visual",
label: "Audio Visual",
active: pathname.includes("/content/audio-visual"),
icon: "line-md:youtube",
children: [],
},
{
href: "/admin/content/document",
label: "Document",
active: pathname.includes("/content/document"),
icon: "heroicons:document",
children: [],
},
{
href: "/admin/content/audio",
label: "Audio",
active: pathname.includes("/content/audio"),
icon: "heroicons:share",
children: [],
},
],
},
],
},
...(roleId === 2
? [
{
groupLabel: "Content Management",
id: "content",
menus: [
{
id: "content",
href: "/admin/content/image",
label: "Content",
active: pathname.includes("/content"),
icon: "line-md:youtube",
submenus: [
{
href: "/admin/content/image",
label: "Image",
active: pathname.includes("/content/image"),
icon: "ic:outline-image",
children: [],
},
{
href: "/admin/content/audio-visual",
label: "Audio Visual",
active: pathname.includes("/content/audio-visual"),
icon: "line-md:youtube",
children: [],
},
{
href: "/admin/content/document",
label: "Document",
active: pathname.includes("/content/document"),
icon: "heroicons:document",
children: [],
},
{
href: "/admin/content/audio",
label: "Audio",
active: pathname.includes("/content/audio"),
icon: "heroicons:share",
children: [],
},
],
},
],
},
]
: []),
...(roleId === 3
? [
{
groupLabel: "",
id: "management-user",
menus: [
{
id: "management-user-menu",
href: "/admin/management-user",
label: "Management User",
active: pathname.includes("/management-user"),
icon: "clarity:users-solid",
submenus: [],
},
],
},
]
: []),
// {
// groupLabel: "Master Data",
// id: "master-data",
@ -120,127 +143,150 @@ export function getMenuList(pathname: string, t: any): Group[] {
// },
// ],
// },
{
groupLabel: "",
id: "agenda-setting",
menus: [
{
id: "agenda-setting",
href: "/admin/agenda-setting",
label: t("agenda-setting"),
active: pathname.includes("/agenda-setting"),
icon: "iconoir:journal-page",
submenus: [],
},
],
},
{
groupLabel: "",
id: "schedule",
menus: [
{
id: "schedule",
href: "/admin/schedule",
label: t("schedule"),
active: pathname.includes("/schedule"),
icon: "uil:schedule",
submenus: [
{
href: "/admin/schedule/live-report",
label: t("live-report"),
active: pathname.includes("/schedule/live-report"),
icon: "heroicons:arrow-trending-up",
children: [],
},
// {
// href: "/contributor/schedule/press-conference",
// label: t("press-conference"),
// active: pathname.includes("/schedule/press-conference"),
// icon: "heroicons:arrow-trending-up",
// children: [],
// },
// {
// href: "/contributor/schedule/event",
// label: "event",
// active: pathname.includes("/schedule/event"),
// icon: "heroicons:shopping-cart",
// children: [],
// },
// {
// href: "/contributor/schedule/press-release",
// label: t("press-release"),
// active: pathname.includes("/schedule/press-release"),
// icon: "heroicons:shopping-cart",
// children: [],
// },
// {
// href: "/contributor/schedule/calendar-polri",
// label: t("calendar-polri"),
// active: pathname.includes("/schedule/calendar-polri"),
// icon: "heroicons:arrow-trending-up",
// children: [],
// },
],
},
],
},
{
groupLabel: "",
id: "task",
menus: [
{
id: "task",
href: "/admin/task",
label: t("task"),
active: pathname.includes("/task"),
icon: "fluent:clipboard-task-add-24-regular",
submenus: [],
},
],
},
{
groupLabel: "",
id: "communication",
menus: [
{
id: "communication",
href: "/admin/shared/communication",
label: t("communication"),
active: pathname.includes("/communication"),
icon: "token:chat",
submenus: [],
},
],
},
{
groupLabel: "Settings",
id: "settings",
menus: [
{
id: "settings",
href: "/admin/settings",
label: "Settings",
active: pathname.includes("/settings"),
icon: "heroicons:cog-6-tooth",
submenus: [
{
href: "/admin/categories",
label: "Categories",
active: pathname.includes("/categories"),
icon: "ic:outline-image",
children: [],
},
{
href: "/admin/settings/tenant",
label: "Tenant",
active: pathname.includes("/tenant"),
icon: "ic:outline-image",
children: [],
},
],
},
],
},
// {
// groupLabel: "",
// id: "agenda-setting",
// menus: [
// {
// id: "agenda-setting",
// href: "/admin/agenda-setting",
// label: t("agenda-setting"),
// active: pathname.includes("/agenda-setting"),
// icon: "iconoir:journal-page",
// submenus: [],
// },
// ],
// },
// {
// groupLabel: "",
// id: "schedule",
// menus: [
// {
// id: "schedule",
// href: "/admin/schedule",
// label: t("schedule"),
// active: pathname.includes("/schedule"),
// icon: "uil:schedule",
// submenus: [
// {
// href: "/admin/schedule/live-report",
// label: t("live-report"),
// active: pathname.includes("/schedule/live-report"),
// icon: "heroicons:arrow-trending-up",
// children: [],
// },
// // {
// // href: "/contributor/schedule/press-conference",
// // label: t("press-conference"),
// // active: pathname.includes("/schedule/press-conference"),
// // icon: "heroicons:arrow-trending-up",
// // children: [],
// // },
// // {
// // href: "/contributor/schedule/event",
// // label: "event",
// // active: pathname.includes("/schedule/event"),
// // icon: "heroicons:shopping-cart",
// // children: [],
// // },
// // {
// // href: "/contributor/schedule/press-release",
// // label: t("press-release"),
// // active: pathname.includes("/schedule/press-release"),
// // icon: "heroicons:shopping-cart",
// // children: [],
// // },
// // {
// // href: "/contributor/schedule/calendar-polri",
// // label: t("calendar-polri"),
// // active: pathname.includes("/schedule/calendar-polri"),
// // icon: "heroicons:arrow-trending-up",
// // children: [],
// // },
// ],
// },
// ],
// },
// {
// groupLabel: "",
// id: "task",
// menus: [
// {
// id: "task",
// href: "/admin/task",
// label: t("task"),
// active: pathname.includes("/task"),
// icon: "fluent:clipboard-task-add-24-regular",
// submenus: [],
// },
// ],
// },
// {
// groupLabel: "",
// id: "communication",
// menus: [
// {
// id: "communication",
// href: "/admin/shared/communication",
// label: t("communication"),
// active: pathname.includes("/communication"),
// icon: "token:chat",
// submenus: [],
// },
// ],
// },
...(roleId === 3
? [
{
groupLabel: "",
id: "tenant",
menus: [
{
id: "tenant",
href: "/admin/settings/tenant",
label: "Tenant",
active: pathname.includes("/tenant"),
icon: "token:chat",
submenus: [],
},
],
},
]
: []),
...(roleId === 2
? [
{
groupLabel: "Settings",
id: "settings",
menus: [
{
id: "settings",
href: "/admin/settings",
label: "Settings",
active: pathname.includes("/settings"),
icon: "heroicons:cog-6-tooth",
submenus: [
{
href: "/admin/categories",
label: "Categories",
active: pathname.includes("/categories"),
icon: "ic:outline-image",
children: [],
},
// kalau nanti Tenant mau dimunculkan lagi:
// {
// href: "/admin/settings/tenant",
// label: "Tenant",
// active: pathname.includes("/tenant"),
// icon: "ic:outline-image",
// children: [],
// },
],
},
],
},
]
: []),
];
return menusSelected;
}

View File

@ -21,6 +21,29 @@ export async function AdministrationUserList(
return httpGetInterceptor(url);
}
export async function getAllUsers({
count = 1,
limit = 10,
nextPage = 1,
page = 1,
previousPage = 1,
sort = "desc",
sortBy = "id",
totalPage = 10,
}: {
count?: number;
limit?: number;
nextPage?: number;
page?: number;
previousPage?: number;
sort?: string;
sortBy?: string;
totalPage?: number;
}) {
const url = `users?count=${count}&limit=${limit}&nextPage=${nextPage}&page=${page}&previousPage=${previousPage}&sort=${sort}&sortBy=${sortBy}&totalPage=${totalPage}`;
return httpGetInterceptor(url);
}
export async function AdministrationLevelList() {
const url = "users/user-levels/list";
return httpGetInterceptor(url);