refactor: enhance ConnectionStatus handling and remove redundant logo field

- Added `ConnectionStatusData` DTO and `ConnectionStatusService` for managing connection statuses with mapped enums.
- Updated `ConnectedAppFactory` and Livewire `StoreConnectedAppForm` to integrate `ConnectionStatusData` and remove `logoUrl` field.
- Adjusted `ConnectedApp` model to rename columns for consistency.
- Implemented error handling in `ConnectedAppService::create()` for improved resilience.
- Updated Blade templates and composer dependencies for compatibility.
This commit is contained in:
= 2026-05-14 06:22:40 +00:00
parent df3a37d6cb
commit f90655bc43
9 changed files with 154 additions and 170 deletions

View File

@ -4,11 +4,11 @@
namespace App\Data\ConnectedApp;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class ConnectAppRequest extends Data
{
public function __construct(
@ -16,8 +16,7 @@ public function __construct(
public int $connectionProviderId,
public int $connectionProtocolId,
public ?string $connectionService = null,
public ?string $logoUrl = null,
public ?string $slug = null,
public ?int $statusId = null,
public ?int $connectionStatusId = null,
) {}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Data\ConnectedApp;
use App\Enums\ConnectionStatusEnum;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Casts\EnumCast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
class ConnectionStatusData extends Data
{
public function __construct(
public int $id,
#[WithCast(EnumCast::class)]
public ConnectionStatusEnum $name,
)
{
}
}

View File

@ -16,7 +16,6 @@ public function createDataFromDto(ConnectAppRequest $data): array
'name' => $data->name,
'connection_provider_id' => $data->connectionProviderId,
'connection_protocol_id' => $data->connectionProtocolId,
'logo_url' => $data->logoUrl,
'slug' => $data->slug,
'connection_status_id' => $data->statusId,
];

View File

@ -23,9 +23,6 @@ class StoreConnectedAppFrom extends Form
#[Validate('required|numeric|min:1|exists:connection_statuses,id')]
public int $statusId = 0;
#[Validate('nullable|string|max:255|min:3')]
public ?string $logoUrl = null;
public function save(): void
{
$this->validate();
@ -34,11 +31,9 @@ public function save(): void
name: $this->name,
connectionProviderId: $this->providerId,
connectionProtocolId: $this->protocolId,
logoUrl: $this->logoUrl,
slug: str($this->name)->slug()->toString(),
statusId: $this->statusId,
connectionStatusId: $this->statusId,
);
app(ConnectedAppService::class)->create($serviceData);
$this->reset();
}

View File

