Add register url
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
philipp lang 2024-05-27 19:47:28 +02:00
parent 0fb259a373
commit db640c8185
9 changed files with 192 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function handle(FormSettings $settings): array
{
return [
'data' => [
'register_url' => $settings->registerUrl,
],
];
}
public function asController(FormSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Module');
return Inertia::render('setting/Form', [
'data' => $this->handle($settings),
]);
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingStoreAction
{
use AsAction;
/**
* @param array<string, mixed> $input
*/
public function handle(array $input): void
{
$settings = app(FormSettings::class);
$settings->fill([
'registerUrl' => $input['register_url'],
]);
$settings->save();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'register_url' => 'present|string',
];
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->validated());
return redirect()->back();
}
}

39
app/Form/FormSettings.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace App\Form;
use App\Form\Actions\SettingIndexAction;
use App\Form\Actions\SettingStoreAction;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings;
class FormSettings extends LocalSettings implements Indexable, Storeable
{
public string $registerUrl;
public static function group(): string
{
return 'form';
}
public static function slug(): string
{
return 'form';
}
public static function title(): string
{
return 'Formulare';
}
public static function indexAction(): string
{
return SettingIndexAction::class;
}
public static function storeAction(): string
{
return SettingStoreAction::class;
}
}

View File

@ -5,6 +5,7 @@ namespace App\Form\Resources;
use App\Form\Enums\NamiType;
use App\Form\Enums\SpecialType;
use App\Form\Fields\Field;
use App\Form\FormSettings;
use App\Form\Scopes\FormFilterScope;
use App\Form\Models\Form;
use App\Form\Models\Formtemplate;
@ -50,6 +51,7 @@ class FormResource extends JsonResource
'update' => route('form.update', ['form' => $this->getModel()]),
'destroy' => route('form.destroy', ['form' => $this->getModel()]),
'is_dirty' => route('form.is-dirty', ['form' => $this->getModel()]),
'frontend' => str(app(FormSettings::class)->registerUrl)->replace('{slug}', $this->slug)
]
];
}

View File

@ -2,6 +2,7 @@
namespace App\Setting;
use App\Form\FormSettings;
use App\Invoice\InvoiceSettings;
use App\Mailgateway\MailgatewaySettings;
use App\Module\ModuleSettings;
@ -30,5 +31,6 @@ class SettingServiceProvider extends ServiceProvider
app(SettingFactory::class)->register(InvoiceSettings::class);
app(SettingFactory::class)->register(MailgatewaySettings::class);
app(SettingFactory::class)->register(NamiSettings::class);
app(SettingFactory::class)->register(FormSettings::class);
}
}

View File

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('form.registerUrl', '');
}
};

View File

@ -153,6 +153,7 @@
<div class="flex space-x-2">
<ui-action-button tooltip="Bearbeiten" class="btn-warning" icon="pencil" @click.prevent="edit(form)"></ui-action-button>
<ui-action-button tooltip="Teilnehmende anzeigen" class="btn-info" icon="user" @click.prevent="showParticipants(form)"></ui-action-button>
<ui-action-button :href="form.links.frontend" target="_BLANK" tooltip="zur Anmeldeseite" class="btn-info" icon="eye"></ui-action-button>
<ui-action-button tooltip="Löschen" class="btn-danger" icon="trash" @click.prevent="deleting = form"></ui-action-button>
</div>
</td>

View File

@ -0,0 +1,47 @@
<template>
<page-layout>
<template #right>
<f-save-button form="formsettingsform"></f-save-button>
</template>
<setting-layout>
<form id="formsettingsform" class="grow p-6 grid grid-cols-2 gap-3 items-start content-start" @submit.prevent="submit">
<div class="col-span-full text-gray-100 mb-3">
<p class="text-sm">Hier kannst du Einstellungen für Anmeldeformulare setzen.</p>
</div>
<div class="grid grid-cols-2 gap-4">
<f-text id="register_url" v-model="inner.register_url" label="Formular-Link" name="register_url"></f-text>
</div>
</form>
</setting-layout>
</page-layout>
</template>
<script>
import SettingLayout from './Layout.vue';
export default {
components: {
SettingLayout,
},
props: {
data: {
type: Object,
default: () => {
return {};
},
},
},
data: function () {
return {
inner: {...this.data.data},
};
},
methods: {
submit() {
this.$inertia.post('/setting/form', this.inner, {
onSuccess: () => this.$success('Einstellungen gespeichert.'),
});
},
},
};
</script>

View File

@ -2,6 +2,7 @@
namespace Tests\EndToEnd\Form;
use App\Form\FormSettings;
use App\Form\Models\Form;
use App\Form\Models\Formtemplate;
use App\Form\Models\Participant;
@ -81,6 +82,16 @@ class FormIndexActionTest extends FormTestCase
->assertInertiaCount('data.data', 2);
}
public function testItDisplaysRegisterUrl(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
FormSettings::fake(['registerUrl' => 'https://example.com/form/{slug}/register']);
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
sleep(1);
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.frontend', 'https://example.com/form/zem-2024/register');
}
public function testItDoesntReturnInactiveForms(): void
{
$this->withoutExceptionHandling()->login()->loginNami();