Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPSH-1070 #355

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 49 additions & 26 deletions src/components/admin/personen/PersonLock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
const { mdAndDown }: { mdAndDown: Ref<boolean> } = useDisplay();

const dialogIsActive: Ref<boolean> = ref(false);
const isEditMode: Ref<boolean> = ref(false);

type Props = {
errorCode: string;
Expand Down Expand Up @@ -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<Props>();
const emit: Emits = defineEmits<Emits>();
Expand Down Expand Up @@ -99,6 +100,14 @@
return organisation ? organisation.id : null;
});

const isManuallyLocked: ComputedRef<boolean> = computed<boolean>(() => {
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');
Expand All @@ -107,6 +116,7 @@
function closeLockPersonDialog(): void {
resetBefristungFields();
dialogIsActive.value = false;
isEditMode.value = false;
}

async function handleOnLockUser(): Promise<void> {
Expand All @@ -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();
}

Expand Down Expand Up @@ -190,7 +202,7 @@
v-else
:enabledCondition="!disabled"
:disabledText="$t('person.finishEditFirst')"
:enabledText="$t('person.unlockUser')"
:enabledText="$t('admin.person.editLock')"
position="start"
>
<v-btn
Expand All @@ -202,22 +214,18 @@
>
{{
person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT)
? $t('person.unlockUser')
? $t('admin.person.editLock')
: $t('person.lockUser')
}}
</v-btn>
</SpshTooltip>
</v-col>
</template>

<!-- Benutzer sperren Dialog -->
<LayoutCard
data-testid="person-lock-card"
:closable="true"
:header="
!props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT)
? $t('person.lockUser')
: $t('person.unlockUser')
"
:header="!isManuallyLocked ? $t('person.lockUser') : $t('admin.person.editLock')"
@onCloseClicked="closeLockPersonDialog"
>
<v-container>
Expand All @@ -239,9 +247,7 @@
</v-col>
</v-row>
<v-row
v-if="
!props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT)
"
v-if="!isManuallyLocked || isManuallyLocked && isEditMode"
class="align-center justify-center w-full"
>
<v-col
Expand Down Expand Up @@ -284,9 +290,7 @@
</v-row>
<v-row
class="justify-center w-full"
v-if="
!props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT)
"
v-if="!isManuallyLocked || isManuallyLocked && isEditMode"
>
<v-col
class="text-body"
Expand Down Expand Up @@ -322,9 +326,7 @@
class="text-body"
>
{{
!props.person.person.userLock?.some(
(lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT,
)
!isManuallyLocked || isManuallyLocked && isEditMode
? $t('person.lockUserInfoText')
: $t('person.unLockUserInfoText')
}}
Expand Down Expand Up @@ -354,23 +356,44 @@
md="4"
>
<v-btn
v-if="isManuallyLocked && !isEditMode"
:block="mdAndDown"
class="primary button"
:disabled="
!props.person.person.userLock?.some(
(lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT,
DeFi3298 marked this conversation as resolved.
Show resolved Hide resolved
) && !selectedOrganisation
"
@click.stop="isEditMode = true"
data-testid="lock-user-button"
>
{{ $t('admin.person.editLock') }}
</v-btn>
<v-btn
v-if="!isManuallyLocked || isManuallyLocked && isEditMode"
:block="mdAndDown"
class="primary button"
:disabled="!isManuallyLocked && !selectedOrganisation"
@click.stop="onSubmit"
data-testid="lock-user-button"
>
{{
props.person.person.userLock?.some(
(lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT,
)
? $t('person.unlockUser')
: $t('person.lockUser')
}}
{{ $t('person.lockUser') }}
</v-btn>
</v-col>
<v-col
v-if="isManuallyLocked && !isEditMode"
cols="12"
sm="6"
md="4"
>
<v-btn
:block="mdAndDown"
class="primary button"
:disabled="!isManuallyLocked && !selectedOrganisation"
@click.stop="onSubmit"
data-testid="lock-user-button"
>
{{ isManuallyLocked ? $t('admin.person.removeLock') : $t('person.lockUser') }}
</v-btn>
</v-col>
</v-row>
Expand Down
2 changes: 2 additions & 0 deletions src/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
"deletePersonSuccessMessage": "{firstname} {lastname} wurde erfolgreich gelöscht.",
"discard": "Benutzer verwerfen",
"disableUser": "Benutzer sperren",
"editLock": "Sperre bearbeiten",
"removeLock": "Sperre aufheben",
"edit": "Benutzer bearbeiten",
"editPersonalInfo": "Persönliche Informationen bearbeiten",
"errors": {
Expand Down
12 changes: 10 additions & 2 deletions src/views/admin/PersonDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@
password.value = personStore.newPassword || '';
}

async function onLockUser(lockedBy: string, date: string | undefined): Promise<void> {
async function onLockUser(
lockedBy: string,
date: string | undefined,
isExistingLockToBeEdited: boolean,
): Promise<void> {
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,
};
Expand Down
Loading