Skip to content

Commit

Permalink
fix: volunteers relation managers
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Jun 17, 2024
1 parent 5c7ee5c commit f28fea5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,73 @@

namespace App\Filament\Resources\OrganizationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use App\Filament\Resources\VolunteerResource;
use App\Models\Project;
use App\Models\Volunteer;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;

class VolunteersRelationManager extends RelationManager
{
protected static string $relationship = 'volunteers';

protected static ?string $recordTitleAttribute = 'full_name';
protected static ?string $recordTitleAttribute = 'name';

public static function getTitle(): string
{
return __('volunteer.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('full_name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('full_name'),
TextColumn::make('id')
->formatStateUsing(function (Volunteer $record) {
return sprintf('#%d', $record->id);
})
->label(__('volunteer.column.id'))
->sortable(),

TextColumn::make('name')
->label(__('volunteer.column.name'))
->searchable(),

TextColumn::make('email')
->label(__('volunteer.column.email'))
->searchable(),

TextColumn::make('project')
->label(__('volunteer.column.project'))
->formatStateUsing(fn ($record) => $record->model_type === Project::class ? VolunteerResource::getResourceLink($record->pivot, 'project') : 'General')
->searchable(),

IconColumn::make('status')
->label(__('volunteer.column.status'))
->options([
'heroicon-o-clock' => 'pending',
'heroicon-o-check-circle' => 'approved',
'heroicon-o-x-circle' => 'rejected',
])->colors([
'warning' => 'pending',
'success' => 'approved',
'danger' => 'rejected',
]),

TextColumn::make('has_user')
->label(__('volunteer.column.has_user'))
->formatStateUsing(fn ($record) => VolunteerResource::getResourceLink($record->pivot, 'user')),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,67 @@

namespace App\Filament\Resources\ProjectResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use App\Filament\Resources\VolunteerResource;
use App\Models\Volunteer;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;

class VolunteersRelationManager extends RelationManager
{
protected static string $relationship = 'volunteers';

protected static ?string $recordTitleAttribute = 'full_name';
protected static ?string $recordTitleAttribute = 'name';

public static function getTitle(): string
{
return __('volunteer.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('full_name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('full_name'),
TextColumn::make('id')
->formatStateUsing(function (Volunteer $record) {
return sprintf('#%d', $record->id);
})
->label(__('volunteer.column.id'))
->sortable(),

TextColumn::make('name')
->label(__('volunteer.column.name'))
->searchable(),

TextColumn::make('email')
->label(__('volunteer.column.email'))
->searchable(),

IconColumn::make('status')
->label(__('volunteer.column.status'))
->options([
'heroicon-o-clock' => 'pending',
'heroicon-o-check-circle' => 'approved',
'heroicon-o-x-circle' => 'rejected',
])->colors([
'warning' => 'pending',
'success' => 'approved',
'danger' => 'rejected',
]),

TextColumn::make('has_user')
->label(__('volunteer.column.has_user'))
->formatStateUsing(fn ($record) => VolunteerResource::getResourceLink($record->pivot, 'user')),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace App\Filament\Resources\UserResource\RelationManagers;

use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;

class VolunteersRelationManager extends RelationManager
Expand All @@ -27,16 +24,6 @@ protected function getTableHeading(): string
return __('user.relations.heading.volunteers', ['count' => $this->getTableQuery()->count()]);
}

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('volunteer.name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
Expand Down Expand Up @@ -64,12 +51,10 @@ public static function table(Table $table): Table
//
])
->headerActions([
//
])
->actions([
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
//
]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/VolunteerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function getPages(): array
];
}

private static function getResourceLink(VolunteerRequest $record, string $type): HtmlString
public static function getResourceLink(VolunteerRequest $record, string $type): HtmlString
{
return match ($type) {
'project' => self::getProjectLink($record),
Expand Down
2 changes: 1 addition & 1 deletion lang/ro/volunteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'label' => [
'singular' => 'Voluntar',
'plural' => 'Voluntarii',
'plural' => 'Voluntari',
],

'column' => [
Expand Down

0 comments on commit f28fea5

Please sign in to comment.