Add nami fields to form field

This commit is contained in:
philipp lang 2024-02-14 00:13:49 +01:00
parent 891f0c21ad
commit e508dd9e6f
7 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,19 @@
<?php
namespace App\Form\Enums;
enum NamiField: string
{
case FIRSTNAME = 'Vorname';
case BIRTHDAY = 'Geburtstag';
/**
* @return array<int, array{name: string, id: string}>
*/
public static function forSelect(): array
{
return collect(static::cases())
->map(fn ($case) => ['id' => $case->value, 'name' => $case->value])
->toArray();
}
}

View File

@ -129,6 +129,7 @@ abstract class Field extends Data
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'default' => static::default(),
'required' => false,
'nami_field' => null,
...collect(static::meta())->mapWithKeys(fn ($meta) => [$meta['key'] => $meta['default']])->toArray(),
],
];

View File

@ -2,6 +2,7 @@
namespace App\Form\Resources;
use App\Form\Enums\NamiField;
use App\Form\Fields\Field;
use App\Form\FilterScope;
use App\Form\Models\Form;
@ -64,6 +65,7 @@ class FormResource extends JsonResource
'formtemplate_index' => route('formtemplate.index'),
],
'templates' => FormtemplateResource::collection(Formtemplate::get()),
'namiFields' => NamiField::forSelect(),
'default' => [
'description' => [],
'name' => '',

View File

@ -2,6 +2,7 @@
namespace App\Form\Resources;
use App\Form\Enums\NamiField;
use App\Form\Fields\Field;
use App\Form\Models\Formtemplate;
use App\Group;
@ -42,6 +43,7 @@ class FormtemplateResource extends JsonResource
'base_url' => url(''),
'groups' => Group::forSelect(),
'fields' => Field::asMeta(),
'namiFields' => NamiField::forSelect(),
'links' => [
'store' => route('formtemplate.store'),
'form_index' => route('form.index'),

View File

@ -22,6 +22,7 @@
<f-text id="fieldname" v-model="singleField.model.name" label="Name" size="sm" name="fieldname"></f-text>
<column-selector v-model="singleField.model.columns"></column-selector>
<component :is="fields[singleField.model.type]" v-model="singleField.model" :payload="inner.sections" :meta="props.meta"></component>
<f-select id="nami_field" v-model="singleField.model.nami_field" :options="meta.namiFields" label="NaMi-Feld" size="sm" name="nami_field"></f-select>
</asideform>
</div>
<ui-box heading="Vorschau" container-class="grid gap-3" class="w-[800px]">

View File

@ -60,6 +60,7 @@ class FormIndexActionTest extends EndToEndTestCase
->assertInertiaPath('data.meta.default.excerpt', '')
->assertInertiaPath('data.meta.default.config', null)
->assertInertiaPath('data.meta.base_url', url(''))
->assertInertiaPath('data.meta.namiFields.0', ['id' => 'Vorname', 'name' => 'Vorname'])
->assertInertiaPath('data.meta.section_default.name', '');
}

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Form;
use App\Form\Enums\NamiField;
use App\Form\Fields\TextField;
use App\Form\Models\Form;
use App\Lib\Events\Succeeded;
@ -37,7 +38,7 @@ class FormStoreActionTest extends TestCase
->mailTop('Guten Tag')
->mailBottom('Viele Grüße')
->headerImage('htzz.jpg')
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)->namiField(NamiField::BIRTHDAY)])])
->fake();
$this->postJson(route('form.store'))->assertOk();
@ -53,6 +54,7 @@ class FormStoreActionTest extends TestCase
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));
$this->assertEquals('2023-07-07', $form->from->format('Y-m-d'));
$this->assertEquals('2023-07-08', $form->to->format('Y-m-d'));
$this->assertEquals('Geburtstag', $form->config['sections'][0]['fields'][0]['nami_field']);
$this->assertCount(1, $form->getMedia('headerImage'));
$this->assertEquals('formname.jpg', $form->getMedia('headerImage')->first()->file_name);
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Veranstaltung gespeichert.');