-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pipeline Stages Resource: Reorderable
- Loading branch information
Showing
10 changed files
with
284 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\PipelineStageResource\Pages; | ||
use App\Filament\Resources\PipelineStageResource\RelationManagers; | ||
use App\Models\PipelineStage; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\SoftDeletingScope; | ||
|
||
class PipelineStageResource extends Resource | ||
{ | ||
protected static ?string $model = PipelineStage::class; | ||
|
||
protected static ?string $navigationGroup = 'Settings'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(), | ||
Tables\Columns\IconColumn::make('is_default') | ||
->boolean(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->defaultSort('position') | ||
->reorderable('position') | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\Action::make('Set Default') | ||
->icon('heroicon-o-star') | ||
->hidden(fn ($record) => $record->is_default) | ||
->requiresConfirmation(function (Tables\Actions\Action $action, $record) { | ||
$action->modalDescription('Are you sure you want to set this as the default pipeline stage?'); | ||
$action->modalHeading('Set "' . $record->name . '" as Default'); | ||
|
||
return $action; | ||
}) | ||
->action(function (PipelineStage $record) { | ||
PipelineStage::where('is_default', true)->update(['is_default' => false]); | ||
|
||
$record->is_default = true; | ||
$record->save(); | ||
}), | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make() | ||
->action(function ($data, $record) { | ||
if ($record->customers()->count() > 0) { | ||
Notification::make() | ||
->danger() | ||
->title('Pipeline Stage is in use') | ||
->body('Pipeline Stage is in use by customers.') | ||
->send(); | ||
|
||
return; | ||
} | ||
|
||
Notification::make() | ||
->success() | ||
->title('Pipeline Stage deleted') | ||
->body('Pipeline Stage has been deleted.') | ||
->send(); | ||
|
||
$record->delete(); | ||
}) | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListPipelineStages::route('/'), | ||
'create' => Pages\CreatePipelineStage::route('/create'), | ||
'edit' => Pages\EditPipelineStage::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/Filament/Resources/PipelineStageResource/Pages/CreatePipelineStage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PipelineStageResource\Pages; | ||
|
||
use App\Filament\Resources\PipelineStageResource; | ||
use App\Models\PipelineStage; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreatePipelineStage extends CreateRecord | ||
{ | ||
protected static string $resource = PipelineStageResource::class; | ||
|
||
protected function mutateFormDataBeforeCreate(array $data): array | ||
{ | ||
$data['position'] = PipelineStage::max('position') + 1; | ||
|
||
return $data; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/PipelineStageResource/Pages/EditPipelineStage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PipelineStageResource\Pages; | ||
|
||
use App\Filament\Resources\PipelineStageResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditPipelineStage extends EditRecord | ||
{ | ||
protected static string $resource = PipelineStageResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/PipelineStageResource/Pages/ListPipelineStages.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PipelineStageResource\Pages; | ||
|
||
use App\Filament\Resources\PipelineStageResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListPipelineStages extends ListRecords | ||
{ | ||
protected static string $resource = PipelineStageResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class PipelineStage extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'position', | ||
'is_default', | ||
]; | ||
|
||
public function customers(): HasMany | ||
{ | ||
return $this->hasMany(Customer::class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
database/migrations/2023_10_15_094706_create_pipeline_stages_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('pipeline_stages', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->integer('position'); | ||
$table->boolean('is_default')->default(false); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('pipeline_stages'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
namespace Database\Seeders; | ||
|
||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; | ||
use App\Models\Customer; | ||
use App\Models\LeadSource; | ||
use App\Models\PipelineStage; | ||
use App\Models\Tag; | ||
use App\Models\User; | ||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
|
@@ -15,14 +20,12 @@ public function run(): void | |
{ | ||
// \App\Models\User::factory(10)->create(); | ||
|
||
\App\Models\User::factory()->create([ | ||
User::factory()->create([ | ||
'name' => 'tuantq', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('12341234'), | ||
]); | ||
|
||
|
||
|
||
$leadSources = [ | ||
'Website', | ||
'Online AD', | ||
|
@@ -33,20 +36,49 @@ public function run(): void | |
'Referral', | ||
]; | ||
foreach ($leadSources as $leadSource) { | ||
\App\Models\LeadSource::create(['name' => $leadSource]); | ||
LeadSource::create(['name' => $leadSource]); | ||
} | ||
|
||
\App\Models\Customer::factory() | ||
->count(10) | ||
->create(); | ||
|
||
$tags = [ | ||
'Priority', | ||
'VIP' | ||
]; | ||
|
||
foreach ($tags as $tag) { | ||
\App\Models\Tag::create(['name' => $tag]); | ||
Tag::create(['name' => $tag]); | ||
} | ||
|
||
$pipelineStages = [ | ||
[ | ||
'name' => 'Lead', | ||
'position' => 1, | ||
'is_default' => true, | ||
], | ||
[ | ||
'name' => 'Contact Made', | ||
'position' => 2, | ||
], | ||
[ | ||
'name' => 'Proposal Made', | ||
'position' => 3, | ||
], | ||
[ | ||
'name' => 'Proposal Rejected', | ||
'position' => 4, | ||
], | ||
[ | ||
'name' => 'Customer', | ||
'position' => 5, | ||
] | ||
]; | ||
|
||
foreach ($pipelineStages as $stage) { | ||
PipelineStage::create($stage); | ||
} | ||
|
||
$defaultPipelineStage = PipelineStage::where('is_default', true)->first()->id; | ||
Customer::factory()->count(10)->create([ | ||
'pipeline_stage_id' => $defaultPipelineStage, | ||
]); | ||
} | ||
} |