This repository has been archived on 2024-05-20. You can view files and clone it, but cannot push or open issues or pull requests.

114 lines
5.0 KiB
PHP

<?php
use App\Models\Quote;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Volt\Component;
new #[Layout('layouts.guest')] class extends Component
{
public Collection $quotes;
public function mount(): void
{
$this->getQuotes();
}
public function request(Quote $quote): void
{
$this->authorize('request', $quote);
$quote->request();
}
public function delete(Quote $quote): void
{
$this->authorize('request', $quote);
$quote->delete();
$this->dispatch('quote-deleted');
}
#[On('quote-approved')]
#[On('quote-deleted')]
public function getQuotes(): void
{
$this->quotes = Quote::all()->whereNull('deleted_at')->sortDesc();
}
}; ?>
<div class="px-4 sm:px-6 lg:px-8">
<div class="-mx-4 mt-10 ring-1 ring-gray-300 sm:mx-0 sm:rounded-lg bg-nexi-primary dark:bg-zinc-800 transition-colors duration-300">
<table class="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-nexi-black dark:text-gray-200 sm:pl-6">
Quotes
</th>
@if(auth()->user())
<th scope="col"></th>
@endif
</tr>
</thead>
<tbody>
@foreach ($quotes as $quote)
<tr>
<td class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
{{ $quote->quote }}
</td>
@if(auth()->user())
<td class="relative w-8 pl-4 pr-3 text-sm sm:pl-6 border-t">
<div class="flex flex-row space-x-2">
@if(auth()->user()->is_admin)
{{-- For now this is admin only, when we add credits we can make it avaliable to users --}}
<form wire:submit="request({{ $quote }})">
<x-button wire:loading.attr="disabled" wire:loading.class="opacity-50" class="bg-nexi-purple w-24">{{ __('Request') }}</x-button>
</form>
@endif
@if(auth()->user()->is_admin)
<x-button
x-data=""
x-on:click.prevent="$dispatch('open-modal', 'confirm-quote-deletion-{{ $quote->id }}')"
wire:loading.attr="disabled"
wire:loading.class="opacity-50"
class="bg-nexi-red w-24"
>{{ __('Delete') }}</x-button>
<x-modal name="confirm-quote-deletion-{{ $quote->id }}" :show="$errors->isNotEmpty()" focusable>
<form wire:submit="delete({{ $quote }})" class="p-6">
<h2 class="text-lg font-medium text-nexi-black dark:text-gray-100">
{{ __('Are you sure you want to delete the quote?') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
"{{ $quote->quote }}"
</p>
<div class="mt-6 flex justify-end">
<x-secondary-button x-on:click="$dispatch('close')">
{{ __('Cancel') }}
</x-secondary-button>
<x-primary-button
wire:loading.attr="disabled"
wire:loading.class="opacity-50"
@click="$dispatch('close')"
class="w-24 ml-3"
>{{ __('Delete') }}</x-primary-button>
</div>
</form>
</x-modal>
@endif
</div>
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
</div>
</div>