-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddMember.php
101 lines (85 loc) · 2.65 KB
/
AddMember.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace App\Livewire\Company;
use App\Mail\CustomCompanyInvitation;
use App\Models\Company;
use App\Models\Invitation;
use Illuminate\Support\Facades\Mail;
use Illuminate\View\View;
use Livewire\Attributes\Validate;
use Livewire\Component;
class AddMember extends Component
{
public Company $company;
public $roles;
#[Validate('required|in:speaker,booth owner,company member')]
public $currentRole;
#[Validate('required|unique:users')]
public string $email;
/**
* Called when initializing the component
* @param $company
* @return void
*/
public function mount($company)
{
$this->company = $company;
$this->roles = [
'speaker' => 'The user can request to give a presentation or become a co-speaker for another presentation
within the company.',
'booth owner' => 'The user can request a booth if one does not already exist and is expected to be present
at the booth during the conference.',
'company member' => 'The user can choose to be a speaker or a booth owner. If they do not take action to
become a speaker or booth owner, they will simply accompany the other members.'
];
}
/**
* Handles the selecting of a new role
*
* @param $role
* @return void
*/
public function selectRole($role)
{
$this->currentRole = $role;
}
/**
* Invite a new team member to the given team.
*/
public function invite(): void
{
$this->validate();
if ($this->currentRole == 'speaker') {
$this->currentRole = 'pending speaker';
} elseif ($this->currentRole == 'booth owner') {
$this->currentRole = 'pending booth owner';
}
$invitation = $this->company->invitations()->create([
'email' => $this->email,
'role' => $this->currentRole
]);
Mail::to($this->email)->send(new CustomCompanyInvitation($invitation));
$this->email = '';
$this->currentRole = '';
$this->company = $this->company->refresh();
session()->flash('message', 'Post successfully updated.');
}
/**
* Cancels the company invitation that was sent
* @param $invitation_id
* @return void
*/
public function cancelInvitation($invitation_id)
{
$invitation = Invitation::find($invitation_id);
$invitation->delete();
$this->company = $this->company->refresh();
}
/**
* Renders the component
* @return View
*/
public function render(): View
{
return view('livewire.company.add-member');
}
}