From db640c8185239a2161b5040fbc31cbb1843049ee Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 27 May 2024 19:47:28 +0200 Subject: [PATCH] Add register url --- app/Form/Actions/SettingIndexAction.php | 35 ++++++++++++++ app/Form/Actions/SettingStoreAction.php | 44 +++++++++++++++++ app/Form/FormSettings.php | 39 +++++++++++++++ app/Form/Resources/FormResource.php | 2 + app/Setting/SettingServiceProvider.php | 2 + ...024_05_27_193133_create_forms_settings.php | 11 +++++ resources/js/views/form/Index.vue | 1 + resources/js/views/setting/Form.vue | 47 +++++++++++++++++++ tests/EndToEnd/Form/FormIndexActionTest.php | 11 +++++ 9 files changed, 192 insertions(+) create mode 100644 app/Form/Actions/SettingIndexAction.php create mode 100644 app/Form/Actions/SettingStoreAction.php create mode 100644 app/Form/FormSettings.php create mode 100644 database/settings/2024_05_27_193133_create_forms_settings.php create mode 100644 resources/js/views/setting/Form.vue diff --git a/app/Form/Actions/SettingIndexAction.php b/app/Form/Actions/SettingIndexAction.php new file mode 100644 index 00000000..3170afdd --- /dev/null +++ b/app/Form/Actions/SettingIndexAction.php @@ -0,0 +1,35 @@ + + */ + 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), + ]); + } +} diff --git a/app/Form/Actions/SettingStoreAction.php b/app/Form/Actions/SettingStoreAction.php new file mode 100644 index 00000000..509f3128 --- /dev/null +++ b/app/Form/Actions/SettingStoreAction.php @@ -0,0 +1,44 @@ + $input + */ + public function handle(array $input): void + { + $settings = app(FormSettings::class); + + $settings->fill([ + 'registerUrl' => $input['register_url'], + ]); + + $settings->save(); + } + + /** + * @return array + */ + public function rules(): array + { + return [ + 'register_url' => 'present|string', + ]; + } + + public function asController(ActionRequest $request): RedirectResponse + { + $this->handle($request->validated()); + + return redirect()->back(); + } +} diff --git a/app/Form/FormSettings.php b/app/Form/FormSettings.php new file mode 100644 index 00000000..5e596d03 --- /dev/null +++ b/app/Form/FormSettings.php @@ -0,0 +1,39 @@ + 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) ] ]; } diff --git a/app/Setting/SettingServiceProvider.php b/app/Setting/SettingServiceProvider.php index d5fd0e85..bb56e90b 100644 --- a/app/Setting/SettingServiceProvider.php +++ b/app/Setting/SettingServiceProvider.php @@ -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); } } diff --git a/database/settings/2024_05_27_193133_create_forms_settings.php b/database/settings/2024_05_27_193133_create_forms_settings.php new file mode 100644 index 00000000..211f0906 --- /dev/null +++ b/database/settings/2024_05_27_193133_create_forms_settings.php @@ -0,0 +1,11 @@ +migrator->add('form.registerUrl', ''); + } +}; diff --git a/resources/js/views/form/Index.vue b/resources/js/views/form/Index.vue index af335fae..03891882 100644 --- a/resources/js/views/form/Index.vue +++ b/resources/js/views/form/Index.vue @@ -153,6 +153,7 @@
+
diff --git a/resources/js/views/setting/Form.vue b/resources/js/views/setting/Form.vue new file mode 100644 index 00000000..4d374621 --- /dev/null +++ b/resources/js/views/setting/Form.vue @@ -0,0 +1,47 @@ + + + diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index 3d6d87c9..80d93c34 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -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();