438 lines
21 KiB
Vue
438 lines
21 KiB
Vue
<script setup lang="ts">
|
|
import { Head, Link, useForm } from '@inertiajs/vue3';
|
|
import { computed, ref } from 'vue';
|
|
import ProjectTicketController from '@/actions/App/Http/Controllers/ProjectTicketController';
|
|
import Heading from '@/components/Heading.vue';
|
|
import InputError from '@/components/InputError.vue';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from '@/components/ui/card';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import AppLayout from '@/layouts/AppLayout.vue';
|
|
import {
|
|
buildAcceptanceCriteria,
|
|
parseChecklistLines,
|
|
} from '@/lib/acceptance-criteria';
|
|
import { index as backlogIndex } from '@/routes/projects/backlog';
|
|
import { index as boardIndex } from '@/routes/projects/board';
|
|
import { index, show } from '@/routes/projects/index';
|
|
import { metadata as metadataSettings } from '@/routes/projects/settings';
|
|
import type { BreadcrumbItem, ProjectTicketCreatePageProps } from '@/types';
|
|
import type { TicketStatusModel } from '@/types/models/ticket-status-model';
|
|
|
|
const props = defineProps<ProjectTicketCreatePageProps>();
|
|
|
|
const returnHref =
|
|
props.source === 'board'
|
|
? boardIndex(props.project.id)
|
|
: backlogIndex(props.project.id);
|
|
const returnLabel =
|
|
props.source === 'board' ? 'Back to board' : 'Back to backlog';
|
|
|
|
const breadcrumbs: BreadcrumbItem[] = [
|
|
{
|
|
title: 'Projects',
|
|
href: index(),
|
|
},
|
|
{
|
|
title: props.project.name,
|
|
href: show(props.project.id),
|
|
},
|
|
{
|
|
title: props.source === 'board' ? 'Board' : 'Backlog',
|
|
href: returnHref,
|
|
},
|
|
{
|
|
title: 'Create ticket',
|
|
href: ProjectTicketController.create({
|
|
project: props.project.id,
|
|
}),
|
|
},
|
|
];
|
|
|
|
const hasTicketMetadata =
|
|
props.ticketTypes.length > 0 &&
|
|
props.ticketPriorities.length > 0 &&
|
|
props.ticketStatusOptions.length > 0;
|
|
|
|
const acceptanceCriteriaChecklist = ref('');
|
|
|
|
const form = useForm({
|
|
acceptance_criteria: buildAcceptanceCriteria(
|
|
acceptanceCriteriaChecklist.value,
|
|
),
|
|
assignee_user_id: '',
|
|
description: '',
|
|
parent_ticket_id: '',
|
|
story_points: '',
|
|
ticket_priority_id: String(props.ticketPriorities[0]?.id ?? ''),
|
|
ticket_status_id: String(
|
|
props.defaultTicketStatusId ?? props.ticketStatusOptions[0]?.id ?? '',
|
|
),
|
|
ticket_type_id: String(props.ticketTypes[0]?.id ?? ''),
|
|
title: '',
|
|
});
|
|
|
|
const acceptanceCriteriaPreviewItems = computed(() =>
|
|
parseChecklistLines(acceptanceCriteriaChecklist.value),
|
|
);
|
|
|
|
const acceptanceCriteriaError = computed(() => {
|
|
return (
|
|
form.errors.acceptance_criteria ??
|
|
Object.entries(form.errors).find(([key]) =>
|
|
key.startsWith('acceptance_criteria.'),
|
|
)?.[1] ??
|
|
''
|
|
);
|
|
});
|
|
|
|
const submit = (): void => {
|
|
form.acceptance_criteria = buildAcceptanceCriteria(
|
|
acceptanceCriteriaChecklist.value,
|
|
);
|
|
|
|
form.submit(ProjectTicketController.store({ project: props.project.id }), {
|
|
preserveScroll: true,
|
|
});
|
|
};
|
|
|
|
const ticketStatusLabel = (ticketStatus: TicketStatusModel): string => {
|
|
if (
|
|
ticketStatus.board_column === null ||
|
|
ticketStatus.board_column === undefined
|
|
) {
|
|
return ticketStatus.name;
|
|
}
|
|
|
|
if (ticketStatus.board_column.name === ticketStatus.name) {
|
|
return ticketStatus.name;
|
|
}
|
|
|
|
return `${ticketStatus.board_column.name} / ${ticketStatus.name}`;
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<AppLayout :breadcrumbs="breadcrumbs">
|
|
<Head :title="`Create ${project.name} ticket`" />
|
|
|
|
<div class="flex flex-1 flex-col gap-6 p-4">
|
|
<div
|
|
class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"
|
|
>
|
|
<div class="space-y-3">
|
|
<Badge variant="outline" class="px-3 py-1">
|
|
{{ project.key }}
|
|
</Badge>
|
|
<Heading
|
|
title="Create ticket"
|
|
:description="`Add a ticket to ${project.name}.`"
|
|
/>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
<Button as-child variant="outline">
|
|
<Link :href="returnHref">{{ returnLabel }}</Link>
|
|
</Button>
|
|
<Button as-child variant="outline">
|
|
<Link :href="show(project.id)">Back to project</Link>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="status"
|
|
class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-900 dark:border-emerald-900/70 dark:bg-emerald-950/40 dark:text-emerald-100"
|
|
>
|
|
{{ status }}
|
|
</div>
|
|
|
|
<Card v-if="hasTicketMetadata">
|
|
<CardHeader>
|
|
<CardTitle>Ticket details</CardTitle>
|
|
<CardDescription>
|
|
The ticket key is assigned after creation.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
|
|
<CardContent>
|
|
<form class="grid gap-6" @submit.prevent="submit">
|
|
<div class="grid gap-2">
|
|
<Label for="title">Title</Label>
|
|
<Input
|
|
id="title"
|
|
v-model="form.title"
|
|
required
|
|
autofocus
|
|
:disabled="form.processing"
|
|
placeholder="Implement repository sync"
|
|
/>
|
|
<InputError :message="form.errors.title" />
|
|
</div>
|
|
|
|
<div
|
|
class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_20rem]"
|
|
>
|
|
<div class="grid gap-6">
|
|
<div class="grid gap-2">
|
|
<Label for="description">Description</Label>
|
|
<textarea
|
|
id="description"
|
|
v-model="form.description"
|
|
rows="4"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
placeholder="Describe the expected behavior and relevant context."
|
|
/>
|
|
<InputError
|
|
:message="form.errors.description"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-4">
|
|
<div class="grid gap-2">
|
|
<Label
|
|
for="acceptance_criteria_checklist"
|
|
>
|
|
Acceptance criteria checklist
|
|
</Label>
|
|
<textarea
|
|
id="acceptance_criteria_checklist"
|
|
v-model="
|
|
acceptanceCriteriaChecklist
|
|
"
|
|
rows="6"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
placeholder="[ ] User can sign in [x] Validation is shown for invalid credentials"
|
|
/>
|
|
<p
|
|
class="text-muted-foreground text-xs"
|
|
>
|
|
Use <code>[ ]</code> /
|
|
<code>[x]</code> for checklist
|
|
items. Indent with two spaces for
|
|
nested steps.
|
|
</p>
|
|
<InputError
|
|
:message="acceptanceCriteriaError"
|
|
/>
|
|
</div>
|
|
|
|
<div
|
|
v-if="
|
|
acceptanceCriteriaPreviewItems.length >
|
|
0
|
|
"
|
|
class="border-border rounded-xl border p-4 text-sm"
|
|
>
|
|
<p class="mb-3 font-medium">
|
|
Checklist preview
|
|
</p>
|
|
<ul class="space-y-2">
|
|
<li
|
|
v-for="(
|
|
item, index
|
|
) in acceptanceCriteriaPreviewItems"
|
|
:key="index"
|
|
:style="{
|
|
marginLeft: `${item.indent * 1.25}rem`,
|
|
}"
|
|
class="flex items-start gap-2"
|
|
>
|
|
<span class="mt-0.5">{{
|
|
item.checked ? '☑' : '☐'
|
|
}}</span>
|
|
<span>{{ item.text }}</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid h-fit gap-6">
|
|
<div class="grid gap-2">
|
|
<Label for="ticket_type_id">Type</Label>
|
|
<select
|
|
id="ticket_type_id"
|
|
v-model="form.ticket_type_id"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option
|
|
v-for="ticketType in ticketTypes"
|
|
:key="ticketType.id"
|
|
:value="String(ticketType.id)"
|
|
>
|
|
{{ ticketType.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="form.errors.ticket_type_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="ticket_priority_id">
|
|
Priority
|
|
</Label>
|
|
<select
|
|
id="ticket_priority_id"
|
|
v-model="form.ticket_priority_id"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option
|
|
v-for="ticketPriority in ticketPriorities"
|
|
:key="ticketPriority.id"
|
|
:value="String(ticketPriority.id)"
|
|
>
|
|
{{ ticketPriority.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="
|
|
form.errors.ticket_priority_id
|
|
"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="ticket_status_id">Status</Label>
|
|
<select
|
|
id="ticket_status_id"
|
|
v-model="form.ticket_status_id"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option
|
|
v-for="ticketStatus in ticketStatusOptions"
|
|
:key="ticketStatus.id"
|
|
:value="String(ticketStatus.id)"
|
|
>
|
|
{{
|
|
ticketStatusLabel(ticketStatus)
|
|
}}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="form.errors.ticket_status_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="assignee_user_id">
|
|
Assignee
|
|
</Label>
|
|
<select
|
|
id="assignee_user_id"
|
|
v-model="form.assignee_user_id"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option value="">Unassigned</option>
|
|
<option
|
|
v-for="user in users"
|
|
:key="user.id"
|
|
:value="String(user.id)"
|
|
>
|
|
{{ user.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="form.errors.assignee_user_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="parent_ticket_id">
|
|
Parent ticket
|
|
</Label>
|
|
<select
|
|
id="parent_ticket_id"
|
|
v-model="form.parent_ticket_id"
|
|
:disabled="form.processing"
|
|
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option value="">
|
|
No parent ticket
|
|
</option>
|
|
<option
|
|
v-for="parentTicketOption in parentTicketOptions"
|
|
:key="parentTicketOption.id"
|
|
:value="
|
|
String(parentTicketOption.id)
|
|
"
|
|
>
|
|
{{
|
|
`${parentTicketOption.ticket_key} - ${parentTicketOption.title}`
|
|
}}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="form.errors.parent_ticket_id"
|
|
/>
|
|
</div>
|
|
|
|
<div
|
|
v-if="project.show_story_points"
|
|
class="grid gap-2"
|
|
>
|
|
<Label for="story_points">
|
|
Estimated story points
|
|
</Label>
|
|
<Input
|
|
id="story_points"
|
|
v-model="form.story_points"
|
|
type="number"
|
|
step="1"
|
|
:disabled="form.processing"
|
|
/>
|
|
<InputError
|
|
:message="form.errors.story_points"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<Button type="submit" :disabled="form.processing">
|
|
Create ticket
|
|
</Button>
|
|
<Button as-child variant="outline">
|
|
<Link :href="returnHref">
|
|
{{ returnLabel }}
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card v-else>
|
|
<CardContent class="flex flex-col gap-4 p-6 text-sm">
|
|
<p class="text-muted-foreground">
|
|
Ticket creation needs at least one type, one priority,
|
|
and one status.
|
|
</p>
|
|
<div>
|
|
<Button as-child variant="outline">
|
|
<Link :href="metadataSettings(project.id)">
|
|
Open ticket settings
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</AppLayout>
|
|
</template>
|