|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\Resources\CompanyJobs\Tables; |
| 4 | + |
| 5 | +use App\Enums\JobStatus; |
| 6 | +use App\Jobs\ProvisionCompanyJobGiteaJob; |
| 7 | +use App\Models\CompanyJob; |
| 8 | +use Filament\Actions\Action; |
| 9 | +use Filament\Actions\BulkActionGroup; |
| 10 | +use Filament\Actions\DeleteBulkAction; |
| 11 | +use Filament\Actions\EditAction; |
| 12 | +use Filament\Support\Icons\Heroicon; |
| 13 | +use Filament\Tables\Columns\IconColumn; |
| 14 | +use Filament\Tables\Columns\TextColumn; |
| 15 | +use Filament\Tables\Table; |
| 16 | + |
| 17 | +class CompanyJobsTable |
| 18 | +{ |
| 19 | + public static function configure(Table $table): Table |
| 20 | + { |
| 21 | + return $table |
| 22 | + ->columns([ |
| 23 | + TextColumn::make('user.name') |
| 24 | + ->label('Owner') |
| 25 | + ->searchable(), |
| 26 | + TextColumn::make('title') |
| 27 | + ->searchable() |
| 28 | + ->limit(40), |
| 29 | + TextColumn::make('company_name') |
| 30 | + ->searchable() |
| 31 | + ->toggleable(), |
| 32 | + TextColumn::make('status') |
| 33 | + ->badge() |
| 34 | + ->sortable(), |
| 35 | + IconColumn::make('first_payment_qi_confirmed') |
| 36 | + ->label('Qi paid') |
| 37 | + ->boolean(), |
| 38 | + TextColumn::make('gitea_owner') |
| 39 | + ->label('Gitea owner') |
| 40 | + ->placeholder('—') |
| 41 | + ->toggleable(isToggledHiddenByDefault: true), |
| 42 | + TextColumn::make('gitea_repo_name') |
| 43 | + ->label('Repo') |
| 44 | + ->placeholder('—') |
| 45 | + ->toggleable(isToggledHiddenByDefault: true), |
| 46 | + TextColumn::make('gitea_provisioned_at') |
| 47 | + ->dateTime() |
| 48 | + ->sortable() |
| 49 | + ->toggleable(isToggledHiddenByDefault: true), |
| 50 | + TextColumn::make('created_at') |
| 51 | + ->dateTime() |
| 52 | + ->sortable() |
| 53 | + ->toggleable(isToggledHiddenByDefault: true), |
| 54 | + ]) |
| 55 | + ->filters([ |
| 56 | + // |
| 57 | + ]) |
| 58 | + ->recordActions([ |
| 59 | + EditAction::make(), |
| 60 | + Action::make('confirmQiPayment') |
| 61 | + ->label('Confirm payment') |
| 62 | + ->icon(Heroicon::OutlinedBanknotes) |
| 63 | + ->color('gray') |
| 64 | + ->visible(fn (CompanyJob $record): bool => $record->status === JobStatus::PENDING |
| 65 | + && ! $record->first_payment_qi_confirmed) |
| 66 | + ->requiresConfirmation() |
| 67 | + ->modalHeading('Confirm first payment received') |
| 68 | + ->modalDescription('Confirm that the minimum first payment was sent to the Qi Card number shown in the page subtitle.') |
| 69 | + ->action(fn (CompanyJob $record): bool => $record->update([ |
| 70 | + 'first_payment_qi_confirmed' => true, |
| 71 | + ])), |
| 72 | + Action::make('approve') |
| 73 | + ->icon(Heroicon::OutlinedCheckCircle) |
| 74 | + ->color('success') |
| 75 | + ->visible(fn (CompanyJob $record): bool => $record->status === JobStatus::PENDING) |
| 76 | + ->disabled(fn (CompanyJob $record): bool => ! $record->first_payment_qi_confirmed) |
| 77 | + ->tooltip(fn (CompanyJob $record): ?string => $record->first_payment_qi_confirmed |
| 78 | + ? null |
| 79 | + : 'Confirm Qi Card payment first.') |
| 80 | + ->requiresConfirmation() |
| 81 | + ->modalHeading('Approve remote work post') |
| 82 | + ->modalDescription('Approves the post and provisions a private Gitea repository for the owner.') |
| 83 | + ->action(function (CompanyJob $record): void { |
| 84 | + $record->update(['status' => JobStatus::APPROVED]); |
| 85 | + ProvisionCompanyJobGiteaJob::dispatch($record->id); |
| 86 | + }) |
| 87 | + ->successNotificationTitle('Post approved and Gitea provisioning queued'), |
| 88 | + Action::make('reject') |
| 89 | + ->icon(Heroicon::OutlinedXCircle) |
| 90 | + ->color('danger') |
| 91 | + ->visible(fn (CompanyJob $record): bool => $record->status === JobStatus::PENDING) |
| 92 | + ->requiresConfirmation() |
| 93 | + ->action(fn (CompanyJob $record): bool => $record->update([ |
| 94 | + 'status' => JobStatus::REJECTED, |
| 95 | + ])) |
| 96 | + ->successNotificationTitle('Post rejected'), |
| 97 | + ]) |
| 98 | + ->toolbarActions([ |
| 99 | + BulkActionGroup::make([ |
| 100 | + DeleteBulkAction::make(), |
| 101 | + ]), |
| 102 | + ]); |
| 103 | + } |
| 104 | +} |
0 commit comments