2023-08-15 12:11:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use App\Jobs\SendConfirmationForWaitlistJob;
|
2023-08-15 12:27:45 +00:00
|
|
|
use App\Models\User;
|
2023-08-15 12:11:38 +00:00
|
|
|
use App\Models\Waitlist as ModelsWaitlist;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Waitlist extends Component
|
|
|
|
{
|
|
|
|
public string $email;
|
|
|
|
public int $waiting_in_line = 0;
|
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'email' => 'required|email',
|
|
|
|
];
|
|
|
|
public function mount()
|
|
|
|
{
|
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-08-15 12:11:38 +00:00
|
|
|
$found = ModelsWaitlist::where('email', $this->email)->first();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
$waitlist = ModelsWaitlist::create([
|
|
|
|
'email' => $this->email,
|
|
|
|
'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));
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return general_error_handler(err: $e, that: $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|