|
| 1 | +<script setup lang="ts"> |
| 2 | +import Heading from '@/components/Heading.vue'; |
| 3 | +import InputError from '@/components/InputError.vue'; |
| 4 | +import { Button } from '@/components/ui/button'; |
| 5 | +import { Input } from '@/components/ui/input'; |
| 6 | +import { Label } from '@/components/ui/label'; |
| 7 | +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; |
| 8 | +import AppLayout from '@/layouts/AppLayout.vue'; |
| 9 | +import type { BreadcrumbItem, VcsInstance } from '@/types'; |
| 10 | +import { Head, useForm } from '@inertiajs/vue3'; |
| 11 | +
|
| 12 | +const breadcrumbs: BreadcrumbItem[] = [ |
| 13 | + { |
| 14 | + title: 'Repositories', |
| 15 | + href: '/repositories', |
| 16 | + }, |
| 17 | + { |
| 18 | + title: 'Add VCS instance', |
| 19 | + href: '#', |
| 20 | + }, |
| 21 | +]; |
| 22 | +
|
| 23 | +interface Props { |
| 24 | + platforms: Record<string, string>; |
| 25 | +} |
| 26 | +
|
| 27 | +defineProps<Props>(); |
| 28 | +
|
| 29 | +const form = useForm<VcsInstance>({ |
| 30 | + name: '', |
| 31 | + api_url: '', |
| 32 | + token: '', |
| 33 | + installation_id: '', |
| 34 | + platform: 'gitlab', |
| 35 | +}); |
| 36 | +
|
| 37 | +const createVcsInstance = () => { |
| 38 | + form.post(route('vcs-instances.store'), { |
| 39 | + preserveScroll: true, |
| 40 | + }); |
| 41 | +}; |
| 42 | +</script> |
| 43 | + |
| 44 | +<template> |
| 45 | + <AppLayout :breadcrumbs="breadcrumbs"> |
| 46 | + <Head title="Add VCS instance" /> |
| 47 | + |
| 48 | + <div class="flex p-4"> |
| 49 | + <div class="mx-auto w-full py-10 sm:w-1/2"> |
| 50 | + <Heading title="Add VCS instance" /> |
| 51 | + <form @submit.prevent="createVcsInstance" class="space-y-6"> |
| 52 | + <div class="grid gap-2"> |
| 53 | + <Label for="name">Name</Label> |
| 54 | + <Input id="name" v-model="form.name" class="mt-1 block w-full" required /> |
| 55 | + <InputError :message="form.errors.name" /> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div class="grid gap-2"> |
| 59 | + <Label for="api_url">API URL</Label> |
| 60 | + <Input id="api_url" v-model="form.api_url" class="mt-1 block w-full" required /> |
| 61 | + <InputError :message="form.errors.api_url" /> |
| 62 | + <p class="text-sm text-muted-foreground">Base API URL e.g. https://api.github.com/ or https://gitlab.com/api/</p> |
| 63 | + </div> |
| 64 | + |
| 65 | + <div class="grid gap-2"> |
| 66 | + <Label for="platform">Platform</Label> |
| 67 | + <Select id="platform" v-model="form.platform" class="mt-1 block w-full" required> |
| 68 | + <SelectTrigger> |
| 69 | + <SelectValue placeholder="Select platform" /> |
| 70 | + </SelectTrigger> |
| 71 | + <SelectContent> |
| 72 | + <SelectItem v-for="(label, value) in platforms" :key="value" :value="value">{{ label }}</SelectItem> |
| 73 | + </SelectContent> |
| 74 | + </Select> |
| 75 | + <InputError :message="form.errors.platform" /> |
| 76 | + </div> |
| 77 | + |
| 78 | + <div class="grid gap-2" v-if="form.platform === 'github'"> |
| 79 | + <Label for="installation_id">Installation ID</Label> |
| 80 | + <Input id="installation_id" v-model="form.installation_id" class="mt-1 block w-full" required /> |
| 81 | + <InputError :message="form.errors.installation_id" /> |
| 82 | + <p class="text-sm text-muted-foreground"> |
| 83 | + Installation ID could be found at Settings → Integrations → Applications → App as part of the URL |
| 84 | + </p> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div class="grid gap-2" v-if="form.platform === 'gitlab'"> |
| 88 | + <Label for="token">Token</Label> |
| 89 | + <Input id="token" type="password" v-model="form.token" class="mt-1 block w-full" required /> |
| 90 | + <InputError :message="form.errors.token" /> |
| 91 | + </div> |
| 92 | + |
| 93 | + <div class="flex items-center gap-4"> |
| 94 | + <Button :disabled="form.processing">Create VCS instance</Button> |
| 95 | + |
| 96 | + <Transition |
| 97 | + enter-active-class="transition ease-in-out" |
| 98 | + enter-from-class="opacity-0" |
| 99 | + leave-active-class="transition ease-in-out" |
| 100 | + leave-to-class="opacity-0" |
| 101 | + > |
| 102 | + <p v-show="form.recentlySuccessful" class="text-sm text-neutral-600">Saved.</p> |
| 103 | + </Transition> |
| 104 | + </div> |
| 105 | + </form> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </AppLayout> |
| 109 | +</template> |
0 commit comments