Skip to content

Commit

Permalink
refact:(SHO-42) add review to refact code to add product view
Browse files Browse the repository at this point in the history
  • Loading branch information
StevyMarlino committed Dec 5, 2024
1 parent 5026158 commit b6b40b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
23 changes: 0 additions & 23 deletions app/Livewire/Forms/ProductReviewsForm.php

This file was deleted.

22 changes: 12 additions & 10 deletions app/Livewire/Modals/Product/AddProductReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@
namespace App\Livewire\Modals\Product;

use App\Actions\Product\AddProductReviewAction;
use App\Livewire\Forms\ProductReviewsForm;
use App\Models\Product;
use Filament\Notifications\Notification;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Validate;
use LivewireUI\Modal\ModalComponent;

final class AddProductReview extends ModalComponent
{
public ProductReviewsForm $form;
public Product $product;

public function mount(Product $product): void
{
$this->form->product = $product;
}
#[Validate('required|integer|min:1|max:5')]
public int $rating = 1;

#[Validate('nullable|string|max:255')]
public ?string $title = null;

#[Validate('nullable|string|max:255')]
public ?string $content = null;

/**
* @throws ValidationException
*/
public function save(): void
{
$this->form->validate();

app(AddProductReviewAction::class)
->execute($this->form->product, $this->form->toArray(), Auth::user());
->execute($this->product, $this->validate(), Auth::user());

Notification::make()
->title(__('Review added'))
Expand All @@ -45,7 +47,7 @@ public function save(): void

public function update(int $rate): void
{
$this->form->rating = $rate;
$this->rating = $rate;
}

public function render(): View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
<div class="space-y-4 pb-5">
<div class="grid grid-cols-2 gap-4">
<div class="space-y-2">
<x-forms.input wire:model="form.rating" id="rate" name="rate" value="1" type="hidden"/>
<x-forms.input wire:model="rating" id="rate" name="rate" value="1" type="hidden"/>
<div class="mt-1 flex items-center hover:cursor-pointer">
@for ($i = 1; $i <= 5; $i++)
<svg wire:click="update('{{$i}}')" class="size-5 shrink-0 {{ $i <= $form->rating ? 'text-yellow-400' : 'text-gray-300' }}" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
<svg wire:click="update('{{$i}}')"
@class([
'size-5 shrink-0',
'text-yellow-400' => $i <= $rating,
'text-gray-300' => $i > $rating,
])
viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
<path fill-rule="evenodd" d="M10.868 2.884c-.321-.772-1.415-.772-1.736 0l-1.83 4.401-4.753.381c-.833.067-1.171 1.107-.536 1.651l3.62 3.102-1.106 4.637c-.194.813.691 1.456 1.405 1.02L10 15.591l4.069 2.485c.713.436 1.598-.207 1.404-1.02l-1.106-4.637 3.62-3.102c.635-.544.297-1.584-.536-1.65l-4.752-.382-1.831-4.401Z" clip-rule="evenodd" />
</svg>
@endfor
Expand All @@ -24,9 +30,9 @@
</div>

<div class="space-y-2">
<x-forms.label for="form.content" :value="__('Content')" />
<x-forms.text-area wire:model="form.content" id="content" name="content" type="text"> </x-forms.text-area>
<x-forms.errors :messages="$errors->get('form.content')" />
<x-forms.label for="content" :value="__('Content')" />
<x-forms.text-area wire:model="content" id="content" name="content" type="text"> </x-forms.text-area>
<x-forms.errors :messages="$errors->get('content')" />
</div>

</div>
Expand Down

0 comments on commit b6b40b2

Please sign in to comment.