feat: improve visits filter UX and update currency label

This commit is contained in:
SajjadMahmoody
2026-04-18 22:47:23 +03:30
parent 4abd856bf9
commit 1e8ec1f76f
13 changed files with 296 additions and 68 deletions
@@ -58,7 +58,6 @@ public function form(Schema $schema): Schema
->label(__('visits.fields.visit_time'))
->native(false)
->seconds(false)
->minutesStep(15)
->afterStateHydrated(function ($component, $state) {
if (blank($state)) {
$component->state(now()->format('Y-m-d H:i:s'));
+15 -2
View File
@@ -5,6 +5,7 @@
namespace App\Filament\Resources;
use App\Filament\Resources\VisitResource\Pages;
use App\Filament\Widgets\VisitStatsWidget;
use App\Models\Doctor;
use App\Models\Patient;
use App\Models\PaymentType;
@@ -29,6 +30,7 @@
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
@@ -42,6 +44,13 @@ class VisitResource extends Resource
protected static ?string $recordTitleAttribute = 'visit_date';
public static function getWidgets(): array
{
return [
VisitStatsWidget::class,
];
}
public static function getGloballySearchableAttributes(): array
{
return ['visit_date', 'patientRecord.first_name', 'patientRecord.last_name', 'treatment_description'];
@@ -311,9 +320,11 @@ public static function table(Table $table): Table
->label(__('visits.filters.to_date'))
->jalali(),
])
->columns(2)
->columnSpan(2)
->query(fn ($query, array $data) => $query
->when($data['from_date'], fn ($q) => $q->whereDate('visit_date', '>=', $data['from_date']))
->when($data['to_date'], fn ($q) => $q->whereDate('visit_date', '<=', $data['to_date']))
->when($data['from_date'] ?? null, fn ($q) => $q->whereDate('visit_date', '>=', $data['from_date']))
->when($data['to_date'] ?? null, fn ($q) => $q->whereDate('visit_date', '<=', $data['to_date']))
)
->indicateUsing(function (array $data): array {
$indicators = [];
@@ -344,6 +355,8 @@ public static function table(Table $table): Table
fn ($p) => [$p->id => $p->payment_type]
)->toArray()),
])
->filtersLayout(FiltersLayout::AboveContent)
->filtersFormColumns(5)
->recordActions([
EditAction::make(),
DeleteAction::make(),
@@ -19,4 +19,40 @@ protected function getHeaderActions(): array
->icon('heroicon-o-plus'),
];
}
protected function getHeaderWidgets(): array
{
return VisitResource::getWidgets();
}
public function applyTableFilters(): void
{
parent::applyTableFilters();
$this->dispatchStatsUpdate();
}
public function updatedTableFilters(): void
{
parent::updatedTableFilters();
$this->dispatchStatsUpdate();
}
public function resetTableFiltersForm(): void
{
parent::resetTableFiltersForm();
$this->dispatchStatsUpdate();
}
protected function dispatchStatsUpdate(): void
{
$filters = $this->tableFilters ?? [];
$this->dispatch('visit-stats-updated',
fromDate: ($filters['visit_date_range']['from_date'] ?? null) ?: null,
toDate: ($filters['visit_date_range']['to_date'] ?? null) ?: null,
doctor: isset($filters['doctor']['value']) && $filters['doctor']['value'] !== '' ? (int) $filters['doctor']['value'] : null,
treatment: isset($filters['treatment']['value']) && $filters['treatment']['value'] !== '' ? (int) $filters['treatment']['value'] : null,
paymentType: isset($filters['payment_type']['value']) && $filters['payment_type']['value'] !== '' ? (int) $filters['payment_type']['value'] : null,
);
}
}