To address the issue where users cannot cancel team invitations after downgrading from a premium subscription, you need to modify the cancelTeamInvitation method to bypass the subscription check. This can be done by customizing the TeamMemberManager Livewire component.
Here's a step-by-step solution:
-
Create a Custom Action for Cancelling Invitations: Create a new action class that handles the cancellation of team invitations without checking the subscription status.
namespace App\Actions\Jetstream; use Laravel\Jetstream\Contracts\DeletesTeamInvitations; class CancelTeamInvitation implements DeletesTeamInvitations { /** * Cancel the given team invitation. * * @param mixed $invitation * @return void */ public function delete($invitation) { $invitation->delete(); } } -
Register the Custom Action: Register your custom action in the
JetstreamServiceProvider.namespace App\Providers; use App\Actions\Jetstream\CancelTeamInvitation; use Illuminate\Support\ServiceProvider; use Laravel\Jetstream\Jetstream; class JetstreamServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { $this->configurePermissions(); Jetstream::deleteTeamInvitationsUsing(CancelTeamInvitation::class); } /** * Configure the permissions that are available within the application. * * @return void */ protected function configurePermissions() { Jetstream::defaultApiTokenPermissions(['read']); Jetstream::permissions([ 'create', 'read', 'update', 'delete', ]); } } -
Modify the
TeamMemberManagerComponent: Update theTeamMemberManagerLivewire component to use the new action for cancelling invitations.namespace App\Http\Livewire; use Livewire\Component; use Laravel\Jetstream\Jetstream; use Laravel\Jetstream\Contracts\DeletesTeamInvitations; class TeamMemberManager extends Component { // Other methods... /** * Cancel a team invitation. * * @param int $invitationId * @return void */ public function cancelTeamInvitation($invitationId) { $invitation = Jetstream::findTeamInvitationOrFail($invitationId); app(DeletesTeamInvitations::class)->delete($invitation); $this->team = $this->team->fresh(); $this->emit('saved'); } }
By following these steps, you ensure that the cancelTeamInvitation method does not check the subscription status, allowing users to cancel invitations even if they are not on a premium plan. This approach keeps the logic for sending invitations and cancelling invitations separate, adhering to the single responsibility principle.