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.

46 lines
1.4 KiB
PHP

<?php
use App\Models\Log;
use Illuminate\Support\Facades\Http;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Rule;
use Livewire\Volt\Component;
new #[Layout('layouts.app')] class extends Component
{
#[Rule(['required', 'string'])]
public string $quote = '';
public function sendQuote(): void
{
$validated = $this->validate();
// TODO: move this to a helper class so we can reuse code between API and FE
$response = Http::post(config('bot.webhook'), ['text' => $validated['quote']]);
Log::create([
'user_id' => auth()?->user()?->id,
'content' => "Quote sent. {$validated['quote']}"
]);
$this->quote = '';
}
}; ?>
<div class="px-4 sm:px-6 lg:px-8">
<form wire:submit="sendQuote">
<x-text-input
wire:model="quote"
placeholder="{{ __('What did he say this time?') }}"
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
></x-text-input>
<x-input-error :messages="$errors->get('quote')" class="mt-2"/>
<x-primary-button wire:loading.attr="disabled"
wire:loading.class="opacity-50"
class="mt-4">
{{ __('Send') }}
</x-primary-button>
</form>
</div>