[sub & master task] saved data in LS + build for stage

This commit is contained in:
romankko2 committed 2024-08-01 17:41:51 +02:00
1 parent 8b1b1a7fb4
commit 7dcd9eda4d
3 files changed
+60 -12

No files matched your search

+30 -3
View File
@@ -158,8 +158,6 @@ import ATimeblock from './_components/a-timeblock.vue'
import { mapGetters } from 'vuex'
import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin'
import axios from 'axios'
export default {
emits: ['close', 'refresh'],
mixins: [VuetifyFixFocusMixin, SelectsMixin, AutocompleteMixin, modalMixin],
@@ -275,7 +273,25 @@ export default {
this.subtask = this._enrichTask(data)
} else {
this.subtask = { master_task: mastertask, employees: [{}], _deadline_time: '17:00' }
const savedSubtask = localStorage.getItem('subtaskData')
try {
if (savedSubtask) {
const parsedSubtask = JSON.parse(savedSubtask)
this.subtask = parsedSubtask
// If the parsed result is not an object, reset to default
if (typeof this.subtask !== 'object' || this.subtask === null) {
throw new Error('Parsed subtask is not an object')
}
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.subtask.description || '');
})
} else {
throw new Error('subtaskData is null or undefined')
}
} catch (error) {
console.error('Error parsing subtaskData:', error);
this.subtask = { master_task: mastertask, employees: [{}], _deadline_time: '17:00' }
}
if (subtask?.deadline && subtask._deadline_time && subtask.employee_id) {
const employee = this.enrichedEmployees.find(employee => employee.id == subtask.employee_id)
@@ -326,6 +342,7 @@ export default {
})
const { subtask } = await this.$axios.patch_auth_form(`v1/subtasks/${this.subtask.id}`, { ...this.subtask, timesheets })
localStorage.removeItem('subtaskData')
this.$store.commit('tm/update_subtask', subtask)
this.$events.emit('on-subtask-edited', this.subtask)
@@ -337,6 +354,7 @@ export default {
const subtaskCopy = this.subtask
delete subtaskCopy._master_task
const { subtasks } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task_id}/subtasks`, subtaskCopy)
localStorage.removeItem('subtaskData')
this.subtask.id = subtasks[0].id
subtasks.forEach((subtask) => {
@@ -459,6 +477,15 @@ export default {
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.subtask.description || '')
})
},
subtask: {
handler(val) {
if (this.editMode && !this.subtask?.id) {
localStorage.setItem('subtaskData', JSON.stringify(val))
}
},
deep: true
}
}
}