- 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.
101 lines
3.0 KiB
PHP
101 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Concerns\Confirmation;
|
|
use App\Concerns\HandlesOperations;
|
|
use App\Data\Ui\ConnectedApps\ConnectedAppData;
|
|
use App\Data\Ui\TableHeader;
|
|
use App\Services\ConnectedAppService;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
|
use Spatie\LaravelData\DataCollection;
|
|
use Spatie\LaravelData\PaginatedDataCollection;
|
|
|
|
new
|
|
#[Title('Connected Apps')]
|
|
class extends Component {
|
|
use WithPagination, HandlesOperations, Confirmation;
|
|
|
|
protected ConnectedAppService $service;
|
|
|
|
#[DataCollectionOf(TableHeader::class)]
|
|
public DataCollection $headers;
|
|
|
|
public function boot(ConnectedAppService $service): void
|
|
{
|
|
$this->service = $service;
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->initTableHeaders();
|
|
}
|
|
|
|
private function initTableHeaders(): void
|
|
{
|
|
$this->headers = TableHeader::collect([
|
|
new TableHeader(key: 'name', label: 'Name',),
|
|
new TableHeader(key: 'provider', label: 'Provider'),
|
|
new TableHeader(key: 'protocol', label: 'Protocol'),
|
|
new TableHeader(key: 'status', label: 'Status'),
|
|
], DataCollection::class);
|
|
}
|
|
|
|
/**
|
|
* @return PaginatedDataCollection<int, ConnectedAppData>
|
|
*/
|
|
#[Computed]
|
|
public function getConnectedApps(): PaginatedDataCollection
|
|
{
|
|
return $this->service->getAll();
|
|
}
|
|
|
|
public function edit(int $appId): void
|
|
{
|
|
$this->redirectRoute('apps.edit', ['id' => $appId], navigate: true);
|
|
}
|
|
|
|
public function delete(int $appId): void
|
|
{
|
|
$this->attempt(
|
|
action: fn() => $this->service->delete($appId),
|
|
successMessage: 'The app has been deleted !'
|
|
);
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div>
|
|
<x-shared.card title="Connected Apps" class="pb-2">
|
|
<x-slot:actions>
|
|
<x-mary-button :link="route('apps.create')" wire:navigate icon="lucide.plus">Add App
|
|
</x-mary-button>
|
|
</x-slot:actions>
|
|
<x-mary-table
|
|
:headers="$headers->toArray()"
|
|
:rows="$this->getConnectedApps->items()"
|
|
with-pagination
|
|
>
|
|
@scope('cell_protocol', $row)
|
|
{{$row->protocol->name}}
|
|
@endscope
|
|
|
|
@scope('cell_status', $row)
|
|
<x-shared.connection-status :status="$row->status"/>
|
|
@endscope
|
|
@scope('actions', $row)
|
|
<div class="flex">
|
|
<x-mary-button icon="lucide.edit" wire:click="edit({{$row->id}})" spinner="edit({{$row->id}})"
|
|
class="mr-2 btn-sm btn-circle text-gray-500"/>
|
|
<x-mary-button icon="lucide.trash" wire:click="requireConfirmation('delete', {{$row->id}})"
|
|
spinner="requireConfirmation('delete', {{$row->id}})"
|
|
variant="danger"
|
|
class="btn-sm btn-circle btn-error btn-soft"/>
|
|
</div>
|
|
@endscope
|
|
</x-mary-table>
|
|
</x-shared.card>
|
|
</div>
|