refactor: make UpdateRoleRequest fields optional, disable auto-code generation in EditRoleModal, and update WorkflowDefinitionModal to use role code as value
This commit is contained in:
parent
eefd4f995a
commit
1054e69caa
@ -15,15 +15,15 @@ import type { Role, UpdateRoleRequest } from "@/types/role";
|
||||
import { useAppSelector } from "@/hooks/redux-hooks";
|
||||
|
||||
// Utility function to generate code from name
|
||||
const generateCodeFromName = (name: string): string => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s]/g, "") // Remove special characters except spaces
|
||||
.replace(/\s+/g, "_") // Replace spaces with underscores
|
||||
.replace(/_+/g, "_") // Replace multiple underscores with single underscore
|
||||
.replace(/^_|_$/g, ""); // Remove leading/trailing underscores
|
||||
};
|
||||
// const generateCodeFromName = (name: string): string => {
|
||||
// return name
|
||||
// .toLowerCase()
|
||||
// .trim()
|
||||
// .replace(/[^a-z0-9\s]/g, "") // Remove special characters except spaces
|
||||
// .replace(/\s+/g, "_") // Replace spaces with underscores
|
||||
// .replace(/_+/g, "_") // Replace multiple underscores with single underscore
|
||||
// .replace(/^_|_$/g, ""); // Remove leading/trailing underscores
|
||||
// };
|
||||
|
||||
// All available resources
|
||||
const ALL_RESOURCES = [
|
||||
@ -124,7 +124,7 @@ export const EditRoleModal = ({
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
watch,
|
||||
// watch,
|
||||
reset,
|
||||
setError,
|
||||
clearErrors,
|
||||
@ -136,15 +136,16 @@ export const EditRoleModal = ({
|
||||
},
|
||||
});
|
||||
|
||||
const nameValue = watch("name");
|
||||
// const nameValue = watch("name");
|
||||
|
||||
// Auto-generate code from name
|
||||
useEffect(() => {
|
||||
if (nameValue) {
|
||||
const generatedCode = generateCodeFromName(nameValue);
|
||||
setValue("code", generatedCode, { shouldValidate: true });
|
||||
}
|
||||
}, [nameValue, setValue]);
|
||||
// Auto-generate code from name - Only during creation (handled in parent or different component)
|
||||
// For EditRoleModal, we want to keep the code unchanged.
|
||||
// useEffect(() => {
|
||||
// if (nameValue) {
|
||||
// const generatedCode = generateCodeFromName(nameValue);
|
||||
// setValue("code", generatedCode, { shouldValidate: true });
|
||||
// }
|
||||
// }, [nameValue, setValue]);
|
||||
|
||||
// Build available resources and actions based on user permissions
|
||||
const availableResourcesAndActions = useMemo(() => {
|
||||
@ -352,8 +353,9 @@ export const EditRoleModal = ({
|
||||
|
||||
clearErrors();
|
||||
try {
|
||||
const { code, ...rest } = data;
|
||||
const submitData = {
|
||||
...data,
|
||||
...rest,
|
||||
// For super_admin, always include tenant_id if defaultTenantId is provided
|
||||
tenant_id: isSuperAdmin
|
||||
? defaultTenantId || undefined
|
||||
|
||||
@ -525,7 +525,7 @@ export const WorkflowDefinitionModal = ({
|
||||
if (response.success) {
|
||||
return {
|
||||
options: response.data.map((r: any) => ({
|
||||
value: r.name,
|
||||
value: r.code,
|
||||
label: r.name,
|
||||
})),
|
||||
pagination: response.pagination,
|
||||
|
||||
@ -55,9 +55,9 @@ export interface GetRoleResponse {
|
||||
}
|
||||
|
||||
export interface UpdateRoleRequest {
|
||||
name: string;
|
||||
code: string;
|
||||
description: string;
|
||||
name?: string;
|
||||
code?: string;
|
||||
description?: string;
|
||||
tenant_id?: string | null;
|
||||
module_ids?: string[] | null;
|
||||
modules?: string[] | null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user