diff --git a/src/components/admin/personen/PersonLock.vue b/src/components/admin/personen/PersonLock.vue index 4c45917d..d3f68750 100644 --- a/src/components/admin/personen/PersonLock.vue +++ b/src/components/admin/personen/PersonLock.vue @@ -18,6 +18,7 @@ const { mdAndDown }: { mdAndDown: Ref } = useDisplay(); const dialogIsActive: Ref = ref(false); + const isEditMode: Ref = ref(false); type Props = { errorCode: string; @@ -65,7 +66,7 @@ ] = formContext.defineField('selectedBefristung', vuetifyConfig); type Emits = { - (event: 'onLockUser', schule: string, date: string | undefined): void; + (event: 'onLockUser', schule: string, date: string | undefined, isExistingLockToBeEdited: boolean): void; }; const props: Props = defineProps(); const emit: Emits = defineEmits(); @@ -99,6 +100,14 @@ return organisation ? organisation.id : null; }); + const isManuallyLocked: ComputedRef = computed(() => { + return ( + props.person.person.userLock?.some( + (lock: UserLock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, + ) ?? false // Default to false if userLock is undefined; + ); + }); + function resetBefristungFields(): void { isUnbefristet.value = true; formContext.resetField('selectedBefristung'); @@ -107,6 +116,7 @@ function closeLockPersonDialog(): void { resetBefristungFields(); dialogIsActive.value = false; + isEditMode.value = false; } async function handleOnLockUser(): Promise { @@ -124,7 +134,9 @@ // Format date if provided const dateISO: string | undefined = formatDateToISO(selectedBefristung.value); - emit('onLockUser', lockingOrgId, dateISO); + const isExistingLockToBeEdited: boolean = isEditMode.value; + + emit('onLockUser', lockingOrgId, dateISO, isExistingLockToBeEdited); closeLockPersonDialog(); } @@ -190,7 +202,7 @@ v-else :enabledCondition="!disabled" :disabledText="$t('person.finishEditFirst')" - :enabledText="$t('person.unlockUser')" + :enabledText="$t('admin.person.editLock')" position="start" > {{ person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) - ? $t('person.unlockUser') + ? $t('admin.person.editLock') : $t('person.lockUser') }} - + @@ -239,9 +247,7 @@ {{ - !props.person.person.userLock?.some( - (lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) + !isManuallyLocked || isManuallyLocked && isEditMode ? $t('person.lockUserInfoText') : $t('person.unLockUserInfoText') }} @@ -354,6 +356,7 @@ md="4" > + {{ $t('admin.person.editLock') }} + + - {{ - props.person.person.userLock?.some( - (lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) - ? $t('person.unlockUser') - : $t('person.lockUser') - }} + {{ $t('person.lockUser') }} + + + + + {{ isManuallyLocked ? $t('admin.person.removeLock') : $t('person.lockUser') }} diff --git a/src/locales/de-DE.json b/src/locales/de-DE.json index 2d271ea4..16354b42 100644 --- a/src/locales/de-DE.json +++ b/src/locales/de-DE.json @@ -178,6 +178,8 @@ }, "discard": "Benutzer verwerfen", "disableUser": "Benutzer sperren", + "editLock": "Sperre bearbeiten", + "removeLock": "Sperre aufheben", "edit": "Benutzer bearbeiten", "editPersonalInfo": "Persönliche Informationen bearbeiten", "errors": { diff --git a/src/views/admin/PersonDetailsView.vue b/src/views/admin/PersonDetailsView.vue index 280716a4..bc0b252b 100644 --- a/src/views/admin/PersonDetailsView.vue +++ b/src/views/admin/PersonDetailsView.vue @@ -153,11 +153,19 @@ devicePassword.value = personStore.newDevicePassword || ''; } - async function onLockUser(lockedBy: string, date: string | undefined): Promise { + async function onLockUser( + lockedBy: string, + date: string | undefined, + isExistingLockToBeEdited: boolean, + ): Promise { if (!personStore.currentPerson) return; + let lock: boolean; + if (isExistingLockToBeEdited) lock = isManuallyLocked.value; + else lock = !isManuallyLocked.value; + let bodyParams: LockUserBodyParams = { - lock: !isManuallyLocked.value, + lock: lock, locked_by: lockedBy, locked_until: date, };