Skip to content
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
8 changes: 4 additions & 4 deletions app/Filament/Resources/SupportTicketResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static function infolist(Schema $schema): Schema
Infolists\Components\TextEntry::make('issue_type')
->label('Issue Type')
->placeholder('N/A'),
Infolists\Components\TextEntry::make('user.name')
Infolists\Components\TextEntry::make('user.email')
->label('User')
->formatStateUsing(fn (SupportTicket $record): string => ($record->user->name ?? '').' ('.$record->user->email.')')
->formatStateUsing(fn (SupportTicket $record): string => trim(($record->user->name ?? '').' ('.$record->user->email.')'))
->url(fn (SupportTicket $record): string => UserResource::getUrl('edit', ['record' => $record->user_id])),
Infolists\Components\TextEntry::make('created_at')
->label('Created')
Expand Down Expand Up @@ -97,9 +97,9 @@ public static function table(Table $table): Table
->sortable()
->limit(50),

Tables\Columns\TextColumn::make('user.name')
Tables\Columns\TextColumn::make('user.email')
->label('User')
->formatStateUsing(fn (SupportTicket $record): string => ($record->user->name ?? '').' ('.$record->user->email.')')
->formatStateUsing(fn (SupportTicket $record): string => trim(($record->user->name ?? '').' ('.$record->user->email.')'))
->searchable(query: fn ($query, string $search) => $query->whereHas('user', fn ($q) => $q->where('name', 'like', "%{$search}%")->orWhere('email', 'like', "%{$search}%")))
->sortable(),

Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/SupportTicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature;

use App\Filament\Resources\SupportTicketResource\Pages\ViewSupportTicket;
use App\Filament\Resources\SupportTicketResource\Widgets\TicketRepliesWidget;
use App\Livewire\Customer\Support\Create;
use App\Livewire\Customer\Support\Index;
Expand Down Expand Up @@ -1138,6 +1139,37 @@ public function only_internal_notes_can_be_pinned(): void
->call('togglePin', $reply->id);
}

#[Test]
public function admin_view_page_shows_user_email_when_name_is_null(): void
{
$admin = User::factory()->create(['email' => 'admin@test.com']);
config(['filament.users' => ['admin@test.com']]);

$namelessUser = User::factory()->create(['name' => null]);
$ticket = SupportTicket::factory()->create(['user_id' => $namelessUser->id]);

Livewire::actingAs($admin)
->test(ViewSupportTicket::class, ['record' => $ticket->getRouteKey()])
->assertOk()
->assertSee($namelessUser->email);
}

#[Test]
public function admin_view_page_shows_name_and_email_when_user_has_name(): void
{
$admin = User::factory()->create(['email' => 'admin@test.com']);
config(['filament.users' => ['admin@test.com']]);

$namedUser = User::factory()->create(['name' => 'Jane Doe']);
$ticket = SupportTicket::factory()->create(['user_id' => $namedUser->id]);

Livewire::actingAs($admin)
->test(ViewSupportTicket::class, ['record' => $ticket->getRouteKey()])
->assertOk()
->assertSee('Jane Doe')
->assertSee($namedUser->email);
}

#[Test]
public function guests_cannot_access_ticket_index(): void
{
Expand Down
Loading