feat: module system menu & module

This commit is contained in:
hanif salafi 2026-01-16 10:25:30 +07:00
parent 8b6d4ae00f
commit ddd82448a4
4248 changed files with 7354 additions and 769992 deletions

3
.env
View File

@ -1 +1,2 @@
NETIDHUB_CLIENT_KEY=b1ce6602-07ad-46c2-85eb-0cd6decfefa3
NETIDHUB_CLIENT_KEY=b1ce6602-07ad-46c2-85eb-0cd6decfefa3
NEXT_PUBLIC_API_URL=http://localhost:8080

2
.env.local Normal file
View File

@ -0,0 +1,2 @@
# API Configuration for Local Development
NEXT_PUBLIC_API_URL=http://localhost:8080/api/

View File

@ -0,0 +1,317 @@
"use client";
import React, { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { PlusIcon, SettingsIcon, MenuIcon, ModuleIcon } from "@/components/icons";
import {
MasterMenu,
MasterModule,
MenuModule,
getMasterMenus,
getMasterModules,
getMenuModulesByMenuId,
createMenuModulesBatch,
deleteMenuModule,
} from "@/service/menu-modules";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import SiteBreadcrumb from "@/components/site-breadcrumb";
import Swal from "sweetalert2";
export default function MenuSettingsPage() {
const [menus, setMenus] = useState<MasterMenu[]>([]);
const [modules, setModules] = useState<MasterModule[]>([]);
const [selectedMenu, setSelectedMenu] = useState<MasterMenu | null>(null);
const [menuModules, setMenuModules] = useState<MenuModule[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [selectedModuleIds, setSelectedModuleIds] = useState<number[]>([]);
useEffect(() => {
loadData();
}, []);
useEffect(() => {
if (selectedMenu) {
loadMenuModules(selectedMenu.id);
}
}, [selectedMenu]);
const loadData = async () => {
setIsLoading(true);
try {
const [menusRes, modulesRes] = await Promise.all([
getMasterMenus({ limit: 100 }),
getMasterModules({ limit: 100 }),
]);
if (!menusRes?.error) {
setMenus(menusRes?.data?.data || []);
}
if (!modulesRes?.error) {
setModules(modulesRes?.data?.data || []);
}
} catch (error) {
console.error("Error loading data:", error);
} finally {
setIsLoading(false);
}
};
const loadMenuModules = async (menuId: number) => {
try {
const res = await getMenuModulesByMenuId(menuId);
if (!res?.error) {
setMenuModules(res?.data?.data || []);
setSelectedModuleIds((res?.data?.data || []).map((mm: MenuModule) => mm.moduleId));
}
} catch (error) {
console.error("Error loading menu modules:", error);
}
};
const handleSaveModules = async () => {
if (!selectedMenu) return;
try {
// Delete existing menu modules
for (const menuModule of menuModules) {
await deleteMenuModule(menuModule.id);
}
// Create new menu modules in batch
if (selectedModuleIds.length > 0) {
const res = await createMenuModulesBatch({
menuId: selectedMenu.id,
moduleIds: selectedModuleIds,
});
if (res?.error) {
Swal.fire({
title: "Error",
text: res?.message || "Failed to save modules",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
} else {
Swal.fire({
title: "Success",
text: "Modules saved successfully",
icon: "success",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
await loadMenuModules(selectedMenu.id);
setIsDialogOpen(false);
}
}
} catch (error) {
console.error("Error saving modules:", error);
Swal.fire({
title: "Error",
text: "An unexpected error occurred",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
}
};
const toggleModuleSelection = (moduleId: number) => {
setSelectedModuleIds((prev) =>
prev.includes(moduleId)
? prev.filter((id) => id !== moduleId)
: [...prev, moduleId]
);
};
return (
<>
<SiteBreadcrumb />
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-gray-900">Menu Settings</h1>
<p className="text-gray-600 mt-2">
Manage menu and module associations
</p>
</div>
<MenuIcon className="h-6 w-6 text-gray-500" />
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Menu List */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<MenuIcon className="h-5 w-5" />
Menus
</CardTitle>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="text-center py-8">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"></div>
</div>
) : menus.length > 0 ? (
<div className="space-y-2">
{menus.map((menu) => (
<button
key={menu.id}
onClick={() => setSelectedMenu(menu)}
className={`w-full text-left p-3 rounded-lg border transition-colors ${
selectedMenu?.id === menu.id
? "bg-blue-50 border-blue-500 text-blue-900"
: "bg-white border-gray-200 hover:bg-gray-50"
}`}
>
<div className="font-medium">{menu.name}</div>
<div className="text-sm text-gray-500">{menu.description}</div>
</button>
))}
</div>
) : (
<div className="text-center py-8 text-gray-500">
No menus found
</div>
)}
</CardContent>
</Card>
{/* Selected Menu Modules */}
<Card className="lg:col-span-2">
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="flex items-center gap-2">
<ModuleIcon className="h-5 w-5" />
{selectedMenu ? `${selectedMenu.name} - Modules` : "Select a Menu"}
</CardTitle>
{selectedMenu && (
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<DialogTrigger asChild>
<Button className="flex items-center gap-2">
<PlusIcon className="h-4 w-4" />
Manage Modules
</Button>
</DialogTrigger>
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Manage Modules for {selectedMenu.name}</DialogTitle>
</DialogHeader>
<div className="space-y-4">
<div className="space-y-2">
{modules.map((module) => (
<label
key={module.id}
className="flex items-start gap-3 p-3 border rounded-lg hover:bg-gray-50 cursor-pointer"
>
<input
type="checkbox"
checked={selectedModuleIds.includes(module.id)}
onChange={() => toggleModuleSelection(module.id)}
className="mt-1"
/>
<div className="flex-1">
<div className="font-medium">{module.name}</div>
<div className="text-sm text-gray-500">{module.description}</div>
<div className="text-xs text-gray-400 mt-1">
{module.pathUrl} {module.actionType}
</div>
</div>
</label>
))}
</div>
<div className="flex items-center justify-end gap-2 pt-4 border-t">
<Button
variant="outline"
onClick={() => setIsDialogOpen(false)}
>
Cancel
</Button>
<Button onClick={handleSaveModules}>
Save Modules
</Button>
</div>
</div>
</DialogContent>
</Dialog>
)}
</div>
</CardHeader>
<CardContent>
{selectedMenu ? (
menuModules.length > 0 ? (
<div className="space-y-2">
{menuModules.map((menuModule) => (
<div
key={menuModule.id}
className="flex items-center justify-between p-3 border rounded-lg"
>
<div>
<div className="font-medium">
{menuModule.module?.name || `Module ${menuModule.moduleId}`}
</div>
<div className="text-sm text-gray-500">
{menuModule.module?.description || "No description"}
</div>
</div>
<div className="flex items-center gap-2">
{menuModule.position && (
<span className="px-2 py-1 text-xs bg-blue-100 text-blue-800 rounded-full">
Position: {menuModule.position}
</span>
)}
{menuModule.isActive ? (
<span className="px-2 py-1 text-xs bg-green-100 text-green-800 rounded-full">
Active
</span>
) : (
<span className="px-2 py-1 text-xs bg-gray-100 text-gray-800 rounded-full">
Inactive
</span>
)}
</div>
</div>
))}
</div>
) : (
<div className="text-center py-12 text-gray-500">
<ModuleIcon className="h-12 w-12 mx-auto mb-4 text-gray-400" />
<p>No modules assigned to this menu</p>
<Button
className="mt-4"
onClick={() => setIsDialogOpen(true)}
>
<PlusIcon className="h-4 w-4 mr-2" />
Add Modules
</Button>
</div>
)
) : (
<div className="text-center py-12 text-gray-500">
<MenuIcon className="h-12 w-12 mx-auto mb-4 text-gray-400" />
<p>Select a menu to view its modules</p>
</div>
)}
</CardContent>
</Card>
</div>
</div>
</>
);
}

View File

@ -0,0 +1,366 @@
"use client";
import React, { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { PlusIcon, ModuleIcon, EditIcon, DeleteIcon } from "@/components/icons";
import {
MasterModule,
getMasterModules,
createMasterModule,
updateMasterModule,
deleteMasterModule,
} from "@/service/menu-modules";
import SiteBreadcrumb from "@/components/site-breadcrumb";
import Swal from "sweetalert2";
import { FormField } from "@/components/form/common/FormField";
export default function ModulesSettingsPage() {
const [modules, setModules] = useState<MasterModule[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [editingModule, setEditingModule] = useState<MasterModule | null>(null);
const [formData, setFormData] = useState({
name: "",
description: "",
pathUrl: "",
actionType: "",
statusId: 1,
});
useEffect(() => {
loadData();
}, []);
const loadData = async () => {
setIsLoading(true);
try {
const res = await getMasterModules({ limit: 100 });
if (!res?.error) {
setModules(res?.data?.data || []);
}
} catch (error) {
console.error("Error loading modules:", error);
} finally {
setIsLoading(false);
}
};
const handleOpenDialog = (module?: MasterModule) => {
if (module) {
setEditingModule(module);
setFormData({
name: module.name,
description: module.description,
pathUrl: module.pathUrl,
actionType: module.actionType,
statusId: module.statusId,
});
} else {
setEditingModule(null);
setFormData({
name: "",
description: "",
pathUrl: "",
actionType: "",
statusId: 1,
});
}
setIsDialogOpen(true);
};
const handleSave = async () => {
try {
if (editingModule) {
const res = await updateMasterModule(editingModule.id, formData);
if (res?.error) {
Swal.fire({
title: "Error",
text: res?.message || "Failed to update module",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
} else {
Swal.fire({
title: "Success",
text: "Module updated successfully",
icon: "success",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
await loadData();
setIsDialogOpen(false);
}
} else {
const res = await createMasterModule(formData);
if (res?.error) {
Swal.fire({
title: "Error",
text: res?.message || "Failed to create module",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
} else {
Swal.fire({
title: "Success",
text: "Module created successfully",
icon: "success",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
await loadData();
setIsDialogOpen(false);
}
}
} catch (error) {
console.error("Error saving module:", error);
Swal.fire({
title: "Error",
text: "An unexpected error occurred",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
}
};
const handleDelete = async (module: MasterModule) => {
const result = await Swal.fire({
title: "Delete Module?",
text: `Are you sure you want to delete "${module.name}"? This action cannot be undone.`,
icon: "warning",
showCancelButton: true,
confirmButtonText: "Yes, delete it",
cancelButtonText: "Cancel",
customClass: {
popup: 'swal-z-index-9999'
}
});
if (result.isConfirmed) {
try {
const res = await deleteMasterModule(module.id);
if (res?.error) {
Swal.fire({
title: "Error",
text: res?.message || "Failed to delete module",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
} else {
Swal.fire({
title: "Deleted!",
text: "Module has been deleted.",
icon: "success",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
await loadData();
}
} catch (error) {
console.error("Error deleting module:", error);
Swal.fire({
title: "Error",
text: "An unexpected error occurred",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
}
}
};
return (
<>
<SiteBreadcrumb />
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-gray-900">Modules Settings</h1>
<p className="text-gray-600 mt-2">
Manage system modules and their configurations
</p>
</div>
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<DialogTrigger asChild>
<Button className="flex items-center gap-2" onClick={() => handleOpenDialog()}>
<PlusIcon className="h-4 w-4" />
Create Module
</Button>
</DialogTrigger>
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>
{editingModule ? `Edit Module: ${editingModule.name}` : "Create New Module"}
</DialogTitle>
</DialogHeader>
<div className="space-y-4">
<FormField
label="Module Name"
name="name"
type="text"
placeholder="e.g., View Articles, Create Content"
value={formData.name}
onChange={(value) => setFormData({ ...formData, name: value })}
required
/>
<FormField
label="Description"
name="description"
type="text"
placeholder="Brief description of the module"
value={formData.description}
onChange={(value) => setFormData({ ...formData, description: value })}
required
/>
<FormField
label="Path URL"
name="pathUrl"
type="text"
placeholder="e.g., /api/articles, /api/content"
value={formData.pathUrl}
onChange={(value) => setFormData({ ...formData, pathUrl: value })}
required
/>
<FormField
label="Action Type"
name="actionType"
type="select"
placeholder="Select action type"
value={formData.actionType}
onChange={(value) => setFormData({ ...formData, actionType: value })}
options={[
{ value: "view", label: "View" },
{ value: "create", label: "Create" },
{ value: "update", label: "Update" },
{ value: "delete", label: "Delete" },
{ value: "approve", label: "Approve" },
{ value: "reject", label: "Reject" },
]}
required
/>
<FormField
label="Status ID"
name="statusId"
type="number"
placeholder="1"
value={formData.statusId}
onChange={(value) => setFormData({ ...formData, statusId: Number(value) || 1 })}
required
/>
<div className="flex items-center justify-end gap-2 pt-4 border-t">
<Button
variant="outline"
onClick={() => setIsDialogOpen(false)}
>
Cancel
</Button>
<Button onClick={handleSave}>
{editingModule ? "Update" : "Create"} Module
</Button>
</div>
</div>
</DialogContent>
</Dialog>
</div>
{isLoading ? (
<div className="text-center py-12">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"></div>
<p className="mt-4 text-gray-600">Loading modules...</p>
</div>
) : modules.length > 0 ? (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{modules.map((module) => (
<Card key={module.id} className="hover:shadow-lg transition-shadow">
<CardHeader>
<CardTitle className="flex items-center justify-between">
<span className="truncate">{module.name}</span>
{module.isActive ? (
<span className="px-2 py-1 text-xs bg-green-100 text-green-800 rounded-full">
Active
</span>
) : (
<span className="px-2 py-1 text-xs bg-gray-100 text-gray-800 rounded-full">
Inactive
</span>
)}
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2 mb-4">
<div className="text-sm text-gray-600">{module.description}</div>
<div className="text-xs text-gray-500 font-mono bg-gray-50 p-2 rounded">
{module.pathUrl}
</div>
<div className="flex items-center gap-2">
<span className="px-2 py-1 text-xs bg-blue-100 text-blue-800 rounded-full">
{module.actionType}
</span>
</div>
</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
className="flex-1"
onClick={() => handleOpenDialog(module)}
>
<EditIcon className="h-4 w-4 mr-2" />
Edit
</Button>
<Button
variant="outline"
size="sm"
className="flex-1 text-red-600 hover:text-red-700 hover:bg-red-50"
onClick={() => handleDelete(module)}
>
<DeleteIcon className="h-4 w-4 mr-2" />
Delete
</Button>
</div>
</CardContent>
</Card>
))}
</div>
) : (
<Card>
<CardContent className="flex items-center justify-center py-12">
<div className="text-center">
<ModuleIcon className="h-12 w-12 text-gray-400 mx-auto mb-4" />
<h3 className="text-lg font-medium text-gray-900 mb-2">No Modules Found</h3>
<p className="text-gray-500 mb-4">
Create your first module to define system capabilities
</p>
<Button onClick={() => handleOpenDialog()}>
<PlusIcon className="h-4 w-4 mr-2" />
Create Module
</Button>
</div>
</CardContent>
</Card>
)}
</div>
</>
);
}

View File

@ -15,6 +15,16 @@ import {
getUserLevels,
getProvinces,
} from "@/service/approval-workflows";
import {
MasterModule,
getMasterModules,
} from "@/service/menu-modules";
import {
getUserLevelModuleAccessesByUserLevelId,
createUserLevelModuleAccessesBatch,
deleteUserLevelModuleAccess,
UserLevelModuleAccess,
} from "@/service/user-level-module-accesses";
import Swal from "sweetalert2";
interface UserLevelsFormProps {
@ -47,6 +57,9 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
const [bulkFormData, setBulkFormData] = useState<UserLevelsCreateRequest[]>([]);
const [userLevels, setUserLevels] = useState<UserLevel[]>([]);
const [provinces, setProvinces] = useState<Province[]>([]);
const [modules, setModules] = useState<MasterModule[]>([]);
const [selectedModuleIds, setSelectedModuleIds] = useState<number[]>([]);
const [userLevelModuleAccesses, setUserLevelModuleAccesses] = useState<UserLevelModuleAccess[]>([]);
const [errors, setErrors] = useState<Record<string, string>>({});
const [isSubmitting, setIsSubmitting] = useState(false);
const [expandedHierarchy, setExpandedHierarchy] = useState(false);
@ -62,13 +75,15 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
useEffect(() => {
const loadData = async () => {
try {
const [userLevelsRes, provincesRes] = await Promise.all([
const [userLevelsRes, provincesRes, modulesRes] = await Promise.all([
getUserLevels(),
getProvinces(),
getMasterModules({ limit: 100 }),
]);
if (!userLevelsRes?.error) setUserLevels(userLevelsRes?.data?.data || []);
if (!provincesRes?.error) setProvinces(provincesRes?.data?.data || []);
if (!modulesRes?.error) setModules(modulesRes?.data?.data || []);
} catch (error) {
console.error("Error loading form data:", error);
} finally {
@ -79,6 +94,25 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
loadData();
}, []);
useEffect(() => {
const loadModuleAccesses = async () => {
if (initialData && (initialData as any).id) {
try {
const res = await getUserLevelModuleAccessesByUserLevelId((initialData as any).id);
if (!res?.error) {
const accesses = res?.data?.data || [];
setUserLevelModuleAccesses(accesses);
setSelectedModuleIds(accesses.filter((a: UserLevelModuleAccess) => a.canAccess).map((a: UserLevelModuleAccess) => a.moduleId));
}
} catch (error) {
console.error("Error loading module accesses:", error);
}
}
};
loadModuleAccesses();
}, [initialData]);
const validateForm = (data: UserLevelsCreateRequest): Record<string, string> => {
const newErrors: Record<string, string> = {};
@ -314,6 +348,47 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
try {
if (onSave) {
if (currentMode === "single") {
// Save user level first
const userLevelResponse = await createUserLevel(formData);
if (userLevelResponse?.error) {
Swal.fire({
title: "Error",
text: userLevelResponse?.message || "Failed to create user level",
icon: "error",
confirmButtonText: "OK",
customClass: {
popup: 'swal-z-index-9999'
}
});
setIsSubmitting(false);
return;
}
// Get the created user level ID
const createdUserLevelId = userLevelResponse?.data?.data?.id || (initialData as any)?.id;
if (createdUserLevelId && selectedModuleIds.length > 0) {
// Delete existing module accesses if editing
if ((initialData as any)?.id) {
for (const access of userLevelModuleAccesses) {
await deleteUserLevelModuleAccess(access.id);
}
}
// Create new module accesses in batch
const moduleAccessResponse = await createUserLevelModuleAccessesBatch({
userLevelId: createdUserLevelId,
moduleIds: selectedModuleIds,
canAccess: true,
});
if (moduleAccessResponse?.error) {
console.error("Error saving module accesses:", moduleAccessResponse?.message);
// Don't fail the whole operation, just log the error
}
}
onSave(formData);
} else {
// For bulk mode, save each item individually
@ -371,6 +446,31 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
}
});
} else {
// Get the created user level ID
const createdUserLevelId = response?.data?.data?.id || (initialData as any)?.id;
// Save module accesses if any selected
if (createdUserLevelId && selectedModuleIds.length > 0) {
// Delete existing module accesses if editing
if ((initialData as any)?.id) {
for (const access of userLevelModuleAccesses) {
await deleteUserLevelModuleAccess(access.id);
}
}
// Create new module accesses in batch
const moduleAccessResponse = await createUserLevelModuleAccessesBatch({
userLevelId: createdUserLevelId,
moduleIds: selectedModuleIds,
canAccess: true,
});
if (moduleAccessResponse?.error) {
console.error("Error saving module accesses:", moduleAccessResponse?.message);
// Don't fail the whole operation, just log the error
}
}
Swal.fire({
title: "Success",
text: "User level created successfully",
@ -507,8 +607,9 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
)}
<Tabs value={activeTab} onValueChange={handleTabChange} className="w-full">
<TabsList className="grid w-full grid-cols-3">
<TabsList className="grid w-full grid-cols-4">
<TabsTrigger value="basic" disabled={isLoadingData}>Basic Information</TabsTrigger>
<TabsTrigger value="modules" disabled={isLoadingData || mode === "bulk"}>Module Access</TabsTrigger>
{/* <TabsTrigger value="hierarchy" disabled={isLoadingData}>Hierarchy</TabsTrigger> */}
<TabsTrigger value="bulk" disabled={isLoadingData}>Bulk Operations</TabsTrigger>
</TabsList>
@ -657,6 +758,54 @@ export const UserLevelsForm: React.FC<UserLevelsFormProps> = ({
</Card>
</TabsContent> */}
{/* Module Access Tab */}
<TabsContent value="modules" className="space-y-6">
<Card>
<CardHeader>
<CardTitle>Module Access Configuration</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<p className="text-sm text-gray-600">
Select which modules this user level can access. Only selected modules will be accessible to users with this level.
</p>
{modules.length > 0 ? (
<div className="space-y-2 max-h-96 overflow-y-auto border rounded-lg p-4">
{modules.map((module) => (
<label
key={module.id}
className="flex items-start gap-3 p-3 border rounded-lg hover:bg-gray-50 cursor-pointer"
>
<input
type="checkbox"
checked={selectedModuleIds.includes(module.id)}
onChange={() => {
setSelectedModuleIds((prev) =>
prev.includes(module.id)
? prev.filter((id) => id !== module.id)
: [...prev, module.id]
);
}}
className="mt-1"
/>
<div className="flex-1">
<div className="font-medium">{module.name}</div>
<div className="text-sm text-gray-500">{module.description}</div>
<div className="text-xs text-gray-400 mt-1">
{module.pathUrl} {module.actionType}
</div>
</div>
</label>
))}
</div>
) : (
<div className="text-center py-8 text-gray-500">
No modules available
</div>
)}
</CardContent>
</Card>
</TabsContent>
{/* Bulk Operations Tab */}
<TabsContent value="bulk" className="space-y-6">
<Card>

View File

@ -2938,6 +2938,63 @@ export const UsersIcon = ({ size = 24, width, height, ...props }: IconSvgProps)
</svg>
);
export const MenuIcon = ({ size = 24, width, height, ...props }: IconSvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size || width}
height={size || height}
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<line x1="3" y1="12" x2="21" y2="12" />
<line x1="3" y1="6" x2="21" y2="6" />
<line x1="3" y1="18" x2="21" y2="18" />
</svg>
);
export const ModuleIcon = ({ size = 24, width, height, ...props }: IconSvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size || width}
height={size || height}
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="3" y="3" width="7" height="7" />
<rect x="14" y="3" width="7" height="7" />
<rect x="14" y="14" width="7" height="7" />
<rect x="3" y="14" width="7" height="7" />
</svg>
);
export const EditIcon = ({ size = 24, width, height, ...props }: IconSvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size || width}
height={size || height}
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
</svg>
);
export const WorkflowIcon = ({ size = 24, width, height, ...props }: IconSvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"

View File

@ -3894,6 +3894,20 @@ export function getMenuList(pathname: string, t: any): Group[] {
icon: "heroicons:arrow-trending-up",
children: [],
},
{
href: "/admin/settings/menu",
label: "Menu Settings",
active: pathname === "/admin/settings/menu",
icon: "heroicons:bars-3",
children: [],
},
{
href: "/admin/settings/modules",
label: "Modules Settings",
active: pathname === "/admin/settings/modules",
icon: "heroicons:puzzle-piece",
children: [],
},
// {
// href: "/admin/settings/tag",
// label: "Tag",

View File

@ -4102,6 +4102,20 @@ export function getMenuList(pathname: string, t: any): Group[] {
icon: "heroicons:arrow-trending-up",
children: [],
},
{
href: "/admin/settings/menu",
label: "Menu Settings",
active: pathname === "/admin/settings/menu",
icon: "heroicons:bars-3",
children: [],
},
{
href: "/admin/settings/modules",
label: "Modules Settings",
active: pathname === "/admin/settings/modules",
icon: "heroicons:puzzle-piece",
children: [],
},
// {
// href: "/admin/settings/tag",
// label: "Tag",

View File

@ -1,6 +1,7 @@
import axios from "axios";
const baseURL = "https://kontenhumas.com/api/";
// Use environment variable for API URL, default to localhost:8080 for local development
const baseURL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api/";
const axiosBaseInstance = axios.create({
baseURL,

View File

@ -2,7 +2,8 @@ import axios from "axios";
import Cookies from "js-cookie";
import { getCsrfToken, login } from "../auth";
const baseURL = "https://kontenhumas.com/api/";
// Use environment variable for API URL, default to localhost:8080 for local development
const baseURL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api/";
const refreshToken = Cookies.get("refresh_token");

228
service/menu-modules.ts Normal file
View File

@ -0,0 +1,228 @@
import {
httpPostInterceptor,
httpGetInterceptor,
httpPutInterceptor,
httpDeleteInterceptor,
} from "./http-config/http-interceptor-service";
// Types
export interface MasterMenu {
id: number;
name: string;
description: string;
moduleId: number;
parentMenuId?: number;
group: string;
icon?: string;
statusId: number;
isActive: boolean;
position?: number;
createdAt?: string;
updatedAt?: string;
}
export interface MasterModule {
id: number;
name: string;
description: string;
pathUrl: string;
actionType: string;
statusId: number;
isActive: boolean;
createdAt?: string;
updatedAt?: string;
}
export interface MenuModule {
id: number;
menuId: number;
moduleId: number;
position?: number;
isActive: boolean;
menu?: MasterMenu;
module?: MasterModule;
createdAt?: string;
updatedAt?: string;
}
export interface MenuModuleCreateRequest {
menuId: number;
moduleId: number;
position?: number;
isActive?: boolean;
}
export interface MenuModuleBatchCreateRequest {
menuId: number;
moduleIds: number[];
}
export interface MenuModuleUpdateRequest {
menuId?: number;
moduleId?: number;
position?: number;
isActive?: boolean;
}
// API Functions
export async function getMenuModules(params?: {
menuId?: number;
moduleId?: number;
page?: number;
limit?: number;
}) {
const queryParams = new URLSearchParams();
if (params?.menuId) queryParams.append("menu_id", params.menuId.toString());
if (params?.moduleId) queryParams.append("module_id", params.moduleId.toString());
if (params?.page) queryParams.append("page", params.page.toString());
if (params?.limit) queryParams.append("limit", params.limit.toString());
const url = `menu-modules${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
return httpGetInterceptor(url);
}
export async function getMenuModuleById(id: number) {
const url = `menu-modules/${id}`;
return httpGetInterceptor(url);
}
export async function getMenuModulesByMenuId(menuId: number) {
const url = `menu-modules/menu/${menuId}`;
return httpGetInterceptor(url);
}
export async function getMenuModulesByModuleId(moduleId: number) {
const url = `menu-modules/module/${moduleId}`;
return httpGetInterceptor(url);
}
export async function createMenuModule(data: MenuModuleCreateRequest) {
const url = "menu-modules";
return httpPostInterceptor(url, data);
}
export async function createMenuModulesBatch(data: MenuModuleBatchCreateRequest) {
const url = "menu-modules/batch";
return httpPostInterceptor(url, data);
}
export async function updateMenuModule(id: number, data: MenuModuleUpdateRequest) {
const url = `menu-modules/${id}`;
return httpPutInterceptor(url, data);
}
export async function deleteMenuModule(id: number) {
const url = `menu-modules/${id}`;
return httpDeleteInterceptor(url);
}
// Master Menus API
export async function getMasterMenus(params?: {
name?: string;
description?: string;
moduleId?: number;
parentMenuId?: number;
statusId?: number;
page?: number;
limit?: number;
}) {
const queryParams = new URLSearchParams();
if (params?.name) queryParams.append("name", params.name);
if (params?.description) queryParams.append("description", params.description);
if (params?.moduleId) queryParams.append("moduleId", params.moduleId.toString());
if (params?.parentMenuId) queryParams.append("parentMenuId", params.parentMenuId.toString());
if (params?.statusId) queryParams.append("statusId", params.statusId.toString());
if (params?.page) queryParams.append("page", params.page.toString());
if (params?.limit) queryParams.append("limit", params.limit.toString());
const url = `master-menus${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
return httpGetInterceptor(url);
}
export async function getMasterMenuById(id: number) {
const url = `master-menus/${id}`;
return httpGetInterceptor(url);
}
export async function createMasterMenu(data: {
name: string;
description: string;
moduleId: number;
group: string;
statusId: number;
parentMenuId?: number;
icon?: string;
}) {
const url = "master-menus";
return httpPostInterceptor(url, data);
}
export async function updateMasterMenu(id: number, data: {
name: string;
description: string;
moduleId: number;
group: string;
statusId: number;
parentMenuId?: number;
icon?: string;
}) {
const url = `master-menus/${id}`;
return httpPutInterceptor(url, data);
}
export async function deleteMasterMenu(id: number) {
const url = `master-menus/${id}`;
return httpDeleteInterceptor(url);
}
// Master Modules API
export async function getMasterModules(params?: {
name?: string;
description?: string;
statusId?: number;
page?: number;
limit?: number;
}) {
const queryParams = new URLSearchParams();
if (params?.name) queryParams.append("name", params.name);
if (params?.description) queryParams.append("description", params.description);
if (params?.statusId) queryParams.append("statusId", params.statusId.toString());
if (params?.page) queryParams.append("page", params.page.toString());
if (params?.limit) queryParams.append("limit", params.limit.toString());
const url = `master-modules${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
return httpGetInterceptor(url);
}
export async function getMasterModuleById(id: number) {
const url = `master-modules/${id}`;
return httpGetInterceptor(url);
}
export async function createMasterModule(data: {
name: string;
description: string;
pathUrl: string;
actionType: string;
statusId: number;
}) {
const url = "master-modules";
return httpPostInterceptor(url, data);
}
export async function updateMasterModule(id: number, data: {
name: string;
description: string;
pathUrl: string;
actionType: string;
statusId: number;
}) {
const url = `master-modules/${id}`;
return httpPutInterceptor(url, data);
}
export async function deleteMasterModule(id: number) {
const url = `master-modules/${id}`;
return httpDeleteInterceptor(url);
}

View File

@ -0,0 +1,108 @@
import {
httpPostInterceptor,
httpGetInterceptor,
httpPutInterceptor,
httpDeleteInterceptor,
} from "./http-config/http-interceptor-service";
import { MasterModule } from "./menu-modules";
// Types
export interface UserLevelModuleAccess {
id: number;
userLevelId: number;
moduleId: number;
canAccess: boolean;
isActive: boolean;
module?: MasterModule;
createdAt?: string;
updatedAt?: string;
}
export interface UserLevelModuleAccessCreateRequest {
userLevelId: number;
moduleId: number;
canAccess?: boolean;
isActive?: boolean;
}
export interface UserLevelModuleAccessBatchCreateRequest {
userLevelId: number;
moduleIds: number[];
canAccess?: boolean;
}
export interface UserLevelModuleAccessUpdateRequest {
userLevelId?: number;
moduleId?: number;
canAccess?: boolean;
isActive?: boolean;
}
export interface CheckAccessRequest {
userLevelId: number;
moduleId: number;
}
export interface CheckAccessResponse {
hasAccess: boolean;
}
// API Functions
export async function getUserLevelModuleAccesses(params?: {
userLevelId?: number;
moduleId?: number;
canAccess?: boolean;
page?: number;
limit?: number;
}) {
const queryParams = new URLSearchParams();
if (params?.userLevelId) queryParams.append("user_level_id", params.userLevelId.toString());
if (params?.moduleId) queryParams.append("module_id", params.moduleId.toString());
if (params?.canAccess !== undefined) queryParams.append("can_access", params.canAccess.toString());
if (params?.page) queryParams.append("page", params.page.toString());
if (params?.limit) queryParams.append("limit", params.limit.toString());
const url = `user-level-module-accesses${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
return httpGetInterceptor(url);
}
export async function getUserLevelModuleAccessById(id: number) {
const url = `user-level-module-accesses/${id}`;
return httpGetInterceptor(url);
}
export async function getUserLevelModuleAccessesByUserLevelId(userLevelId: number) {
const url = `user-level-module-accesses/user-level/${userLevelId}`;
return httpGetInterceptor(url);
}
export async function getUserLevelModuleAccessesByModuleId(moduleId: number) {
const url = `user-level-module-accesses/module/${moduleId}`;
return httpGetInterceptor(url);
}
export async function createUserLevelModuleAccess(data: UserLevelModuleAccessCreateRequest) {
const url = "user-level-module-accesses";
return httpPostInterceptor(url, data);
}
export async function createUserLevelModuleAccessesBatch(data: UserLevelModuleAccessBatchCreateRequest) {
const url = "user-level-module-accesses/batch";
return httpPostInterceptor(url, data);
}
export async function updateUserLevelModuleAccess(id: number, data: UserLevelModuleAccessUpdateRequest) {
const url = `user-level-module-accesses/${id}`;
return httpPutInterceptor(url, data);
}
export async function deleteUserLevelModuleAccess(id: number) {
const url = `user-level-module-accesses/${id}`;
return httpDeleteInterceptor(url);
}
export async function checkAccess(data: CheckAccessRequest) {
const url = "user-level-module-accesses/check-access";
return httpPostInterceptor(url, data);
}

View File

@ -1,16 +0,0 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=`cygpath -w "$basedir"`
fi
;;
esac
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
else
exec node "$basedir/../typescript/bin/tsc" "$@"
fi

View File

@ -1,17 +0,0 @@
@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\typescript\bin\tsc" %*

View File

@ -1,28 +0,0 @@
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/node$exe" "$basedir/../typescript/bin/tsc" $args
} else {
& "$basedir/node$exe" "$basedir/../typescript/bin/tsc" $args
}
$ret=$LASTEXITCODE
} else {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$basedir/../typescript/bin/tsc" $args
} else {
& "node$exe" "$basedir/../typescript/bin/tsc" $args
}
$ret=$LASTEXITCODE
}
exit $ret

View File

@ -1,16 +0,0 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=`cygpath -w "$basedir"`
fi
;;
esac
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
else
exec node "$basedir/../typescript/bin/tsserver" "$@"
fi

View File

@ -1,17 +0,0 @@
@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\typescript\bin\tsserver" %*

View File

@ -1,28 +0,0 @@
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/node$exe" "$basedir/../typescript/bin/tsserver" $args
} else {
& "$basedir/node$exe" "$basedir/../typescript/bin/tsserver" $args
}
$ret=$LASTEXITCODE
} else {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$basedir/../typescript/bin/tsserver" $args
} else {
& "node$exe" "$basedir/../typescript/bin/tsserver" $args
}
$ret=$LASTEXITCODE
}
exit $ret

Some files were not shown because too many files have changed in this diff Show More