-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompleteTask.vue
More file actions
110 lines (95 loc) · 2.64 KB
/
Copy pathCompleteTask.vue
File metadata and controls
110 lines (95 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<UForm
:validate="createValidator(completeTaskSchema)"
:state="state"
class="flex flex-col gap-3"
@submit="onSubmit"
>
<div class="mb-4 flex flex-col gap-1">
<h2 class="text-lg/5 font-semibold">
«{{ task?.name }}»
</h2>
<p class="text-sm text-muted leading-4">
{{ task?.description }}
</p>
</div>
<UFormField :label="$t('common.resolution')" name="resolution">
<USelectMenu
v-model="selectedResolution"
:items="getResolutionForSelect()"
:placeholder="$t('common.select')"
:content="{
side: 'top',
}"
size="xl"
class="w-full"
/>
</UFormField>
<UFormField :label="$t('common.report')" name="report">
<UTextarea
v-model="state.report"
:rows="4"
size="xl"
class="w-full"
/>
</UFormField>
<UButton
type="submit"
variant="solid"
color="secondary"
size="xl"
trailing-icon="i-lucide-flag"
block
:label="$t('app.update.task.close')"
:ui="{
trailingIcon: 'ms-0',
}"
/>
</UForm>
</template>
<script setup lang="ts">
import type { FormSubmitEvent } from '@nuxt/ui'
import type { CompleteTask, Resolution } from '~~/shared/services/task'
import { completeTaskSchema } from '~~/shared/services/task'
import { getResolutionForSelect } from '~~/shared/utils/helpers'
const { taskId } = defineProps<{
taskId: string
}>()
const emit = defineEmits(['success', 'submitted'])
const { t } = useI18n()
const { pop } = useConfetti()
const actionToast = useActionToast()
const userStore = useUserStore()
const taskStore = useTaskStore()
const task = computed(() => taskStore.lists.flatMap((list) => list.tasks).find((task) => task.id === taskId))
const state = ref<Partial<CompleteTask>>({
resolution: 'success',
report: undefined,
})
const selectedResolution = ref<{ label: string, value: Resolution, icon: string } | undefined>(
getResolutionForSelect().find((resolution) => resolution.value === 'success'),
)
watch(selectedResolution, () => {
state.value.resolution = selectedResolution.value?.value
})
async function onSubmit(event: FormSubmitEvent<CompleteTask>) {
const toastId = actionToast.start()
emit('submitted')
try {
await $fetch(`/api/task/id/${taskId}/complete`, {
method: 'POST',
body: event.data,
})
await Promise.all([
taskStore.update(),
userStore.update(),
])
actionToast.success(toastId, t('toast.task-completed'))
pop()
emit('success')
} catch (error) {
console.error(error)
actionToast.error(toastId)
}
}
</script>