Skip to content

Commit 15c3a17

Browse files
authored
add filament action to unsuspend a license (#156)
1 parent 173010e commit 15c3a17

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Actions\Licenses;
4+
5+
use App\Models\License;
6+
use App\Services\Anystack\Anystack;
7+
8+
class UnsuspendLicense
9+
{
10+
/**
11+
* Handle the un-suspension of a license.
12+
*/
13+
public function handle(License $license): License
14+
{
15+
Anystack::api()
16+
->license($license->anystack_id, $license->anystack_product_id)
17+
->suspend(false);
18+
19+
$license->update([
20+
'is_suspended' => false,
21+
]);
22+
23+
return $license;
24+
}
25+
}

app/Filament/Resources/LicenseResource/Pages/EditLicense.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Actions\Licenses\DeleteLicense;
66
use App\Actions\Licenses\SuspendLicense;
7+
use App\Actions\Licenses\UnsuspendLicense;
78
use App\Filament\Resources\LicenseResource;
89
use App\Jobs\UpsertLicenseFromAnystackLicense;
910
use App\Models\License;
@@ -57,19 +58,52 @@ protected function getHeaderActions(): array
5758
Actions\Action::make('suspend')
5859
->label('Suspend')
5960
->icon('heroicon-o-archive-box-x-mark')
60-
->color('danger')
61+
->color('warning')
6162
->requiresConfirmation()
6263
->modalHeading('Suspend')
6364
->modalDescription('Are you sure you want to suspend this license?')
64-
->modalSubmitActionLabel('Suspend license')
65+
->modalSubmitActionLabel('Suspend')
6566
->visible(fn () => ! $this->record->is_suspended)
6667
->action(function () {
67-
app(SuspendLicense::class)->handle($this->record);
68+
try {
69+
app(SuspendLicense::class)->handle($this->record);
6870

69-
Notification::make()
70-
->title('License suspended successfully')
71-
->success()
72-
->send();
71+
Notification::make()
72+
->title('License suspended successfully')
73+
->success()
74+
->send();
75+
} catch (\Exception $e) {
76+
Notification::make()
77+
->title('Error suspending license')
78+
->body('Failed to suspend license: '.$e->getMessage())
79+
->danger()
80+
->send();
81+
}
82+
}),
83+
Actions\Action::make('unsuspend')
84+
->label('Unsuspend')
85+
->icon('heroicon-o-power')
86+
->color('warning')
87+
->requiresConfirmation()
88+
->modalHeading('Unsuspend')
89+
->modalDescription('Are you sure you want to remove the suspension for this license?')
90+
->modalSubmitActionLabel('Unsuspend')
91+
->visible(fn () => $this->record->is_suspended)
92+
->action(function () {
93+
try {
94+
app(UnsuspendLicense::class)->handle($this->record);
95+
96+
Notification::make()
97+
->title('License unsuspended successfully')
98+
->success()
99+
->send();
100+
} catch (\Exception $e) {
101+
Notification::make()
102+
->title('Error unsuspending license')
103+
->body('Failed to unsuspend license: '.$e->getMessage())
104+
->danger()
105+
->send();
106+
}
73107
}),
74108
Actions\Action::make('delete')
75109
->label('Delete')

0 commit comments

Comments
 (0)