Skip to content

Commit

Permalink
fix layout on organization page
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Aug 4, 2023
1 parent 42e3c07 commit 6032e78
Show file tree
Hide file tree
Showing 25 changed files with 671 additions and 189 deletions.
4 changes: 2 additions & 2 deletions app/Enums/OrganizationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ enum OrganizationStatus: string
{
use ArrayableEnum;
case pending = 'pending';
case active = 'active';
case disabled = 'disabled';
case approved = 'active';
case rejected = 'disabled';

protected function translationKeyPrefix(): ?string
{
Expand Down
30 changes: 27 additions & 3 deletions app/Filament/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

use App\Enums\OrganizationStatus;
use App\Filament\Resources\OrganizationResource\Pages;
use App\Filament\Resources\OrganizationResource\Widgets\ApprovedOrganizationWidget;
use App\Filament\Resources\OrganizationResource\Widgets\NewOrganizationWidget;
use App\Models\Organization;
use App\Tables\Columns\OrganizationNameColumn;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Layout;
use Filament\Tables\Filters\SelectFilter;

Expand Down Expand Up @@ -89,9 +93,9 @@ public static function table(Table $table): Table
->columns([
Tables\Columns\IconColumn::make('status')->options([
'heroicon-o-x-circle',
'heroicon-o-pencil' => OrganizationStatus::disabled->value,
'heroicon-o-pencil' => OrganizationStatus::rejected->value,
'heroicon-o-clock' => OrganizationStatus::pending->value,
'heroicon-o-check-circle' => OrganizationStatus::active->value,
'heroicon-o-check-circle' => OrganizationStatus::approved->value,
]),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('created_at')
Expand Down Expand Up @@ -131,12 +135,32 @@ public static function getRelations(): array
];
}

public static function getWidgets(): array
{
return [
NewOrganizationWidget::class,
ApprovedOrganizationWidget::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListOrganizations::route('/'),
'index' => Pages\OrganisationIndex::route('/'),
'create' => Pages\CreateOrganization::route('/create'),
'edit' => Pages\EditOrganization::route('/{record}/edit'),
];
}

public static function getWidgetColumns()
{
return [
OrganizationNameColumn::make('organisation_info')->label(__('organization.organization')),

TextColumn::make('created_at')
->label(__('field.created_at'))
->sortable(),

];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ protected function getActions(): array
Actions\DeleteAction::make(),
Action::make('Approve')
->action(function () {
$this->record->status = OrganizationStatus::active->value;
$this->record->status = OrganizationStatus::approved->value;
$this->record->save();
})
->requiresConfirmation()->hidden(fn () => $this->record->status == OrganizationStatus::active->value),
->requiresConfirmation()->hidden(fn () => $this->record->status == OrganizationStatus::approved->value),
Action::make('Reject')
->action(function () {
$this->record->status = OrganizationStatus::disabled->value;
$this->record->status = OrganizationStatus::rejected->value;
$this->record->save();
})
->requiresConfirmation()->hidden(fn () => $this->record->status == OrganizationStatus::disabled->value),
->requiresConfirmation()->hidden(fn () => $this->record->status == OrganizationStatus::rejected->value),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ class ListOrganizations extends ListRecords
{
protected static string $resource = OrganizationResource::class;

protected static ?string $title = '';

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}

protected function getHeaderWidgets(): array
{
return [
OrganizationResource\Widgets\NewOrganizationWidget::class,

];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Pages;

use App\Filament\Resources\OrganizationResource;
use Filament\Resources\Pages\Page;

class OrganisationIndex extends Page
{
protected static string $resource = OrganizationResource::class;

protected static string $view = 'filament.resources.organization-resource.pages.organisation-index';

protected static ?string $title = '';

protected function getHeaderWidgets(): array
{
return [
OrganizationResource\Widgets\NewOrganizationWidget::class,
OrganizationResource\Widgets\ApprovedOrganizationWidget::class,
OrganizationResource\Widgets\RejectedOrganizationWidget::class,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Widgets;

use App\Enums\OrganizationStatus;
use App\Filament\Resources\OrganizationResource;
use App\Models\Organization;
use Filament\Tables\Actions\Action;
use Filament\Tables\Concerns\CanPaginateRecords;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class ApprovedOrganizationWidget extends BaseWidget
{
use CanPaginateRecords {
paginateTableQuery as protected;
}

/** @var string */
protected static string $resource = OrganizationResource::class;

protected static ?int $sort = 1;

protected int|string|array $columnSpan = [
'lg' => 2,
];

protected static ?string $recordTitleAttribute = 'title';

public static function canView(): bool
{
return true;
}

protected function getTableHeading(): string
{
return __('organization.heading.approved');
}

protected function getTableQuery(): Builder
{
return Organization::isApproved();
}

protected function getTableQueryStringIdentifier(): ?string
{
return 'approved_organization';
}

protected function getDefaultTableSortColumn(): ?string
{
return 'id';
}

protected function getDefaultTableSortDirection(): ?string
{
return 'desc';
}

protected function getTableColumns(): array
{
return self::$resource::getWidgetColumns();
}

protected function getTableFilters(): array
{
return [

];
}

protected function getTableRecordUrlUsing(): \Closure
{
return fn (Organization $record) => OrganizationResource::getUrl('edit', [
'record' => $record,
]);
}

protected function getTableActions(): array
{
return [
Action::make('view')
->label(__('organization.actions.edit'))
->url(self::getTableRecordUrlUsing())
->size('sm')
->icon(null),
Action::make('reject')
->label(__('organization.actions.reject'))
->action(fn (Organization $record) => $record->status = OrganizationStatus::rejected->value)
->size('sm')
->icon(null), ];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Widgets;

use App\Enums\OrganizationStatus;
use App\Filament\Resources\OrganizationResource;
use App\Models\Organization;
use Filament\Tables\Actions\Action;
use Filament\Tables\Concerns\CanPaginateRecords;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class NewOrganizationWidget extends BaseWidget
{
use CanPaginateRecords {
paginateTableQuery as protected;
}

protected static ?int $sort = 1;

/** @var string */
protected static string $resource = OrganizationResource::class;

protected int|string|array $columnSpan = [
'lg' => 2,
];

protected static ?string $recordTitleAttribute = 'title';

public static function canView(): bool
{
return true;
}

protected function getTableHeading(): string
{
return __('organization.heading.in_approval');
}

protected function getTableQuery(): Builder
{
return Organization::query()->isPending();
}

protected function getTableQueryStringIdentifier(): ?string
{
return 'new_organization';
}

protected function getDefaultTableSortColumn(): ?string
{
return 'id';
}

protected function getDefaultTableSortDirection(): ?string
{
return 'desc';
}

protected function getTableColumns(): array
{
return self::$resource::getWidgetColumns();
}

protected function getTableFilters(): array
{
return [

];
}

protected function getTableRecordUrlUsing(): \Closure
{
return fn (Organization $record) => OrganizationResource::getUrl('edit', [
'record' => $record,
]);
}

protected function getTableActions(): array
{
return [
Action::make('edit')
->label(__('organization.actions.edit'))
->url(self::getTableRecordUrlUsing())
->size('sm')
->icon(null),
Action::make('accept')
->label(__('organization.actions.approve'))
->size('sm')
->icon(null)
->action(fn (Organization $record) => $record->status = OrganizationStatus::approved->value)
->requiresConfirmation(),
Action::make('reject')
->label(__('organization.actions.reject'))
->action(fn (Organization $record) => $record->status = OrganizationStatus::rejected->value)
->size('sm')
->icon(null),
];
}
}
Loading

0 comments on commit 6032e78

Please sign in to comment.