From 42737a6a2f0e98cae6a26f2410dba7a85a0b9701 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 22 May 2026 12:59:12 +0000 Subject: [PATCH] Feat: integrate reusable confirmation logic across components - Applied `Confirmation` trait to multiple Livewire components for unified confirmation handling. - Replaced inline confirmation modals with `requireConfirmation` method for streamlined interaction. - Updated button styles and added reusable confirmation prompts for delete/detach actions. - Enhanced `AppRoleService` and `ConnectionProviderService` to support deletion with confirmation. --- app/Services/AppRoleService.php | 14 +++++++ app/Services/ConnectedAppService.php | 3 +- app/Services/ConnectionProviderService.php | 5 +++ resources/css/app.css | 4 ++ .../roles-and-apps/⚡index.blade.php | 40 ++++++++++++++----- .../roles-and-apps/⚡show.blade.php | 22 +++++----- .../access-manager/users/⚡index.blade.php | 17 ++++---- .../pages/connected-apps/⚡index.blade.php | 10 +++-- .../connecton-providers/⚡index.blade.php | 29 +++----------- 9 files changed, 85 insertions(+), 59 deletions(-) diff --git a/app/Services/AppRoleService.php b/app/Services/AppRoleService.php index 0571e22..2733ec2 100644 --- a/app/Services/AppRoleService.php +++ b/app/Services/AppRoleService.php @@ -63,9 +63,23 @@ private function assignAppPermissionsRole(Role $role, array $appIds): void }, $appIds); } + /** + * Detach an app from a role; + * + * @param array $appIds Apps to be detached. + */ + public function detachApps(array $appIds): void + { + AppRole::query() + ->whereIn('app_id', $appIds) + ->delete(); + } + /** * Remove an app-role assignment. * + * @param int $id The ID of the pivot table record. + * * @throws InvalidArgumentException when id is invalid. * @throws Throwable when an error occurs during the deletion. */ diff --git a/app/Services/ConnectedAppService.php b/app/Services/ConnectedAppService.php index cf93b46..4c447c5 100644 --- a/app/Services/ConnectedAppService.php +++ b/app/Services/ConnectedAppService.php @@ -7,7 +7,7 @@ use App\Data\ConnectedApp\{ConnectAppRequest, ConnectedAppData}; use App\Data\Ui\ConnectedApps\ConnectedAppData as UiConnectedAppData; use App\Enums\ConnectedAppPermissonEnum; -use App\Models\ConnectedApp; +use App\Models\{AppRole, ConnectedApp}; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\DB; use InvalidArgumentException; @@ -69,6 +69,7 @@ public function delete(int $id): void DB::transaction( function () use ($id): void { $app = ConnectedApp::query()->findOrFail($id); + AppRole::query()->where('app_id', $app->id)->delete(); $app->delete(); } ); diff --git a/app/Services/ConnectionProviderService.php b/app/Services/ConnectionProviderService.php index 454957b..b101e54 100644 --- a/app/Services/ConnectionProviderService.php +++ b/app/Services/ConnectionProviderService.php @@ -16,6 +16,10 @@ class ConnectionProviderService { + public function __construct( + private readonly AppRoleService $appRoleService, + ) {} + /** * @return Collection */ @@ -85,6 +89,7 @@ function () use ($slug): void { ->get() ->toArray(); + $this->appRoleService->detachApps(array_column($deletedApps, 'id')); // Note: This performs a mass soft-delete query. // Model events for ConnectedApp will NOT fire. $provider->connectedApps()->delete(); diff --git a/resources/css/app.css b/resources/css/app.css index 5b70b22..5628d53 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -137,3 +137,7 @@ .mary-table-pagination { } } +/*set background color for table header*/ +thead { + @apply bg-gray-50 +} diff --git a/resources/views/pages/access-manager/roles-and-apps/⚡index.blade.php b/resources/views/pages/access-manager/roles-and-apps/⚡index.blade.php index f293024..21dc554 100644 --- a/resources/views/pages/access-manager/roles-and-apps/⚡index.blade.php +++ b/resources/views/pages/access-manager/roles-and-apps/⚡index.blade.php @@ -1,5 +1,6 @@ form->appIds = []; } + public function test() + { + dd('hi'); + } public function openCreateModal(): void { @@ -152,8 +157,8 @@ class="btn-sm btn-circle btn-soft" /> @@ -181,17 +186,32 @@ class="btn-sm btn-circle btn-error btn-soft" clear-action="clearApps" label="Apps" /> - +
+ +
+ +
+ + +
Cancel - - Save Role + + Save diff --git a/resources/views/pages/access-manager/roles-and-apps/⚡show.blade.php b/resources/views/pages/access-manager/roles-and-apps/⚡show.blade.php index 7b49cc9..134517d 100644 --- a/resources/views/pages/access-manager/roles-and-apps/⚡show.blade.php +++ b/resources/views/pages/access-manager/roles-and-apps/⚡show.blade.php @@ -1,6 +1,6 @@ attempt( - action: function () use ($appId): void { - $this->appRoleService->detach($appId); + action: function () use ($id): void { + $this->appRoleService->detach($id); unset($this->apps); }, successMessage: 'App removed from role.', @@ -305,8 +304,8 @@ class="btn-sm btn-soft btn-circle" /> @@ -321,7 +320,8 @@ class="btn-sm btn-error btn-soft btn-circle" - + Add User @@ -338,8 +338,8 @@ class="btn-sm btn-error btn-soft btn-circle" @scope('actions', $row) diff --git a/resources/views/pages/access-manager/users/⚡index.blade.php b/resources/views/pages/access-manager/users/⚡index.blade.php index f764e33..273edf7 100644 --- a/resources/views/pages/access-manager/users/⚡index.blade.php +++ b/resources/views/pages/access-manager/users/⚡index.blade.php @@ -1,24 +1,21 @@ - + + class="btn-sm btn-circle btn-error btn-soft"/> @endscope diff --git a/resources/views/pages/connecton-providers/⚡index.blade.php b/resources/views/pages/connecton-providers/⚡index.blade.php index 931453b..b200d2b 100644 --- a/resources/views/pages/connecton-providers/⚡index.blade.php +++ b/resources/views/pages/connecton-providers/⚡index.blade.php @@ -1,5 +1,6 @@ cnfModal = false; $this->attempt( action: function () { $this->service->delete($this->selectedProvider); + $this->selectedProvider = ''; } ); } @@ -61,13 +61,7 @@ public function delete(): void public function showModal(string $providerSlug): void { $this->selectedProvider = $providerSlug; - $this->cnfModal = true; - } - - public function cancelModal(): void - { - $this->selectedProvider = ''; - $this->cnfModal = false; + $this->requireConfirmation('delete', description: 'This will delete all the connected apps of this provider.'); } }; ?> @@ -83,24 +77,13 @@ public function cancelModal(): void @scope('actions', $row)
+ class="mr-2 btn-sm btn-circle text-gray-500"/> + class="btn-sm btn-error btn-circle btn-soft"/>
@endscope
- - - - - - - -