salix-front/src/pages/Worker/Card/WorkerDescriptorMenu.vue

66 lines
1.7 KiB
Vue

<script setup>
import { computed, ref, toRefs } from 'vue';
import axios from 'axios';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useState } from 'src/composables/useState';
const $props = defineProps({
worker: {
type: Object,
required: true,
},
isExcluded: {
type: Boolean,
required: true,
},
});
const route = useRoute();
const { t } = useI18n();
const state = useState();
const user = state.getUser();
const { worker } = toRefs($props);
const workerExcluded = ref($props.isExcluded);
const entityId = computed(() => {
return $props.worker.id || route.params.id;
});
const emit = defineEmits(['show-dialog']);
const handleExcluded = async () => {
if (workerExcluded.value)
await axios.delete(`WorkerDisableExcludeds/${entityId.value}`);
else
await axios.post(`WorkerDisableExcludeds`, {
workerFk: entityId.value,
dated: new Date(),
});
workerExcluded.value = !workerExcluded.value;
};
const showChangePasswordDialog = () => {
emit('show-dialog', true);
};
</script>
<template>
<QItem v-ripple clickable @click="handleExcluded">
<QItemSection>
{{
workerExcluded
? t('Click to allow the user to be disabled')
: t('Click to exclude the user from getting disabled')
}}
</QItemSection>
</QItem>
<QItem
v-if="!worker.user.emailVerified && user.id == worker.id"
v-ripple
clickable
@click="showChangePasswordDialog"
>
<QItemSection>
{{ t('globals.changePass') }}
</QItemSection>
</QItem>
</template>