Added Create Custom, Random, Gmail Generation
This commit is contained in:
65
app/Livewire/Frontend/Email.php
Normal file
65
app/Livewire/Frontend/Email.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\ZEmail;
|
||||
use Livewire\Component;
|
||||
|
||||
class Email extends Component
|
||||
{
|
||||
public $list = false;
|
||||
public $type, $email, $emails, $initial;
|
||||
|
||||
protected $listeners = ['updateEmail' => 'syncEmail', 'getEmail' => 'generateEmail'];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
private function checkMultipleEmails(): void
|
||||
{
|
||||
if (count($this->emails) == 0) {
|
||||
$this->emails = [$this->email];
|
||||
}
|
||||
if (count($this->emails) > 1) {
|
||||
$this->list = true;
|
||||
} else {
|
||||
$this->list = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function switchEmail($email): void
|
||||
{
|
||||
ZEmail::setEmail($email);
|
||||
$this->email = $email;
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function syncEmail(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
if (count($this->emails) == 0) {
|
||||
$this->dispatch('getEmail');
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
public function generateEmail(): void
|
||||
{
|
||||
if ($this->email == null) {
|
||||
ZEmail::generateRandomEmail();
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.email')->with(['email' => $this->email, 'emails' => $this->emails, 'initial' => $this->initial, 'type' => $this->type, 'list' => $this->list]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user