<?php
|
|
|
|
namespace App\Http\Livewire\Collaborators\Associates;
|
|
|
|
use App\Associate;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Component;
|
|
|
|
class Edit extends Component
|
|
{
|
|
/** @var string */
|
|
public $name;
|
|
|
|
/** @var string */
|
|
public $birthday;
|
|
|
|
/** @var array */
|
|
public $document;
|
|
|
|
/** @var array */
|
|
public $address;
|
|
|
|
/** @var array */
|
|
public $profile;
|
|
|
|
/** @var string */
|
|
public $email;
|
|
|
|
/** @var string */
|
|
public $discussion;
|
|
|
|
/** @var int */
|
|
public $contribution;
|
|
|
|
/** \App\Associate */
|
|
public $associate;
|
|
|
|
public function mount(Associate $associate)
|
|
{
|
|
$this->associate = $associate;
|
|
$this->name = $associate->name;
|
|
$this->birthday = $associate->birthday->format('d/m/Y');
|
|
$this->document = $associate->document;
|
|
$this->address = $associate->address;
|
|
$this->profile = $associate->profile;
|
|
$this->email = $associate->email;
|
|
$this->discussion = $associate->discussion;
|
|
$this->contribution = $associate->contribution;
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->validate([
|
|
'address.city' => ['required', 'string'],
|
|
'address.complement' => ['nullable', 'string'],
|
|
'address.country' => ['required', 'string'],
|
|
'address.neighbourhood' => ['required', 'string'],
|
|
'address.number' => ['required', 'string'],
|
|
'address.postcode' => ['required', 'string'],
|
|
'address.state' => ['required', 'string'],
|
|
'address.street' => ['required', 'string'],
|
|
'birthday' => ['required', 'date_format:d/m/Y'],
|
|
'contribution' => ['required', 'numeric'],
|
|
'discussion' => ['required', 'string', 'in:all,daily,occasional'],
|
|
'document.number' => ['required', 'string'],
|
|
'document.type' => ['required', 'string', 'in:cpf,identity,passport'],
|
|
'email' => ['required', 'email', Rule::unique('associates')->ignore($this->associate->id)],
|
|
'name' => ['required'],
|
|
'profile.bike_activities' => ['nullable', 'string'],
|
|
'profile.bike_use' => ['nullable', 'string'],
|
|
'profile.comments' => ['nullable', 'string'],
|
|
'profile.expectation' => ['nullable', 'string'],
|
|
'profile.gender' => ['required', 'string', 'in:male,female,other'],
|
|
'profile.occupation' => ['required', 'string'],
|
|
'profile.org_participation' => ['nullable', 'string'],
|
|
'profile.phone' => ['required', 'string'],
|
|
'profile.scholarity' => ['required', 'string', 'in:primary-school,high-school,bachelor,master,phd'],
|
|
'profile.secondary_emails' => ['nullable', 'string'],
|
|
'profile.social' => ['nullable', 'string'],
|
|
'profile.ucb_comments' => ['nullable', 'string'],
|
|
'profile.website' => ['nullable', 'string'],
|
|
]);
|
|
|
|
$this->associate->update([
|
|
'address' => $this->address,
|
|
'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday),
|
|
'contribution' => $this->contribution,
|
|
'discussion' => $this->discussion,
|
|
'document' => $this->document,
|
|
'email' => $this->email,
|
|
'name' => $this->name,
|
|
'profile' => $this->profile,
|
|
]);
|
|
|
|
session()->flash('notify-saved');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.collaborators.associates.edit');
|
|
}
|
|
}
|