diff --git a/app/Filament/Resources/Events/Tables/EventsTable.php b/app/Filament/Resources/Events/Tables/EventsTable.php index 939b2264..1e9b8111 100644 --- a/app/Filament/Resources/Events/Tables/EventsTable.php +++ b/app/Filament/Resources/Events/Tables/EventsTable.php @@ -3,7 +3,7 @@ namespace App\Filament\Resources\Events\Tables; use App\Filament\Resources\Events\Tables\Tools\CompareOptions; -use App\Filament\Resources\Events\Tables\Tools\LoadBettype; +use App\Filament\Resources\Events\Tables\Tools\LoadBettypeSettings; use App\Filament\Resources\Events\Tables\Tools\LoadCompareDifferences; use App\Filament\Resources\Events\Tables\Tools\LoadMultiline; use App\Filament\Tables\Columns\ColumnOdds; @@ -59,7 +59,7 @@ class EventsTable { LoadMultiline::load(); - LoadBettype::load(); + LoadBettypeSettings::load(); return $table ->striped() diff --git a/app/Filament/Resources/Events/Tables/Tools/LoadBettype.php b/app/Filament/Resources/Events/Tables/Tools/LoadBettypeSettings.php similarity index 96% rename from app/Filament/Resources/Events/Tables/Tools/LoadBettype.php rename to app/Filament/Resources/Events/Tables/Tools/LoadBettypeSettings.php index 0ef671e7..15dbcb70 100644 --- a/app/Filament/Resources/Events/Tables/Tools/LoadBettype.php +++ b/app/Filament/Resources/Events/Tables/Tools/LoadBettypeSettings.php @@ -5,7 +5,7 @@ namespace App\Filament\Resources\Events\Tables\Tools; use App\Filament\Resources\Events\Tables\EventsTable; use App\Models\BettypeUser; -class LoadBettype +class LoadBettypeSettings { public static function load() { diff --git a/app/Livewire/PersonalNotificationTable.php b/app/Livewire/PersonalNotificationTable.php index a8f66646..34d7ca50 100644 --- a/app/Livewire/PersonalNotificationTable.php +++ b/app/Livewire/PersonalNotificationTable.php @@ -29,16 +29,19 @@ class PersonalNotificationTable extends Component implements HasActions, HasSche public function table(Table $table): Table { return $table - ->query(PersonalNotification::query()->with('bookmaker')->where('user_id', auth()->user()->id)) + ->query(PersonalNotification::query() + ->with('bookmaker') + ->where('alarm_level_id', '>', 1) + ->where('user_id', auth()->user()->id)) ->description('Send a notification when favorit enters an alarm level.') ->striped() ->columns([ - BookmakerIcon::make('bookmaker.icon') - ->label('Bookmaker')->size('lg'), TextColumn::make('alarm_level.name') ->color(fn ($record) => $record->alarm_level->color) - ->weight(FontWeight::Black) - ->extraCellAttributes(['class' => 'alarm-level-style']), + ->weight(FontWeight::Black), + BookmakerIcon::make('bookmaker.icon') + ->alignCenter() + ->label('Bookmaker')->size('sm'), ]) ->defaultSort('alarm_level_id', 'desc') ->deferFilters(false) diff --git a/app/Livewire/UserNotifications.php b/app/Livewire/UserNotifications.php index 02a91a14..38fcea49 100644 --- a/app/Livewire/UserNotifications.php +++ b/app/Livewire/UserNotifications.php @@ -4,19 +4,18 @@ namespace App\Livewire; use App\Mail\UserNotification; use App\Models\User; -use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; -use Filament\Forms\Components\Textarea; +use Filament\Forms\Components\MarkdownEditor; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Notifications\Notification; use Filament\Schemas\Concerns\InteractsWithSchemas; use Filament\Schemas\Contracts\HasSchemas; -use Filament\Support\Enums\Width; -use Filament\Tables\Columns\TextColumn; +use Filament\Schemas\Schema; use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Contracts\HasTable; -use Filament\Tables\Table; use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Mail; use Livewire\Component; @@ -27,53 +26,53 @@ class UserNotifications extends Component implements HasActions, HasSchemas, Has use InteractsWithSchemas; use InteractsWithTable; - protected Table $table2; + public ?array $data = []; - public function table(Table $table): Table + public function mount(): void { - return $table - ->query(User::query()->where('client_id', auth()->user()->client_id)->orwhereIn('id', [1, 2])) - ->description('Send a message to one of the user listed') - ->columns([ - TextColumn::make('name')->icon('phosphor-user-duotone')->searchable(), - TextColumn::make('email')->icon('phosphor-envelope-duotone'), + $this->form->fill(); + } + + public function form(Schema $schema): Schema + { + return $schema + ->components([ + Select::make('recipient') + ->placeholder('Select an recipient') + ->required() + ->options(fn () => User::query()->where('client_id', auth()->user()->client_id)->orwhereIn('id', [1, 2])->pluck('name', 'id')), + Toggle::make('notify_by_email')->label('Send also as E-Mail'), + TextInput::make('subject') + ->required(), + MarkdownEditor::make('message') + ->required(), ]) - ->recordActions([ - Action::make('notification') - ->icon('phosphor-note-pencil-duotone') - ->tooltip('Create a notification') - ->modalHeading(fn ($record) => 'Send a notification to '.$record->name) - ->iconButton() - ->modalWidth(Width::Large) - // ->modalDescription('Send a notification') - ->modalSubmitActionLabel('Send') - ->modalIcon('phosphor-envelope-duotone') - ->schema([ - Textarea::make('message') - ->required() - ->rows(4), - Toggle::make('notify_by_email')->label('Send also as email') - // ->belowContent('Notify me also by e-mail') - ->onColor('info') - ->offColor('gray'), - ])->action(function (array $data, $record) { + ->statePath('data'); + } - if ($data['notify_by_email']) { - Mail::to($record) - ->send(new UserNotification($data['message'])); - } - Notification::make() - ->title('Notification from '.$record->name) - ->icon('phosphor-envelope-duotone') - ->body($data['message']) - ->sendToDatabase($record); + public function create(): void + { + $data = $this->form->getState(); - Notification::make() - ->title('Message send successfully') - ->success() - ->send(); - }), - ]); + $recipient = User::find((int) $data['recipient']); + + if ($recipient) { + if ($data['notify_by_email']) { + Mail::to($recipient)->send(new UserNotification($data['subject'], $data['message'])); + } + Notification::make() + ->title($data['subject']) + ->icon('phosphor-envelope-duotone') + ->body($data['message']) + ->sendToDatabase($recipient); + + Notification::make() + ->title('Message send successfully') + ->success() + ->send(); + + $this->dispatch('close-modal', id: 'send_message_modal'); + } } public function render(): View diff --git a/app/Mail/UserNotification.php b/app/Mail/UserNotification.php index eaef6bd9..8db5fc7f 100644 --- a/app/Mail/UserNotification.php +++ b/app/Mail/UserNotification.php @@ -14,11 +14,15 @@ class UserNotification extends Mailable protected string $message; + protected string $subject; + /** * Create a new message instance. */ - public function __construct($message) + public function __construct($subject, $message) { + $this->subject = $subject; + $this->message = $message; } @@ -28,7 +32,7 @@ class UserNotification extends Mailable public function envelope(): Envelope { return new Envelope( - subject: 'NUH-Odds Notification', + subject: $this->subject, ); } diff --git a/resources/views/livewire/client-group-list-editor.blade.php b/resources/views/livewire/client-group-list-editor.blade.php index 059cb892..004dc967 100644 --- a/resources/views/livewire/client-group-list-editor.blade.php +++ b/resources/views/livewire/client-group-list-editor.blade.php @@ -1,5 +1,5 @@
- + {{ auth()->user()->sport->name }} diff --git a/resources/views/livewire/top-menu-items.blade.php b/resources/views/livewire/top-menu-items.blade.php index 5c7f0c95..ac21a86b 100644 --- a/resources/views/livewire/top-menu-items.blade.php +++ b/resources/views/livewire/top-menu-items.blade.php @@ -1,6 +1,6 @@
@if ($this->current == 'filament.admin.resources.events.index') - + {{-- Client Swop Bookmaker --}} @@ -60,9 +60,9 @@ - {{-- Notifications --}} + {{-- Notifications --}} - @livewire('personal-notification-table') - - + + --}} {{-- Send Message --}} - + @@ -97,17 +97,18 @@ {{-- Event Mapper --}} - + - +
- Event Mapper {{ auth()->user()->sport->name }} + Event Mapper {{ auth()->user()->sport->name }} @php if (!auth()->user()->provider_id) { @@ -230,7 +231,8 @@ {{-- Calculation --}} - + @@ -246,7 +248,8 @@ {{-- Custom Groups --}} - + diff --git a/resources/views/livewire/user-notifications.blade.php b/resources/views/livewire/user-notifications.blade.php index c3fedc4a..bc2ec9cb 100644 --- a/resources/views/livewire/user-notifications.blade.php +++ b/resources/views/livewire/user-notifications.blade.php @@ -1,3 +1,12 @@
- {{ $this->table }} +
+ {{ $this->form }} + + + Send Message + + +
+ +