@ -11,9 +11,9 @@
#[Fillable([
'name',
'slug',
'service_protocol_id',
'service_provider_id',
'service_status_id',
'connection_protocol_id',
'connection_provider_id',
'connection_status_id',
])]
class ConnectedApp extends Model
{

View File

@ -5,18 +5,21 @@
namespace App\Services;
use App\Data\ConnectedApp\ConnectAppRequest;
use App\Factories\ConnectedAppFactory;
use App\Models\ConnectedApp;
use Illuminate\Support\Facades\DB;
use Throwable;
final class ConnectedAppService
{
/**
* Create a new connected app.
* @throws Throwable
*/
public function create(ConnectAppRequest $data): void
{
$data = app(ConnectedAppFactory::class)->createDataFromDto($data);
DB::transaction(
fn () => ConnectedApp::create(
$data
fn () => ConnectedApp::query()->create(
$data->toArray()
)
);
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Services;
use App\Data\ConnectedApp\ConnectionStatusData;
use App\Models\ConnectionStatus;
use Spatie\LaravelData\DataCollection;
class ConnectionStatusService
{
/**
* @return DataCollection<int, ConnectionStatusData>
*/
public function getAll(): DataCollection
{
$statuses = ConnectionStatus::query()->get();
return ConnectionStatusData::collect($statuses, DataCollection::class);
}
}

218
composer.lock generated
View File

@ -1494,16 +1494,16 @@
},
{
"name": "laravel/framework",
"version": "v13.8.0",
"version": "v13.9.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "e7db333a025a1e93ebca7744953069d7719f4bcf"
"reference": "a0c6ad03b380287015287d8d5a0fa2459e2332fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/e7db333a025a1e93ebca7744953069d7719f4bcf",
"reference": "e7db333a025a1e93ebca7744953069d7719f4bcf",
"url": "https://api.github.com/repos/laravel/framework/zipball/a0c6ad03b380287015287d8d5a0fa2459e2332fd",
"reference": "a0c6ad03b380287015287d8d5a0fa2459e2332fd",
"shasum": ""
},
"require": {
@ -1607,7 +1607,7 @@
"aws/aws-sdk-php": "^3.322.9",
"ext-gmp": "*",
"fakerphp/faker": "^1.24",
"guzzlehttp/psr7": "^2.4",
"guzzlehttp/psr7": "^2.9",
"laravel/pint": "^1.18",
"league/flysystem-aws-s3-v3": "^3.25.1",
"league/flysystem-ftp": "^3.25.1",
@ -1714,7 +1714,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2026-05-05T21:01:14+00:00"
"time": "2026-05-13T15:38:40+00:00"
},
{
"name": "laravel/passkeys",
@ -3011,16 +3011,16 @@
},
{
"name": "nette/utils",
"version": "v4.1.3",
"version": "v4.1.4",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "bb3ea637e3d131d72acc033cfc2746ee893349fe"
"reference": "7da6c396d7ebe142bc857c20479d5e70a5e1aac7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/bb3ea637e3d131d72acc033cfc2746ee893349fe",
"reference": "bb3ea637e3d131d72acc033cfc2746ee893349fe",
"url": "https://api.github.com/repos/nette/utils/zipball/7da6c396d7ebe142bc857c20479d5e70a5e1aac7",
"reference": "7da6c396d7ebe142bc857c20479d5e70a5e1aac7",
"shasum": ""
},
"require": {
@ -3096,9 +3096,9 @@
],
"support": {
"issues": "https://github.com/nette/utils/issues",
"source": "https://github.com/nette/utils/tree/v4.1.3"
"source": "https://github.com/nette/utils/tree/v4.1.4"
},
"time": "2026-02-13T03:05:33+00:00"
"time": "2026-05-11T20:49:54+00:00"
},
{
"name": "nikic/php-parser",
@ -3314,78 +3314,6 @@
},
"time": "2025-09-24T15:06:41+00:00"
},
{
"name": "phpdocumentor/reflection",
"version": "6.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/Reflection.git",
"reference": "c8d36446027506a005103d57265ba5ea56beabfc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/Reflection/zipball/c8d36446027506a005103d57265ba5ea56beabfc",
"reference": "c8d36446027506a005103d57265ba5ea56beabfc",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"nikic/php-parser": "~4.18 || ^5.0",
"php": "8.1.*|8.2.*|8.3.*|8.4.*|8.5.*",
"phpdocumentor/reflection-common": "^2.1",
"phpdocumentor/reflection-docblock": "^5",
"phpdocumentor/type-resolver": "^1.4",
"symfony/polyfill-php80": "^1.28",
"webmozart/assert": "^1.7"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"doctrine/coding-standard": "^13.0",
"eliashaeussler/phpunit-attributes": "^1.8",
"mikey179/vfsstream": "~1.2",
"mockery/mockery": "~1.6.0",
"phpspec/prophecy-phpunit": "^2.4",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^10.5.53",
"psalm/phar": "^6.0",
"rector/rector": "^1.0.0",
"squizlabs/php_codesniffer": "^3.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-5.x": "5.3.x-dev",
"dev-6.x": "6.0.x-dev"
}
},
"autoload": {
"files": [
"src/php-parser/Modifiers.php"
],
"psr-4": {
"phpDocumentor\\": "src/phpDocumentor"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Reflection library to do Static Analysis for PHP Projects",
"homepage": "http://www.phpdoc.org",
"keywords": [
"phpDocumentor",
"phpdoc",
"reflection",
"static analysis"
],
"support": {
"issues": "https://github.com/phpDocumentor/Reflection/issues",
"source": "https://github.com/phpDocumentor/Reflection/tree/6.6.0"
},
"time": "2026-04-12T18:07:10+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
@ -4426,22 +4354,24 @@
},
{
"name": "spatie/laravel-data",
"version": "4.22.1",
"version": "4.23.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-data.git",
"reference": "ec254c0ebc3f3b37515cd7449e2dbb10588e606b"
"reference": "230543769c996e407fec2873930626aed7dd0d3b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-data/zipball/ec254c0ebc3f3b37515cd7449e2dbb10588e606b",
"reference": "ec254c0ebc3f3b37515cd7449e2dbb10588e606b",
"url": "https://api.github.com/repos/spatie/laravel-data/zipball/230543769c996e407fec2873930626aed7dd0d3b",
"reference": "230543769c996e407fec2873930626aed7dd0d3b",
"shasum": ""
},
"require": {
"illuminate/contracts": "^10.0|^11.0|^12.0|^13.0",
"php": "^8.1",
"phpdocumentor/reflection": "^6.0",
"phpdocumentor/reflection-common": "^2.2",
"phpdocumentor/reflection-docblock": "^5.3 || ^6.0",
"phpdocumentor/type-resolver": "^1.7 || ^2.0",
"spatie/laravel-package-tools": "^1.9.0",
"spatie/php-structure-discoverer": "^2.0"
},
@ -4496,7 +4426,7 @@
],
"support": {
"issues": "https://github.com/spatie/laravel-data/issues",
"source": "https://github.com/spatie/laravel-data/tree/4.22.1"
"source": "https://github.com/spatie/laravel-data/tree/4.23.0"
},
"funding": [
{
@ -4504,7 +4434,7 @@
"type": "github"
}
],
"time": "2026-04-27T07:30:53+00:00"
"time": "2026-05-08T14:41:13+00:00"
},
{
"name": "spatie/laravel-package-tools",
@ -4994,16 +4924,16 @@
},
{
"name": "symfony/console",
"version": "v8.0.9",
"version": "v8.0.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d"
"reference": "3156577f46a38aa1b9323aad223de7a9cd426782"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/7113778e2e91f4709cb3194a75dfa9c0d028d94d",
"reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d",
"url": "https://api.github.com/repos/symfony/console/zipball/3156577f46a38aa1b9323aad223de7a9cd426782",
"reference": "3156577f46a38aa1b9323aad223de7a9cd426782",
"shasum": ""
},
"require": {
@ -5060,7 +4990,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v8.0.9"
"source": "https://github.com/symfony/console/tree/v8.0.11"
},
"funding": [
{
@ -5080,7 +5010,7 @@
"type": "tidelift"
}
],
"time": "2026-04-29T15:02:55+00:00"
"time": "2026-05-13T12:07:53+00:00"
},
{
"name": "symfony/css-selector",
@ -5618,16 +5548,16 @@
},
{
"name": "symfony/http-kernel",
"version": "v8.0.10",
"version": "v8.0.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-kernel.git",
"reference": "fb3f65b3d4ca2dad31c80d323819a762ca31d6ac"
"reference": "20d3680373f4b791903c09e74b45402b4aeda71c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/fb3f65b3d4ca2dad31c80d323819a762ca31d6ac",
"reference": "fb3f65b3d4ca2dad31c80d323819a762ca31d6ac",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/20d3680373f4b791903c09e74b45402b4aeda71c",
"reference": "20d3680373f4b791903c09e74b45402b4aeda71c",
"shasum": ""
},
"require": {
@ -5698,7 +5628,7 @@
"description": "Provides a structured process for converting a Request into a Response",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/http-kernel/tree/v8.0.10"
"source": "https://github.com/symfony/http-kernel/tree/v8.0.11"
},
"funding": [
{
@ -5718,7 +5648,7 @@
"type": "tidelift"
}
],
"time": "2026-05-06T12:27:31+00:00"
"time": "2026-05-13T18:07:14+00:00"
},
{
"name": "symfony/mailer",
@ -6797,16 +6727,16 @@
},
{
"name": "symfony/process",
"version": "v8.0.8",
"version": "v8.0.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "cb8939aff03470d1a9d1d1b66d08c6fa71b3bbdc"
"reference": "26d89e459f037d2873300605d0a07e7a8ef84db0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/cb8939aff03470d1a9d1d1b66d08c6fa71b3bbdc",
"reference": "cb8939aff03470d1a9d1d1b66d08c6fa71b3bbdc",
"url": "https://api.github.com/repos/symfony/process/zipball/26d89e459f037d2873300605d0a07e7a8ef84db0",
"reference": "26d89e459f037d2873300605d0a07e7a8ef84db0",
"shasum": ""
},
"require": {
@ -6838,7 +6768,7 @@
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/process/tree/v8.0.8"
"source": "https://github.com/symfony/process/tree/v8.0.11"
},
"funding": [
{
@ -6858,7 +6788,7 @@
"type": "tidelift"
}
],
"time": "2026-03-30T15:14:47+00:00"
"time": "2026-05-11T16:56:32+00:00"
},
{
"name": "symfony/property-access",
@ -7113,16 +7043,16 @@
},
{
"name": "symfony/serializer",
"version": "v7.4.8",
"version": "v7.4.10",
"source": {
"type": "git",
"url": "https://github.com/symfony/serializer.git",
"reference": "006fd51717addf2df2bd1a64dafef6b7fab6b455"
"reference": "268c5aa6c4bd675eddd89348e7ecac292a843ddd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/serializer/zipball/006fd51717addf2df2bd1a64dafef6b7fab6b455",
"reference": "006fd51717addf2df2bd1a64dafef6b7fab6b455",
"url": "https://api.github.com/repos/symfony/serializer/zipball/268c5aa6c4bd675eddd89348e7ecac292a843ddd",
"reference": "268c5aa6c4bd675eddd89348e7ecac292a843ddd",
"shasum": ""
},
"require": {
@ -7135,7 +7065,7 @@
"phpdocumentor/reflection-docblock": "<5.2|>=7",
"phpdocumentor/type-resolver": "<1.5.1",
"symfony/dependency-injection": "<6.4",
"symfony/property-access": "<6.4",
"symfony/property-access": "<6.4.31|>=7.0,<7.4.2|>=8.0,<8.0.2",
"symfony/property-info": "<6.4",
"symfony/type-info": "<7.2.5",
"symfony/uid": "<6.4",
@ -7157,7 +7087,7 @@
"symfony/http-kernel": "^6.4|^7.0|^8.0",
"symfony/messenger": "^6.4|^7.0|^8.0",
"symfony/mime": "^6.4|^7.0|^8.0",
"symfony/property-access": "^6.4|^7.0|^8.0",
"symfony/property-access": "^6.4.31|^7.4.2|^8.0.2",
"symfony/property-info": "^6.4|^7.0|^8.0",
"symfony/translation-contracts": "^2.5|^3",
"symfony/type-info": "^7.2.5|^8.0",
@ -7193,7 +7123,7 @@
"description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/serializer/tree/v7.4.8"
"source": "https://github.com/symfony/serializer/tree/v7.4.10"
},
"funding": [
{
@ -7213,7 +7143,7 @@
"type": "tidelift"
}
],
"time": "2026-03-30T21:34:42+00:00"
"time": "2026-05-03T13:03:28+00:00"
},
{
"name": "symfony/service-contracts",
@ -7304,16 +7234,16 @@
},
{
"name": "symfony/string",
"version": "v8.0.8",
"version": "v8.0.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "ae9488f874d7603f9d2dfbf120203882b645d963"
"reference": "39be2ad058a3c0bd558edca23e65f009865d75ff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/ae9488f874d7603f9d2dfbf120203882b645d963",
"reference": "ae9488f874d7603f9d2dfbf120203882b645d963",
"url": "https://api.github.com/repos/symfony/string/zipball/39be2ad058a3c0bd558edca23e65f009865d75ff",
"reference": "39be2ad058a3c0bd558edca23e65f009865d75ff",
"shasum": ""
},
"require": {
@ -7370,7 +7300,7 @@
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v8.0.8"
"source": "https://github.com/symfony/string/tree/v8.0.11"
},
"funding": [
{
@ -7390,7 +7320,7 @@
"type": "tidelift"
}
],
"time": "2026-03-30T15:14:47+00:00"
"time": "2026-05-13T12:07:53+00:00"
},
{
"name": "symfony/translation",
@ -8186,23 +8116,23 @@
},
{
"name": "webmozart/assert",
"version": "1.12.1",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/webmozarts/assert.git",
"reference": "9be6926d8b485f55b9229203f962b51ed377ba68"
"reference": "eb0d790f735ba6cff25c683a85a1da0eadeff9e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/9be6926d8b485f55b9229203f962b51ed377ba68",
"reference": "9be6926d8b485f55b9229203f962b51ed377ba68",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/eb0d790f735ba6cff25c683a85a1da0eadeff9e4",
"reference": "eb0d790f735ba6cff25c683a85a1da0eadeff9e4",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-date": "*",
"ext-filter": "*",
"php": "^7.2 || ^8.0"
"php": "^8.2"
},
"suggest": {
"ext-intl": "",
@ -8212,7 +8142,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
"dev-feature/2-0": "2.0-dev"
}
},
"autoload": {
@ -8228,6 +8158,10 @@
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
},
{
"name": "Woody Gilk",
"email": "woody.gilk@gmail.com"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
@ -8238,9 +8172,9 @@
],
"support": {
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.12.1"
"source": "https://github.com/webmozarts/assert/tree/2.3.0"
},
"time": "2025-10-29T15:56:20+00:00"
"time": "2026-04-11T10:33:05+00:00"
}
],
"packages-dev": [
@ -9284,16 +9218,16 @@
},
{
"name": "laravel/sail",
"version": "v1.58.0",
"version": "v1.59.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/sail.git",
"reference": "2e5e968138ca52ed87d712449697a8364d73b466"
"reference": "a41abad557e487eaefde6c9873085ed086fdf47a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/sail/zipball/2e5e968138ca52ed87d712449697a8364d73b466",
"reference": "2e5e968138ca52ed87d712449697a8364d73b466",
"url": "https://api.github.com/repos/laravel/sail/zipball/a41abad557e487eaefde6c9873085ed086fdf47a",
"reference": "a41abad557e487eaefde6c9873085ed086fdf47a",
"shasum": ""
},
"require": {
@ -9343,7 +9277,7 @@
"issues": "https://github.com/laravel/sail/issues",
"source": "https://github.com/laravel/sail"
},
"time": "2026-04-27T13:38:34+00:00"
"time": "2026-05-13T14:02:20+00:00"
},
{
"name": "mockery/mockery",
@ -11553,16 +11487,16 @@
},
{
"name": "symfony/yaml",
"version": "v8.0.8",
"version": "v8.0.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "54174ab48c0c0f9e21512b304be17f8150ccf8f1"
"reference": "48046fbd5567bd1717f278eaa2cfc3131f489984"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/54174ab48c0c0f9e21512b304be17f8150ccf8f1",
"reference": "54174ab48c0c0f9e21512b304be17f8150ccf8f1",
"url": "https://api.github.com/repos/symfony/yaml/zipball/48046fbd5567bd1717f278eaa2cfc3131f489984",
"reference": "48046fbd5567bd1717f278eaa2cfc3131f489984",
"shasum": ""
},
"require": {
@ -11604,7 +11538,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v8.0.8"
"source": "https://github.com/symfony/yaml/tree/v8.0.11"
},
"funding": [
{
@ -11624,7 +11558,7 @@
"type": "tidelift"
}
],
"time": "2026-03-30T15:14:47+00:00"
"time": "2026-05-13T12:07:53+00:00"
},
{
"name": "ta-tikoma/phpunit-architecture-test",

View File

@ -1,19 +1,24 @@
<?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 Spatie\LaravelData\DataCollection;
new
#[Title('Create a service')]
class extends Component {
public StoreConnectedAppFrom $form;
#[Computed]
@ -35,13 +40,17 @@ public function protocols(): Collection
}
/**
* @returns Collection<int, ConnectionStatus>
* @returns DataCollection<int, ConnectionStatus>
*/
#[Computed]
public function connectionStatuses(): Collection
public function connectionStatuses(): DataCollection
{
return ConnectionStatus::query()->get()->map(function (ConnectionStatus $status) {
$status->name = ucfirst($status->name);
$statusService = app(ConnectionStatusService::class);
return $statusService->getAll()->map(function (ConnectionStatusData $status) {
if ($status->name === ConnectionStatusEnum::Disconnected) {
$this->form->statusId = $status->id;
}
return $status;
});
}
@ -54,7 +63,11 @@ public function searchProvider(string $name)
public function save()
{
$this->form->save();
try {
$this->form->save();
} catch (Throwable $e) {
\Illuminate\Support\Facades\Log::error('Error while submitting Create a connected app', [$e->getMessage()]);
}
}
};
?>
@ -63,17 +76,16 @@ public function save()
<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-input wire:model.live.blur="form.logoUrl" :label="__('Logo Link')"/>
<x-choices
required
wire:model.live="form.protocolId"
wire:model="form.protocolId"
:label="__('Protocol')"
:single="true"
:options="$this->protocols"
placeholder="Select"
/>
<x-choices required
wire:model.live="form.providerId"
wire:model="form.providerId"
:label="__('Provider')"
placeholder="Search ..."
:single="true"
@ -84,10 +96,10 @@ public function save()
/>
<x-choices
required
wire:model.live="form.statusId"
wire:model="form.statusId"
:label="__('Status')"
:single="true"
:options="$this->connectionStatuses"
:options="$this->connectionStatuses->toArray()"
placeholder="Select"
/>
<div class="md:col-span-2 flex gap-x-4 font-medium justify-end">