- Added `mary.php` configuration file for customizable component and route prefixes. - Upgraded `livewire/livewire` to v4.3 and added `robsontenorio/mary` v2.8 for maryUI support. - Updated `ConnectedApps` component to fetch data dynamically via `ConnectedAppService`. - Replaced static services with computed properties and streamlined data mappings in templates. - Enhanced frontend styling with `daisyUI` and TailwindCSS v4.3 integration. - Improved user feedback in `ConnectedAppForm` with success/error toasts.
121 lines
3.8 KiB
PHP
121 lines
3.8 KiB
PHP
<?php
|
|
|
|
use App\Data\ConnectedApp\ConnectionStatusData;
|
|
use App\Enums\ConnectionStatusEnum;
|
|
use App\Livewire\Forms\StoreConnectedAppFrom;
|
|
use App\Models\ConnectionProtocol;
|
|
use App\Models\ConnectionProvider;
|
|
use App\Models\ConnectionStatus;
|
|
use App\Services\ConnectionProtocolService;
|
|
use App\Services\ConnectionProviderService;
|
|
use App\Services\ConnectionStatusService;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\Title;
|
|
use Mary\Traits\Toast;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
new
|
|
#[Title('Create a service')]
|
|
class extends Component {
|
|
use Toast;
|
|
|
|
public StoreConnectedAppFrom $form;
|
|
|
|
#[Computed]
|
|
public function providers()
|
|
{
|
|
return ConnectionProvider::query()->get();
|
|
}
|
|
|
|
|
|
#[Computed]
|
|
public function protocols(): Collection
|
|
{
|
|
$protocolService = app(ConnectionProtocolService::class);
|
|
|
|
return $protocolService->getAll()->map(function (ConnectionProtocol $protocol) {
|
|
$protocol->name = strtoupper($protocol->name);
|
|
return $protocol;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @returns DataCollection<int, ConnectionStatus>
|
|
*/
|
|
#[Computed]
|
|
public function connectionStatuses(): DataCollection
|
|
{
|
|
$statusService = app(ConnectionStatusService::class);
|
|
|
|
return $statusService->getAll()->map(function (ConnectionStatusData $status) {
|
|
if ($status->name === ConnectionStatusEnum::Disconnected) {
|
|
$this->form->statusId = $status->id;
|
|
}
|
|
return $status;
|
|
});
|
|
}
|
|
|
|
public function searchProvider(string $name)
|
|
{
|
|
$providerService = app(ConnectionProviderService::class);
|
|
$this->providers = $providerService->search($name);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
try {
|
|
$this->form->save();
|
|
$this->success('New App connected ');
|
|
return to_route('dashboard');
|
|
} catch (Throwable $e) {
|
|
$this->error('Something gone wrong. Try again');
|
|
\Illuminate\Support\Facades\Log::error('Error while submitting Create a connected app', [$e->getMessage()]);
|
|
}
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div>
|
|
<x-shared.card :title="__('Create a service')" class="">
|
|
<form wire:submit="save" class="p-4 grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
<x-input wire:model.live.blur="form.name" required :label="__('Name')"/>
|
|
<x-choices
|
|
required
|
|
wire:model="form.protocolId"
|
|
:label="__('Protocol')"
|
|
:single="true"
|
|
:options="$this->protocols"
|
|
placeholder="Select"
|
|
/>
|
|
<x-choices required
|
|
wire:model="form.providerId"
|
|
:label="__('Provider')"
|
|
placeholder="Search ..."
|
|
:single="true"
|
|
:options="$this->providers"
|
|
searchable
|
|
search-function="searchProvider"
|
|
debounce="300"
|
|
/>
|
|
<x-choices
|
|
required
|
|
wire:model="form.statusId"
|
|
:label="__('Status')"
|
|
:single="true"
|
|
:options="$this->connectionStatuses->toArray()"
|
|
placeholder="Select"
|
|
/>
|
|
<div class="md:col-span-2 flex gap-x-4 font-medium justify-end">
|
|
<x-shared.button>Cancel</x-shared.button>
|
|
<x-shared.button type="submit">Save & Add Another</x-shared.button>
|
|
<x-shared.button type="submit"
|
|
class="bg-blue-600 text-blue-50 hover:bg-blue-700 border-blue-600 min-w-20 flex justify-center items-center">
|
|
Save
|
|
</x-shared.button>
|
|
</div>
|
|
</form>
|
|
</x-shared.card>
|
|
</div>
|