Skip to content

Commit

Permalink
cleanup fix rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 17, 2023
1 parent 5c0e89e commit ecf5bf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
31 changes: 8 additions & 23 deletions app/Filament/Resources/ProjectResource/Widgets/RejectedProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
namespace App\Filament\Resources\ProjectResource\Widgets;

use App\Enums\ProjectStatus;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\ApproveProjectAction;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\RejectProjectAction;
use App\Models\Project;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Illuminate\Database\Eloquent\Builder;

class RejectedProject extends BaseProjectWidget
Expand Down Expand Up @@ -40,29 +44,10 @@ protected function getTableRecordUrlUsing(): \Closure
protected function getTableActions(): array
{
return [
Action::make('edit')
->label(__('project.actions.edit'))
->url(self::getTableRecordUrlUsing())
->size('sm')
->icon(null),
Action::make('accept')
->label(__('project.actions.approve'))
->size('sm')
->icon(null)
->action(function (Project $record) {
$record->status = ProjectStatus::approved->value;
$record->save();
})
->requiresConfirmation(),
Action::make('reject')
->label(__('project.actions.reject'))
->action(function (Project $record) {
$record->status = ProjectStatus::rejected->value;
$record->save();
})
->requiresConfirmation()
->size('sm')
->icon(null),
ViewAction::make()->label(__('project.actions.view'))
->url($this->getTableRecordUrlUsing()),
EditAction::make(),
ApproveProjectAction::make(),
];
}
}
15 changes: 3 additions & 12 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,15 @@ public function changeStatus($id, Request $request)
'counties' => ['required_if:is_national,0', 'array', 'min:1'],
'description' => ['required', 'min:100', 'max:1000'],
'scope' => ['required', 'min:100', 'max:1000'],
'beneficiaries' => ['required', 'min:100', 'max:1000'],
'reason_to_donate' => ['required', 'min:100', 'max:1000'],
'beneficiaries' => ['required', 'min:50', 'max:1000'],
'reason_to_donate' => ['required', 'min:50', 'max:1000'],
'preview' => ['required'],
],
[
'start.after_or_equal' => __('custom_validation.start_date.after_or_equal'),
]
)->validate();

try {
(new ProjectService(Project::class))->changeStatus($project, $request->get('status'));
} catch (\Exception $exception) {
dd($exception->getMessage());

return redirect()->back()
->with('error', $exception->getMessage());
}

(new ProjectService(Project::class))->changeStatus($project, $request->get('status'));
return redirect()->back()
->with('success', 'Project status changed.');
}
Expand Down

0 comments on commit ecf5bf5

Please sign in to comment.