refactor(admin): replace raw form elements with shared Input, Textarea, and Switch components in RoleEditPage
This commit is contained in:
@@ -401,7 +401,7 @@ async function handleListRoles() {
|
||||
async function handleCreateRole(request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { name, description, color } = body;
|
||||
const { name, description, color, permissionKeys } = body;
|
||||
|
||||
if (!name || !String(name).trim()) {
|
||||
return apiError('Bad Request', 'Role name is required');
|
||||
@@ -413,7 +413,12 @@ async function handleCreateRole(request) {
|
||||
color: color ? String(color) : '#6b7280'
|
||||
});
|
||||
|
||||
return apiSuccess({ role });
|
||||
if (Array.isArray(permissionKeys) && permissionKeys.length > 0) {
|
||||
const updatedRole = await updateRole(role.id, { permissionKeys });
|
||||
return apiSuccess({ role: updatedRole });
|
||||
}
|
||||
|
||||
return apiSuccess({ role: { ...role, permission_keys: [] } });
|
||||
} catch (error) {
|
||||
if (error.message === 'Role name is required') return apiError('Bad Request', error.message);
|
||||
logAndObscureError(error, null);
|
||||
|
||||
Reference in New Issue
Block a user