Add all files
This commit is contained in:
85
app/Admin/Resources/ServiceResource/Pages/EditService.php
Normal file
85
app/Admin/Resources/ServiceResource/Pages/EditService.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ServiceResource;
|
||||
use App\Helpers\ExtensionHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
use App\Models\Service;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EditService extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServiceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\Action::make('changeStatus')
|
||||
->label('Trigger Extension Action')
|
||||
->form([
|
||||
Select::make('action')
|
||||
->label('Action')
|
||||
->options([
|
||||
'create' => 'Create server',
|
||||
'suspend' => 'Suspend server',
|
||||
'unsuspend' => 'Unsuspend server',
|
||||
'terminate' => 'Terminate server',
|
||||
'upgrade' => 'Upgrade server',
|
||||
])->required(),
|
||||
Checkbox::make('sendNotification')
|
||||
->label('Send Notification')
|
||||
->default(false),
|
||||
])
|
||||
->action(function (array $data, Service $record, Actions\Action $action): void {
|
||||
try {
|
||||
switch ($data['action']) {
|
||||
case 'create':
|
||||
$sdata = ExtensionHelper::createServer($record);
|
||||
if ($data['sendNotification']) {
|
||||
NotificationHelper::serverCreatedNotification($record->order->user, $record, $sdata);
|
||||
}
|
||||
break;
|
||||
case 'suspend':
|
||||
$sdata = ExtensionHelper::suspendServer($record);
|
||||
break;
|
||||
case 'unsuspend':
|
||||
$sdata = ExtensionHelper::unsuspendServer($record);
|
||||
break;
|
||||
case 'terminate':
|
||||
$sdata = ExtensionHelper::terminateServer($record);
|
||||
break;
|
||||
case 'upgrade':
|
||||
$sdata = ExtensionHelper::upgradeServer($record);
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if (config('app.debug')) {
|
||||
throw $e;
|
||||
}
|
||||
Log::error($e);
|
||||
Notification::make('Error')
|
||||
->title('Error occured while triggering the action:')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
$action->halt();
|
||||
}
|
||||
Notification::make('Success')
|
||||
->title('Action triggered successfully')
|
||||
->body('The action has been triggered successfully')
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->color('primary')
|
||||
->modalSubmitActionLabel('Trigger'),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user