feat: NewLabel script setup (#2414)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2414 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
parent
ecd0df21c1
commit
7f581cbe27
1 changed files with 35 additions and 44 deletions
|
@ -34,52 +34,43 @@
|
|||
</create-edit>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from 'vue'
|
||||
import {mapState} from 'pinia'
|
||||
<script setup lang="ts">
|
||||
import {computed, ref} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {useRouter} from 'vue-router'
|
||||
|
||||
import LabelModel from '../../models/label'
|
||||
import CreateEdit from '@/components/misc/create-edit.vue'
|
||||
import ColorPicker from '../../components/input/colorPicker.vue'
|
||||
import { setTitle } from '@/helpers/setTitle'
|
||||
import { useLabelStore } from '@/stores/labels'
|
||||
import ColorPicker from '@/components/input/colorPicker.vue'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'NewLabel',
|
||||
data() {
|
||||
return {
|
||||
label: new LabelModel(),
|
||||
showError: false,
|
||||
}
|
||||
},
|
||||
components: {
|
||||
CreateEdit,
|
||||
ColorPicker,
|
||||
},
|
||||
mounted() {
|
||||
setTitle(this.$t('label.create.title'))
|
||||
},
|
||||
computed: {
|
||||
...mapState(useLabelStore, {
|
||||
loading: state => state.isLoading,
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
async newLabel() {
|
||||
if (this.label.title === '') {
|
||||
this.showError = true
|
||||
import LabelModel from '@/models/label'
|
||||
import {useLabelStore} from '@/stores/labels'
|
||||
import {useTitle} from '@/composables/useTitle'
|
||||
import {success} from '@/message'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
useTitle(() => t('label.create.title'))
|
||||
|
||||
const labelStore = useLabelStore()
|
||||
const label = ref(new LabelModel())
|
||||
|
||||
const showError = ref(false)
|
||||
const loading = computed(() => labelStore.isLoading)
|
||||
|
||||
async function newLabel() {
|
||||
if (label.value.title === '') {
|
||||
showError.value = true
|
||||
return
|
||||
}
|
||||
this.showError = false
|
||||
showError.value = false
|
||||
|
||||
const labelStore = useLabelStore()
|
||||
const label = labelStore.createLabel(this.label)
|
||||
this.$router.push({
|
||||
const newLabel = labelStore.createLabel(label.value)
|
||||
router.push({
|
||||
name: 'labels.index',
|
||||
params: {id: label.id},
|
||||
params: {id: newLabel.id},
|
||||
})
|
||||
this.$message.success({message: this.$t('label.create.success')})
|
||||
},
|
||||
},
|
||||
})
|
||||
success({message: t('label.create.success')})
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue