Skip to content

Commit

Permalink
Merge pull request #3782 from HDInnovations/Bug-3752
Browse files Browse the repository at this point in the history
(Fix) Bug #3752
  • Loading branch information
HDVinnie committed Apr 26, 2024
2 parents 33748bc + 78d5f91 commit 1706578
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 26 additions & 7 deletions app/Http/Livewire/UserNotes.php
Expand Up @@ -17,7 +17,6 @@
use App\Models\User;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Livewire\WithPagination;

Expand All @@ -29,15 +28,11 @@ class UserNotes extends Component

#TODO: Update URL attributes once Livewire 3 fixes upstream bug. See: https://github.com/livewire/livewire/discussions/7746

#[Url(history: true)]
#[Validate('required|filled')]
public string $message = '';

/**
* @var array<int, string>
*/
#[Url(history: true)]
#[Validate('array')]
public array $messages = [];

#[Url(history: true)]
Expand All @@ -49,6 +44,23 @@ class UserNotes extends Component
#[Url(history: true)]
public string $sortDirection = 'desc';

/**
* @var array<mixed>
*/
protected array $rules = [
'message' => [
'required',
'filled',
],
'messages' => [
'array',
],
'messages.*' => [
'required',
'filled',
]
];

final public function mount(): void
{
$this->messages = Note::where('user_id', '=', $this->user->id)->pluck('message', 'id')->toArray();
Expand All @@ -73,11 +85,14 @@ final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\C
]);
}

/**
* @throws \Illuminate\Validation\ValidationException
*/
final public function store(): void
{
abort_unless(auth()->user()->group->is_modo, 403);

$this->validate();
$this->validateOnly('message');

Note::create([
'user_id' => $this->user->id,
Expand All @@ -90,11 +105,15 @@ final public function store(): void
$this->dispatch('success', type: 'success', message: 'Note has successfully been posted!');
}

/**
* @throws \Illuminate\Validation\ValidationException
*/
final public function update(int $id): void
{
abort_unless(auth()->user()->group->is_modo, 403);

$this->validate();
$this->validateOnly('messages');
$this->validateOnly('messages.*');

Note::whereKey($id)->update([
'staff_id' => auth()->id(),
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/user-notes.blade.php
Expand Up @@ -92,6 +92,7 @@ class="form__textarea"
name="message"
placeholder=" "
wire:model="messages.{{ $note->id }}"
value="{{ $note->message }}"
></textarea>
<label
class="form__label form__label--floating"
Expand Down

0 comments on commit 1706578

Please sign in to comment.