diff --git a/app/Actions/Licenses/UnsuspendLicense.php b/app/Actions/Licenses/UnsuspendLicense.php new file mode 100644 index 00000000..a35d5c21 --- /dev/null +++ b/app/Actions/Licenses/UnsuspendLicense.php @@ -0,0 +1,25 @@ +license($license->anystack_id, $license->anystack_product_id) + ->suspend(false); + + $license->update([ + 'is_suspended' => false, + ]); + + return $license; + } +} diff --git a/app/Filament/Resources/LicenseResource/Pages/EditLicense.php b/app/Filament/Resources/LicenseResource/Pages/EditLicense.php index 11467a8d..2d4c2b2b 100644 --- a/app/Filament/Resources/LicenseResource/Pages/EditLicense.php +++ b/app/Filament/Resources/LicenseResource/Pages/EditLicense.php @@ -4,6 +4,7 @@ use App\Actions\Licenses\DeleteLicense; use App\Actions\Licenses\SuspendLicense; +use App\Actions\Licenses\UnsuspendLicense; use App\Filament\Resources\LicenseResource; use App\Jobs\UpsertLicenseFromAnystackLicense; use App\Models\License; @@ -57,19 +58,52 @@ protected function getHeaderActions(): array Actions\Action::make('suspend') ->label('Suspend') ->icon('heroicon-o-archive-box-x-mark') - ->color('danger') + ->color('warning') ->requiresConfirmation() ->modalHeading('Suspend') ->modalDescription('Are you sure you want to suspend this license?') - ->modalSubmitActionLabel('Suspend license') + ->modalSubmitActionLabel('Suspend') ->visible(fn () => ! $this->record->is_suspended) ->action(function () { - app(SuspendLicense::class)->handle($this->record); + try { + app(SuspendLicense::class)->handle($this->record); - Notification::make() - ->title('License suspended successfully') - ->success() - ->send(); + Notification::make() + ->title('License suspended successfully') + ->success() + ->send(); + } catch (\Exception $e) { + Notification::make() + ->title('Error suspending license') + ->body('Failed to suspend license: '.$e->getMessage()) + ->danger() + ->send(); + } + }), + Actions\Action::make('unsuspend') + ->label('Unsuspend') + ->icon('heroicon-o-power') + ->color('warning') + ->requiresConfirmation() + ->modalHeading('Unsuspend') + ->modalDescription('Are you sure you want to remove the suspension for this license?') + ->modalSubmitActionLabel('Unsuspend') + ->visible(fn () => $this->record->is_suspended) + ->action(function () { + try { + app(UnsuspendLicense::class)->handle($this->record); + + Notification::make() + ->title('License unsuspended successfully') + ->success() + ->send(); + } catch (\Exception $e) { + Notification::make() + ->title('Error unsuspending license') + ->body('Failed to unsuspend license: '.$e->getMessage()) + ->danger() + ->send(); + } }), Actions\Action::make('delete') ->label('Delete')