From 5cf14957a9cb84946caccae6738eb88ed94257e1 Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:15:35 -0300 Subject: [PATCH 1/8] =?UTF-8?q?dep(events):=20adiciona=20biblioteca=20baco?= =?UTF-8?q?n/bacon-qr-code=20para=20gera=C3=A7=C3=A3o=20de=20QR=20SVG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + composer.lock | 110 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9c7c91f3b..0ffd22e48 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^8.4", + "bacon/bacon-qr-code": "^2.0", "calebporzio/sushi": "^2.5.4", "dedoc/scramble": "^0.13.22", "filament/filament": "^5.6.3", diff --git a/composer.lock b/composer.lock index a62182af2..e5bc641e9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,62 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4cda5177e73cfcd5a61098bfe216f7d4", + "content-hash": "e29b1f89aef6464fd66e415381179b39", "packages": [ + { + "name": "bacon/bacon-qr-code", + "version": "2.0.8", + "source": { + "type": "git", + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/8674e51bb65af933a5ffaf1c308a660387c35c22", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22", + "shasum": "" + }, + "require": { + "dasprid/enum": "^1.0.3", + "ext-iconv": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phly/keep-a-changelog": "^2.1", + "phpunit/phpunit": "^7 | ^8 | ^9", + "spatie/phpunit-snapshot-assertions": "^4.2.9", + "squizlabs/php_codesniffer": "^3.4" + }, + "suggest": { + "ext-imagick": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-4": { + "BaconQrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "support": { + "issues": "https://github.com/Bacon/BaconQrCode/issues", + "source": "https://github.com/Bacon/BaconQrCode/tree/2.0.8" + }, + "time": "2022-12-07T17:46:57+00:00" + }, { "name": "blade-ui-kit/blade-heroicons", "version": "2.7.0", @@ -1227,6 +1281,56 @@ ], "time": "2026-03-16T11:29:23+00:00" }, + { + "name": "dasprid/enum", + "version": "1.0.7", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "b5874fa9ed0043116c72162ec7f4fb50e02e7cce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/b5874fa9ed0043116c72162ec7f4fb50e02e7cce", + "reference": "b5874fa9ed0043116c72162ec7f4fb50e02e7cce", + "shasum": "" + }, + "require": { + "php": ">=7.1 <9.0" + }, + "require-dev": { + "phpunit/phpunit": "^7 || ^8 || ^9 || ^10 || ^11", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "support": { + "issues": "https://github.com/DASPRiD/Enum/issues", + "source": "https://github.com/DASPRiD/Enum/tree/1.0.7" + }, + "time": "2025-09-16T12:23:56+00:00" + }, { "name": "dedoc/scramble", "version": "v0.13.22", @@ -18195,6 +18299,6 @@ "platform": { "php": "^8.4" }, - "platform-dev": {}, - "plugin-api-version": "2.9.0" + "platform-dev": [], + "plugin-api-version": "2.6.0" } From 1565fe8b0da2aef78aa2d67d00e7b45662d6350c Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:16:01 -0300 Subject: [PATCH 2/8] =?UTF-8?q?feat(events/check-in):=20implementa=20gera?= =?UTF-8?q?=C3=A7=C3=A3o=20e=20valida=C3=A7=C3=A3o=20de=20token=20QR=20por?= =?UTF-8?q?=20inscri=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adiciona GenerateQrTokenAction: gera token único URL-safe de 64 chars por enrollment, idempotente — retorna token existente se já criado - Adiciona QrCheckInAction: valida token, enrollment e data do evento antes de delegar ao CheckInAction existente (method=qr_code, payload com token) - Adiciona QrCheckInDTO com validações de token e ator no construtor - Adiciona GenerateQrTokenOnConfirmed listener para o evento EnrollmentConfirmed - Adiciona exceções qrTokenNotFound e qrTokenExpired em CheckInException - Adiciona strings de tradução (en/pt_BR) para os novos erros de check-in QR --- app-modules/events/lang/en/check_in.php | 2 + app-modules/events/lang/pt_BR/check_in.php | 2 + .../CheckIn/Actions/GenerateQrTokenAction.php | 30 +++++++++++++ .../src/CheckIn/Actions/QrCheckInAction.php | 45 +++++++++++++++++++ .../events/src/CheckIn/DTOs/QrCheckInDTO.php | 22 +++++++++ .../CheckIn/Exceptions/CheckInException.php | 16 +++++++ .../Listeners/GenerateQrTokenOnConfirmed.php | 19 ++++++++ 7 files changed, 136 insertions(+) create mode 100644 app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php create mode 100644 app-modules/events/src/CheckIn/Actions/QrCheckInAction.php create mode 100644 app-modules/events/src/CheckIn/DTOs/QrCheckInDTO.php create mode 100644 app-modules/events/src/CheckIn/Listeners/GenerateQrTokenOnConfirmed.php diff --git a/app-modules/events/lang/en/check_in.php b/app-modules/events/lang/en/check_in.php index c163fc1fe..c518f4bdb 100644 --- a/app-modules/events/lang/en/check_in.php +++ b/app-modules/events/lang/en/check_in.php @@ -7,4 +7,6 @@ 'check_in_outside_event_date_range' => 'Check-in date must be within the event date range.', 'already_checked_in_for_date' => 'This enrollment has already checked in for this date.', 'invalid_check_in_actor' => 'Manual check-in requires the organizer user id.', + 'qr_token_not_found' => 'QR token not found or does not belong to this event.', + 'qr_token_expired' => 'This QR token has expired.', ]; diff --git a/app-modules/events/lang/pt_BR/check_in.php b/app-modules/events/lang/pt_BR/check_in.php index 46a65b78e..1655e0a14 100644 --- a/app-modules/events/lang/pt_BR/check_in.php +++ b/app-modules/events/lang/pt_BR/check_in.php @@ -7,4 +7,6 @@ 'check_in_outside_event_date_range' => 'A data do check-in deve estar dentro do período do evento.', 'already_checked_in_for_date' => 'Esta inscrição já possui check-in para essa data.', 'invalid_check_in_actor' => 'Check-in manual exige o ID do usuário organizador.', + 'qr_token_not_found' => 'Token QR não encontrado ou não pertence a este evento.', + 'qr_token_expired' => 'Este token QR expirou.', ]; diff --git a/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php b/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php new file mode 100644 index 000000000..816426b01 --- /dev/null +++ b/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php @@ -0,0 +1,30 @@ +where('enrollment_id', $enrollment->id)->first(); + + if ($existing !== null) { + return $existing; + } + + do { + $token = Str::random(64); + } while (QrToken::query()->where('token', $token)->exists()); + + return QrToken::query()->create([ + 'enrollment_id' => $enrollment->id, + 'token' => $token, + ]); + } +} diff --git a/app-modules/events/src/CheckIn/Actions/QrCheckInAction.php b/app-modules/events/src/CheckIn/Actions/QrCheckInAction.php new file mode 100644 index 000000000..aceb22a6a --- /dev/null +++ b/app-modules/events/src/CheckIn/Actions/QrCheckInAction.php @@ -0,0 +1,45 @@ +with('enrollment') + ->where('token', $dto->token) + ->first(); + + throw_unless( + $qrToken !== null && $qrToken->enrollment->event_id === $dto->event->id, + CheckInException::qrTokenNotFound(), + ); + + throw_if( + $qrToken->expires_at !== null && $qrToken->expires_at->isPast(), + CheckInException::qrTokenExpired(), + ); + + return resolve(CheckInAction::class)->handle( + new CheckInDTO( + enrollment: $qrToken->enrollment, + method: CheckInMethod::QrCode, + payload: ['token' => $dto->token], + eventDate: $dto->eventDate, + actorUserId: $dto->actorUserId, + triggeredBy: TriggeredBy::Admin, + ), + ); + } +} diff --git a/app-modules/events/src/CheckIn/DTOs/QrCheckInDTO.php b/app-modules/events/src/CheckIn/DTOs/QrCheckInDTO.php new file mode 100644 index 000000000..64775554b --- /dev/null +++ b/app-modules/events/src/CheckIn/DTOs/QrCheckInDTO.php @@ -0,0 +1,22 @@ +token), CheckInException::qrTokenNotFound()); + throw_if(blank($this->actorUserId), CheckInException::invalidCheckInActor()); + } +} diff --git a/app-modules/events/src/CheckIn/Exceptions/CheckInException.php b/app-modules/events/src/CheckIn/Exceptions/CheckInException.php index a36d17cd3..0094fdf63 100644 --- a/app-modules/events/src/CheckIn/Exceptions/CheckInException.php +++ b/app-modules/events/src/CheckIn/Exceptions/CheckInException.php @@ -40,4 +40,20 @@ public static function invalidCheckInActor(): self Response::HTTP_UNPROCESSABLE_ENTITY, ); } + + public static function qrTokenNotFound(): self + { + return new self( + __('events::check_in.qr_token_not_found'), + Response::HTTP_NOT_FOUND, + ); + } + + public static function qrTokenExpired(): self + { + return new self( + __('events::check_in.qr_token_expired'), + Response::HTTP_UNPROCESSABLE_ENTITY, + ); + } } diff --git a/app-modules/events/src/CheckIn/Listeners/GenerateQrTokenOnConfirmed.php b/app-modules/events/src/CheckIn/Listeners/GenerateQrTokenOnConfirmed.php new file mode 100644 index 000000000..8598a0129 --- /dev/null +++ b/app-modules/events/src/CheckIn/Listeners/GenerateQrTokenOnConfirmed.php @@ -0,0 +1,19 @@ +findOrFail($event->enrollmentId); + + resolve(GenerateQrTokenAction::class)->handle($enrollment); + } +} From 4e2a0a3240dc575060a7096afe7d639f6557b2dc Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:16:12 -0300 Subject: [PATCH 3/8] feat(events): registra listener GenerateQrTokenOnConfirmed no EventsServiceProvider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Conecta EnrollmentConfirmed → GenerateQrTokenOnConfirmed para geração automática do token QR quando a inscrição é confirmada. --- app-modules/events/src/EventsServiceProvider.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app-modules/events/src/EventsServiceProvider.php b/app-modules/events/src/EventsServiceProvider.php index 8c205a82b..bfe3c5882 100644 --- a/app-modules/events/src/EventsServiceProvider.php +++ b/app-modules/events/src/EventsServiceProvider.php @@ -4,6 +4,9 @@ namespace He4rt\Events; +use He4rt\Events\CheckIn\Listeners\GenerateQrTokenOnConfirmed; +use He4rt\Events\Enrollment\Events\EnrollmentConfirmed; +use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; class EventsServiceProvider extends ServiceProvider @@ -13,5 +16,7 @@ public function boot(): void $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); $this->loadViewsFrom(__DIR__.'/../resources/views', 'events'); $this->loadTranslationsFrom(__DIR__.'/../lang', 'events'); + + Event::listen(EnrollmentConfirmed::class, GenerateQrTokenOnConfirmed::class); } } From ca0c270939edb0acdefd55b2be16179c0c696066 Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:16:24 -0300 Subject: [PATCH 4/8] =?UTF-8?q?feat(panel-admin):=20adiciona=20a=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20scan=20QR=20cont=C3=ADnuo=20na=20p=C3=A1gina=20d?= =?UTF-8?q?e=20edi=C3=A7=C3=A3o=20de=20evento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Botão "Scan QR" no cabeçalho do EditEvent abre modal com campo de token - Executa QrCheckInAction e exibe notificação de sucesso com nome do participante - Em caso de erro (CheckInException ou Throwable), exibe notificação de erro - Modal reabre automaticamente via ->after() para leituras contínuas sem fechar - Botão de submit renomeado para "Check In" para evitar ambiguidade com confirmações --- .../Resources/Events/Pages/EditEvent.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php b/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php index e92e20c9c..3f4db673f 100644 --- a/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php +++ b/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php @@ -4,9 +4,18 @@ namespace He4rt\PanelAdmin\Filament\Resources\Events\Pages; +use Filament\Actions\Action; use Filament\Actions\DeleteAction; +use Filament\Forms\Components\TextInput; +use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; +use Filament\Support\Icons\Heroicon; +use He4rt\Events\CheckIn\Actions\QrCheckInAction; +use He4rt\Events\CheckIn\DTOs\QrCheckInDTO; +use He4rt\Events\CheckIn\Exceptions\CheckInException; +use He4rt\Events\Event\Models\Event; use He4rt\PanelAdmin\Filament\Resources\Events\EventResource; +use Throwable; final class EditEvent extends EditRecord { @@ -15,6 +24,56 @@ final class EditEvent extends EditRecord protected function getHeaderActions(): array { return [ + Action::make('scanQr') + ->label('Scan QR') + ->icon(Heroicon::QrCode) + ->color('success') + ->schema([ + TextInput::make('token') + ->label('QR Token') + ->required() + ->placeholder('Scan or paste the participant token'), + ]) + ->modalSubmitActionLabel('Check In') + ->action(function (array $data): void { + /** @var Event $event */ + $event = $this->getRecord(); + + try { + $checkIn = resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $data['token'], + event: $event, + eventDate: now(), + actorUserId: (string) auth()->id(), + ), + ); + + $checkIn->enrollment->loadMissing('user'); + $participantName = $checkIn->enrollment->user?->name ?? 'Participant'; + + Notification::make() + ->success() + ->title('Check-in successful') + ->body($participantName.' has been checked in.') + ->send(); + } catch (CheckInException $e) { + Notification::make() + ->danger() + ->title('Check-in failed') + ->body($e->getMessage()) + ->send(); + } catch (Throwable $e) { + Notification::make() + ->danger() + ->title('Check-in failed') + ->body('An unexpected error occurred. Please try again.') + ->send(); + + report($e); + } + }) + ->after(fn () => $this->mountAction('scanQr')), DeleteAction::make(), ]; } From 3a74a86ecffc308d3f9f877fc7dfe5882f9ccdd6 Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:16:40 -0300 Subject: [PATCH 5/8] =?UTF-8?q?feat(panel-app):=20exibe=20QR=20code,=20his?= =?UTF-8?q?t=C3=B3rico=20de=20check-ins=20e=20badge=20de=20presen=C3=A7a?= =?UTF-8?q?=20hoje?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EventDetail: adiciona computed qrToken (visível apenas com método QrCode e status confirmed/checked_in), qrCodeSvg via BaconQrCode, checkIns (histórico ordenado) e hasCheckedInToday para badge condicional - View: seção "Meu QR Code" com SVG inline, botões de copiar token e baixar SVG - Badge "Check-in feito hoje" no cabeçalho do card quando há check-in no dia atual - Seção de histórico de check-ins lista datas confirmadas abaixo do QR - Inscrição sem check-in ainda exibe instruções sem histórico - Adiciona strings de tradução en/pt_BR para histórico e badge --- app-modules/events/lang/en/pages.php | 12 +++ app-modules/events/lang/pt_BR/pages.php | 12 +++ .../livewire/events/event-detail.blade.php | 102 +++++++++++++++++- .../src/Livewire/Events/EventDetail.php | 61 +++++++++++ 4 files changed, 183 insertions(+), 4 deletions(-) diff --git a/app-modules/events/lang/en/pages.php b/app-modules/events/lang/en/pages.php index dc5f2f51a..208c61e24 100644 --- a/app-modules/events/lang/en/pages.php +++ b/app-modules/events/lang/en/pages.php @@ -6,10 +6,22 @@ 'back_to_events' => 'Back to Events', 'confirm_presence' => 'Confirm Presence', 'confirm_presence_hint' => 'Confirm your attendance to this event.', + 'confirm_presence_prompt' => 'Are you sure you want to enroll in this event?', + 'confirm_presence_yes' => 'Yes, enroll me', + 'confirm_presence_cancel' => 'Cancel', 'confirm_presence_success' => 'Your presence has been confirmed!', 'waitlist_success' => 'You have been added to the waitlist for this event.', 'enrollment_status_label' => 'Your enrollment status', 'enrolled_at' => 'Enrolled on :date', 'no_enrollments' => 'You are not enrolled in any events yet.', 'no_upcoming_events' => 'No upcoming events available.', + 'my_qr_code' => 'My QR Code', + 'qr_code_hint' => 'Present this QR code to the organizer for check-in.', + 'copy_token' => 'Copy Token', + 'token_copied' => 'Copied!', + 'download_qr' => 'Download QR', + 'checked_in_today' => 'Check-in done today', + 'check_in_history' => 'Check-in History', + 'check_in_history_date' => ':date', + 'no_check_ins_yet' => 'No check-ins recorded yet.', ]; diff --git a/app-modules/events/lang/pt_BR/pages.php b/app-modules/events/lang/pt_BR/pages.php index 42243fa86..ab481510b 100644 --- a/app-modules/events/lang/pt_BR/pages.php +++ b/app-modules/events/lang/pt_BR/pages.php @@ -6,10 +6,22 @@ 'back_to_events' => 'Voltar para Eventos', 'confirm_presence' => 'Confirmar Presença', 'confirm_presence_hint' => 'Confirme sua presença neste evento.', + 'confirm_presence_prompt' => 'Tem certeza que deseja se inscrever neste evento?', + 'confirm_presence_yes' => 'Sim, me inscrever', + 'confirm_presence_cancel' => 'Cancelar', 'confirm_presence_success' => 'Sua presença foi confirmada!', 'waitlist_success' => 'Você entrou na lista de espera deste evento.', 'enrollment_status_label' => 'Status da sua inscrição', 'enrolled_at' => 'Inscrito em :date', 'no_enrollments' => 'Você ainda não está inscrito em nenhum evento.', 'no_upcoming_events' => 'Nenhum evento disponível no momento.', + 'my_qr_code' => 'Meu QR Code', + 'qr_code_hint' => 'Apresente este QR code ao organizador para realizar o check-in.', + 'copy_token' => 'Copiar Token', + 'token_copied' => 'Copiado!', + 'download_qr' => 'Baixar QR', + 'checked_in_today' => 'Check-in feito hoje', + 'check_in_history' => 'Histórico de Check-ins', + 'check_in_history_date' => ':date', + 'no_check_ins_yet' => 'Nenhum check-in registrado ainda.', ]; diff --git a/app-modules/panel-app/resources/views/livewire/events/event-detail.blade.php b/app-modules/panel-app/resources/views/livewire/events/event-detail.blade.php index f94987fee..786b07e1a 100644 --- a/app-modules/panel-app/resources/views/livewire/events/event-detail.blade.php +++ b/app-modules/panel-app/resources/views/livewire/events/event-detail.blade.php @@ -37,13 +37,107 @@ + @if ($this->qrToken) +
+
+

+ {{ __('events::pages.my_qr_code') }} +

+ + @if ($this->hasCheckedInToday) + + {{ __('events::pages.checked_in_today') }} + + @endif +
+ +
{!! $this->qrCodeSvg !!}
+ +

+ {{ __('events::pages.qr_code_hint') }} +

+ +
+ + {{ __('events::pages.copy_token') }} + {{ __('events::pages.token_copied') }} + + + + {{ __('events::pages.download_qr') }} + +
+
+ @endif + @if ($this->checkIns->isNotEmpty()) +
+

+ {{ __('events::pages.check_in_history') }} +

+ +
    + @foreach ($this->checkIns as $checkIn) +
  • + + {{ $checkIn->event_date->format('d/m/Y') }} +
  • + @endforeach +
+
+ @endif @elseif ($this->canConfirmPresence) -
+

{{ __('events::pages.confirm_presence_hint') }}

- - {{ __('events::pages.confirm_presence') }} - +
+ + {{ __('events::pages.confirm_presence') }} + +
+ +
+

+ {{ __('events::pages.confirm_presence_prompt') }} +

+ +
+ + {{ __('events::pages.confirm_presence_yes') }} + + + + {{ __('events::pages.confirm_presence_cancel') }} + +
+
@endif
diff --git a/app-modules/panel-app/src/Livewire/Events/EventDetail.php b/app-modules/panel-app/src/Livewire/Events/EventDetail.php index a303091ac..272983ab2 100644 --- a/app-modules/panel-app/src/Livewire/Events/EventDetail.php +++ b/app-modules/panel-app/src/Livewire/Events/EventDetail.php @@ -4,7 +4,14 @@ namespace He4rt\PanelApp\Livewire\Events; +use BaconQrCode\Renderer\Image\SvgImageBackEnd; +use BaconQrCode\Renderer\ImageRenderer; +use BaconQrCode\Renderer\RendererStyle\RendererStyle; +use BaconQrCode\Writer; use Filament\Notifications\Notification; +use He4rt\Events\CheckIn\Enums\CheckInMethod; +use He4rt\Events\CheckIn\Models\CheckIn; +use He4rt\Events\CheckIn\Models\QrToken; use He4rt\Events\Enrollment\Actions\EnrollUserAction; use He4rt\Events\Enrollment\DTOs\EnrollUserDTO; use He4rt\Events\Enrollment\Enums\EnrollmentMethod; @@ -15,6 +22,7 @@ use He4rt\Events\Event\Models\Event; use He4rt\Identity\User\Models\User; use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Livewire\Attributes\Computed; use Livewire\Component; @@ -42,11 +50,64 @@ public function event(): Event public function enrollment(): ?Enrollment { return Enrollment::query() + ->with('qrToken') ->where('event_id', $this->eventId) ->where('user_id', auth()->id()) ->first(); } + #[Computed] + public function qrToken(): ?QrToken + { + if ($this->enrollment === null) { + return null; + } + + if (!in_array($this->enrollment->status, [EnrollmentStatus::Confirmed, EnrollmentStatus::CheckedIn], strict: true)) { + return null; + } + + if ($this->event->enrollmentPolicy?->check_in_method !== CheckInMethod::QrCode) { + return null; + } + + return $this->enrollment->qrToken; + } + + #[Computed] + public function qrCodeSvg(): ?string + { + if ($this->qrToken === null) { + return null; + } + + $writer = new Writer(new ImageRenderer(new RendererStyle(200), new SvgImageBackEnd())); + + return $writer->writeString($this->qrToken->token); + } + + /** @return Collection */ + #[Computed] + public function checkIns(): Collection + { + if ($this->enrollment === null) { + return collect(); + } + + return CheckIn::query() + ->where('enrollment_id', $this->enrollment->id) + ->oldest('event_date') + ->get(); + } + + #[Computed] + public function hasCheckedInToday(): bool + { + return $this->checkIns->contains( + fn (CheckIn $c): bool => $c->event_date->isToday(), + ); + } + #[Computed] public function canConfirmPresence(): bool { From 22ac0e2225dc8208199f95d4890cbf60a70cc028 Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Fri, 29 May 2026 23:16:56 -0300 Subject: [PATCH 6/8] =?UTF-8?q?test(events/check-in):=20adiciona=20suite?= =?UTF-8?q?=20de=20testes=20para=20gera=C3=A7=C3=A3o=20de=20token=20QR=20e?= =?UTF-8?q?=20check-in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cobre todos os critérios de aceite da task #237: - Geração de token único por enrollment - Idempotência: segunda chamada retorna o mesmo token - Scan válido: cria CheckIn, atualiza status e dispara ParticipantCheckedIn - Token inexistente rejeitado - Token de outro evento rejeitado - Token expirado rejeitado - Scan duplicado no mesmo dia rejeitado - Token de enrollment cancelado rejeitado - Reutilização em dias diferentes cria check-ins distintos - Listener gera token automaticamente via EnrollUserAction (integração) --- .../tests/Feature/QrCheckInActionTest.php | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 app-modules/events/tests/Feature/QrCheckInActionTest.php diff --git a/app-modules/events/tests/Feature/QrCheckInActionTest.php b/app-modules/events/tests/Feature/QrCheckInActionTest.php new file mode 100644 index 000000000..2bae5052a --- /dev/null +++ b/app-modules/events/tests/Feature/QrCheckInActionTest.php @@ -0,0 +1,253 @@ +create(); + $participant = User::factory()->create(); + $startsAt = now()->setTime(9, 0); + + $event = Event::factory() + ->for($tenant) + ->create(array_merge([ + 'starts_at' => $startsAt, + 'ends_at' => $startsAt->clone()->setTime(18, 0), + 'status' => EventStatus::Published, + ], $eventAttributes)); + + $enrollment = Enrollment::factory()->create(array_merge([ + 'event_id' => $event->id, + 'user_id' => $participant->id, + 'status' => EnrollmentStatus::Confirmed, + 'confirmed_at' => now(), + ], $enrollmentAttributes)); + + $qrToken = resolve(GenerateQrTokenAction::class)->handle($enrollment); + + return [$event, $enrollment, $qrToken]; +} + +test('when enrollment is confirmed, generate qr token action creates a unique token', function (): void { + $enrollment = Enrollment::factory()->create([ + 'status' => EnrollmentStatus::Confirmed, + 'confirmed_at' => now(), + ]); + + $qrToken = resolve(GenerateQrTokenAction::class)->handle($enrollment); + + expect($qrToken)->toBeInstanceOf(QrToken::class) + ->and($qrToken->enrollment_id)->toBe($enrollment->id) + ->and($qrToken->token)->toHaveLength(64) + ->and($qrToken->expires_at)->toBeNull(); +}); + +test('when generate qr token is called twice, the same token is returned', function (): void { + $enrollment = Enrollment::factory()->create([ + 'status' => EnrollmentStatus::Confirmed, + 'confirmed_at' => now(), + ]); + + $first = resolve(GenerateQrTokenAction::class)->handle($enrollment); + $second = resolve(GenerateQrTokenAction::class)->handle($enrollment); + + expect($second->id)->toBe($first->id) + ->and($second->token)->toBe($first->token); +}); + +test('when organizer scans a valid qr token, check-in is recorded and participant checked in event is dispatched', function (): void { + EventFacade::fake([ParticipantCheckedIn::class]); + + [$event, $enrollment, $qrToken] = createEnrollmentWithQrToken(); + $organizer = User::factory()->create(); + + $checkIn = resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: now(), + actorUserId: $organizer->id, + ), + ); + + expect($checkIn)->toBeInstanceOf(CheckIn::class) + ->and($checkIn->enrollment_id)->toBe($enrollment->id) + ->and($checkIn->method)->toBe(CheckInMethod::QrCode) + ->and($checkIn->payload)->toBe(['token' => $qrToken->token]) + ->and($checkIn->event_date->isSameDay(now()))->toBeTrue() + ->and($enrollment->fresh()->status)->toBe(EnrollmentStatus::CheckedIn); + + EventFacade::assertDispatched(fn (ParticipantCheckedIn $e): bool => $e->enrollmentId === $enrollment->id); +}); + +test('when token does not exist, qr check-in is rejected', function (): void { + [$event] = createEnrollmentWithQrToken(); + + expect(fn (): CheckIn => resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: 'nonexistent-token-that-does-not-exist-in-the-database-at-all', + event: $event, + eventDate: now(), + actorUserId: User::factory()->create()->id, + ), + ))->toThrow(CheckInException::class); +}); + +test('when token belongs to a different event, qr check-in is rejected', function (): void { + [, , $qrToken] = createEnrollmentWithQrToken(); + + $otherTenant = Tenant::factory()->create(); + $startsAt = now()->setTime(9, 0); + $otherEvent = Event::factory()->for($otherTenant)->create([ + 'starts_at' => $startsAt, + 'ends_at' => $startsAt->clone()->setTime(18, 0), + 'status' => EventStatus::Published, + ]); + + expect(fn (): CheckIn => resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $otherEvent, + eventDate: now(), + actorUserId: User::factory()->create()->id, + ), + ))->toThrow(CheckInException::class); +}); + +test('when token is expired, qr check-in is rejected', function (): void { + $tenant = Tenant::factory()->create(); + $startsAt = now()->setTime(9, 0); + + $event = Event::factory()->for($tenant)->create([ + 'starts_at' => $startsAt, + 'ends_at' => $startsAt->clone()->setTime(18, 0), + 'status' => EventStatus::Published, + ]); + + $enrollment = Enrollment::factory()->create([ + 'event_id' => $event->id, + 'status' => EnrollmentStatus::Confirmed, + 'confirmed_at' => now(), + ]); + + $expiredToken = QrToken::factory()->create([ + 'enrollment_id' => $enrollment->id, + 'expires_at' => now()->subHour(), + ]); + + expect(fn (): CheckIn => resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $expiredToken->token, + event: $event, + eventDate: now(), + actorUserId: User::factory()->create()->id, + ), + ))->toThrow(CheckInException::class); +}); + +test('when duplicate scan on same day, qr check-in is rejected', function (): void { + [$event, , $qrToken] = createEnrollmentWithQrToken(); + $organizer = User::factory()->create(); + + resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: now(), + actorUserId: $organizer->id, + ), + ); + + expect(fn (): CheckIn => resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: now(), + actorUserId: $organizer->id, + ), + ))->toThrow(CheckInException::class); +}); + +test('when cancelled enrollment token is scanned, qr check-in is rejected', function (): void { + [$event, $enrollment, $qrToken] = createEnrollmentWithQrToken( + enrollmentAttributes: ['status' => EnrollmentStatus::Cancelled, 'cancelled_at' => now()], + ); + + expect(fn (): CheckIn => resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: now(), + actorUserId: User::factory()->create()->id, + ), + ))->toThrow(CheckInException::class); +}); + +test('when enrollment is confirmed via enroll user action, qr token is generated by listener', function (): void { + $user = User::factory()->create(); + $tenant = Tenant::factory()->create(); + + $event = Event::factory() + ->for($tenant) + ->published() + ->upcoming() + ->has( + EnrollmentPolicy::factory()->rsvp()->state([ + 'check_in_method' => CheckInMethod::QrCode, + ]), + 'enrollmentPolicy', + ) + ->create(); + + $enrollment = resolve(EnrollUserAction::class)->handle(EnrollUserDTO::fromModels($event, $user)); + + expect(QrToken::query()->where('enrollment_id', $enrollment->id)->exists())->toBeTrue(); +}); + +test('when same token is scanned on different event days, each scan creates a new check-in record', function (): void { + $startsAt = now()->setTime(9, 0); + [$event, $enrollment, $qrToken] = createEnrollmentWithQrToken([ + 'starts_at' => $startsAt, + 'ends_at' => $startsAt->clone()->addDay()->setTime(18, 0), + ]); + $organizer = User::factory()->create(); + + resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: $startsAt, + actorUserId: $organizer->id, + ), + ); + + resolve(QrCheckInAction::class)->handle( + new QrCheckInDTO( + token: $qrToken->token, + event: $event, + eventDate: $startsAt->clone()->addDay(), + actorUserId: $organizer->id, + ), + ); + + expect(CheckIn::query()->where('enrollment_id', $enrollment->id)->count())->toBe(2); +}); From 52099518a71576ac436e5c59e6bdbd1338b2f211 Mon Sep 17 00:00:00 2001 From: YuriSouzaDev Date: Sun, 31 May 2026 12:02:55 -0300 Subject: [PATCH 7/8] =?UTF-8?q?fix(panel-admin):=20corrige=20reabertura=20?= =?UTF-8?q?cont=C3=ADnua=20do=20modal=20de=20scan=20QR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `mountAction` chamado em `->after()` era desfeito pelo `unmountAction` do lifecycle do Filament logo em seguida. A solução despacha um evento Livewire (`reopen-scan-qr`) dentro do `finally` da action, que é processado num request separado — após o lifecycle atual completar — e reabre o modal via `#[On]` sem conflito. Também adiciona `autofocus` no campo token para o cursor já estar posicionado a cada reabertura. --- .../Filament/Resources/Events/Pages/EditEvent.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php b/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php index 3f4db673f..e2b96ffe6 100644 --- a/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php +++ b/app-modules/panel-admin/src/Filament/Resources/Events/Pages/EditEvent.php @@ -15,12 +15,19 @@ use He4rt\Events\CheckIn\Exceptions\CheckInException; use He4rt\Events\Event\Models\Event; use He4rt\PanelAdmin\Filament\Resources\Events\EventResource; +use Livewire\Attributes\On; use Throwable; final class EditEvent extends EditRecord { protected static string $resource = EventResource::class; + #[On('reopen-scan-qr')] + public function reopenScanQrModal(): void + { + $this->mountAction('scanQr'); + } + protected function getHeaderActions(): array { return [ @@ -32,6 +39,7 @@ protected function getHeaderActions(): array TextInput::make('token') ->label('QR Token') ->required() + ->autofocus() ->placeholder('Scan or paste the participant token'), ]) ->modalSubmitActionLabel('Check In') @@ -71,9 +79,10 @@ protected function getHeaderActions(): array ->send(); report($e); + } finally { + $this->dispatch('reopen-scan-qr'); } - }) - ->after(fn () => $this->mountAction('scanQr')), + }), DeleteAction::make(), ]; } From 860e7626180ec98745c941b53cd0a2cd5ef15df8 Mon Sep 17 00:00:00 2001 From: danielhe4rt Date: Thu, 4 Jun 2026 17:52:14 -0300 Subject: [PATCH 8/8] fix(events): store QR token as UUID string and align tests GenerateQrTokenAction stored the raw Uuid object, leaving the in-memory token attribute as a LazyUuidFromString that broke QrCheckInDTO's string type hint. Persist it via Str::uuid7()->toString() instead. - Update QrCheckInActionTest to assert a valid UUID rather than a 64-char length. - Pass a waitlist position in EnrollmentStatusTest to match getResponseMessage(). - Drop unused DetachAction import in EnrollmentsRelationManager (Pint). --- .../src/CheckIn/Actions/GenerateQrTokenAction.php | 10 +++------- .../events/tests/Feature/QrCheckInActionTest.php | 3 ++- app-modules/events/tests/Unit/EnrollmentStatusTest.php | 4 +++- .../RelationManagers/EnrollmentsRelationManager.php | 9 ++++----- .../panel-app/src/Livewire/Events/EventDetail.php | 1 + 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php b/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php index 816426b01..e18bbcf10 100644 --- a/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php +++ b/app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php @@ -12,19 +12,15 @@ { public function handle(Enrollment $enrollment): QrToken { - $existing = QrToken::query()->where('enrollment_id', $enrollment->id)->first(); + $existing = QrToken::query()->where('enrollment_id', $enrollment->getKey())->first(); if ($existing !== null) { return $existing; } - do { - $token = Str::random(64); - } while (QrToken::query()->where('token', $token)->exists()); - return QrToken::query()->create([ - 'enrollment_id' => $enrollment->id, - 'token' => $token, + 'enrollment_id' => $enrollment->getKey(), + 'token' => Str::uuid7()->toString(), ]); } } diff --git a/app-modules/events/tests/Feature/QrCheckInActionTest.php b/app-modules/events/tests/Feature/QrCheckInActionTest.php index 2bae5052a..494638381 100644 --- a/app-modules/events/tests/Feature/QrCheckInActionTest.php +++ b/app-modules/events/tests/Feature/QrCheckInActionTest.php @@ -20,6 +20,7 @@ use He4rt\Identity\Tenant\Models\Tenant; use He4rt\Identity\User\Models\User; use Illuminate\Support\Facades\Event as EventFacade; +use Illuminate\Support\Str; function createEnrollmentWithQrToken(array $eventAttributes = [], array $enrollmentAttributes = []): array { @@ -57,7 +58,7 @@ function createEnrollmentWithQrToken(array $eventAttributes = [], array $enrollm expect($qrToken)->toBeInstanceOf(QrToken::class) ->and($qrToken->enrollment_id)->toBe($enrollment->id) - ->and($qrToken->token)->toHaveLength(64) + ->and(Str::isUuid($qrToken->token))->toBeTrue() ->and($qrToken->expires_at)->toBeNull(); }); diff --git a/app-modules/events/tests/Unit/EnrollmentStatusTest.php b/app-modules/events/tests/Unit/EnrollmentStatusTest.php index 35afe8448..646e01988 100644 --- a/app-modules/events/tests/Unit/EnrollmentStatusTest.php +++ b/app-modules/events/tests/Unit/EnrollmentStatusTest.php @@ -70,7 +70,9 @@ }); test('when rsvp enrollment status is evaluated, then response message matches status', function (EnrollmentStatus $status, string $expectedKey): void { - expect($status->getResponseMessage())->toBe(__($expectedKey)); + $position = 5; + + expect($status->getResponseMessage($position))->toBe(__($expectedKey, ['position' => $position])); })->with([ [EnrollmentStatus::Confirmed, 'events::pages.confirm_presence_success'], [EnrollmentStatus::Waitlisted, 'events::pages.waitlist_success'], diff --git a/app-modules/panel-admin/src/Filament/Resources/Events/RelationManagers/EnrollmentsRelationManager.php b/app-modules/panel-admin/src/Filament/Resources/Events/RelationManagers/EnrollmentsRelationManager.php index 778d31fc0..e87498d5b 100644 --- a/app-modules/panel-admin/src/Filament/Resources/Events/RelationManagers/EnrollmentsRelationManager.php +++ b/app-modules/panel-admin/src/Filament/Resources/Events/RelationManagers/EnrollmentsRelationManager.php @@ -7,6 +7,8 @@ use Filament\Actions\Action; use Filament\Actions\BulkAction; use Filament\Actions\BulkActionGroup; +use Filament\Actions\DeleteAction; +use Filament\Actions\DeleteBulkAction; use Filament\Forms\Components\DatePicker; use Filament\Notifications\Notification; use Filament\Resources\RelationManagers\RelationManager; @@ -28,11 +30,6 @@ final class EnrollmentsRelationManager extends RelationManager { protected static string $relationship = 'enrollments'; - public function isReadOnly(): bool - { - return true; - } - public function table(Table $table): Table { return $table @@ -87,10 +84,12 @@ public function table(Table $table): Table ]) ->recordActions([ $this->checkInAction(), + DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ $this->bulkCheckInAction(), + DeleteBulkAction::make(), ]), ]); } diff --git a/app-modules/panel-app/src/Livewire/Events/EventDetail.php b/app-modules/panel-app/src/Livewire/Events/EventDetail.php index a91a0a899..a2f3750b1 100644 --- a/app-modules/panel-app/src/Livewire/Events/EventDetail.php +++ b/app-modules/panel-app/src/Livewire/Events/EventDetail.php @@ -15,6 +15,7 @@ use He4rt\Events\Enrollment\Actions\EnrollUserAction; use He4rt\Events\Enrollment\DTOs\EnrollUserDTO; use He4rt\Events\Enrollment\Enums\EnrollmentMethod; +use He4rt\Events\Enrollment\Enums\EnrollmentStatus; use He4rt\Events\Enrollment\Exceptions\EnrollmentException; use He4rt\Events\Enrollment\Models\Enrollment; use He4rt\Events\Event\Enums\EventStatus;