Skip to content

Commit

Permalink
remake approve flow on activities
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 17, 2023
1 parent de34007 commit dbab3f8
Show file tree
Hide file tree
Showing 26 changed files with 901 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Filament\Resources\OrganizationResource\Actions\Tables\Activity;

use App\Models\Activity;
use Filament\Forms\Components\Textarea;
use Filament\Tables\Actions\Action as BaseAction;

class RejectActivityAction extends BaseAction
Expand All @@ -17,14 +18,39 @@ public static function getDefaultName(): ?string
protected function setUp(): void
{
parent::setUp();

$this->label(__('activity.actions.reject'));

$this->icon('heroicon-s-x');

$this->color('danger');

$this->action(fn (Activity $record) => $record->reject());
$this->requiresConfirmation();

$this->modalHeading(__('activity.reject_modal.heading'));

$this->modalSubheading(
fn (Activity $record) => __('activity.reject_modal.subheading', [
'name' => __('project.labels.' . $record->changed_field),
'resource' => $record->subject->name,
])
);

$this->form([
Textarea::make('reason')
->label(__('activity.reject_modal.reason'))
->default(function (Activity $record) {
return $record->subject->name;
})
->required(),
]);

$this->modalButton(__('activity.actions.reject'));

$this->action(function (Activity $record, array $data) {
$reason = strip_tags($data['reason']);

$record->reject($reason);
});

$this->visible(fn (Activity $record) => $record->isPending());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

use App\Filament\Resources\OrganizationResource;
use App\Filament\Resources\OrganizationResource\Actions\Pages\ApproveOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\ApproveProjectAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\DeactivateOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\ReactivateOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\RejectOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\RejectProjectAction;
use Filament\Pages\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

Expand All @@ -25,7 +26,7 @@ protected function getActions(): array
->record($this->getRecord())
->visible($this->getRecord()->isPending()),

RejectOrganizationAction::make()
ApproveOrganizationAction::make()
->record($this->getRecord())
->visible($this->getRecord()->isPending()),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Resources\OrganizationResource\Widgets;

use App\Filament\Resources\OrganizationResource;
use App\Models\Activity;
use App\Models\Organization;
use App\Tables\Columns\TitleWithImageColumn;
Expand Down Expand Up @@ -74,6 +75,11 @@ protected function getTableColumns(): array
];
}

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

protected function getTableActions(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Pages;

use App\Models\Organization;
use App\Models\Project;
use Filament\Pages\Actions\Action;

class ApproveProjectAction extends Action
{
public static function getDefaultName(): ?string
{
return 'approve';
}

protected function setUp(): void
{
parent::setUp();

$this->color('success');

$this->icon('heroicon-s-check');

$this->label(__('project.actions.approve'));

$this->requiresConfirmation();

$this->modalHeading(__('project.approve_modal.heading'));

$this->modalSubheading(
fn (Project $record) => __('project.approve_modal.subheading', [
'name' => $record->name,
])
);

$this->modalButton(__('project.actions.approve'));

$this->action(function (Project $record) {
$record->markAsApproved();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Pages;

use App\Models\Project;
use Filament\Pages\Actions\Action;

class DeactivateProjectAction extends Action
{
public static function getDefaultName(): ?string
{
return 'deactivate';
}

protected function setUp(): void
{
parent::setUp();

$this->color('danger');

$this->icon('heroicon-s-x');

$this->label(__('project.actions.deactivate'));

$this->requiresConfirmation();

$this->modalHeading(__('project.deactivate_modal.heading'));

$this->modalSubheading(
fn (Project $record) => __('project.deactivate_modal.subheading', [
'name' => $record->name,
])
);

$this->modalButton(__('project.actions.deactivate'));

$this->action(function (Project $record) {
$record->markAsRejected();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Pages;

use App\Models\Organization;
use App\Models\Project;
use Filament\Pages\Actions\Action;

class ReactivateProjectAction extends Action
{
public static function getDefaultName(): ?string
{
return 'reactivate';
}

protected function setUp(): void
{
parent::setUp();

$this->color('success');

$this->icon('heroicon-s-check');

$this->label(__('project.actions.reactivate'));

$this->requiresConfirmation();

$this->modalHeading(__('project.reactivate_modal.heading'));

$this->modalSubheading(
fn (Project $record) => __('project.reactivate_modal.subheading', [
'name' => $record->name,
])
);

$this->modalButton(__('project.actions.reactivate'));

$this->action(function (Project $record) {
$record->markAsApproved();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Pages;

use App\Models\Organization;
use App\Models\Project;
use Filament\Forms\Components\Textarea;
use Filament\Pages\Actions\Action;

class RejectProjectAction extends Action
{
public static function getDefaultName(): ?string
{
return 'reject';
}

protected function setUp(): void
{
parent::setUp();

$this->color('danger');

$this->icon('heroicon-s-x');

$this->label(__('project.actions.reject'));

$this->requiresConfirmation();

$this->modalHeading(__('project.reject_modal.heading'));

$this->modalSubheading(
fn (Project $record) => __('project.reject_modal.subheading', [
'name' => $record->name,
])
);

$this->form([
Textarea::make('reason')
->label(__('project.reject_modal.reason'))
->required(),
]);

$this->modalButton(__('project.actions.reject'));

$this->action(function (Project $record, array $data) {
$reason = strip_tags($data['reason']);

$record->markAsRejected($reason);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Tables\Activity;

use App\Models\Activity;
use Filament\Tables\Actions\Action as BaseAction;

class ApproveActivityAction extends BaseAction
{
public static function getDefaultName(): ?string
{
return 'approve';
}

protected function setUp(): void
{
parent::setUp();

$this->label(__('activity.actions.approve'));

$this->icon('heroicon-s-check');

$this->color('success');

$this->action(fn (Activity $record) => $record->approve());

$this->visible(fn (Activity $record) => $record->isPending());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\Actions\Tables\Activity;

use App\Models\Activity;
use Filament\Forms\Components\Textarea;
use Filament\Tables\Actions\Action as BaseAction;

class RejectActivityAction extends BaseAction
{
public static function getDefaultName(): ?string
{
return 'reject';
}

protected function setUp(): void
{
parent::setUp();
$this->label(__('activity.actions.reject'));

$this->icon('heroicon-s-x');

$this->color('danger');

$this->requiresConfirmation();

$this->modalHeading(__('activity.reject_modal.heading'));

$this->modalSubheading(
fn (Activity $record) => __('activity.reject_modal.subheading', [
'name' => __('project.labels.' . $record->changed_field),
'resource' => $record->subject->name,
])
);

$this->form([
Textarea::make('reason')
->label(__('activity.reject_modal.reason'))
->default(function (Activity $record) {
return $record->subject->name;
})
->required(),
]);

$this->modalButton(__('activity.actions.reject'));

$this->action(function (Activity $record, array $data) {
$reason = strip_tags($data['reason']);

$record->reject($reason);
});

$this->visible(fn (Activity $record) => $record->isPending());
}
}
Loading

0 comments on commit dbab3f8

Please sign in to comment.