2024-01-07 15:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Team;
|
|
|
|
|
|
|
|
use App\Models\Team;
|
|
|
|
use App\Models\TeamInvitation;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Index extends Component
|
|
|
|
{
|
|
|
|
public $invitations = [];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public Team $team;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
protected $rules = [
|
|
|
|
'team.name' => 'required|min:3|max:255',
|
|
|
|
'team.description' => 'nullable|min:3|max:255',
|
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'team.name' => 'name',
|
|
|
|
'team.description' => 'description',
|
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->team = currentTeam();
|
|
|
|
|
|
|
|
if (auth()->user()->isAdminFromSession()) {
|
|
|
|
$this->invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.team.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
try {
|
|
|
|
$this->team->save();
|
|
|
|
refreshSession();
|
2024-02-22 13:53:42 +00:00
|
|
|
$this->dispatch('success', 'Team updated.');
|
2024-01-07 15:23:41 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$currentTeam = currentTeam();
|
|
|
|
$currentTeam->delete();
|
|
|
|
|
|
|
|
$currentTeam->members->each(function ($user) use ($currentTeam) {
|
|
|
|
if ($user->id === auth()->user()->id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$user->teams()->detach($currentTeam);
|
|
|
|
$session = DB::table('sessions')->where('user_id', $user->id)->first();
|
|
|
|
if ($session) {
|
|
|
|
DB::table('sessions')->where('id', $session->id)->delete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
refreshSession();
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
return redirect()->route('team.index');
|
|
|
|
}
|
|
|
|
}
|