fix: allow invitations via email

This commit is contained in:
Andras Bacsai
2024-05-31 11:03:43 +02:00
parent 0ddd5f0a79
commit ca934e7cdf
2 changed files with 20 additions and 11 deletions

View File

@@ -17,6 +17,10 @@ class InviteLink extends Component
public string $email; public string $email;
public string $role = 'member'; public string $role = 'member';
protected $rules = [
'email' => 'required|email',
'role' => 'required|string',
];
public function mount() public function mount()
{ {
$this->email = isDev() ? 'test3@example.com' : ''; $this->email = isDev() ? 'test3@example.com' : '';
@@ -34,6 +38,7 @@ class InviteLink extends Component
private function generate_invite_link(bool $sendEmail = false) private function generate_invite_link(bool $sendEmail = false)
{ {
try { try {
$this->validate();
$member_emails = currentTeam()->members()->get()->pluck('email'); $member_emails = currentTeam()->members()->get()->pluck('email');
if ($member_emails->contains($this->email)) { if ($member_emails->contains($this->email)) {
return handleError(livewire: $this, customErrorMessage: "$this->email is already a member of " . currentTeam()->name . "."); return handleError(livewire: $this, customErrorMessage: "$this->email is already a member of " . currentTeam()->name . ".");

View File

@@ -1,14 +1,18 @@
<div> <div>
<form wire:submit='viaLink' class="flex flex-col gap-2 lg:items-center lg:flex-row"> <form wire:submit='viaLink' class="flex flex-col items-start gap-2 lg:items-end lg:flex-row">
<x-forms.input id="email" type="email" name="email" placeholder="Email" /> <div class="flex w-full gap-2">
<x-forms.select id="role" name="role"> <x-forms.input id="email" type="email" label="Email" name="email" placeholder="Email" required />
<x-forms.select id="role" name="role" label="Role">
<option value="owner">Owner</option> <option value="owner">Owner</option>
<option value="admin">Admin</option> <option value="admin">Admin</option>
<option value="member">Member</option> <option value="member">Member</option>
</x-forms.select> </x-forms.select>
</div>
<div class="flex gap-2">
<x-forms.button type="submit">Generate Invitation Link</x-forms.button> <x-forms.button type="submit">Generate Invitation Link</x-forms.button>
@if (is_transactional_emails_active()) @if (is_transactional_emails_active())
<x-forms.button wire:click.prevent='viaEmail'>Send Invitation Email</x-forms.button> <x-forms.button wire:click.prevent='viaEmail'>Send Invitation via Email</x-forms.button>
@endif @endif
</div>
</form> </form>
</div> </div>