implement admin panel
This commit is contained in:
92 files changed
+5426
-9
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Pages;
|
||||
|
||||
use App\Actions\WorkflowConfiguration\CreateWorkflowConfigurationAction;
|
||||
use App\Filament\Resources\WorkflowConfigurations\WorkflowConfigurationResource;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\User;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateWorkflowConfiguration extends CreateRecord
|
||||
{
|
||||
protected static string $resource = WorkflowConfigurationResource::class;
|
||||
|
||||
private CreateWorkflowConfigurationAction $createWorkflowConfiguration;
|
||||
|
||||
public function boot(CreateWorkflowConfigurationAction $createWorkflowConfiguration): void
|
||||
{
|
||||
$this->createWorkflowConfiguration = $createWorkflowConfiguration;
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$user = auth()->user();
|
||||
abort_unless($user instanceof User, 403);
|
||||
|
||||
return $this->createWorkflowConfiguration->handle(
|
||||
LoanType::query()->findOrFail($data['loan_type_id']),
|
||||
$data['name'],
|
||||
$user,
|
||||
$data['steps'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Pages;
|
||||
|
||||
use App\Actions\WorkflowConfiguration\PublishWorkflowConfigurationAction;
|
||||
use App\Actions\WorkflowConfiguration\UpdateWorkflowConfigurationAction;
|
||||
use App\Filament\Resources\WorkflowConfigurations\WorkflowConfigurationResource;
|
||||
use App\Models\User;
|
||||
use App\Models\WorkflowConfiguration;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditWorkflowConfiguration extends EditRecord
|
||||
{
|
||||
protected static string $resource = WorkflowConfigurationResource::class;
|
||||
|
||||
private UpdateWorkflowConfigurationAction $updateWorkflowConfiguration;
|
||||
|
||||
private PublishWorkflowConfigurationAction $publishWorkflowConfiguration;
|
||||
|
||||
public function boot(
|
||||
UpdateWorkflowConfigurationAction $updateWorkflowConfiguration,
|
||||
PublishWorkflowConfigurationAction $publishWorkflowConfiguration,
|
||||
): void {
|
||||
$this->updateWorkflowConfiguration = $updateWorkflowConfiguration;
|
||||
$this->publishWorkflowConfiguration = $publishWorkflowConfiguration;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
/** @var WorkflowConfiguration $record */
|
||||
$record = $this->record;
|
||||
|
||||
$data['steps'] = $record->steps()
|
||||
->get(['stage_definition_id', 'rules', 'is_enabled'])
|
||||
->map(fn ($step): array => [
|
||||
'stage_definition_id' => $step->stage_definition_id,
|
||||
'rules' => $step->rules,
|
||||
'is_enabled' => $step->is_enabled,
|
||||
])
|
||||
->all();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var WorkflowConfiguration $record */
|
||||
return $this->updateWorkflowConfiguration->handle($record, $data['name'], $data['steps']);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ViewAction::make(),
|
||||
Action::make('publish')
|
||||
->icon('heroicon-o-rocket-launch')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('This archives the currently published version. Existing loans remain attached to their original workflow.')
|
||||
->action(function () {
|
||||
$user = auth()->user();
|
||||
abort_unless($user instanceof User, 403);
|
||||
|
||||
$published = $this->publishWorkflowConfiguration->handle($this->record, $user);
|
||||
Notification::make()->title('Workflow published')->success()->send();
|
||||
|
||||
return redirect(WorkflowConfigurationResource::getUrl('view', ['record' => $published]));
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Pages;
|
||||
|
||||
use App\Domain\Loan\Enums\WorkflowConfigurationStatus;
|
||||
use App\Filament\Resources\WorkflowConfigurations\WorkflowConfigurationResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListWorkflowConfigurations extends ListRecords
|
||||
{
|
||||
protected static string $resource = WorkflowConfigurationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()->label('New workflow draft')->icon('heroicon-o-plus'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTabs(): array
|
||||
{
|
||||
return [
|
||||
'all' => Tab::make('All versions'),
|
||||
'draft' => Tab::make('Drafts')
|
||||
->icon('heroicon-o-pencil-square')
|
||||
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('status', WorkflowConfigurationStatus::Draft)),
|
||||
'published' => Tab::make('Published')
|
||||
->icon('heroicon-o-check-badge')
|
||||
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('status', WorkflowConfigurationStatus::Published)),
|
||||
'archived' => Tab::make('Archive')
|
||||
->icon('heroicon-o-archive-box')
|
||||
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('status', WorkflowConfigurationStatus::Archived)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Pages;
|
||||
|
||||
use App\Actions\WorkflowConfiguration\PublishWorkflowConfigurationAction;
|
||||
use App\Filament\Resources\WorkflowConfigurations\WorkflowConfigurationResource;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewWorkflowConfiguration extends ViewRecord
|
||||
{
|
||||
protected static string $resource = WorkflowConfigurationResource::class;
|
||||
|
||||
private PublishWorkflowConfigurationAction $publishWorkflowConfiguration;
|
||||
|
||||
public function boot(PublishWorkflowConfigurationAction $publishWorkflowConfiguration): void
|
||||
{
|
||||
$this->publishWorkflowConfiguration = $publishWorkflowConfiguration;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make()->visible(fn (): bool => $this->record->isEditable()),
|
||||
Action::make('publish')
|
||||
->icon('heroicon-o-rocket-launch')
|
||||
->color('success')
|
||||
->visible(fn (): bool => $this->record->isEditable())
|
||||
->requiresConfirmation()
|
||||
->action(function (): void {
|
||||
$user = auth()->user();
|
||||
abort_unless($user instanceof User, 403);
|
||||
|
||||
$this->record = $this->publishWorkflowConfiguration->handle($this->record, $user);
|
||||
Notification::make()->title('Workflow published')->success()->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\RelationManagers;
|
||||
|
||||
use App\Filament\Resources\Loans\LoanResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LoansRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'loans';
|
||||
|
||||
protected static ?string $relatedResource = LoanResource::class;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Schemas;
|
||||
|
||||
use App\Domain\Loan\Enums\LoanStage;
|
||||
use App\Models\StageDefinition;
|
||||
use App\Models\WorkflowConfiguration;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class WorkflowConfigurationForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Workflow identity')
|
||||
->description('Drafts are isolated versions. Publishing never changes loans already assigned to an older version.')
|
||||
->icon('heroicon-o-finger-print')
|
||||
->schema([
|
||||
Select::make('loan_type_id')
|
||||
->label('Loan type')
|
||||
->relationship('loanType', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->disabled(fn (?WorkflowConfiguration $record): bool => $record !== null)
|
||||
->dehydrated(),
|
||||
TextInput::make('name')
|
||||
->placeholder('e.g. Personal lending — summer policy')
|
||||
->required()
|
||||
->maxLength(150),
|
||||
Placeholder::make('version_summary')
|
||||
->label('Version')
|
||||
->content(fn (?WorkflowConfiguration $record): string => $record === null
|
||||
? 'Assigned automatically when the draft is created'
|
||||
: "Version {$record->version} · {$record->status->value}"),
|
||||
])
|
||||
->columns(3),
|
||||
Section::make('Execution path')
|
||||
->description('Drag stages into execution order. Rule fields change with the selected stage.')
|
||||
->icon('heroicon-o-arrows-right-left')
|
||||
->schema([
|
||||
Repeater::make('steps')
|
||||
->hiddenLabel()
|
||||
->schema([
|
||||
Select::make('stage_definition_id')
|
||||
->label('Stage')
|
||||
->options(fn (): array => StageDefinition::query()
|
||||
->where('is_active', true)
|
||||
->orderBy('name')
|
||||
->pluck('name', 'id')
|
||||
->all())
|
||||
->searchable()
|
||||
->required()
|
||||
->distinct()
|
||||
->disableOptionsWhenSelectedInSiblingRepeaterItems()
|
||||
->live()
|
||||
->afterStateUpdated(function (Set $set, mixed $state): void {
|
||||
$stageCode = StageDefinition::query()->whereKey($state)->value('code');
|
||||
$set('rules', self::defaultRules($stageCode));
|
||||
}),
|
||||
Toggle::make('is_enabled')
|
||||
->label('Enabled')
|
||||
->default(true)
|
||||
->inline(false),
|
||||
Grid::make(4)
|
||||
->schema(fn (Get $get): array => self::ruleFields(
|
||||
StageDefinition::query()->whereKey($get('stage_definition_id'))->value('code'),
|
||||
))
|
||||
->key('stageRules')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2)
|
||||
->itemLabel(fn (array $state): string => StageDefinition::query()
|
||||
->whereKey($state['stage_definition_id'] ?? null)
|
||||
->value('name') ?? 'Choose a stage')
|
||||
->addActionLabel('Add workflow stage')
|
||||
->reorderable()
|
||||
->collapsible()
|
||||
->minItems(1)
|
||||
->required(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, TextInput|Toggle|Placeholder>
|
||||
*/
|
||||
private static function ruleFields(?string $stageCode): array
|
||||
{
|
||||
return match ($stageCode) {
|
||||
LoanStage::FraudCheck->value => [
|
||||
TextInput::make('rules.fraudPrefix')
|
||||
->label('Reject prefix')
|
||||
->required()
|
||||
->maxLength(50),
|
||||
TextInput::make('rules.manualReviewPrefix')
|
||||
->label('Manual-review prefix')
|
||||
->required()
|
||||
->maxLength(50),
|
||||
],
|
||||
LoanStage::GuarantorCheck->value => [
|
||||
Toggle::make('rules.guarantorRequired')
|
||||
->label('Guarantor required')
|
||||
->default(true)
|
||||
->inline(false),
|
||||
],
|
||||
LoanStage::CreditCheck->value => [
|
||||
TextInput::make('rules.rejectBelow')
|
||||
->label('Reject below')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1000)
|
||||
->required(),
|
||||
TextInput::make('rules.manualReviewMin')
|
||||
->label('Review from')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1000)
|
||||
->required(),
|
||||
TextInput::make('rules.manualReviewMax')
|
||||
->label('Review through')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1000)
|
||||
->required(),
|
||||
TextInput::make('rules.approveFrom')
|
||||
->label('Approve from')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1000)
|
||||
->required(),
|
||||
],
|
||||
LoanStage::ManagerApproval->value => [
|
||||
TextInput::make('rules.activationThreshold')
|
||||
->label('Activation threshold')
|
||||
->helperText('Manager approval is skipped at or below this amount.')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->prefix('IRR')
|
||||
->formatStateUsing(fn (mixed $state): mixed => $state)
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
TextInput::make('rules.incomeMultiplier')
|
||||
->label('Income multiplier')
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->suffix('×')
|
||||
->required(),
|
||||
Placeholder::make('threshold_preview')
|
||||
->label('Default policy')
|
||||
->content(fn (Get $get): string => Number::format((int) ($get('rules.activationThreshold') ?? 0)).' IRR'),
|
||||
],
|
||||
LoanStage::Validation->value => [
|
||||
Placeholder::make('validation_policy')
|
||||
->label('Built-in validation')
|
||||
->content('Transport-safe values are checked against the BankFlow validation policy.')
|
||||
->columnSpanFull(),
|
||||
],
|
||||
default => [
|
||||
Placeholder::make('choose_stage')
|
||||
->label('Stage rules')
|
||||
->content('Choose a stage to configure its policy.')
|
||||
->columnSpanFull(),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private static function defaultRules(?string $stageCode): array
|
||||
{
|
||||
return match ($stageCode) {
|
||||
LoanStage::FraudCheck->value => [
|
||||
'fraudPrefix' => 'FRAUD',
|
||||
'manualReviewPrefix' => 'REVIEW',
|
||||
],
|
||||
LoanStage::GuarantorCheck->value => ['guarantorRequired' => true],
|
||||
LoanStage::CreditCheck->value => [
|
||||
'rejectBelow' => 500,
|
||||
'manualReviewMin' => 500,
|
||||
'manualReviewMax' => 649,
|
||||
'approveFrom' => 650,
|
||||
],
|
||||
LoanStage::ManagerApproval->value => [
|
||||
'activationThreshold' => 500_000_000,
|
||||
'incomeMultiplier' => 20,
|
||||
],
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Schemas;
|
||||
|
||||
use App\Domain\Loan\Enums\WorkflowConfigurationStatus;
|
||||
use Filament\Infolists\Components\IconEntry;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class WorkflowConfigurationInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
Section::make('Workflow')
|
||||
->icon('heroicon-o-queue-list')
|
||||
->schema([
|
||||
TextEntry::make('name')->weight('semibold'),
|
||||
TextEntry::make('loanType.name')->label('Loan type'),
|
||||
TextEntry::make('version')->badge()->prefix('Version '),
|
||||
TextEntry::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (WorkflowConfigurationStatus $state): string => str($state->value)->headline()->toString())
|
||||
->color(fn (WorkflowConfigurationStatus $state): string => match ($state) {
|
||||
WorkflowConfigurationStatus::Draft => 'warning',
|
||||
WorkflowConfigurationStatus::Published => 'success',
|
||||
WorkflowConfigurationStatus::Archived => 'gray',
|
||||
}),
|
||||
])
|
||||
->columns(2)
|
||||
->columnSpan(2),
|
||||
Section::make('Audit')
|
||||
->icon('heroicon-o-clock')
|
||||
->schema([
|
||||
TextEntry::make('creator.name')->label('Created by')->placeholder('System'),
|
||||
TextEntry::make('published_at')->dateTime()->placeholder('Not published'),
|
||||
TextEntry::make('loans_count')->label('Assigned loans')->numeric(),
|
||||
]),
|
||||
]),
|
||||
Section::make('Execution path')
|
||||
->description('The rule snapshot shown here is the policy attached to this exact version.')
|
||||
->icon('heroicon-o-arrows-right-left')
|
||||
->schema([
|
||||
RepeatableEntry::make('steps')
|
||||
->hiddenLabel()
|
||||
->schema([
|
||||
TextEntry::make('position')->label('#')->badge()->color('gray'),
|
||||
TextEntry::make('stageDefinition.name')->label('Stage')->weight('semibold'),
|
||||
TextEntry::make('stageDefinition.code')->label('Code')->badge()->color('info'),
|
||||
IconEntry::make('is_enabled')->label('Enabled')->boolean(),
|
||||
TextEntry::make('rules')
|
||||
->label('Rules')
|
||||
->formatStateUsing(fn (array $state): string => collect($state)
|
||||
->map(fn (mixed $value, string $key): string => str($key)->headline().': '.(is_bool($value) ? ($value ? 'Yes' : 'No') : $value))
|
||||
->implode(' · '))
|
||||
->placeholder('No configurable rules')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(4),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations\Tables;
|
||||
|
||||
use App\Actions\WorkflowConfiguration\CreateWorkflowConfigurationAction;
|
||||
use App\Actions\WorkflowConfiguration\PublishWorkflowConfigurationAction;
|
||||
use App\Domain\Loan\Enums\WorkflowConfigurationStatus;
|
||||
use App\Filament\Resources\WorkflowConfigurations\WorkflowConfigurationResource;
|
||||
use App\Models\User;
|
||||
use App\Models\WorkflowConfiguration;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class WorkflowConfigurationsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('loanType.name')
|
||||
->label('Loan type')
|
||||
->icon('heroicon-o-building-library')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('name')
|
||||
->weight('semibold')
|
||||
->searchable(),
|
||||
TextColumn::make('version')
|
||||
->badge()
|
||||
->prefix('v')
|
||||
->color('gray')
|
||||
->sortable(),
|
||||
TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (WorkflowConfigurationStatus $state): string => str($state->value)->headline()->toString())
|
||||
->color(fn (WorkflowConfigurationStatus $state): string => match ($state) {
|
||||
WorkflowConfigurationStatus::Draft => 'warning',
|
||||
WorkflowConfigurationStatus::Published => 'success',
|
||||
WorkflowConfigurationStatus::Archived => 'gray',
|
||||
}),
|
||||
TextColumn::make('steps_count')
|
||||
->label('Stages')
|
||||
->counts('steps')
|
||||
->numeric()
|
||||
->alignEnd(),
|
||||
TextColumn::make('loans_count')
|
||||
->label('Assigned')
|
||||
->counts('loans')
|
||||
->numeric()
|
||||
->alignEnd(),
|
||||
TextColumn::make('published_at')
|
||||
->label('Published')
|
||||
->since()
|
||||
->placeholder('Not yet')
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('loan_type_id')
|
||||
->label('Loan type')
|
||||
->relationship('loanType', 'name')
|
||||
->preload(),
|
||||
SelectFilter::make('status')
|
||||
->options(collect(WorkflowConfigurationStatus::cases())
|
||||
->mapWithKeys(fn (WorkflowConfigurationStatus $status): array => [$status->value => str($status->value)->headline()->toString()])
|
||||
->all()),
|
||||
])
|
||||
->defaultSort('version', 'desc')
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make()->visible(fn (WorkflowConfiguration $record): bool => $record->isEditable()),
|
||||
Action::make('copy')
|
||||
->label('Copy as draft')
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->color('gray')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('New draft name')
|
||||
->required()
|
||||
->maxLength(150),
|
||||
])
|
||||
->fillForm(fn (WorkflowConfiguration $record): array => ['name' => "{$record->name} copy"])
|
||||
->action(function (
|
||||
array $data,
|
||||
WorkflowConfiguration $record,
|
||||
CreateWorkflowConfigurationAction $createWorkflowConfiguration,
|
||||
) {
|
||||
$user = auth()->user();
|
||||
abort_unless($user instanceof User, 403);
|
||||
|
||||
$draft = $createWorkflowConfiguration->handle(
|
||||
$record->loanType,
|
||||
$data['name'],
|
||||
$user,
|
||||
copyFrom: $record,
|
||||
);
|
||||
|
||||
Notification::make()->title('Draft copy created')->success()->send();
|
||||
|
||||
return redirect(WorkflowConfigurationResource::getUrl('edit', ['record' => $draft]));
|
||||
}),
|
||||
Action::make('publish')
|
||||
->icon('heroicon-o-rocket-launch')
|
||||
->color('success')
|
||||
->visible(fn (WorkflowConfiguration $record): bool => $record->isEditable())
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Publish this workflow version?')
|
||||
->modalDescription('The currently published workflow for this loan type will be archived. Existing loans keep their assigned version.')
|
||||
->action(function (
|
||||
WorkflowConfiguration $record,
|
||||
PublishWorkflowConfigurationAction $publishWorkflowConfiguration,
|
||||
): void {
|
||||
$user = auth()->user();
|
||||
abort_unless($user instanceof User, 403);
|
||||
|
||||
$publishWorkflowConfiguration->handle($record, $user);
|
||||
|
||||
Notification::make()->title('Workflow published')->success()->send();
|
||||
}),
|
||||
])
|
||||
->emptyStateHeading('No workflow versions yet')
|
||||
->emptyStateDescription('Create a draft, arrange its stages, then publish it for new applications.')
|
||||
->emptyStateIcon('heroicon-o-queue-list');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkflowConfigurations;
|
||||
|
||||
use App\Filament\Resources\WorkflowConfigurations\Pages\CreateWorkflowConfiguration;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Pages\EditWorkflowConfiguration;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Pages\ListWorkflowConfigurations;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Pages\ViewWorkflowConfiguration;
|
||||
use App\Filament\Resources\WorkflowConfigurations\RelationManagers\LoansRelationManager;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Schemas\WorkflowConfigurationForm;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Schemas\WorkflowConfigurationInfolist;
|
||||
use App\Filament\Resources\WorkflowConfigurations\Tables\WorkflowConfigurationsTable;
|
||||
use App\Models\WorkflowConfiguration;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use UnitEnum;
|
||||
|
||||
class WorkflowConfigurationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = WorkflowConfiguration::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedQueueList;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Configuration';
|
||||
|
||||
protected static ?string $navigationLabel = 'Workflows';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return WorkflowConfigurationForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return WorkflowConfigurationInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return WorkflowConfigurationsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
LoansRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListWorkflowConfigurations::route('/'),
|
||||
'create' => CreateWorkflowConfiguration::route('/create'),
|
||||
'view' => ViewWorkflowConfiguration::route('/{record}'),
|
||||
'edit' => EditWorkflowConfiguration::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['loanType', 'creator'])
|
||||
->withCount(['steps', 'loans']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user