diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index ba683d88e..dc699124f 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -164,6 +164,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -397,6 +400,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -630,6 +636,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -863,6 +872,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -1096,6 +1108,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -1329,6 +1344,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -1562,6 +1580,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -1795,6 +1816,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -2028,6 +2052,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -2261,6 +2288,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, @@ -2494,6 +2524,9 @@ 'Livewire\EventBus' => \Livewire\EventBus::class, 'Livewire\LivewireManager' => \Livewire\LivewireManager::class, 'Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys' => \Livewire\Mechanisms\ExtendBlade\DeterministicBladeKeys::class, + 'Lorisleiva\Actions\ActionManager' => \Lorisleiva\Actions\ActionManager::class, + 'Lorisleiva\Lody\LodyManager' => \Lorisleiva\Lody\LodyManager::class, + 'Lorisleiva\Lody\Psr4Resolver' => \Lorisleiva\Lody\Psr4Resolver::class, 'Maatwebsite\Excel\Cache\CacheManager' => \Maatwebsite\Excel\Cache\CacheManager::class, 'Maatwebsite\Excel\Files\Filesystem' => \Maatwebsite\Excel\Files\Filesystem::class, 'Maatwebsite\Excel\Files\TemporaryFileFactory' => \Maatwebsite\Excel\Files\TemporaryFileFactory::class, diff --git a/_ide_helper.php b/_ide_helper.php index b259bfeb2..5fc8dcff3 100644 --- a/_ide_helper.php +++ b/_ide_helper.php @@ -19364,6 +19364,310 @@ public static function originalMethod() } +} + + namespace Lorisleiva\Actions\Facades { + /** + * + * + * @see ActionManager + */ + class Actions { + /** + * + * + * @param \Lorisleiva\Actions\class-string $jobDecoratorClass + * @static + */ + public static function useJobDecorator($jobDecoratorClass) + { + return \Lorisleiva\Actions\ActionManager::useJobDecorator($jobDecoratorClass); + } + /** + * + * + * @param \Lorisleiva\Actions\class-string $uniqueJobDecoratorClass + * @static + */ + public static function useUniqueJobDecorator($uniqueJobDecoratorClass) + { + return \Lorisleiva\Actions\ActionManager::useUniqueJobDecorator($uniqueJobDecoratorClass); + } + /** + * + * + * @static + */ + public static function setBacktraceLimit($backtraceLimit) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->setBacktraceLimit($backtraceLimit); + } + /** + * + * + * @static + */ + public static function setDesignPatterns($designPatterns) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->setDesignPatterns($designPatterns); + } + /** + * + * + * @static + */ + public static function getDesignPatterns() + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->getDesignPatterns(); + } + /** + * + * + * @static + */ + public static function registerDesignPattern($designPattern) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->registerDesignPattern($designPattern); + } + /** + * + * + * @static + */ + public static function getDesignPatternsMatching($usedTraits) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->getDesignPatternsMatching($usedTraits); + } + /** + * + * + * @static + */ + public static function extend($app, $abstract) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->extend($app, $abstract); + } + /** + * + * + * @static + */ + public static function isExtending($abstract) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->isExtending($abstract); + } + /** + * + * + * @static + */ + public static function shouldExtend($abstract) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->shouldExtend($abstract); + } + /** + * + * + * @static + */ + public static function identifyAndDecorate($instance) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->identifyAndDecorate($instance); + } + /** + * + * + * @static + */ + public static function identifyFromBacktrace($usedTraits, $frame = null) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->identifyFromBacktrace($usedTraits, $frame); + } + /** + * + * + * @static + */ + public static function registerRoutes($paths = 'app/Actions') + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->registerRoutes($paths); + } + /** + * + * + * @static + */ + public static function registerCommands($paths = 'app/Actions') + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->registerCommands($paths); + } + /** + * + * + * @static + */ + public static function registerRoutesForAction($className) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->registerRoutesForAction($className); + } + /** + * + * + * @static + */ + public static function registerCommandsForAction($className) + { + /** @var \Lorisleiva\Actions\ActionManager $instance */ + return $instance->registerCommandsForAction($className); + } + + } + +} + + namespace Lorisleiva\Lody { + /** + * + * + * @see LodyManager + */ + class Lody { + /** + * + * + * @static + */ + public static function classes($paths, $recursive = true) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->classes($paths, $recursive); + } + /** + * + * + * @static + */ + public static function classesFromFinder($finder) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->classesFromFinder($finder); + } + /** + * + * + * @static + */ + public static function files($paths, $recursive = true, $hidden = false) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->files($paths, $recursive, $hidden); + } + /** + * + * + * @static + */ + public static function filesFromFinder($finder) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->filesFromFinder($finder); + } + /** + * + * + * @static + */ + public static function resolvePathUsing($callback) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->resolvePathUsing($callback); + } + /** + * + * + * @static + */ + public static function resolvePath($path) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->resolvePath($path); + } + /** + * + * + * @static + */ + public static function resolveClassnameUsing($callback) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->resolveClassnameUsing($callback); + } + /** + * + * + * @static + */ + public static function resolveClassname($file) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->resolveClassname($file); + } + /** + * + * + * @static + */ + public static function setBasePath($basePath) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->setBasePath($basePath); + } + /** + * + * + * @static + */ + public static function getBasePath($path = '') + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->getBasePath($path); + } + /** + * + * + * @static + */ + public static function setAutoloadPath($autoloadPath) + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->setAutoloadPath($autoloadPath); + } + /** + * + * + * @static + */ + public static function getAutoloadPath() + { + /** @var \Lorisleiva\Lody\LodyManager $instance */ + return $instance->getAutoloadPath(); + } + + } + } namespace Maatwebsite\Excel\Facades { @@ -27437,6 +27741,8 @@ class Vite extends \Illuminate\Support\Facades\Vite {} class TimeZoneHelper extends \App\Helpers\TimeZoneHelper {} class EloquentSerialize extends \AnourValar\EloquentSerialize\Facades\EloquentSerializeFacade {} class Livewire extends \Livewire\Livewire {} + class Action extends \Lorisleiva\Actions\Facades\Actions {} + class Lody extends \Lorisleiva\Lody\Lody {} class Excel extends \Maatwebsite\Excel\Facades\Excel {} class Flare extends \Spatie\LaravelIgnition\Facades\Flare {} diff --git a/app/Actions/Notifications/SendDatabaseTestNotification.php b/app/Actions/Notifications/SendDatabaseTestNotification.php new file mode 100644 index 000000000..6611ad491 --- /dev/null +++ b/app/Actions/Notifications/SendDatabaseTestNotification.php @@ -0,0 +1,29 @@ +notify( + Notification::make() + ->title('Test database notification received!') + ->body('You say pong') + ->success() + ->toDatabase(), + ); + + Notification::make() + ->title('Test database notification sent.') + ->body('I say ping') + ->success() + ->send(); + } +} diff --git a/app/Actions/Notifications/SendMailTestNotification.php b/app/Actions/Notifications/SendMailTestNotification.php new file mode 100644 index 000000000..735a114c7 --- /dev/null +++ b/app/Actions/Notifications/SendMailTestNotification.php @@ -0,0 +1,35 @@ +title('You need to add mail recipients!') + ->warning() + ->send(); + + return; + } + + foreach ($recipients as $recipient) { + Mail::to($recipient) + ->send(new TestMail()); + } + + Notification::make() + ->title('Test mail notification sent.') + ->success() + ->send(); + } +} diff --git a/app/Actions/Notifications/SendTelegramTestNotification.php b/app/Actions/Notifications/SendTelegramTestNotification.php new file mode 100644 index 000000000..c7c64a815 --- /dev/null +++ b/app/Actions/Notifications/SendTelegramTestNotification.php @@ -0,0 +1,35 @@ +title('You need to add Telegram recipients!') + ->warning() + ->send(); + + return; + } + + foreach ($recipients as $recipient) { + FacadesNotification::route('telegram_chat_id', $recipient['telegram_chat_id']) + ->notify(new TestNotification); + } + + Notification::make() + ->title('Test Telegram notification sent.') + ->success() + ->send(); + } +} diff --git a/app/Actions/Notifications/SendWebhookTestNotification.php b/app/Actions/Notifications/SendWebhookTestNotification.php new file mode 100644 index 000000000..eff22684d --- /dev/null +++ b/app/Actions/Notifications/SendWebhookTestNotification.php @@ -0,0 +1,37 @@ +title('You need to add webhook urls!') + ->warning() + ->send(); + + return; + } + + foreach ($urls as $url) { + WebhookCall::create() + ->url($url['url']) + ->payload(['message' => '👋 Testing the Webhook notification channel.']) + ->doNotSign() + ->dispatch(); + } + + Notification::make() + ->title('Test webhook notification sent.') + ->success() + ->send(); + } +} diff --git a/app/Filament/Pages/Settings/NotificationPage.php b/app/Filament/Pages/Settings/NotificationPage.php index c51650eaf..a79d61165 100755 --- a/app/Filament/Pages/Settings/NotificationPage.php +++ b/app/Filament/Pages/Settings/NotificationPage.php @@ -2,19 +2,15 @@ namespace App\Filament\Pages\Settings; -use App\Forms\Components\TestDatabaseNotification; -use App\Forms\Components\TestMailNotification; -use App\Forms\Components\TestTelegramNotification; -use App\Mail\Test; -use App\Notifications\Telegram\TestNotification as TelegramTestNotification; +use App\Actions\Notifications\SendDatabaseTestNotification; +use App\Actions\Notifications\SendMailTestNotification; +use App\Actions\Notifications\SendTelegramTestNotification; +use App\Actions\Notifications\SendWebhookTestNotification; use App\Settings\NotificationSettings; use Filament\Forms; use Filament\Forms\Form; -use Filament\Notifications\Notification; use Filament\Pages\SettingsPage; -use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\Notification as FacadesNotification; -use Spatie\WebhookServer\WebhookCall; +use Illuminate\Support\Facades\Auth; class NotificationPage extends SettingsPage { @@ -61,7 +57,7 @@ public function form(Form $form): Form Forms\Components\Toggle::make('database_enabled') ->label('Enable database notifications') ->reactive() - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Grid::make([ 'default' => 1, ]) @@ -71,12 +67,16 @@ public function form(Form $form): Form ->schema([ Forms\Components\Toggle::make('database_on_speedtest_run') ->label('Notify on every speedtest run') - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Toggle::make('database_on_threshold_failure') ->label('Notify on threshold failures') - ->columnSpan(2), + ->columnSpanFull(), ]), - TestDatabaseNotification::make('test channel'), + Forms\Components\Actions::make([ + Forms\Components\Actions\Action::make('test database') + ->label('Test database channel') + ->action(fn () => SendDatabaseTestNotification::run(user: Auth::user())), + ]), ]), ]) ->compact() @@ -90,34 +90,36 @@ public function form(Form $form): Form Forms\Components\Toggle::make('mail_enabled') ->label('Enable mail notifications') ->reactive() - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Grid::make([ 'default' => 1, ]) + ->hidden(fn (Forms\Get $get) => $get('mail_enabled') !== true) ->schema([ Forms\Components\Fieldset::make('Triggers') ->schema([ Forms\Components\Toggle::make('mail_on_speedtest_run') ->label('Notify on every speedtest run') - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Toggle::make('mail_on_threshold_failure') ->label('Notify on threshold failures') - ->columnSpan(2), + ->columnSpanFull(), ]), - ]) - ->hidden(fn (Forms\Get $get) => $get('mail_enabled') !== true), - - Forms\Components\Repeater::make('mail_recipients') - ->label('Recipients') - ->schema([ - Forms\Components\TextInput::make('email_address') - ->email() - ->required(), - ]) - ->hidden(fn (Forms\Get $get) => $get('mail_enabled') !== true) - ->columnSpan(['md' => 2]), - TestMailNotification::make('test channel') - ->hidden(fn (Forms\Get $get) => $get('mail_enabled') !== true), + Forms\Components\Repeater::make('mail_recipients') + ->label('Recipients') + ->schema([ + Forms\Components\TextInput::make('email_address') + ->email() + ->required(), + ]) + ->columnSpanFull(), + Forms\Components\Actions::make([ + Forms\Components\Actions\Action::make('test mail') + ->label('Test mail channel') + ->action(fn (Forms\Get $get) => SendMailTestNotification::run(recipients: $get('mail_recipients'))) + ->hidden(fn (Forms\Get $get) => ! count($get('mail_recipients'))), + ]), + ]), ]) ->compact() ->columns([ @@ -130,33 +132,37 @@ public function form(Form $form): Form Forms\Components\Toggle::make('telegram_enabled') ->label('Enable telegram notifications') ->reactive() - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Grid::make([ - 'default' => 1, ]) + 'default' => 1, + ]) ->hidden(fn (Forms\Get $get) => $get('telegram_enabled') !== true) ->schema([ Forms\Components\Fieldset::make('Triggers') ->schema([ Forms\Components\Toggle::make('telegram_on_speedtest_run') ->label('Notify on every speedtest run') - ->columnSpan(2), + ->columnSpanFull(), Forms\Components\Toggle::make('telegram_on_threshold_failure') ->label('Notify on threshold failures') - ->columnSpan(2), + ->columnSpanFull(), ]), + Forms\Components\Repeater::make('telegram_recipients') + ->label('Recipients') + ->schema([ + Forms\Components\TextInput::make('telegram_chat_id') + ->label('Telegram Chat ID') + ->maxLength(50) + ->required(), + ]) + ->columnSpanFull(), + Forms\Components\Actions::make([ + Forms\Components\Actions\Action::make('test telegram') + ->label('Test Telegram channel') + ->action(fn (Forms\Get $get) => SendTelegramTestNotification::run(recipients: $get('telegram_recipients'))) + ->hidden(fn (Forms\Get $get) => ! count($get('telegram_recipients')) || blank(config('telegram.bot'))), + ]), ]), - Forms\Components\Repeater::make('telegram_recipients') - ->label('Recipients') - ->schema([ - Forms\Components\TextInput::make('telegram_chat_id') - ->maxLength(50) - ->required() - ->columnSpan(['md' => 2]), - ]) - ->hidden(fn (Forms\Get $get) => $get('telegram_enabled') !== true) - ->columnSpan(['md' => 2]), - TestTelegramNotification::make('test channel') - ->hidden(fn (Forms\Get $get) => $get('telegram_enabled') !== true), ]) ->compact() ->columns([ @@ -171,7 +177,8 @@ public function form(Form $form): Form ->reactive() ->columnSpanFull(), Forms\Components\Grid::make([ - 'default' => 1, ]) + 'default' => 1, + ]) ->hidden(fn (Forms\Get $get) => $get('webhook_enabled') !== true) ->schema([ Forms\Components\Fieldset::make('Triggers') @@ -183,49 +190,22 @@ public function form(Form $form): Form ->label('Notify on threshold failures') ->columnSpan(2), ]), - ]), - Forms\Components\Repeater::make('webhook_urls') - ->label('Recipients') - ->schema([ - Forms\Components\TextInput::make('url') - ->maxLength(2000) - ->required() - ->url() + Forms\Components\Repeater::make('webhook_urls') + ->label('Recipients') + ->schema([ + Forms\Components\TextInput::make('url') + ->maxLength(2000) + ->required() + ->url(), + ]) ->columnSpanFull(), - ]) - ->hidden(fn (Forms\Get $get) => $get('webhook_enabled') !== true) - ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test webhook') - ->label('Test webhook channel') - ->action(function (): void { - $notificationSettings = new (NotificationSettings::class); - - if (blank($notificationSettings->webhook_urls)) { - Notification::make() - ->title('You need to add webhook urls.') - ->body('Make sure to click "Save changes" before testing webhook notifications.') - ->warning() - ->send(); - - return; - } - - foreach ($notificationSettings->webhook_urls as $url) { - WebhookCall::create() - ->url($url['url']) - ->payload(['message' => '👋 Testing the Webhook notification channel.']) - ->doNotSign() - ->dispatch(); - } - - Notification::make() - ->title('Test webhook notification sent.') - ->success() - ->send(); - }) - ->hidden(fn (Forms\Get $get) => $get('webhook_enabled') !== true), - ]), + Forms\Components\Actions::make([ + Forms\Components\Actions\Action::make('test webhook') + ->label('Test webhook channel') + ->action(fn (Forms\Get $get) => SendWebhookTestNotification::run(urls: $get('webhook_urls'))) + ->hidden(fn (Forms\Get $get) => ! count($get('webhook_urls'))), + ]), + ]), ]) ->compact() ->columns([ @@ -247,85 +227,4 @@ public function form(Form $form): Form ]), ]); } - - public function sendTestDatabaseNotification(): void - { - $recipient = auth()->user(); - - $recipient->notify( - Notification::make() - ->title('Test database notification received!') - ->body('You say pong') - ->success() - ->toDatabase(), - ); - - Notification::make() - ->title('Test database notification sent.') - ->body('I say ping') - ->success() - ->send(); - } - - public function sendTestMailNotification(): void - { - $notificationSettings = new (NotificationSettings::class); - - if (blank($notificationSettings->mail_recipients)) { - Notification::make() - ->title('You need to add mail recipients.') - ->body('Make sure to click "Save changes" before testing mail notifications.') - ->warning() - ->send(); - - return; - } - - foreach ($notificationSettings->mail_recipients as $recipient) { - Mail::to($recipient) - ->send(new Test()); - } - - Notification::make() - ->title('Test mail notification sent.') - ->success() - ->send(); - } - - public function sendTestTelegramNotification(): void - { - $notificationSettings = new (NotificationSettings::class); - - $bot = config('telegram.bot'); - - if (blank($bot)) { - Notification::make() - ->title('No Telegram bot provided.') - ->body('You need to add "TELEGRAM_BOT_TOKEN" in your .env file or add it as environment variable') - ->danger() - ->send(); - - return; - } - - if (blank($notificationSettings->telegram_recipients)) { - Notification::make() - ->title('You need to add Telegram recipients.') - ->body('Make sure to click "Save changes" before testing Telegram notifications.') - ->warning() - ->send(); - - return; - } - - foreach ($notificationSettings->telegram_recipients as $recipient) { - FacadesNotification::route('telegram_chat_id', $recipient['telegram_chat_id']) - ->notify(new TelegramTestNotification); - } - - Notification::make() - ->title('Test Telegram notification sent.') - ->success() - ->send(); - } } diff --git a/app/Forms/Components/TestDatabaseNotification.php b/app/Forms/Components/TestDatabaseNotification.php deleted file mode 100644 index 017e4c8e0..000000000 --- a/app/Forms/Components/TestDatabaseNotification.php +++ /dev/null @@ -1,10 +0,0 @@ - - - Test database channel - - diff --git a/resources/views/forms/components/test-mail-notification.blade.php b/resources/views/forms/components/test-mail-notification.blade.php deleted file mode 100644 index dba69b249..000000000 --- a/resources/views/forms/components/test-mail-notification.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -
- - Test mail channel - -
diff --git a/resources/views/forms/components/test-telegram-notification.blade.php b/resources/views/forms/components/test-telegram-notification.blade.php deleted file mode 100644 index e6778ab3a..000000000 --- a/resources/views/forms/components/test-telegram-notification.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -
- - Test telegram channel - -