[Profile] Update fixed

This commit is contained in:
Matej Glasnák committed 2023-03-13 21:54:14 +01:00
1 parent 0d5bfa3b9b
commit eb7b44fbfe
4 files changed
+54 -75

No files matched your search

+7 -7
View File
@@ -44,13 +44,13 @@ const options: Options = {
},
moxios: {
routes: {
'GET v1/auth/info': true,
'POST v1/auth/forgot': true,
'POST v1/auth/reset': true,
'POST v1/auth/info': true,
'POST v1/auth/invalidate': true,
'POST v1/auth/login': true,
'POST v1/auth/post': true,
// 'GET v1/auth/info': true,
// 'POST v1/auth/forgot': true,
// 'POST v1/auth/reset': true,
// 'POST v1/auth/info': true,
// 'POST v1/auth/invalidate': true,
// 'POST v1/auth/login': true,
// 'POST v1/auth/post': true,
'GET v1/overview/teams': true,
'GET v1/overview/tasks': true,
+6 -2
View File
@@ -11,6 +11,7 @@ import ZTimeline from '@/plugins/tm@dashboard/_components/z-timeline.vue
import { addDays, subDays } from 'date-fns'
import moment from 'moment'
import timelineUtils from './_utils/timeline.utils'
import { mapGetters } from 'vuex'
export default {
components: {
@@ -30,6 +31,10 @@ export default {
},
computed: {
...mapGetters('auth', [
'user'
]),
splitDays() {
const days = []
const workingHours = {}
@@ -89,8 +94,7 @@ export default {
},
unmounted() {
this.$events.off('on-subtask-edited')
this.$events.off('on-subtask-deleted')
this.$events.off('on-user-updated')
},
methods: {
@@ -1,61 +1,13 @@
<template>
<div class="border-bottom py-5 px-5">
<h1>Všeobecné informácie</h1>
<v-text-field
class="w-75"
variant="solo"
label="Meno"
v-model="user.name"
:class="{ error: v$.user.name.$errors.length }"
:hint="
v$.user.name.$errors
? errorUtils.parseErrors(v$.user.name.$errors)
: null
"
></v-text-field>
<v-text-field
class="w-75"
variant="solo"
label="Priezvisko"
v-model="user.surname"
:class="{ error: v$.user.surname.$errors.length }"
:hint="
v$.user.surname.$errors
? errorUtils.parseErrors(v$.user.surname.$errors)
: null
"
></v-text-field>
<v-text-field class="w-75" variant="solo" label="Meno" :disabled="true" v-model="user.name"></v-text-field>
<v-text-field class="w-75" variant="solo" label="Priezvisko" v-model="user.surname" :disabled="true"></v-text-field>
</div>
<div class="py-5 px-5 border-bottom">
<h1>Pracovná doba</h1>
<v-text-field
class="w-75"
variant="solo"
label="Začiatok"
v-model="user.work_hours_from"
append-inner-icon="mdi-clock-outline"
type="time"
:class="{ error: v$.user.work_hours_from.$errors.length }"
:hint="
v$.user.work_hours_from.$errors
? errorUtils.parseErrors(v$.user.work_hours_from.$errors)
: null
"
></v-text-field>
<v-text-field
class="w-75"
variant="solo"
label="Koniec"
v-model="user.work_hours_to"
append-inner-icon="mdi-clock-outline"
:class="{ error: v$.user.work_hours_to.$errors.length }"
:hint="
v$.user.work_hours_to.$errors
? errorUtils.parseErrors(v$.user.work_hours_to.$errors)
: null
"
type="time"
></v-text-field>
<v-text-field class="w-75" variant="solo" label="Začiatok" v-model="form.work_start" append-inner-icon="mdi-clock-outline" type="time" :class="{ error: v$.form.work_start.$errors.length }" :hint="v$.form.work_start.$errors ? errorUtils.parseErrors(v$.form.work_start.$errors) : null"></v-text-field>
<v-text-field class="w-75" variant="solo" label="Koniec" v-model="form.work_end" append-inner-icon="mdi-clock-outline" type="time" :class="{ error: v$.form.work_end.$errors.length }" :hint="v$.form.work_end.$errors ? errorUtils.parseErrors(v$.form.work_end.$errors) : null"></v-text-field>
</div>
<div class="py-5 px-5">
<v-btn class="button primary" @click="updateUserInfo()">ULOŽIŤ ZMENY</v-btn>
@@ -63,46 +15,69 @@
</template>
<script>
import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import { mapGetters } from 'vuex'
import useVuelidate from "@vuelidate/core"
import { required } from "@vuelidate/validators"
import errorUtils from "@/plugins/lib@auth/_utils/error.utils"
import { mapGetters } from "vuex"
export default {
data() {
return {
errorUtils,
v$: useVuelidate(),
form: {}
}
},
computed: {
...mapGetters('auth', ['user']),
...mapGetters("auth", ["user"])
},
validations() {
return {
user: {
name: { required },
surname: { required },
work_hours_from: { required },
work_hours_to: { required },
},
form: {
work_start: { required },
work_end: { required }
}
}
},
mounted() {
this._setDates()
},
methods: {
async updateUserInfo() {
if (!(await this.v$.$validate())) return
try {
await this.$store.dispatch('auth/updateUserInfo', this.user)
const data = {
id: this.user.id,
work_start: parseInt(this.form.work_start.split(':')[0]),
work_end: parseInt(this.form.work_end.split(':')[0])
}
try {
await this.$store.dispatch('auth/updateUserInfo', data)
this.$toast.success('Profil bol úspešne zmenený')
this.$events.emit('on-user-updated', this.user)
} catch (error) {
this.$toast.error(error)
}
},
_setDates() {
this.form = {
work_start: this.user.work_start < 10 ? `0${this.user.work_start}:00` : `${this.user.work_start}:00`,
work_end: this.user.work_end < 10 ? `0${this.user.work_end}:00` : `${this.user.work_end}:00`
}
}
},
watch: {
user() {
this._setDates()
}
}
}
</script>
+1 -1
View File
@@ -135,7 +135,7 @@ export default {
},
updateUserInfo({commit}: {commit: any}, data: any) {
return new Promise((resolve, reject) => {
axios.post_auth_data('v1/auth/info', data)
axios.put_auth(`v1/users/${data.id}`, {data: data})
.then((response: any) => {
const user = response.user