Skip to content

Instantly share code, notes, and snippets.

@BataBoom
Created July 18, 2024 03:22
Show Gist options
  • Save BataBoom/c1d41eb29d0bcd40338e865e6be971d7 to your computer and use it in GitHub Desktop.
Save BataBoom/c1d41eb29d0bcd40338e865e6be971d7 to your computer and use it in GitHub Desktop.
Filament Custom Support Tickets Infolist page
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Components\Section::make()
->schema([
Components\Split::make([
Components\Grid::make(2)
->schema([
Components\Group::make([
Infolists\Components\TextEntry::make('id')->label('ID'),
Infolists\Components\TextEntry::make('ref_id')->label('Shipment ID'),
Infolists\Components\TextEntry::make('winner.name')
->visible(fn (Dispute $record) => !is_null($record->winner_id) || $record->winner_id !== 0)
->label('Dispute Winner'),
]),
Components\Group::make([
Infolists\Components\TextEntry::make('created_at')
->since()
->badge()
->date()
->color('success'),
Components\TextEntry::make('updated_at')
->since()
->badge()
->color('warning'),
Infolists\Components\TextEntry::make('status')
->color('info'),
]),
])->extraAttributes(['class' => 'flex justify-center']),
])->from('md'),
])
->id('manageTicketSection')
->headerActions([
Action::make('Close Dispute')
->action(fn (Dispute $record) => $record->update(['winner_id' => 0]))
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->visible(fn (Dispute $record) => is_null($record->winner_id)),
Action::make('Re-Open Dispute')
->action(fn (Dispute $record) => $record->update(['winner_id' => null]))
->icon('heroicon-o-lock-open')
->color('info')
->requiresConfirmation()
->visible(fn (Dispute $record) => !is_null($record->winner_id)),
Action::make('Set Winner')
->form(fn (Dispute $record) => [
Select::make('author_name')
->label('Select Winner')
->options($record->messages->pluck('author.name', 'author.id')->unique()->toArray())
->required(),
])
->action(function (Dispute $record, array $data) {
// \Log::info($data);
//There isn't a way to close Disputes naturally. Cause I made the system quickly. The best way currently is to set the winner_id to zero. If an admin is selected, ensure that it's set to zero. Ghetto, but works for now..
if($data['author_name'] == 1) {
$data['author_name'] = 0;
}
// Handle the form submission
$record->update([
'winner_id' => $data['author_name'],
]);
})
->icon('heroicon-m-check-circle')
->color('success')
->visible(fn (Dispute $record) => is_null($record->winner_id))
->requiresConfirmation()
->modalDescription('Are you sure you want to set a winner? By doing so automatic jobs will processed, and the dispute will be closed!'),
]),
Components\Section::make('Messages')
->schema([
Components\Split::make([
Components\Grid::make(1)
->schema([
Components\Group::make([
RepeatableEntry::make('messages')->label('')
->schema([
Fieldset::make('')
->schema([
TextEntry::make('author.name')
->label('From')
->size(TextEntry\TextEntrySize::Medium)
->columnSpan(2),
TextEntry::make('created_at')
->since()
->label('Created')
->size(TextEntry\TextEntrySize::Small)
->columnSpan(2),
]),
Components\Group::make([
TextEntry::make('message')
->label('Message')->alignment(Alignment::End)
->size(TextEntry\TextEntrySize::Large),
//->extraAttributes(['class' => 'flex justify-center']),
]),
])->columns(2)->alignment(Alignment::Center),
]),
]),
])->from('lg'),
])->collapsible(),
Components\Section::make('Reply')
->schema([
Livewire::make(NewMessage::class),
])->collapsible(),
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment