feat(task wizard): allow setting a due date via popup or quick add magic

This commit is contained in:
kolaente 2022-09-21 22:44:42 +02:00
parent 169f95af33
commit e492ce40d2
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 26 additions and 8 deletions

View file

@ -1,8 +1,10 @@
<template>
<div class="datepicker">
<BaseButton @click.stop="toggleDatePopup" class="show" :disabled="disabled || undefined">
{{ date === null ? chooseDateLabel : formatDateShort(date) }}
</BaseButton>
<slot :date="date" :openPopup="toggleDatePopup">
<BaseButton @click.stop="toggleDatePopup" class="show" :disabled="disabled || undefined">
{{ date === null ? chooseDateLabel : formatDateShort(date) }}
</BaseButton>
</slot>
<transition name="fade">
<div v-if="show" class="datepicker-popup" ref="datepickerPopup">

View file

@ -30,11 +30,21 @@
:preview-is-default="false"
class="m-4"
/>
<div class="px-4">
<Datepicker
v-model="newTask.dueDate"
v-slot="{ date, openPopup }"
>
<XButton variant="secondary" @click.stop="openPopup()">
{{ date ? formatDateShort(date) : t('task.attributes.dueDate') }}
</XButton>
</Datepicker>
</div>
</CreateEdit>
</template>
<script lang="ts" setup>
import {computed, ref} from 'vue'
import {computed, ref, watch} from 'vue'
import {useI18n} from 'vue-i18n'
import {formatISO} from 'date-fns'
@ -42,6 +52,8 @@ import CreateEdit from '@/components/misc/create-edit.vue'
import Editor from '@/components/input/AsyncEditor'
import BaseButton from '@/components/base/BaseButton.vue'
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic.vue'
import XButton from '@/components/input/button.vue'
import Datepicker from '@/components/input/datepicker.vue'
import type {ITask} from '@/modelTypes/ITask'
import TaskModel from '@/models/task'
@ -51,6 +63,7 @@ import {useListStore} from '@/stores/lists'
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
import {parseTaskText} from '@/modules/parseTaskText'
import {findAssignees} from '@/helpers/findAssignees'
import {formatDateShort} from '@/helpers/time/formatDate'
const listStore = useListStore()
const router = useRouter()
@ -67,11 +80,15 @@ const heading = computed(() => {
})
const errorMessage = ref('')
const taskService = ref(new TaskService())
const descriptionFormVisible = ref(false)
const newTask = ref<ITask>(new TaskModel({}))
const taskService = ref(new TaskService())
const parsedTask = computed(() => parseTaskText(newTask.value.title, getQuickAddMagicMode()))
watch(
() => parsedTask.value.date,
date => newTask.value.dueDate = date
)
async function create() {
if (newTask.value.title === '') {
@ -83,16 +100,15 @@ async function create() {
newTask.value.listId = props.listId
newTask.value.title = parsedTask.value.text
const assignees = await findAssignees(parsedTask.value.assignees)
const dueDate = parsedTask.value.date !== null ? formatISO(parsedTask.value.date) : null
const finalTask = new TaskModel({
...newTask.value,
title: parsedTask.value.text,
dueDate,
dueDate: newTask.value.dueDate !== null ? formatISO(newTask.value.dueDate) : null,
priority: parsedTask.value.priority,
assignees: parsedTask.value.assignees,
})
const task = await taskService.value.create(finalTask)
return router.push({name: 'task.detail', params: {id: task.id}})
}