From 657a648f469b8ff1b825e2ecae0bb1994edaccba Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 13 Jul 2024 18:24:43 +0200 Subject: [PATCH] Add: Store participant --- app/Form/Actions/ParticipantStoreAction.php | 56 +++++++++++++++++++ app/Form/Resources/ParticipantResource.php | 2 + resources/js/views/form/Participants.vue | 14 +++-- routes/web.php | 2 + .../Form/ParticipantIndexActionTest.php | 4 +- .../Form/ParticipantStoreActionTest.php | 43 ++++++++++++++ 6 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 app/Form/Actions/ParticipantStoreAction.php create mode 100644 tests/Feature/Form/ParticipantStoreActionTest.php diff --git a/app/Form/Actions/ParticipantStoreAction.php b/app/Form/Actions/ParticipantStoreAction.php new file mode 100644 index 00000000..db9d572d --- /dev/null +++ b/app/Form/Actions/ParticipantStoreAction.php @@ -0,0 +1,56 @@ + + */ + public function rules(): array + { + /** @var Form */ + $form = request()->route('form'); + + return $form->getRegistrationRules(); + } + + /** + * @return array + */ + public function getValidationAttributes(): array + { + /** @var Form */ + $form = request()->route('form'); + + return $form->getRegistrationAttributes(); + } + + /** + * @return array + */ + public function getValidationMessages(): array + { + /** @var Form */ + $form = request()->route('form'); + + return $form->getRegistrationMessages(); + } + + public function handle(Form $form, ActionRequest $request): JsonResponse + { + $form->participants()->create(['data' => $request->validated()]); + ExportSyncAction::dispatch($form->id); + Succeeded::message('Teilnehmer*in erstellt.')->dispatch(); + return response()->json([]); + } +} diff --git a/app/Form/Resources/ParticipantResource.php b/app/Form/Resources/ParticipantResource.php index 95ec8556..0c8cd739 100644 --- a/app/Form/Resources/ParticipantResource.php +++ b/app/Form/Resources/ParticipantResource.php @@ -60,12 +60,14 @@ class ParticipantResource extends JsonResource return [ 'filter' => ParticipantFilterScope::fromRequest(request()->input('filter', ''))->setForm($form), + 'form_config' => $form->config, 'default_filter_value' => ParticipantFilterScope::$nan, 'filters' => $filterData, 'form_meta' => $form->meta, 'has_nami_field' => $form->getFields()->hasNamiField(), 'links' => [ 'update_form_meta' => route('form.update-meta', ['form' => $form]), + 'store_participant' => route('form.participant.store', ['form' => $form]), ], 'columns' => $fieldData->push([ 'name' => 'Registriert am', diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index f8d04c79..1539bd27 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -1,8 +1,8 @@