Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/Actions/Licenses/UnsuspendLicense.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Actions\Licenses;

use App\Models\License;
use App\Services\Anystack\Anystack;

class UnsuspendLicense
{
/**
* Handle the un-suspension of a license.
*/
public function handle(License $license): License
{
Anystack::api()
->license($license->anystack_id, $license->anystack_product_id)
->suspend(false);

$license->update([
'is_suspended' => false,
]);

return $license;
}
}
48 changes: 41 additions & 7 deletions app/Filament/Resources/LicenseResource/Pages/EditLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down