[Master task modal] Fixed team verification

This commit is contained in:
Matej Glasnák committed 2023-06-13 12:07:24 +02:00
1 parent b2470a80c2
commit 3f37acd04f
3 files changed
+28 -25

No files matched your search

@@ -23,10 +23,10 @@
<v-text-field v-model="mastertask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" :label="`${mastertask.duration} h`" :disabled="true"></v-text-field>
<v-select v-model="mastertask.team_id" @focus="onInputFocus" class="modal-input border-select" label="Tím" variant="solo" :items="teams" item-value="id" item-title="name"></v-select>
<v-select v-model="mastertask.team_id" @focus="onInputFocus" class="modal-input border-select" :class="{error: v$.mastertask.employees.$errors.length}" label="Tím" variant="solo" :items="teams" item-value="id" item-title="name"></v-select>
<template v-if="mastertask.employees">
<v-text-field v-for="(employee, index) in mastertask.employees" :key="employee.id" @focus="onInputFocus" class="modal-input" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="mastertask.employees[index].duration" type="number" min="1" @input="onEmployeeDurationChanged">
<v-text-field v-for="(employee, index) in mastertask.employees" :key="employee.id" @focus="onInputFocus" class="modal-input" :class="{error: employee.invalid}" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="mastertask.employees[index].duration" type="number" min="1" @input="onEmployeeDurationChanged">
<p class="employee-select-avatar d-flex justify-center align-center">
{{ employee?.name.charAt(0) + employee?.surname.charAt(0) }}
</p>
@@ -88,7 +88,7 @@
import Datepicker from '@vuepic/vue-datepicker'
import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue'
import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import { required, minLength } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
// import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
@@ -163,6 +163,7 @@ export default {
validations() {
return {
mastertask: {
employees: { required, minLength: minLength(1), $each: {duration: { required}} },
project_id: { required },
name: { required },
description: { required },
@@ -209,7 +210,7 @@ export default {
methods: {
removeEmployee({ id }) {
const isEmployeeInTeam = this.mastertask.team.employees.find(employee => employee.id == id)
const isEmployeeInTeam = this.mastertask.team?.employees.find(employee => employee.id == id)
if (isEmployeeInTeam) {
this.mastertask.team_id = null
@@ -258,8 +259,9 @@ export default {
},
async save() {
console.log(this.mastertask)
if (!(await this.v$.$validate())) return
const vuelidateValid = await this.v$.$validate()
const employeesValid = await this._validateEmployees()
if (!vuelidateValid || !employeesValid) return
if (this.$refs['description'])
this.mastertask.description = this.$refs['description'].getHTML()
@@ -302,6 +304,21 @@ export default {
date.setMinutes(parseInt(timeParts[1]));
this.mastertask.deadline = date
},
_validateEmployees() {
let isValid = true
this.mastertask.employees = this.mastertask.employees.map(employee => {
if (!employee.duration) {
employee.invalid = true
isValid = false
}
return employee
})
return isValid
}
},