- Introduced `livewire.php` for customizable Livewire configuration. - Enhanced ConnectedApp management by adding delete functionality and dynamic navigation handling (`goBack()`). - Updated forms (`create`, `edit`) with `maryUI` components (`mary-form`, `mary-button`, `mary-input`, `mary-choices`). - Consolidated provider imports and refactored UI for reusability and improved styling. - Improved exception handling and validation rules in `ConnectedAppService` and Livewire components.
98 lines
2.9 KiB
PHP
98 lines
2.9 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
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('connected-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('connected-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"
|
|
class="mr-2 btn-sm text-gray-500"/>
|
|
<x-mary-button icon="lucide.trash" wire:click="delete({{$row->id}})" spinner="delete" variant="danger"
|
|
class="btn-sm btn-error btn-soft"/>
|
|
</div>
|
|
@endscope
|
|
</x-mary-table>
|
|
</x-shared.card>
|
|
</div>
|