Skip to content

Commit

Permalink
254 admin bb organizatii organizatii active cannot deactivate an orga…
Browse files Browse the repository at this point in the history
…nization from preview table (#270)

* clean up

* clean up data loading

* wip

---------

Co-authored-by: Andrei Ioniță <[email protected]>
  • Loading branch information
gheorghelupu17 and andreiio authored Aug 18, 2023
1 parent b7db9a4 commit b328c54
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 96 deletions.
2 changes: 2 additions & 0 deletions app/Filament/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'),

];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Actions;

use App\Enums\OrganizationStatus;
use App\Models\Organization;
use Filament\Tables\Actions\Action;

class ApproveAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->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]);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Actions;

use App\Enums\OrganizationStatus;
use App\Models\Organization;
use Filament\Tables\Actions\Action;

class RejectAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->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]);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\Pages;

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

class ViewOrganization extends ViewRecord
{
protected static string $resource = OrganizationResource::class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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\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 ApprovedOrganizationWidget extends BaseWidget
{
use CanPaginateRecords {
paginateTableQuery as protected;
}

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

Expand All @@ -41,7 +36,9 @@ protected function getTableHeading(): string

protected function getTableQuery(): Builder
{
return Organization::isApproved();
return Organization::isApproved()
->with(['media'])
->select(['id', 'name', 'created_at', 'status']);
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down Expand Up @@ -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'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -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'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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'),
];
}
}
30 changes: 3 additions & 27 deletions app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,14 @@ 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.
*/
public function show(Organization $organization)
{
/* Return inertia page. */
return Inertia::render('Public/Organizations/Organization', [
'organization' => $organization,
'organization' => $organization->loadMissing(['activityDomains', 'counties', 'projects', 'media']),
]);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions lang/ro/organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'disabled' => 'Inactivă',
],
'actions' => [
'view' => 'Vizualizează',
'edit' => 'Editează',
'approve' => 'Aprobă',
'reject' => 'Respinge',
Expand Down Expand Up @@ -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!',
]
];

0 comments on commit b328c54

Please sign in to comment.