95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Mail\Modal;
|
|
|
|
use App\Models\MailAlias;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class AliasDeleteModal extends ModalComponent
|
|
{
|
|
|
|
public MailAlias $alias;
|
|
|
|
// Anzeige / Bestätigung
|
|
public string $aliasEmail = '';
|
|
public string $confirm = '';
|
|
public bool $confirmMatches = false; // <-- reaktiv, kein computed
|
|
|
|
// Meta
|
|
public string $targetLabel = '';
|
|
public int $recipientCount = 0;
|
|
public int $extraRecipients = 0;
|
|
public bool $isSingle = false;
|
|
|
|
public function mount(int $aliasId): void
|
|
{
|
|
$this->alias = MailAlias::with(['domain', 'recipients.mailUser'])->findOrFail($aliasId);
|
|
|
|
$this->aliasEmail = $this->alias->local . '@' . $this->alias->domain->domain;
|
|
$this->recipientCount = $this->alias->recipients->count();
|
|
$this->isSingle = ($this->alias->type ?? 'single') === 'single';
|
|
|
|
if ($this->isSingle && $this->recipientCount === 1) {
|
|
$r = $this->alias->recipients->first();
|
|
$this->targetLabel = $r->mailUser
|
|
? $r->mailUser->localpart . '@' . $this->alias->domain->domain
|
|
: (string) $r->email;
|
|
} else {
|
|
$group = trim((string) ($this->alias->group_name ?? 'Gruppe'));
|
|
$this->targetLabel = $group . ' (' . $this->recipientCount . ')';
|
|
}
|
|
|
|
$this->extraRecipients = max(0, $this->recipientCount - 3);
|
|
|
|
// initialer Vergleich (falls Autocomplete o.ä.)
|
|
$this->recomputeConfirmMatch();
|
|
}
|
|
|
|
public function updatedConfirm(): void
|
|
{
|
|
$this->resetErrorBag('confirm');
|
|
$this->recomputeConfirmMatch();
|
|
}
|
|
|
|
private function recomputeConfirmMatch(): void
|
|
{
|
|
$this->confirmMatches =
|
|
mb_strtolower(trim($this->confirm)) === mb_strtolower($this->aliasEmail);
|
|
}
|
|
|
|
#[On('alias:delete')]
|
|
public function delete(): void
|
|
{
|
|
if (! $this->confirmMatches) {
|
|
$this->dispatch('toast', [
|
|
'type' => 'warn',
|
|
'badge' => 'Alias',
|
|
'title' => 'Eingabe erforderlich',
|
|
'text' => 'Bitte gib die Alias-Adresse korrekt ein, um den Löschvorgang zu bestätigen.',
|
|
'duration' => 6000,
|
|
]);
|
|
return;
|
|
}
|
|
|
|
$email = $this->aliasEmail;
|
|
$this->alias->delete();
|
|
|
|
$this->dispatch('alias:deleted');
|
|
$this->dispatch('closeModal');
|
|
$this->dispatch('toast',
|
|
type: 'done',
|
|
badge: 'Alias',
|
|
title: 'Alias gelöscht',
|
|
text: 'Der Alias <b>' . e($email) . '</b> wurde entfernt.',
|
|
duration: 6000
|
|
);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.mail.modal.alias-delete-modal');
|
|
}
|
|
}
|