309 lines
14 KiB
Vue
309 lines
14 KiB
Vue
<script setup lang="ts">
|
|
import { Form, Head, Link } from '@inertiajs/vue3';
|
|
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 { 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 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
|
|
v-bind="ProjectTicketController.store.form(project.id)"
|
|
class="grid gap-6"
|
|
v-slot="{ errors, processing }"
|
|
>
|
|
<div class="grid gap-2">
|
|
<Label for="title">Title</Label>
|
|
<Input
|
|
id="title"
|
|
name="title"
|
|
required
|
|
autofocus
|
|
placeholder="Implement repository sync"
|
|
/>
|
|
<InputError :message="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"
|
|
name="description"
|
|
rows="4"
|
|
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]"
|
|
placeholder="Describe the expected behavior and relevant context."
|
|
/>
|
|
<InputError :message="errors.description" />
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="acceptance_criteria">
|
|
Acceptance criteria
|
|
</Label>
|
|
<textarea
|
|
id="acceptance_criteria"
|
|
name="acceptance_criteria"
|
|
rows="4"
|
|
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]"
|
|
placeholder="List the conditions that must be true before this ticket is done."
|
|
/>
|
|
<InputError
|
|
:message="errors.acceptance_criteria"
|
|
/>
|
|
</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"
|
|
name="ticket_type_id"
|
|
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]"
|
|
>
|
|
<option
|
|
v-for="ticketType in ticketTypes"
|
|
:key="ticketType.id"
|
|
:value="ticketType.id"
|
|
>
|
|
{{ ticketType.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="errors.ticket_type_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="ticket_priority_id">
|
|
Priority
|
|
</Label>
|
|
<select
|
|
id="ticket_priority_id"
|
|
name="ticket_priority_id"
|
|
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]"
|
|
>
|
|
<option
|
|
v-for="ticketPriority in ticketPriorities"
|
|
:key="ticketPriority.id"
|
|
:value="ticketPriority.id"
|
|
>
|
|
{{ ticketPriority.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="errors.ticket_priority_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="ticket_status_id">Status</Label>
|
|
<select
|
|
id="ticket_status_id"
|
|
name="ticket_status_id"
|
|
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]"
|
|
>
|
|
<option
|
|
v-for="ticketStatus in ticketStatusOptions"
|
|
:key="ticketStatus.id"
|
|
:value="ticketStatus.id"
|
|
:selected="
|
|
ticketStatus.id ===
|
|
defaultTicketStatusId
|
|
"
|
|
>
|
|
{{ ticketStatusLabel(ticketStatus) }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="errors.ticket_status_id"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid gap-2">
|
|
<Label for="assignee_user_id">
|
|
Assignee
|
|
</Label>
|
|
<select
|
|
id="assignee_user_id"
|
|
name="assignee_user_id"
|
|
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]"
|
|
>
|
|
<option value="">Unassigned</option>
|
|
<option
|
|
v-for="user in users"
|
|
:key="user.id"
|
|
:value="user.id"
|
|
>
|
|
{{ user.name }}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:message="errors.assignee_user_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"
|
|
name="story_points"
|
|
type="number"
|
|
step="1"
|
|
/>
|
|
<InputError
|
|
:message="errors.story_points"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<Button type="submit" :disabled="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>
|