feat(frontend) : add archive/unarchive buttons and delete confirmation to TaskDrawer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-12 18:03:27 +01:00
parent 7fe434fa07
commit c097849dad

View File

@@ -50,25 +50,25 @@
/> />
<div class="mt-4"> <div class="mt-4">
<p class="mb-2 text-sm font-medium text-neutral-700">Types</p> <p class="mb-2 text-sm font-medium text-neutral-700">Tags</p>
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
<label <label
v-for="type in types" v-for="tag in tags"
:key="type.id" :key="tag.id"
class="cursor-pointer rounded-full px-3 py-1 text-xs font-semibold transition" class="cursor-pointer rounded-full px-3 py-1 text-xs font-semibold transition"
:class="form.typeIds.includes(type.id) :class="form.tagIds.includes(tag.id)
? 'text-white' ? 'text-white'
: 'bg-neutral-100 text-neutral-600 hover:bg-neutral-200'" : 'bg-neutral-100 text-neutral-600 hover:bg-neutral-200'"
:style="form.typeIds.includes(type.id) ? { backgroundColor: type.color } : {}" :style="form.tagIds.includes(tag.id) ? { backgroundColor: tag.color } : {}"
> >
<input <input
type="checkbox" type="checkbox"
class="hidden" class="hidden"
:value="type.id" :value="tag.id"
:checked="form.typeIds.includes(type.id)" :checked="form.tagIds.includes(tag.id)"
@change="toggleType(type.id)" @change="toggleTag(tag.id)"
/> />
{{ type.label }} {{ tag.label }}
</label> </label>
</div> </div>
</div> </div>
@@ -79,19 +79,44 @@
type="button" type="button"
class="rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-50" class="rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="isSubmitting" :disabled="isSubmitting"
@click="handleDelete" @click="confirmDeleteOpen = true"
> >
Supprimer Supprimer
</button> </button>
<button <div class="flex gap-2">
type="submit" <button
class="rounded-md bg-primary-500 px-6 py-2 text-sm font-semibold text-white hover:bg-secondary-500 disabled:cursor-not-allowed disabled:opacity-50" v-if="canArchive"
:disabled="isSubmitting" type="button"
> class="rounded-md bg-neutral-500 px-4 py-2 text-sm font-semibold text-white hover:bg-neutral-600 disabled:cursor-not-allowed disabled:opacity-50"
Enregistrer :disabled="isSubmitting"
</button> @click="handleArchive"
>
{{ $t('archive.archiveButton') }}
</button>
<button
v-if="canUnarchive"
type="button"
class="rounded-md bg-neutral-500 px-4 py-2 text-sm font-semibold text-white hover:bg-neutral-600 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="isSubmitting"
@click="handleUnarchive"
>
{{ $t('archive.unarchiveButton') }}
</button>
<button
type="submit"
class="rounded-md bg-primary-500 px-6 py-2 text-sm font-semibold text-white hover:bg-secondary-500 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="isSubmitting"
>
Enregistrer
</button>
</div>
</div> </div>
</form> </form>
<ConfirmDeleteTaskModal
v-model="confirmDeleteOpen"
@confirm="handleDelete"
/>
</AppDrawer> </AppDrawer>
</template> </template>
@@ -100,7 +125,7 @@ import type { Task, TaskWrite } from '~/services/dto/task'
import type { TaskStatus } from '~/services/dto/task-status' import type { TaskStatus } from '~/services/dto/task-status'
import type { TaskEffort } from '~/services/dto/task-effort' import type { TaskEffort } from '~/services/dto/task-effort'
import type { TaskPriority } from '~/services/dto/task-priority' import type { TaskPriority } from '~/services/dto/task-priority'
import type { TaskType } from '~/services/dto/task-type' import type { TaskTag } from '~/services/dto/task-tag'
import type { TaskGroup } from '~/services/dto/task-group' import type { TaskGroup } from '~/services/dto/task-group'
import type { UserData } from '~/services/dto/user-data' import type { UserData } from '~/services/dto/user-data'
import { useTaskService } from '~/services/tasks' import { useTaskService } from '~/services/tasks'
@@ -112,7 +137,7 @@ const props = defineProps<{
statuses: TaskStatus[] statuses: TaskStatus[]
efforts: TaskEffort[] efforts: TaskEffort[]
priorities: TaskPriority[] priorities: TaskPriority[]
types: TaskType[] tags: TaskTag[]
groups: TaskGroup[] groups: TaskGroup[]
users: UserData[] users: UserData[]
}>() }>()
@@ -129,6 +154,7 @@ const isOpen = computed({
const isEditing = computed(() => !!props.task) const isEditing = computed(() => !!props.task)
const isSubmitting = ref(false) const isSubmitting = ref(false)
const confirmDeleteOpen = ref(false)
const form = reactive({ const form = reactive({
title: '', title: '',
@@ -138,7 +164,7 @@ const form = reactive({
priorityId: null as number | null, priorityId: null as number | null,
assigneeId: null as number | null, assigneeId: null as number | null,
groupId: null as number | null, groupId: null as number | null,
typeIds: [] as number[], tagIds: [] as number[],
}) })
const touched = reactive({ const touched = reactive({
@@ -165,12 +191,23 @@ const groupOptions = computed(() =>
props.groups.map(g => ({ label: g.title, value: g.id })) props.groups.map(g => ({ label: g.title, value: g.id }))
) )
function toggleType(id: number) { const canArchive = computed(() => {
const idx = form.typeIds.indexOf(id) if (!isEditing.value || !props.task) return false
if (props.task.archived) return false
const status = props.statuses.find(s => s.id === props.task?.status?.id)
return !!status?.isFinal
})
const canUnarchive = computed(() => {
return isEditing.value && !!props.task?.archived
})
function toggleTag(id: number) {
const idx = form.tagIds.indexOf(id)
if (idx >= 0) { if (idx >= 0) {
form.typeIds.splice(idx, 1) form.tagIds.splice(idx, 1)
} else { } else {
form.typeIds.push(id) form.tagIds.push(id)
} }
} }
@@ -183,7 +220,7 @@ function populateForm(task: Task | null) {
form.priorityId = task.priority?.id ?? null form.priorityId = task.priority?.id ?? null
form.assigneeId = task.assignee?.id ?? null form.assigneeId = task.assignee?.id ?? null
form.groupId = task.group?.id ?? null form.groupId = task.group?.id ?? null
form.typeIds = task.types.map(t => t.id) form.tagIds = task.tags.map(t => t.id)
} else { } else {
form.title = '' form.title = ''
form.description = '' form.description = ''
@@ -192,7 +229,7 @@ function populateForm(task: Task | null) {
form.priorityId = null form.priorityId = null
form.assigneeId = null form.assigneeId = null
form.groupId = null form.groupId = null
form.typeIds = [] form.tagIds = []
} }
touched.title = false touched.title = false
} }
@@ -216,6 +253,40 @@ async function handleDelete() {
isSubmitting.value = true isSubmitting.value = true
try { try {
await remove(props.task.id) await remove(props.task.id)
confirmDeleteOpen.value = false
emit('saved')
isOpen.value = false
} finally {
isSubmitting.value = false
}
}
async function handleArchive() {
if (!props.task) return
const timerStore = useTimerStore()
if (timerStore.activeEntry?.task) {
const taskIri = typeof timerStore.activeEntry.task === 'string'
? timerStore.activeEntry.task
: (timerStore.activeEntry.task as any)?.['@id'] ?? `/api/tasks/${(timerStore.activeEntry.task as any)?.id}`
if (taskIri === `/api/tasks/${props.task.id}`) {
await timerStore.stop()
}
}
isSubmitting.value = true
try {
await update(props.task.id, { archived: true })
emit('saved')
isOpen.value = false
} finally {
isSubmitting.value = false
}
}
async function handleUnarchive() {
if (!props.task) return
isSubmitting.value = true
try {
await update(props.task.id, { archived: false })
emit('saved') emit('saved')
isOpen.value = false isOpen.value = false
} finally { } finally {
@@ -238,7 +309,7 @@ async function handleSubmit() {
assignee: form.assigneeId ? `/api/users/${form.assigneeId}` : null, assignee: form.assigneeId ? `/api/users/${form.assigneeId}` : null,
group: form.groupId ? `/api/task_groups/${form.groupId}` : null, group: form.groupId ? `/api/task_groups/${form.groupId}` : null,
project: `/api/projects/${props.projectId}`, project: `/api/projects/${props.projectId}`,
types: form.typeIds.map(id => `/api/task_types/${id}`), tags: form.tagIds.map(id => `/api/task_tags/${id}`),
} }
if (isEditing.value && props.task) { if (isEditing.value && props.task) {