enum fix, create form wip

This commit is contained in:
2025-04-01 16:33:50 +00:00
parent 0cd00c641b
commit 8f0e319a63
12 changed files with 74 additions and 21 deletions

View File

@@ -69,6 +69,14 @@ class GenerateJSEnums extends Command
$js .= "\n"; $js .= "\n";
} }
if (method_exists($enum, 'getDescription')) {
$values = $enum::toArray();
$descriptions = array_map(fn($key) => $enum::getDescription($key), $values);
$js .= 'export const DescriptionMap = ';
$js .= json_encode($descriptions, JSON_PRETTY_PRINT) . "\n";
$js .= "\n";
}
if (method_exists($enum, 'colours')) { if (method_exists($enum, 'colours')) {
$colours = $enum::colours(); $colours = $enum::colours();
$js .= 'export const ColourMap = '; $js .= 'export const ColourMap = ';

View File

@@ -13,4 +13,20 @@ enum ServiceCategory: string
case GATEWAY = 'gateway'; case GATEWAY = 'gateway';
case STORAGE = 'storage'; case STORAGE = 'storage';
case CACHE = 'cache'; case CACHE = 'cache';
public static function getDescription(ServiceCategory|string $category) {
if (is_string($category)) {
$category = ServiceCategory::from($category);
}
if (! $category instanceof ServiceCategory) {
throw new \InvalidArgumentException('Invalid category provided');
}
return match ($category) {
self::APPLICATION => 'The base container image for your application',
self::DATABASE => 'Postgres or MySQL',
self::GATEWAY => 'The gateway is the first point of contact for your application',
self::STORAGE => 'S3 or S3-compatible service',
self::CACHE => 'Redis, Memcached or similar',
};
}
} }

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"PENDING": "pending", "PENDING": "pending",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"NOT_APPLIED": "not-applied", "NOT_APPLIED": "not-applied",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"ADMIN": "admin", "ADMIN": "admin",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"GIT": "git" "GIT": "git"

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"HETZNER": "hetzner", "HETZNER": "hetzner",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"WAITING_FOR_PROVIDER": "waiting-for-provider", "WAITING_FOR_PROVIDER": "waiting-for-provider",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"DATABASE": "database", "DATABASE": "database",
@@ -9,3 +9,11 @@ export default {
"CACHE": "cache" "CACHE": "cache"
} }
export const DescriptionMap = {
"DATABASE": "Postgres or MySQL",
"APPLICATION": "The base container image for your application",
"GATEWAY": "The gateway is the first point of contact for your application",
"STORAGE": "S3 or S3-compatible service",
"CACHE": "Redis, Memcached or similar"
}

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"NOT_INSTALLED": "not-installed", "NOT_INSTALLED": "not-installed",

View File

@@ -1,5 +1,5 @@
// This is a generated file. // This is a generated file.
// Published at 2025-04-01 16:18:32 // Published at 2025-04-01 16:27:12
export default { export default {
"FRANKENPHP": "frankenphp", "FRANKENPHP": "frankenphp",

View File

@@ -1,13 +1,14 @@
<script setup> <script setup>
import RadioButton from '@/components/RadioButton.vue';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import AppLayout from '@/layouts/AppLayout.vue'; import AppLayout from '@/layouts/AppLayout.vue';
import { Head, router, useForm } from '@inertiajs/vue3'; import { Head, useForm } from '@inertiajs/vue3';
import { watch } from 'vue'; import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
import InputError from '@/components/InputError.vue';
import ServiceCategory, { DescriptionMap as serviceCategoryDescriptions } from '@/enums/ServiceCategory';
import RadioButton from '@/components/RadioButton.vue';
const props = defineProps({ const props = defineProps({});
});
const form = useForm({ const form = useForm({
name: null, name: null,
@@ -32,14 +33,34 @@ const form = useForm({
}, },
{ {
title: 'Create', title: 'Create',
} },
]" ]"
> >
<div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4"> <div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4">
<div class="flex gap-2">
<RadioButton
v-for="(category, categoryKey) in ServiceCategory"
v-model="form.category"
:value="category"
name="category"
>
<h4 class="text-lg font-semibold tracking-tighter">{{ category }}</h4>
<p class="text-sm">{{ serviceCategoryDescriptions[categoryKey] }}</p>
</RadioButton>
</div>
<div class="grid gap-2">
<div> <Label for="name">Name</Label>
<Input
id="name"
type="text"
required
autofocus
:tabindex="1"
v-model="form.name"
placeholder="postgres-db"
/>
<InputError :message="form.errors.name" />
</div> </div>
<div class="flex items-center justify-end"> <div class="flex items-center justify-end">