fix/crosstable-trustee
This commit is contained in:
parent
891d1dc944
commit
4620cc2b99
2 changed files with 28 additions and 17 deletions
|
|
@ -420,20 +420,23 @@ export function useFeatureAccess() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a user's roles in a feature instance
|
* Update a user's roles and active flag in a feature instance
|
||||||
*/
|
*/
|
||||||
const updateInstanceUserRoles = useCallback(async (
|
const updateInstanceUserRoles = useCallback(async (
|
||||||
mandateId: string,
|
mandateId: string,
|
||||||
instanceId: string,
|
instanceId: string,
|
||||||
userId: string,
|
userId: string,
|
||||||
roleIds: string[]
|
payload: { roleIds: string[]; enabled?: boolean }
|
||||||
): Promise<{ success: boolean; data?: any; error?: string }> => {
|
): Promise<{ success: boolean; data?: any; error?: string }> => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
|
const body = payload.enabled !== undefined
|
||||||
|
? { roleIds: payload.roleIds, enabled: payload.enabled }
|
||||||
|
: { roleIds: payload.roleIds };
|
||||||
const response = await api.put(
|
const response = await api.put(
|
||||||
`/api/features/instances/${instanceId}/users/${userId}/roles`,
|
`/api/features/instances/${instanceId}/users/${userId}/roles`,
|
||||||
roleIds,
|
body,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'X-Mandate-Id': mandateId
|
'X-Mandate-Id': mandateId
|
||||||
|
|
|
||||||
|
|
@ -275,15 +275,23 @@ export const AdminFeatureInstanceUsersPage: React.FC = () => {
|
||||||
];
|
];
|
||||||
}, [userOptions, roleOptions]);
|
}, [userOptions, roleOptions]);
|
||||||
|
|
||||||
// Form attributes for editing user roles
|
// Form attributes for editing user roles and active flag
|
||||||
const editRolesFields: AttributeDefinition[] = useMemo(() => {
|
const editRolesFields: AttributeDefinition[] = useMemo(() => {
|
||||||
return [{
|
return [
|
||||||
name: 'roleIds',
|
{
|
||||||
label: 'Rollen',
|
name: 'roleIds',
|
||||||
type: 'multiselect' as const,
|
label: 'Rollen',
|
||||||
required: true,
|
type: 'multiselect' as const,
|
||||||
options: roleOptions,
|
required: true,
|
||||||
}];
|
options: roleOptions,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'enabled',
|
||||||
|
label: 'Aktiv',
|
||||||
|
type: 'checkbox' as const,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
];
|
||||||
}, [roleOptions]);
|
}, [roleOptions]);
|
||||||
|
|
||||||
// Handle add user submit
|
// Handle add user submit
|
||||||
|
|
@ -304,8 +312,8 @@ export const AdminFeatureInstanceUsersPage: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle edit roles submit
|
// Handle edit roles and active submit
|
||||||
const handleEditRoles = async (data: { roleIds: string[] }) => {
|
const handleEditRoles = async (data: { roleIds: string[]; enabled?: boolean }) => {
|
||||||
if (!selectedMandateId || !selectedInstanceId || !editingUser) return;
|
if (!selectedMandateId || !selectedInstanceId || !editingUser) return;
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -313,14 +321,14 @@ export const AdminFeatureInstanceUsersPage: React.FC = () => {
|
||||||
selectedMandateId,
|
selectedMandateId,
|
||||||
selectedInstanceId,
|
selectedInstanceId,
|
||||||
editingUser.userId,
|
editingUser.userId,
|
||||||
data.roleIds
|
{ roleIds: data.roleIds, enabled: data.enabled }
|
||||||
);
|
);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
setEditingUser(null);
|
setEditingUser(null);
|
||||||
refreshUsers();
|
refreshUsers();
|
||||||
showSuccess('Rollen aktualisiert', 'Die Benutzerrollen wurden erfolgreich aktualisiert.');
|
showSuccess('Eintrag aktualisiert', 'Rollen und Aktiv-Status wurden erfolgreich aktualisiert.');
|
||||||
} else {
|
} else {
|
||||||
showError('Fehler', result.error || 'Fehler beim Aktualisieren der Rollen');
|
showError('Fehler', result.error || 'Fehler beim Aktualisieren');
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|
@ -606,7 +614,7 @@ export const AdminFeatureInstanceUsersPage: React.FC = () => {
|
||||||
<div className={styles.modalContent}>
|
<div className={styles.modalContent}>
|
||||||
<FormGeneratorForm
|
<FormGeneratorForm
|
||||||
attributes={editRolesFields}
|
attributes={editRolesFields}
|
||||||
data={{ roleIds: editingUser.roleIds }}
|
data={{ roleIds: editingUser.roleIds, enabled: editingUser.enabled }}
|
||||||
mode="edit"
|
mode="edit"
|
||||||
onSubmit={handleEditRoles}
|
onSubmit={handleEditRoles}
|
||||||
onCancel={() => setEditingUser(null)}
|
onCancel={() => setEditingUser(null)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue