2023-08-15 12:11:38 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\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-09-15 09:19:36 +00:00
|
|
|
use Illuminate\Support\Str;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Livewire\Component;
|
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;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-11 11:53:08 +00:00
|
|
|
public int $users = 0;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
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',
|
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-01 07:34:25 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.waitlist.index')->layout('layouts.simple');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-15 12:11:38 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-10-02 13:09:57 +00:00
|
|
|
if (config('coolify.waitlist') == false) {
|
2023-12-27 15:45:01 +00:00
|
|
|
return redirect()->route('register');
|
2023-10-02 13:09:57 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
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) {
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $found->verified) {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('error', 'You are already on the waitlist. <br>Please check your email to verify your email address.');
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-15 12:11:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('error', 'You are already on the waitlist. <br>You will be notified when your turn comes. <br>Thank you.');
|
2024-06-10 20:43:34 +00:00
|
|
|
|
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-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|