-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathEditEvent.php
More file actions
91 lines (81 loc) · 3.56 KB
/
Copy pathEditEvent.php
File metadata and controls
91 lines (81 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
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 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 [
Action::make('scanQr')
->label(__('panel-admin::events.edit.scan_qr'))
->icon(Heroicon::QrCode)
->color('success')
->schema([
TextInput::make('token')
->label(__('panel-admin::events.edit.qr_token'))
->required()
->autofocus()
->placeholder(__('panel-admin::events.edit.qr_token_placeholder')),
])
->modalSubmitActionLabel(__('panel-admin::events.edit.check_in_submit'))
->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 ?? __('panel-admin::events.edit.participant_fallback');
Notification::make()
->success()
->title(__('panel-admin::events.edit.notifications.check_in_success_title'))
->body(__('panel-admin::events.edit.notifications.check_in_success_body', [
'name' => $participantName,
]))
->send();
} catch (CheckInException $e) {
Notification::make()
->danger()
->title(__('panel-admin::events.edit.notifications.check_in_failed_title'))
->body($e->getMessage())
->send();
} catch (Throwable $e) {
Notification::make()
->danger()
->title(__('panel-admin::events.edit.notifications.check_in_failed_title'))
->body(__('panel-admin::events.edit.notifications.check_in_unexpected_error'))
->send();
report($e);
} finally {
$this->dispatch('reopen-scan-qr');
}
}),
DeleteAction::make(),
];
}
}