Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release #16

Merged
merged 9 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected].0
uses: aglipanci/[email protected].1

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ You can install the package via composer:
composer require concept7/filament-invite
```

Register the plugin in your panel provider:
```php
use Concept7\FilamentInvite\InvitePlugin;

public function panel(Panel $panel): Panel
{
return $panel
->plugin(new InvitePlugin());
}
```

You can publish and run the migrations with:

```bash
Expand All @@ -38,6 +49,67 @@ php artisan vendor:publish --tag="filament-invite-views"
use Concept7\FilamentInvite\Models\Traits\Invitable;
```

### Create a mailable

In app/Mail, create SendInviteMail.php, e.g.

```
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use App\Models\User;
use Concept7\FilamentInvite\Contracts\SendInviteMail as SendInviteMailContract;

class SendInviteMail extends Mailable implements SendInviteMailContract
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
/**
* Create a new message instance.
*/
public function __construct(
private User $user,
private $url
) {
//
}

/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
to: $this->user->email,
subject: 'You are invited to join ' . config('app.name'),
);
}

/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'filament-invite::mail.invite',
with: [
'user' => $this->user,
'link' => $this->url,
]
);
}
}
```

### Event listener
If for some reason you need to listen to the InviteAccepted Event, you can register a listener handling a InviteProcessedEvent.
Register the listener in your EventServiceProvider.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"filament/filament": "^3.0",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/validation": "^10.0|^11.0",
"spatie/laravel-package-tools": "^1.13.5"
"spatie/laravel-package-tools": "^1.16"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
3 changes: 2 additions & 1 deletion config/filament-invite.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

// config for Concept7/FilamentInvite
return [
'expiration_time_in_hours' => '24',
'accept_route' => 'filament.admin.accept-invite',
'after_login_redirect_route' => 'filament.admin.pages.dashboard',
];
26 changes: 17 additions & 9 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php

use Concept7\FilamentInvite\Http\Livewire\Accept;
use Filament\Facades\Filament;

Route::domain(config('filament.domain'))
->middleware(config('filament.middleware.base'))
->prefix(config('filament.path'))
->name('filament.auth.')
->group(function () {
Route::get('invite/accept/{acceptId}/{hash}', Accept::class)
// ->middleware('signed')
->name('accept-invite');
});
Route::name('filament.')->group(function () {
foreach (Filament::getPanels() as $panel) {
$domains = $panel->getDomains();

foreach ((empty($domains) ? [null] : $domains) as $domain) {
Route::domain($domain)
->middleware($panel->getMiddleware())
->name($panel->getId().'.')
->prefix($panel->getPath())
->group(function () {
Route::get('invite/accept', Accept::class)
->name('accept-invite');
});
}
}
});
58 changes: 9 additions & 49 deletions src/FilamentInviteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,19 @@
namespace Concept7\FilamentInvite;

use Concept7\FilamentInvite\Http\Livewire\Accept;
use Filament\Facades\Filament;
use Filament\Panel;
use Livewire\Livewire;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class FilamentInviteServiceProvider extends PackageServiceProvider
{
public static string $name = 'filament-invite';

protected array $resources = [
// CustomResource::class,
];

protected array $pages = [
// CustomPage::class,
];

protected array $widgets = [
// CustomWidget::class,
];

protected array $styles = [
// 'plugin-filament-invite' => __DIR__.'/../resources/dist/filament-invite.css',
];

protected array $scripts = [
// 'plugin-filament-invite' => __DIR__.'/../resources/dist/filament-invite.js',
];

// protected array $beforeCoreScripts = [
// 'plugin-filament-invite' => __DIR__ . '/../resources/dist/filament-invite.js',
// ];

public function register(): void
{
parent::register();

Filament::registerPanel(
$this->panel(Panel::make()),
);
}

public function packageBooted(): void
{
Livewire::component('concept7.'.static::$name.'.pages.accept', Accept::class);
parent::packageBooted();

Livewire::component('accept', Accept::class);
}

public function configurePackage(Package $package): void
Expand All @@ -59,18 +24,13 @@ public function configurePackage(Package $package): void
->name(static::$name)
->hasConfigFile()
->hasViews()
// ->hasRoute('web')
->hasRoute('web')
->hasMigration('2023_05_19_083051_create_invites_table')
->runsMigrations();
}

public function panel(Panel $panel): Panel
{
return $panel
->id('invite')
->path('invite')
->pages([
Accept::class,
]);
->runsMigrations()
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishMigrations()
->copyAndRegisterServiceProviderInApp();
});
}
}
2 changes: 1 addition & 1 deletion src/Http/Livewire/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
}
$this->acceptId = $acceptId ?? request()->query('acceptId');
$this->hash = $hash ?? request()->query('hash');
$this->expired = ! Invite::query()

Check failure on line 59 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'expires_at' does not exist in Concept7\FilamentInvite\Models\Invite model.

Check failure on line 59 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'token' does not exist in Concept7\FilamentInvite\Models\Invite model.
->where('id', $this->acceptId)
->where('token', $this->hash)
->where('expires_at', '>=', now())
->exists();

$this->form->fill();

Check failure on line 65 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Concept7\FilamentInvite\Http\Livewire\Accept::$form.
}

/**
Expand Down Expand Up @@ -94,16 +94,16 @@
]);
}

$data = $this->form->getState();

Check failure on line 97 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Concept7\FilamentInvite\Http\Livewire\Accept::$form.

$invite = Invite::query()

Check failure on line 99 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'email' does not exist in Concept7\FilamentInvite\Models\Invite model.

Check failure on line 99 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'expires_at' does not exist in Concept7\FilamentInvite\Models\Invite model.

Check failure on line 99 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'token' does not exist in Concept7\FilamentInvite\Models\Invite model.
->where('id', $this->acceptId)
->where('token', $this->hash)
->where('email', $data['email'])
->where('expires_at', '>=', now())
->firstOrFail();

$user = User::where('email', $data['email'])->first();

Check failure on line 106 in src/Http/Livewire/Accept.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to static method where() on an unknown class App\Models\User.

$user->update([
'password' => $data['password'],
Expand All @@ -126,7 +126,7 @@
return route('filament.auth.login');
}

return redirect()->intended(route('filament.admin.pages.dashboard'));
return redirect()->intended(route(config('filament-invite.after_login_redirect_route')));

}

Expand Down
34 changes: 34 additions & 0 deletions src/InvitePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Concept7\FilamentInvite;

use Filament\Contracts\Plugin;
use Filament\Panel;

class InvitePlugin implements Plugin
{
public function getId(): string
{
return 'filament-invite';
}

public function register(Panel $panel): void
{

}

public function boot(Panel $panel): void
{

}

public static function make(): static
{
return app(static::class);
}

public static function get(): static
{
return filament(app(static::class)->getId());
}
}
2 changes: 1 addition & 1 deletion src/Notifications/SendInviteNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function toMail(object $notifiable): SendInviteMail

public function getLink(): string
{
return route('filament.invite.pages.accept', [
return route(config('filament-invite.accept_route'), [
'acceptId' => $this->invite->id,
'hash' => $this->invite->token,
]);
Expand Down
Loading