Refactor deleteInvitation method in Invitations component
This commit is contained in:
		| @@ -13,17 +13,18 @@ class Invitations extends Component | |||||||
| 
 | 
 | ||||||
|     public function deleteInvitation(int $invitation_id) |     public function deleteInvitation(int $invitation_id) | ||||||
|     { |     { | ||||||
|         $initiation_found = TeamInvitation::find($invitation_id); |         try { | ||||||
|         if (! $initiation_found) { |             $initiation_found = TeamInvitation::ownedByCurrentTeam()->findOrFail($invitation_id); | ||||||
|             return $this->dispatch('error', 'Invitation not found.'); |  | ||||||
|         } |  | ||||||
|             $initiation_found->delete(); |             $initiation_found->delete(); | ||||||
|             $this->refreshInvitations(); |             $this->refreshInvitations(); | ||||||
|             $this->dispatch('success', 'Invitation revoked.'); |             $this->dispatch('success', 'Invitation revoked.'); | ||||||
|  |         } catch (\Exception $e) { | ||||||
|  |             return $this->dispatch('error', 'Invitation not found.'); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function refreshInvitations() |     public function refreshInvitations() | ||||||
|     { |     { | ||||||
|         $this->invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get(); |         $this->invitations = TeamInvitation::ownedByCurrentTeam()->get(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,6 +20,11 @@ class TeamInvitation extends Model | |||||||
|         return $this->belongsTo(Team::class); |         return $this->belongsTo(Team::class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public static function ownedByCurrentTeam() | ||||||
|  |     { | ||||||
|  |         return TeamInvitation::whereTeamId(currentTeam()->id); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function isValid() |     public function isValid() | ||||||
|     { |     { | ||||||
|         $createdAt = $this->created_at; |         $createdAt = $this->created_at; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andras Bacsai
					Andras Bacsai