add projects detail page, task create / delete

This commit is contained in:
Gregor Vostrak
2024-04-08 18:41:04 +02:00
parent 0081aa7a6e
commit 5293bc7a05
32 changed files with 733 additions and 215 deletions

View File

@@ -0,0 +1,74 @@
<script setup lang="ts">
import TextInput from '@/Components/TextInput.vue';
import SecondaryButton from '@/Components/SecondaryButton.vue';
import DialogModal from '@/Components/DialogModal.vue';
import { ref } from 'vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import { useFocus } from '@vueuse/core';
import { useTasksStore } from '@/utils/useTasks';
import ProjectDropdown from '@/Components/Common/Project/ProjectDropdown.vue';
const { createTask } = useTasksStore();
const show = defineModel('show', { default: false });
const saving = ref(false);
const taskName = ref('');
const props = defineProps<{
projectId: string;
}>();
async function submit() {
await createTask({
name: taskName.value,
project_id: props.projectId,
});
show.value = false;
}
const taskNameInput = ref<HTMLInputElement | null>(null);
useFocus(taskNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<template #title>
<div class="flex space-x-2">
<span> Create Task </span>
</div>
</template>
<template #content>
<div class="flex items-center space-x-4">
<div class="col-span-6 sm:col-span-4 flex-1">
<TextInput
id="taskName"
ref="taskNameInput"
v-model="taskName"
type="text"
placeholder="Task Name"
@keydown.enter="submit()"
class="mt-1 block w-full"
required
autocomplete="taskName" />
</div>
<div class="col-span-6 sm:col-span-4">
<ProjectDropdown :modelValue="projectId"></ProjectDropdown>
</div>
</div>
</template>
<template #footer>
<SecondaryButton @click="show = false"> Cancel </SecondaryButton>
<PrimaryButton
class="ms-3"
:class="{ 'opacity-25': saving }"
:disabled="saving"
@click="submit">
Create Task
</PrimaryButton>
</template>
</DialogModal>
</template>
<style scoped></style>

View File

@@ -0,0 +1,44 @@
<script setup lang="ts">
import Dropdown from '@/Components/Dropdown.vue';
import { TrashIcon } from '@heroicons/vue/20/solid';
import type { Task } from '@/utils/api';
const emit = defineEmits<{
delete: [];
}>();
const props = defineProps<{
task: Task;
}>();
</script>
<template>
<Dropdown>
<template #trigger>
<svg
data-testid="task_actions"
:aria-label="'Actions for Task ' + props.task.name"
class="h-10 w-10 p-2 rounded-full hover:bg-card-background opacity-20 group-hover:opacity-100 transition"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="1.5"
d="M12 5.92A.96.96 0 1 0 12 4a.96.96 0 0 0 0 1.92m0 7.04a.96.96 0 1 0 0-1.92a.96.96 0 0 0 0 1.92M12 20a.96.96 0 1 0 0-1.92a.96.96 0 0 0 0 1.92" />
</svg>
</template>
<template #content>
<button
@click="emit('delete')"
:aria-label="'Delete Task ' + props.task.name"
data-testid="task_delete"
class="flex items-center space-x-3 w-full px-3 py-2.5 text-start text-sm font-medium leading-5 text-white hover:bg-card-background-active focus:outline-none focus:bg-card-background-active transition duration-150 ease-in-out">
<TrashIcon class="w-5 text-icon-active"></TrashIcon>
<span>Delete</span>
</button>
</template>
</Dropdown>
</template>
<style scoped></style>

View File

@@ -0,0 +1,53 @@
<script setup lang="ts">
import SecondaryButton from '@/Components/SecondaryButton.vue';
import { PlusCircleIcon } from '@heroicons/vue/24/solid';
import { PlusIcon } from '@heroicons/vue/16/solid';
import { computed, ref } from 'vue';
import { storeToRefs } from 'pinia';
import { useTasksStore } from '@/utils/useTasks';
import TaskTableRow from '@/Components/Common/Task/TaskTableRow.vue';
import TaskTableHeading from '@/Components/Common/Task/TaskTableHeading.vue';
import TaskCreateModal from '@/Components/Common/Task/TaskCreateModal.vue';
const { tasks } = storeToRefs(useTasksStore());
const props = defineProps<{
projectId: string;
}>();
const projectTasks = computed(() => {
return tasks.value.filter((task) => task.project_id === props.projectId);
});
const createTask = ref(false);
</script>
<template>
<TaskCreateModal
:project-id="props.projectId"
v-model:show="createTask"></TaskCreateModal>
<div class="flow-root">
<div class="inline-block min-w-full align-middle">
<div
data-testid="task_table"
class="grid min-w-full"
style="grid-template-columns: 1fr 150px 80px">
<TaskTableHeading></TaskTableHeading>
<div
class="col-span-5 py-24 text-center"
v-if="projectTasks.length === 0">
<PlusCircleIcon
class="w-8 text-icon-default inline pb-2"></PlusCircleIcon>
<h3 class="text-white font-semibold">No tasks found</h3>
<p class="pb-5">Create your first task now!</p>
<SecondaryButton @click="createTask = true" :icon="PlusIcon"
>Create your First Task
</SecondaryButton>
</div>
<template v-for="task in projectTasks" :key="task.id">
<TaskTableRow :task="task"></TaskTableRow>
</template>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,20 @@
<script setup lang="ts">
import TableHeading from '@/Components/Common/TableHeading.vue';
</script>
<template>
<TableHeading>
<div
class="py-1.5 pr-3 text-left text-sm font-semibold text-white pl-4 sm:pl-6 lg:pl-8 3xl:pl-12">
Task Name
</div>
<div class="px-3 py-1.5 text-left text-sm font-semibold text-white">
Status
</div>
<div class="relative py-1.5 pl-3 pr-4 sm:pr-6 lg:pr-8 3xl:pr-12">
<span class="sr-only">Edit</span>
</div>
</TableHeading>
</template>
<style scoped></style>

View File

@@ -0,0 +1,39 @@
<script setup lang="ts">
import type { Task } from '@/utils/api';
import { CheckCircleIcon } from '@heroicons/vue/20/solid';
import { useTasksStore } from '@/utils/useTasks';
import TaskMoreOptionsDropdown from '@/Components/Common/Task/TaskMoreOptionsDropdown.vue';
import TableRow from '@/Components/TableRow.vue';
const props = defineProps<{
task: Task;
}>();
function deleteTask() {
useTasksStore().deleteTask(props.task.id);
}
</script>
<template>
<TableRow>
<div
class="whitespace-nowrap flex items-center space-x-5 3xl:pl-12 py-4 pr-3 text-sm font-medium text-white pl-4 sm:pl-6 lg:pl-8 3xl:pl-12">
<span>
{{ task.name }}
</span>
</div>
<div
class="whitespace-nowrap px-3 py-4 text-sm text-muted flex space-x-1 items-center font-medium">
<CheckCircleIcon class="w-5"></CheckCircleIcon>
<span>Active</span>
</div>
<div
class="relative whitespace-nowrap flex items-center pl-3 text-right text-sm font-medium sm:pr-0 pr-4 sm:pr-6 lg:pr-8 3xl:pr-12">
<TaskMoreOptionsDropdown
:task="task"
@delete="deleteTask"></TaskMoreOptionsDropdown>
</div>
</TableRow>
</template>
<style scoped></style>