2023-08-15 12:11:38 +00:00
|
|
|
<?php
|
|
|
|
|
2023-09-01 07:34:25 +00:00
|
|
|
namespace App\Http\Livewire\Waitlist;
|
2023-08-15 12:11:38 +00:00
|
|
|
|
|
|
|
use App\Jobs\SendConfirmationForWaitlistJob;
|
2023-08-15 12:27:45 +00:00
|
|
|
use App\Models\User;
|
2023-09-01 07:34:25 +00:00
|
|
|
use App\Models\Waitlist;
|
2023-08-15 12:11:38 +00:00
|
|
|
use Livewire\Component;
|
2023-09-15 09:19:36 +00:00
|
|
|
use Illuminate\Support\Str;
|
2023-08-15 12:11:38 +00:00
|
|
|
|
2023-09-01 07:34:25 +00:00
|
|
|
class Index extends Component
|
2023-08-15 12:11:38 +00:00
|
|
|
{
|
|
|
|
public string $email;
|
2023-09-11 11:53:08 +00:00
|
|
|
public int $users = 0;
|
2023-09-01 07:34:25 +00:00
|
|
|
public int $waitingInLine = 0;
|
2023-08-15 12:11:38 +00:00
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'email' => 'required|email',
|
|
|
|
];
|
2023-09-01 07:34:25 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.waitlist.index')->layout('layouts.simple');
|
|
|
|
}
|
2023-08-15 12:11:38 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-09-01 07:34:25 +00:00
|
|
|
$this->waitingInLine = Waitlist::whereVerified(true)->count();
|
2023-09-11 11:53:08 +00:00
|
|
|
$this->users = User::count();
|
2023-08-27 13:23:47 +00:00
|
|
|
if (isDev()) {
|
2023-08-17 13:19:37 +00:00
|
|
|
$this->email = 'waitlist@example.com';
|
2023-08-15 12:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
try {
|
2023-08-15 12:27:45 +00:00
|
|
|
$already_registered = User::whereEmail($this->email)->first();
|
|
|
|
if ($already_registered) {
|
2023-08-17 13:19:37 +00:00
|
|
|
throw new \Exception('You are already on the waitlist or registered. <br>Please check your email to verify your email address or contact support.');
|
2023-08-15 12:27:45 +00:00
|
|
|
}
|
2023-09-01 07:34:25 +00:00
|
|
|
$found = Waitlist::where('email', $this->email)->first();
|
2023-08-15 12:11:38 +00:00
|
|
|
if ($found) {
|
|
|
|
if (!$found->verified) {
|
|
|
|
$this->emit('error', 'You are already on the waitlist. <br>Please check your email to verify your email address.');
|
|
|
|
return;
|
|
|
|
}
|
2023-08-17 13:19:37 +00:00
|
|
|
$this->emit('error', 'You are already on the waitlist. <br>You will be notified when your turn comes. <br>Thank you.');
|
2023-08-15 12:11:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-09-01 07:34:25 +00:00
|
|
|
$waitlist = Waitlist::create([
|
2023-09-13 18:48:13 +00:00
|
|
|
'email' => Str::lower($this->email),
|
2023-08-15 12:11:38 +00:00
|
|
|
'type' => 'registration',
|
|
|
|
]);
|
|
|
|
|
2023-08-15 14:09:40 +00:00
|
|
|
$this->emit('success', 'Check your email to verify your email address.');
|
2023-08-15 12:11:38 +00:00
|
|
|
dispatch(new SendConfirmationForWaitlistJob($this->email, $waitlist->uuid));
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-15 12:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|