diff --git a/app/Livewire/Admin/AddClient.php b/app/Livewire/Admin/AddClient.php index 99f8b74..22cf03f 100644 --- a/app/Livewire/Admin/AddClient.php +++ b/app/Livewire/Admin/AddClient.php @@ -24,7 +24,6 @@ public function save(ClientService $clientService) $data = $this->form->all(); $data['name'] = $data['client_name']; - if ($this->form->profile_image_path) { $path = $this->form->profile_image_path->store('client_logos', 'public'); $data['profile_image_path'] = $path; @@ -32,15 +31,16 @@ public function save(ClientService $clientService) $data['root_password'] = Crypt::encryptString($data['root_password']); - $clientService->addClient($data); + $client = $clientService->addClient($data); $this->dispatch('client-added'); - $this->dispatch('notify', message: 'Cliente adicionado com sucesso!'); + $this->dispatch('notify', message: $client->name . ' Cliente adicionado com sucesso!'); } catch (\Exception $e) { $this->dispatch('notify', message: 'Ocorreu um erro inesperado ao salvar.', type: 'error'); } } + public function render() { return view('livewire.admin.add-client'); diff --git a/app/Livewire/Admin/EditClient.php b/app/Livewire/Admin/EditClient.php new file mode 100644 index 0000000..0ac03ad --- /dev/null +++ b/app/Livewire/Admin/EditClient.php @@ -0,0 +1,45 @@ +client = Client::find($id); + + if ($this->client) { + $this->clientForm->addClient($this->client); + } + } catch (Exception $e) { + $this->dispatch('notify', message: 'Ocorreu um erro inesperado ao editar o cliente. ' + $e); + } + } + public function edit($clientId) + { + $this->clientForm->validate(); + + try { + $this->clientForm->updateClient($this->client); + $this->dispatch('notify', message: $this->client->client_name + ' atualizado com sucesso!'); + } catch (Exception $e) { + $this->dispatch('notify', message: 'Ocorreu um erro inesperado ao tentar confirmar edição do cliente. ' + $e); + } + } + public function render() + { + return view('livewire.admin.edit-client'); + } +} diff --git a/app/Livewire/Admin/ShowClient.php b/app/Livewire/Admin/ShowClient.php index bc522bb..740c13a 100644 --- a/app/Livewire/Admin/ShowClient.php +++ b/app/Livewire/Admin/ShowClient.php @@ -10,6 +10,7 @@ class ShowClient extends Component { #[On('clientDeleted')] + #[On('client-added')] public function refreshClientList() {} public function render() diff --git a/app/Livewire/Forms/ClientForm.php b/app/Livewire/Forms/ClientForm.php index 0f04d91..416241e 100644 --- a/app/Livewire/Forms/ClientForm.php +++ b/app/Livewire/Forms/ClientForm.php @@ -2,6 +2,8 @@ namespace App\Livewire\Forms; +use App\Services\ClientService; +use Exception; use Livewire\Attributes\Validate; use Livewire\Form; use App\Models\Client; @@ -24,6 +26,7 @@ class ClientForm extends Form public $modules = ''; public $whatsapp_number = ''; public $whatsapp_activation_date; + public ClientService $clientService; // Método para preencher o formulário (para edição futura) public function addClient(Client $client) @@ -32,10 +35,19 @@ public function addClient(Client $client) $data['has_call_center'] = (bool) $client->has_call_center; $data['has_voice_gateway'] = (bool) $client->has_voice_gateway; $data['has_fop2'] = (bool) $client->has_fop2; + $data['client_name'] = $data['name']; $this->fill($data); } + public function updateClient(Client $client) + { + if(!$this->clientService->updateClient($client)){ + throw new Exception('Ocorreu um erro.'); + } + + + } // 4. ADICIONADO: Método de Regras /** * Define as regras de validação para o formulário. diff --git a/app/Services/ClientService.php b/app/Services/ClientService.php index 8368323..2d713af 100644 --- a/app/Services/ClientService.php +++ b/app/Services/ClientService.php @@ -19,4 +19,6 @@ public function addClient(array $client) return Client::create($client); } + + public function updateClient($client) {} } diff --git a/resources/css/app.css b/resources/css/app.css index 8413264..9823b0e 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -144,44 +144,20 @@ @layer components { @apply transition-colors; } - /* 9. Estilizando as mensagens de erro (x-session-messages) */ - .messages { - @apply flex justify-center mb-4; - } - .messages div[role="alert"] { /* Assumindo que seu componente renderiza um div */ @apply bg-red-500/50 text-white p-3 rounded-md border border-red-700 text-sm; } - /* --- FIM DOS ESTILOS DE LOGIN --- */ - - /* 9. Estilizando as mensagens de erro (x-session-messages) */ .messages { @apply flex justify-center mb-4; - - /* 1. MUDANÇA: Usando "vidro branco" (como o card) - em vez de "vidro vermelho". - */ @apply bg-white/10 backdrop-blur-md; - /* 'md' para um borrão mais forte */ - - /* 2. MUDANÇA: Borda sutil de "vidro" */ @apply border border-white/10; - - /* 3. NOVO: Sombra para "flutuar" */ @apply shadow-lg rounded-lg; - - /* 4. MUDANÇA: A cor do erro agora está no texto. - 'text-red-200' (ou 300) tem ótimo contraste - no fundo de ondas. - */ @apply text-red-300 font-semibold p-4 text-sm; } - /* Classes antigas genéricas (podem ser usadas em outros lugares) */ .container { - /* Deixe APENAS as classes de largura, margem e padding */ @apply w-full mx-auto px-4 sm:px-6 lg:px-8 mt-15 mb-10; } diff --git a/resources/views/components/are-you-sure.blade.php b/resources/views/components/are-you-sure.blade.php index 629159c..8d662d7 100644 --- a/resources/views/components/are-you-sure.blade.php +++ b/resources/views/components/are-you-sure.blade.php @@ -35,7 +35,7 @@ class="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded- -