Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Filament/actions #5

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions app/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
namespace App\Livewire;

use App\Models\Category;
use App\Models\Note;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Support\Enums\ActionSize;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Livewire\Attributes\Url;
use Livewire\Component;

class Dashboard extends Component
class Dashboard extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public $years;

public $months;
Expand All @@ -20,9 +33,47 @@ class Dashboard extends Component
#[Url(keep: true)]
public int $month;

public $listeners = [
'noteCreated' => 'render',
];
public function addToCategoryAction(): Action
{
return CreateAction::make('addToCategory')
->model(Note::class)
->form(function (array $arguments) {
$category = Category::with('postes')->find($arguments['category']);
$fields = [
TextInput::make('price')
->numeric()
->inputMode('decimal')
->required(),
TextInput::make('label')
->required($category->postes->count() == 0)
->maxLength(255),
];
// TODO : insert in 2nd place
if ($category->postes->count() > 0) {
$select = Select::make('poste_id')
->required()
->label('Poste')
->options($category->postes->pluck('label', 'id'));
array_splice($fields, 1, 0, [$select]);
}

return $fields;
})
->label('Add note')
->labeledFrom('md')
->button()
->outlined()
->size(ActionSize::Small)
->icon('heroicon-m-plus-circle')
->mutateFormDataUsing(function (array $data, array $arguments): array {
$data['user_id'] = auth()->id();
$data['year'] = $this->year;
$data['month'] = $this->month;
$data['category_id'] = $arguments['category'];

return $data;
});
}

public function mount()
{
Expand Down
72 changes: 0 additions & 72 deletions app/Livewire/EditNote.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Category extends Model
/**
* The attributes that are mass assignable.
*
* @var array<string>
* @var array<int, string>
*/
protected $fillable = ['label', 'credit'];

Expand Down
4 changes: 2 additions & 2 deletions app/Models/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Note extends Model
/**
* The attributes that are mass assignable.
*
* @var array<string>
* @var array<int, string>
*/
protected $fillable = ['label', 'price', 'year', 'month', 'category_id', 'poste_id'];
protected $fillable = ['label', 'price', 'year', 'month', 'category_id', 'poste_id', 'user_id'];

protected $casts = [
'price' => MoneyCast::class,
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Poste.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Poste extends Model
/**
* The attributes that are mass assignable.
*
* @var array<string>
* @var array<int, string>
*/
protected $fillable = ['label', 'category_id'];

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"license": "MIT",
"require": {
"php": "^8.2",
"filament/actions": "^3.2",
"filament/notifications": "^v3.2.44",
"guzzlehttp/guzzle": "^7.8.1",
"laravel/framework": "v10.47.0",
"laravel/sanctum": "^v3.3.3",
"laravel/tinker": "^v2.9.0",
"livewire/livewire": "v3.4.7",
"livewire/volt": "^v1.6.2",
"wire-elements/modal": "^2.0.9"
"livewire/volt": "^v1.6.2"
},
"require-dev": {
"barryvdh/laravel-debugbar": "v3.10.6",
Expand Down Expand Up @@ -46,7 +46,8 @@
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
Expand Down
102 changes: 22 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading