58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Models\Goal;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
class NewGoal extends Component
|
|
{
|
|
public bool $open = false;
|
|
|
|
#[Validate('required|string|min:3|max:160')]
|
|
public string $title = '';
|
|
|
|
#[Validate('nullable|string|max:2000')]
|
|
public string $description = '';
|
|
|
|
public function show(): void
|
|
{
|
|
$this->resetForm();
|
|
$this->open = true;
|
|
}
|
|
|
|
public function close(): void
|
|
{
|
|
$this->open = false;
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$this->validate();
|
|
|
|
Goal::create([
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'status' => Goal::STATUS_ACTIVE,
|
|
'progress' => 0,
|
|
]);
|
|
|
|
$this->dispatch('goal-created');
|
|
$this->close();
|
|
$this->resetForm();
|
|
}
|
|
|
|
protected function resetForm(): void
|
|
{
|
|
$this->title = '';
|
|
$this->description = '';
|
|
$this->resetErrorBag();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.modals.new-goal');
|
|
}
|
|
}
|