Skip to content

Commit

Permalink
Merge pull request #244 from pelican-dev/charles/fix-newuser
Browse files Browse the repository at this point in the history
fix: Creating User
  • Loading branch information
notAreYouScared authored May 18, 2024
2 parents 68dbd6e + 9b2e00e commit 89d555f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 73 deletions.
1 change: 0 additions & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
Expand Down
69 changes: 0 additions & 69 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php

This file was deleted.

48 changes: 46 additions & 2 deletions app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use App\Filament\Resources\UserResource;
use App\Models\User;
use App\Services\Users\UserCreationService;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Table;
use Filament\Tables;
use Filament\Forms;

class ListUsers extends ListRecords
{
Expand Down Expand Up @@ -73,8 +76,49 @@ public function table(Table $table): Table
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->label('Create User'),
Actions\CreateAction::make('create')
->label('Create User')
->createAnother(false)
->form([
Forms\Components\Grid::make()
->schema([
Forms\Components\TextInput::make('username')
->alphaNum()
->required()
->maxLength(191),
Forms\Components\TextInput::make('email')
->email()
->required()
->unique()
->maxLength(191),

Forms\Components\TextInput::make('password')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Providing a user password is optional. New user email will prompt users to create a password the first time they login.')
->password(),

Forms\Components\ToggleButtons::make('root_admin')
->label('Administrator (Root)')
->options([
false => 'No',
true => 'Admin',
])
->colors([
false => 'primary',
true => 'danger',
])
->inline()
->required()
->default(false),
]),
])
->successRedirectUrl(route('filament.admin.resources.users.index'))
->action(function (array $data) {
resolve(UserCreationService::class)->handle($data);
Notification::make()->title('User Created!')->success()->send();

return redirect()->route('filament.admin.resources.users.index');
}),
];
}
}
Loading

0 comments on commit 89d555f

Please sign in to comment.