feat: Upload de imagem na edição de clientes/Exibição de imagem do cliente.
feat: Upload de imagem na edição de clientes/Exibição de imagem do cliente.
This commit is contained in:
commit
576e4cfe57
|
|
@ -5,12 +5,16 @@
|
||||||
use App\Livewire\Forms\ClientForm;
|
use App\Livewire\Forms\ClientForm;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Services\ClientService;
|
use App\Services\ClientService;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\WithFileUploads;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class EditClient extends Component
|
class EditClient extends Component
|
||||||
{
|
{
|
||||||
|
use WithFileUploads;
|
||||||
|
|
||||||
public Client $client;
|
public Client $client;
|
||||||
public ClientForm $clientForm;
|
public ClientForm $clientForm;
|
||||||
|
|
@ -35,6 +39,14 @@ public function edit(ClientService $clientService)
|
||||||
{
|
{
|
||||||
$data = $this->clientForm->validate();
|
$data = $this->clientForm->validate();
|
||||||
|
|
||||||
|
if ($this->clientForm->profile_image_path) {
|
||||||
|
$path = $this->clientForm->profile_image_path->store('client_logos', 'public');
|
||||||
|
$data['profile_image_path'] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['root_password'] = Crypt::encryptString($data['root_password']);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!$clientService->updateClient($this->client, $data)) {
|
if (!$clientService->updateClient($this->client, $data)) {
|
||||||
throw new Exception('O serviço não confirmou a atualização.');
|
throw new Exception('O serviço não confirmou a atualização.');
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,15 @@
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
|
||||||
class ShowUsers extends Component
|
class ShowUsers extends Component
|
||||||
{
|
{
|
||||||
public $users = [];
|
public $users = [];
|
||||||
|
|
||||||
|
#[On('user-updated')]
|
||||||
|
#[On('user-created')]
|
||||||
|
|
||||||
public function mount(UserService $userService)
|
public function mount(UserService $userService)
|
||||||
{
|
{
|
||||||
$this->users = $userService->showUsers();
|
$this->users = $userService->showUsers();
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public function editUser(UserService $userService)
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatch('user-updated');
|
$this->dispatch('user-updated');
|
||||||
$this->dispatch('notify', message: $this->clientForm->client_name . ' atualizado com sucesso!');
|
$this->dispatch('notify', message: $this->userForm->name . ' atualizado com sucesso!');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->dispatch('notify', message: 'Falha na edição: ' . $e->getMessage(), type: 'error');
|
$this->dispatch('notify', message: 'Falha na edição: ' . $e->getMessage(), type: 'error');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<div class="client-card">
|
<div class="client-card">
|
||||||
<div class="client-card-header">
|
<div class="client-card-header">
|
||||||
<div class="client-avatar">
|
<div class="client-avatar">
|
||||||
<img src="{{ Vite::asset('resources/images/mr-distribuidora.svg') }}" alt="Avatar do Cliente"
|
<img src="{{ asset('storage/' . $client->profile_image_path) }}" alt="Avatar do Cliente"
|
||||||
class="w-32 h-32 rounded-full object-cover">
|
class="w-32 h-32 rounded-full object-cover">
|
||||||
</div>
|
</div>
|
||||||
<div x-data="{ open: false }" @click.outside="open = false" class="client-options-menu">
|
<div x-data="{ open: false }" @click.outside="open = false" class="client-options-menu">
|
||||||
|
|
@ -16,9 +16,15 @@ class="w-32 h-32 rounded-full object-cover">
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<ul x-show="open" class="client-options-list" x-transition>
|
<ul x-show="open" class="client-options-list" x-transition>
|
||||||
<li><a href="#" class="client-option-item" x-on:click.prevent="$dispatch('view-client', { id: '{{ $client->id }}' })">Ver Detalhes</a></li>
|
<li><a href="#" class="client-option-item"
|
||||||
<li><a href=" #" class="client-option-item" x-on:click.prevent="$dispatch('update-client', { id: '{{ $client->id }}' })">Editar Cliente</a></li>
|
x-on:click.prevent="$dispatch('view-client', { id: '{{ $client->id }}' })">Ver Detalhes</a>
|
||||||
<li><a href="#" class="client-option-item text-red-600" x-on:click.prevent="$dispatch('sure', { id: '{{ $client->id }}' })"> Excluir Cliente</a></li>
|
</li>
|
||||||
|
<li><a href=" #" class="client-option-item"
|
||||||
|
x-on:click.prevent="$dispatch('update-client', { id: '{{ $client->id }}' })">Editar
|
||||||
|
Cliente</a></li>
|
||||||
|
<li><a href="#" class="client-option-item text-red-600"
|
||||||
|
x-on:click.prevent="$dispatch('sure', { id: '{{ $client->id }}' })"> Excluir Cliente</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue