feat: refs #7702 fine tunning
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-09-16 10:36:56 +02:00
parent 153c9b743f
commit 9ec2fb4c77
2 changed files with 31 additions and 23 deletions

View File

@ -7,7 +7,7 @@ import FetchData from '../FetchData.vue';
import useNotify from 'src/composables/useNotify';
const props = defineProps({ submitFn: { type: Function, default: () => {} } });
const emit = defineEmits(['onSubmit']);
const { t } = useI18n();
const { notify } = useNotify();
@ -15,19 +15,27 @@ const form = ref();
const changePassDialog = ref();
const passwords = ref({ newPassword: null, repeatPassword: null });
const requirements = ref([]);
const isLoading = ref(false);
const validate = async () => {
const { newPassword, repeatPassword } = passwords.value;
if (!newPassword) {
notify(t('You must enter a new password'), 'negative');
return;
}
if (newPassword !== repeatPassword) {
notify(t("Passwords don't match"), 'negative');
return;
}
try {
isLoading.value = true;
await props.submitFn(newPassword);
emit('onSubmit');
} catch (e) {
notify('errors.writeRequest', 'negative');
} finally {
changePassDialog.value.hide();
isLoading.value = false;
}
};
@ -84,6 +92,8 @@ defineExpose({ show: () => changePassDialog.value.show() });
<QCardActions>
<slot name="actions">
<QBtn
:disabled="isLoading"
:loading="isLoading"
:label="t('globals.cancel')"
class="q-ml-sm"
color="primary"
@ -92,6 +102,8 @@ defineExpose({ show: () => changePassDialog.value.show() });
v-close-popup
/>
<QBtn
:disabled="isLoading"
:loading="isLoading"
:label="t('globals.confirm')"
color="primary"
@click="validate"

View File

@ -5,7 +5,7 @@ import { useI18n } from 'vue-i18n';
import CardDescriptor from 'src/components/ui/CardDescriptor.vue';
import VnLv from 'src/components/ui/VnLv.vue';
import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
import WorkerChangePasswordForm from 'src/pages/Worker/Card/WorkerChangePasswordForm.vue';
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
import { useState } from 'src/composables/useState';
import axios from 'axios';
import VnImg from 'src/components/ui/VnImg.vue';
@ -24,18 +24,13 @@ const route = useRoute();
const { t } = useI18n();
const state = useState();
const user = state.getUser();
const changePasswordFormDialog = ref(null);
const cardDescriptorRef = ref(null);
const showEditPhotoForm = ref(false);
const toggleEditPictureForm = () => {
showEditPhotoForm.value = !showEditPhotoForm.value;
};
const entityId = computed(() => {
return $props.id || route.params.id;
});
const worker = ref();
const workerExcluded = ref(false);
const getIsExcluded = async () => {
@ -61,10 +56,10 @@ const handleExcluded = async () => {
workerExcluded.value = !workerExcluded.value;
};
const handlePhotoUpdated = (evt = false) => {
image.value.reload(evt);
};
const refetch = async () => await cardDescriptorRef.value.getData();
</script>
<template>
<CardDescriptor
@ -74,15 +69,10 @@ const refetch = async () => await cardDescriptorRef.value.getData();
url="Workers/descriptor"
:filter="{ where: { id: entityId } }"
title="user.nickname"
@on-fetch="
(data) => {
worker = data;
getIsExcluded();
}
"
@on-fetch="getIsExcluded"
>
<template #menu="{}">
<QItem v-ripple clickable @click="handleExcluded()">
<template #menu="{ entity }">
<QItem v-ripple clickable @click="handleExcluded">
<QItemSection>
{{
workerExcluded
@ -92,16 +82,13 @@ const refetch = async () => await cardDescriptorRef.value.getData();
</QItemSection>
</QItem>
<QItem
v-if="!worker.user.emailVerified && user.id != worker.id"
v-if="!entity.user.emailVerified && user.id != entity.id"
v-ripple
clickable
@click="$refs.changePasswordFormDialog.show()"
@click="$refs.changePassRef.show"
>
<QItemSection>
{{ t('Change password') }}
<QDialog ref="changePasswordFormDialog">
<WorkerChangePasswordForm @on-submit="refetch()" :id="entityId" />
</QDialog>
</QItemSection>
</QItem>
</template>
@ -163,10 +150,10 @@ const refetch = async () => await cardDescriptorRef.value.getData();
<VnLinkPhone :phone-number="entity.phone" />
</template>
</VnLv>
<VnLv :value="worker?.sip?.extension">
<VnLv :value="entity?.sip?.extension">
<template #label>
{{ t('worker.summary.sipExtension') }}
<VnLinkPhone :phone-number="worker?.sip?.extension" />
<VnLinkPhone :phone-number="entity?.sip?.extension" />
</template>
</VnLv>
</template>
@ -197,6 +184,15 @@ const refetch = async () => await cardDescriptorRef.value.getData();
</QCardActions>
</template>
</CardDescriptor>
<VnChangePassword
ref="changePassRef"
:submit-fn="
async (newPass) => {
await axios.patch(`Workers/${$route.params.id}/setPassword`, { newPass });
}
"
@on-submit="$refs.cardDescriptorRef?.getData"
/>
</template>
<style lang="scss" scoped>