From b328c5403eba1d4618d6ab47fae388a6929e7890 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe <46172059+gheorghelupu17@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:43:56 +0300 Subject: [PATCH] 254 admin bb organizatii organizatii active cannot deactivate an organization from preview table (#270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * clean up * clean up data loading * wip --------- Co-authored-by: Andrei Ioniță --- .../Resources/OrganizationResource.php | 2 + .../Actions/ApproveAction.php | 25 ++++++++++ .../Actions/RejectAction.php | 25 ++++++++++ .../Pages/ViewOrganization.php | 13 ++++++ .../Widgets/ApprovedOrganizationWidget.php | 31 ++++++------- .../Widgets/NewOrganizationWidget.php | 46 +++++++------------ .../Widgets/RejectedOrganizationWidget.php | 31 ++++++------- .../Controllers/OrganizationController.php | 30 ++---------- app/Models/Organization.php | 2 - lang/ro/organization.php | 11 ++++- 10 files changed, 120 insertions(+), 96 deletions(-) create mode 100644 app/Filament/Resources/OrganizationResource/Actions/ApproveAction.php create mode 100644 app/Filament/Resources/OrganizationResource/Actions/RejectAction.php create mode 100644 app/Filament/Resources/OrganizationResource/Pages/ViewOrganization.php diff --git a/app/Filament/Resources/OrganizationResource.php b/app/Filament/Resources/OrganizationResource.php index 1cd8c13b..8d8c3c5c 100644 --- a/app/Filament/Resources/OrganizationResource.php +++ b/app/Filament/Resources/OrganizationResource.php @@ -214,6 +214,8 @@ public static function getPages(): array 'index' => Pages\OrganisationIndex::route('/'), 'create' => Pages\CreateOrganization::route('/create'), 'edit' => Pages\EditOrganization::route('/{record}/edit'), + 'view' => Pages\ViewOrganization::route('/{record}'), + ]; } diff --git a/app/Filament/Resources/OrganizationResource/Actions/ApproveAction.php b/app/Filament/Resources/OrganizationResource/Actions/ApproveAction.php new file mode 100644 index 00000000..e4633946 --- /dev/null +++ b/app/Filament/Resources/OrganizationResource/Actions/ApproveAction.php @@ -0,0 +1,25 @@ +label(__('organization.actions.approve')); + $this->requiresConfirmation(); + $this->modalHeading(__('organization.actions.approve')); + $this->modalButton(__('organization.actions.approve')); + $this->action(function (Organization $record) { + $record->update(['status' => OrganizationStatus::approved]); + }); + } +} diff --git a/app/Filament/Resources/OrganizationResource/Actions/RejectAction.php b/app/Filament/Resources/OrganizationResource/Actions/RejectAction.php new file mode 100644 index 00000000..72b330e6 --- /dev/null +++ b/app/Filament/Resources/OrganizationResource/Actions/RejectAction.php @@ -0,0 +1,25 @@ +label(__('organization.actions.reject')); + $this->requiresConfirmation(); + $this->modalHeading(__('organization.actions.reject')); + $this->modalButton(__('organization.actions.reject')); + $this->action(function (Organization $record) { + $record->update(['status' => OrganizationStatus::rejected]); + }); + } +} diff --git a/app/Filament/Resources/OrganizationResource/Pages/ViewOrganization.php b/app/Filament/Resources/OrganizationResource/Pages/ViewOrganization.php new file mode 100644 index 00000000..3d823b88 --- /dev/null +++ b/app/Filament/Resources/OrganizationResource/Pages/ViewOrganization.php @@ -0,0 +1,13 @@ +with(['media']) + ->select(['id', 'name', 'created_at', 'status']); } protected function getTableQueryStringIdentifier(): ?string @@ -73,23 +70,23 @@ protected function getTableFilters(): array protected function getTableRecordUrlUsing(): \Closure { - return fn (Organization $record) => OrganizationResource::getUrl('edit', [ - 'record' => $record, - ]); + return fn (Organization $record) => OrganizationResource::getUrl('view', $record); } protected function getTableActions(): array { return [ Action::make('view') + ->label(__('organization.actions.view')) + ->url($this->getTableRecordUrlUsing()) + ->icon(null), + + Action::make('edit') ->label(__('organization.actions.edit')) - ->url(self::getTableRecordUrlUsing()) - ->size('sm') + ->url(fn (Organization $record) => OrganizationResource::getUrl('edit', $record)) ->icon(null), - Action::make('reject') - ->label(__('organization.actions.reject')) - ->action(fn (Organization $record) => $record->status = OrganizationStatus::rejected->value) - ->size('sm') - ->icon(null), ]; + + RejectAction::make('reject'), + ]; } } diff --git a/app/Filament/Resources/OrganizationResource/Widgets/NewOrganizationWidget.php b/app/Filament/Resources/OrganizationResource/Widgets/NewOrganizationWidget.php index 65a43d35..2f60805c 100644 --- a/app/Filament/Resources/OrganizationResource/Widgets/NewOrganizationWidget.php +++ b/app/Filament/Resources/OrganizationResource/Widgets/NewOrganizationWidget.php @@ -4,20 +4,16 @@ namespace App\Filament\Resources\OrganizationResource\Widgets; -use App\Enums\OrganizationStatus; use App\Filament\Resources\OrganizationResource; +use App\Filament\Resources\OrganizationResource\Actions\ApproveAction; +use App\Filament\Resources\OrganizationResource\Actions\RejectAction; 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 */ @@ -41,7 +37,9 @@ protected function getTableHeading(): string protected function getTableQuery(): Builder { - return Organization::query()->isPending(); + return Organization::query()->isPending() + ->with(['media']) + ->select(['id', 'name', 'created_at', 'status']); } protected function getTableQueryStringIdentifier(): ?string @@ -73,37 +71,25 @@ protected function getTableFilters(): array protected function getTableRecordUrlUsing(): \Closure { - return fn (Organization $record) => OrganizationResource::getUrl('edit', [ - 'record' => $record, - ]); + return fn (Organization $record) => OrganizationResource::getUrl('view', $record); } protected function getTableActions(): array { return [ + Action::make('view') + ->label(__('organization.actions.view')) + ->url($this->getTableRecordUrlUsing()) + ->icon(null), + 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(function (Organization $record) { - $record->status = OrganizationStatus::approved->value; - $record->save(); - }) - ->requiresConfirmation(), - Action::make('reject') - ->label(__('organization.actions.reject')) - ->action(function (Organization $record) { - $record->status = OrganizationStatus::rejected->value; - $record->save(); - }) - ->requiresConfirmation() - ->size('sm') + ->url(fn (Organization $record) => OrganizationResource::getUrl('edit', $record)) ->icon(null), + + ApproveAction::make('approve'), + + RejectAction::make('reject'), ]; } } diff --git a/app/Filament/Resources/OrganizationResource/Widgets/RejectedOrganizationWidget.php b/app/Filament/Resources/OrganizationResource/Widgets/RejectedOrganizationWidget.php index b7aa1c4b..bc8d916b 100644 --- a/app/Filament/Resources/OrganizationResource/Widgets/RejectedOrganizationWidget.php +++ b/app/Filament/Resources/OrganizationResource/Widgets/RejectedOrganizationWidget.php @@ -4,20 +4,15 @@ namespace App\Filament\Resources\OrganizationResource\Widgets; -use App\Enums\OrganizationStatus; use App\Filament\Resources\OrganizationResource; +use App\Filament\Resources\OrganizationResource\Actions\ApproveAction; 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 RejectedOrganizationWidget extends BaseWidget { - use CanPaginateRecords { - paginateTableQuery as protected; - } - /** @var string */ protected static string $resource = OrganizationResource::class; @@ -41,7 +36,9 @@ protected function getTableHeading(): string protected function getTableQuery(): Builder { - return Organization::isRejected(); + return Organization::isRejected() + ->with(['media']) + ->select(['id', 'name', 'created_at', 'status']); } protected function getTableQueryStringIdentifier(): ?string @@ -73,25 +70,23 @@ protected function getTableFilters(): array protected function getTableRecordUrlUsing(): \Closure { - return fn (Organization $record) => OrganizationResource::getUrl('edit', [ - 'record' => $record, - ]); + return fn (Organization $record) => OrganizationResource::getUrl('view', $record); } protected function getTableActions(): array { return [ + Action::make('view') + ->label(__('organization.actions.view')) + ->url($this->getTableRecordUrlUsing()) + ->icon(null), + Action::make('edit') ->label(__('organization.actions.edit')) - ->url(self::getTableRecordUrlUsing()) - ->size('sm') + ->url(fn (Organization $record) => OrganizationResource::getUrl('edit', $record)) ->icon(null), - Action::make('accept') - ->label(__('organization.actions.approve')) - ->size('sm') - ->icon(null) - ->action(fn (Organization $record) => $record->status = OrganizationStatus::approved->value) - ->requiresConfirmation(), + + ApproveAction::make('approve'), ]; } } diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php index ba7a5120..fd38ca8d 100644 --- a/app/Http/Controllers/OrganizationController.php +++ b/app/Http/Controllers/OrganizationController.php @@ -52,22 +52,6 @@ public function index(Request $request) ]); } - /** - * Show the form for creating a new resource. - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - */ - public function store(StoreOrganizationRequest $request) - { - // - } - /** * Display the specified resource. */ @@ -75,7 +59,7 @@ public function show(Organization $organization) { /* Return inertia page. */ return Inertia::render('Public/Organizations/Organization', [ - 'organization' => $organization, + 'organization' => $organization->loadMissing(['activityDomains', 'counties', 'projects', 'media']), ]); } @@ -119,20 +103,12 @@ public function update(Request $request, Organization $organization) $organization->update($modelData); - return redirect()->route('admin.ong.edit')->with('success_message', 'Organization updated successfully'); + return redirect()->route('admin.ong.edit')->with('success_message', __('organization.messages.update_success')); } catch (\Throwable $th) { - return redirect()->route('admin.ong.edit')->with('error_message', 'Organization update failed'); + return redirect()->route('admin.ong.edit')->with('error_message', __('organization.messages.update_error')); } } - /** - * Remove the specified resource from storage. - */ - public function destroy(Organization $organization) - { - // - } - public function removeCoverImage(Request $request) { $organization = auth()->user()->organization; diff --git a/app/Models/Organization.php b/app/Models/Organization.php index dd0fe383..fc2bf687 100644 --- a/app/Models/Organization.php +++ b/app/Models/Organization.php @@ -60,8 +60,6 @@ class Organization extends Model implements HasMedia 'accepts_volunteers' => 'boolean', ]; - protected $with = ['counties', 'activityDomains', 'projects', 'media']; - protected $appends = ['cover_image', 'statute_link']; public function projects(): HasMany diff --git a/lang/ro/organization.php b/lang/ro/organization.php index 458461c7..3f04b490 100644 --- a/lang/ro/organization.php +++ b/lang/ro/organization.php @@ -7,6 +7,7 @@ 'disabled' => 'Inactivă', ], 'actions' => [ + 'view' => 'Vizualizează', 'edit' => 'Editează', 'approve' => 'Aprobă', 'reject' => 'Respinge', @@ -39,7 +40,13 @@ 'eu_platesc_merchant_id' => 'Merchant ID', 'eu_platesc_private_key' => 'Key', 'administrator' => 'Administrator' - - + ], + 'messages'=>[ + 'update_success' => 'Organizația a fost actualizată cu succes!', + 'update_error' => 'A apărut o eroare la actualizarea organizației!', + 'approve_success' => 'Organizația a fost aprobată cu succes!', + 'approve_error' => 'A apărut o eroare la aprobarea organizației!', + 'reject_success' => 'Organizația a fost respinsă cu succes!', + 'reject_error' => 'A apărut o eroare la respingerea organizației!', ] ];