2023-03-24 13:54:17 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire;
|
2023-03-24 13:54:17 +00:00
|
|
|
|
|
|
|
use App\Models\Team;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class SwitchTeam extends Component
|
|
|
|
{
|
2023-06-02 10:34:45 +00:00
|
|
|
public string $selectedTeamId = 'default';
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2024-03-21 13:30:35 +00:00
|
|
|
$this->selectedTeamId = auth()->user()->currentTeam()->id;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-02 10:34:45 +00:00
|
|
|
public function updatedSelectedTeamId()
|
|
|
|
{
|
|
|
|
$this->switch_to($this->selectedTeamId);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-03-24 13:54:17 +00:00
|
|
|
public function switch_to($team_id)
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! auth()->user()->teams->contains($team_id)) {
|
2023-03-24 13:54:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$team_to_switch_to = Team::find($team_id);
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $team_to_switch_to) {
|
2023-03-24 13:54:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-09-08 16:33:26 +00:00
|
|
|
refreshSession($team_to_switch_to);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-03-24 13:54:17 +00:00
|
|
|
return redirect(request()->header('Referer'));
|
|
|
|
}
|
|
|
|
}
|