diff --git a/app/Filament/Resources/ClientResource.php b/app/Filament/Resources/ClientResource.php index 5e0b44d6..dee96260 100644 --- a/app/Filament/Resources/ClientResource.php +++ b/app/Filament/Resources/ClientResource.php @@ -6,6 +6,8 @@ use App\Filament\Resources\ClientResource\Pages; use App\Models\Client; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; @@ -26,7 +28,14 @@ public static function form(Form $form): Form { return $form ->schema([ - // + TextInput::make('name') + ->label('Name') + ->required(), + Select::make('organization_id') + ->relationship(name: 'organization', titleAttribute: 'name') + ->label('Organization') + ->searchable(['name']) + ->required(), ]); } diff --git a/app/Filament/Resources/OrganizationResource.php b/app/Filament/Resources/OrganizationResource.php index eb2a9e0d..080a5993 100644 --- a/app/Filament/Resources/OrganizationResource.php +++ b/app/Filament/Resources/OrganizationResource.php @@ -5,6 +5,7 @@ namespace App\Filament\Resources; use App\Filament\Resources\OrganizationResource\Pages; +use App\Filament\Resources\OrganizationResource\RelationManagers\UsersRelationManager; use App\Models\Organization; use App\Service\Import\Importers\ImporterProvider; use App\Service\Import\Importers\ImportException; @@ -71,10 +72,13 @@ public static function table(Table $table): Table Action::make('Import') ->icon('heroicon-o-inbox-arrow-down') ->action(function (Organization $record, array $data) { - // TODO: different disk! try { /** @var ReportDto $report */ - $report = app(ImportService::class)->import($record, $data['type'], Storage::disk('public')->get($data['file'])); + $report = app(ImportService::class)->import( + $record, + $data['type'], + Storage::disk(config('filament.default_filesystem_disk'))->get($data['file']) + ); Notification::make() ->title('Import successful') ->success() @@ -101,7 +105,6 @@ public static function table(Table $table): Table ->tooltip(fn (Organization $record): string => 'Import into '.$record->name) ->form([ Forms\Components\FileUpload::make('file') - // TODO: disk! ->label('File') ->required(), Select::make('type') @@ -126,7 +129,7 @@ public static function table(Table $table): Table public static function getRelations(): array { return [ - // + UsersRelationManager::class, ]; } diff --git a/app/Filament/Resources/OrganizationResource/RelationManagers/UsersRelationManager.php b/app/Filament/Resources/OrganizationResource/RelationManagers/UsersRelationManager.php new file mode 100644 index 00000000..a923e49e --- /dev/null +++ b/app/Filament/Resources/OrganizationResource/RelationManagers/UsersRelationManager.php @@ -0,0 +1,51 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + ]); + } + + public function table(Table $table): Table + { + return $table + ->recordTitleAttribute('name') + ->columns([ + Tables\Columns\TextColumn::make('name'), + Tables\Columns\TextColumn::make('role'), + ]) + ->filters([ + // + ]) + ->headerActions([ + Tables\Actions\CreateAction::make(), + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index a5d3681b..c1568b10 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -5,12 +5,16 @@ namespace App\Filament\Resources; use App\Filament\Resources\UserResource\Pages; +use App\Filament\Resources\UserResource\RelationManagers\OrganizationsRelationManager; +use App\Filament\Resources\UserResource\RelationManagers\OwnedOrganizationsRelationManager; use App\Models\User; use Filament\Forms; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Support\Facades\Hash; class UserResource extends Resource { @@ -41,10 +45,11 @@ public static function form(Form $form): Form ->label('Email') ->required() ->maxLength(255), - Forms\Components\TextInput::make('password') - ->label('Password') - ->required() + TextInput::make('password') ->password() + ->dehydrateStateUsing(fn ($state) => Hash::make($state)) + ->dehydrated(fn ($state) => filled($state)) + ->required(fn (string $context): bool => $context === 'create') ->maxLength(255), ]); } @@ -77,7 +82,8 @@ public static function table(Table $table): Table public static function getRelations(): array { return [ - // + OwnedOrganizationsRelationManager::class, + OrganizationsRelationManager::class, ]; } diff --git a/app/Filament/Resources/UserResource/Pages/CreateUser.php b/app/Filament/Resources/UserResource/Pages/CreateUser.php index 72b81bb0..b5cac367 100644 --- a/app/Filament/Resources/UserResource/Pages/CreateUser.php +++ b/app/Filament/Resources/UserResource/Pages/CreateUser.php @@ -5,9 +5,23 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; +use App\Models\Organization; +use App\Models\User; use Filament\Resources\Pages\CreateRecord; class CreateUser extends CreateRecord { protected static string $resource = UserResource::class; + + protected function afterCreate(): void + { + /** @var User $user */ + $user = $this->record; + + $user->ownedTeams()->save(Organization::forceCreate([ + 'user_id' => $user->id, + 'name' => explode(' ', $user->name, 2)[0]."'s Organization", + 'personal_team' => true, + ])); + } } diff --git a/app/Filament/Resources/UserResource/RelationManagers/OrganizationsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/OrganizationsRelationManager.php new file mode 100644 index 00000000..ac67f248 --- /dev/null +++ b/app/Filament/Resources/UserResource/RelationManagers/OrganizationsRelationManager.php @@ -0,0 +1,50 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + ]); + } + + public function table(Table $table): Table + { + return $table + ->recordTitleAttribute('name') + ->columns([ + Tables\Columns\TextColumn::make('name'), + ]) + ->filters([ + // + ]) + ->headerActions([ + Tables\Actions\CreateAction::make(), + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Filament/Resources/UserResource/RelationManagers/OwnedOrganizationsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/OwnedOrganizationsRelationManager.php new file mode 100644 index 00000000..7630ec26 --- /dev/null +++ b/app/Filament/Resources/UserResource/RelationManagers/OwnedOrganizationsRelationManager.php @@ -0,0 +1,47 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + ]); + } + + public function table(Table $table): Table + { + return $table + ->recordTitleAttribute('name') + ->columns([ + Tables\Columns\TextColumn::make('name'), + ]) + ->filters([ + // + ]) + ->headerActions([ + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + ]); + } +}