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