2023-06-12 10:00:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Team;
|
2023-06-12 10:00:01 +00:00
|
|
|
|
|
|
|
|
use App\Models\TeamInvitation;
|
2025-06-25 09:45:55 +00:00
|
|
|
use App\Models\User;
|
2023-06-12 10:00:01 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Invitations extends Component
|
|
|
|
|
{
|
|
|
|
|
public $invitations;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-12 10:00:01 +00:00
|
|
|
protected $listeners = ['refreshInvitations'];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-12 10:00:01 +00:00
|
|
|
public function deleteInvitation(int $invitation_id)
|
|
|
|
|
{
|
2024-10-24 11:44:38 +00:00
|
|
|
try {
|
2025-06-25 09:45:55 +00:00
|
|
|
$invitation = TeamInvitation::ownedByCurrentTeam()->findOrFail($invitation_id);
|
2025-06-25 10:14:35 +00:00
|
|
|
$user = User::whereEmail($invitation->email)->first();
|
|
|
|
|
if (filled($user)) {
|
|
|
|
|
$user->deleteIfNotVerifiedAndForcePasswordReset();
|
2025-06-25 09:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$invitation->delete();
|
2024-10-24 11:44:38 +00:00
|
|
|
$this->refreshInvitations();
|
|
|
|
|
$this->dispatch('success', 'Invitation revoked.');
|
2024-10-31 14:19:37 +00:00
|
|
|
} catch (\Exception) {
|
2024-01-31 13:19:45 +00:00
|
|
|
return $this->dispatch('error', 'Invitation not found.');
|
|
|
|
|
}
|
2023-06-12 10:00:01 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
|
public function refreshInvitations()
|
|
|
|
|
{
|
2024-10-24 11:44:38 +00:00
|
|
|
$this->invitations = TeamInvitation::ownedByCurrentTeam()->get();
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|
2023-06-12 10:00:01 +00:00
|
|
|
}
|