52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Domains\Workspace\Models\WorkspaceInvitation;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\View\View;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class InviteMember extends ModalComponent
|
|
{
|
|
public string $email = '';
|
|
|
|
public string $role = 'editor';
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'email' => 'required|email|max:255',
|
|
'role' => 'required|in:admin,editor,viewer',
|
|
];
|
|
}
|
|
|
|
public function invite(): void
|
|
{
|
|
$this->validate();
|
|
$workspace = app('current_workspace');
|
|
|
|
WorkspaceInvitation::create([
|
|
'workspace_id' => $workspace->id,
|
|
'email' => strtolower($this->email),
|
|
'role' => $this->role,
|
|
'token' => Str::random(40),
|
|
'invited_by' => auth()->id(),
|
|
'expires_at' => now()->addDays(7),
|
|
]);
|
|
|
|
$this->dispatch('memberInvited');
|
|
$this->closeModal();
|
|
}
|
|
|
|
public static function modalMaxWidth(): string
|
|
{
|
|
return 'sm';
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.modals.invite-member');
|
|
}
|
|
}
|