Skip to content

Commit

Permalink
feat: update Announcement resource navigation icon and use of time in…
Browse files Browse the repository at this point in the history
… date handling
  • Loading branch information
vincentauger committed Jan 7, 2025
1 parent 493ddd0 commit a6a8d90
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
29 changes: 11 additions & 18 deletions app/Filament/Resources/AnnouncementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnnouncementResource extends Resource
{
protected static ?string $model = Announcement::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-o-bell';

public static function form(Form $form): Form
{
Expand Down Expand Up @@ -47,21 +47,18 @@ public static function form(Form $form): Form
->maxLength(500),
]),
Forms\Components\Section::make('Dates')
->description('All announcements will start at 00:00:00 UTC and end at 23:59:59 UTC of the dates selected!')
->description('Announcements times are in UTC')
->schema([
Forms\Components\DateTimePicker::make('start_at')
->label('Start Date')
->Time(false)
->default(fn () => now()->startOfDay())
->default(fn () => now())
->required()
->afterOrEqual('yesterday')
->beforeOrEqual('end_at'),
->before('end_at'),
Forms\Components\DateTimePicker::make('end_at')
->label('End Date')
->Time(false)
->default(fn () => now()->endOfDay())
->default(fn () => now()->addDay()->endOfDay())
->required()
->afterOrEqual('start_at'),
->after('start_at'),
]),
]);
}
Expand Down Expand Up @@ -89,9 +86,10 @@ public static function table(Table $table): Table
->label('End (UTC)')
->datetime('M d, Y H:i')
->sortable(),
Tables\Columns\BadgeColumn::make('status')
Tables\Columns\TextColumn::make('status')
->badge(true)
->label('Status')
->getStateUsing(function ($record) {
->getStateUsing(function (Announcement $record) {
$now = Carbon::now();
if ($record->start_at > $now) {
return 'Upcoming';
Expand All @@ -115,12 +113,7 @@ public static function table(Table $table): Table
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['end_at'] = $data['end_at'].'T23:59:59';

return $data;
}),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Expand Down Expand Up @@ -199,7 +192,7 @@ public static function getPages(): array
return [
'index' => Pages\ListAnnouncements::route('/'),
'create' => Pages\CreateAnnouncement::route('/create'),
// 'edit' => Pages\EditAnnouncement::route('/{record}/edit'),
'edit' => Pages\EditAnnouncement::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,4 @@ class CreateAnnouncement extends CreateRecord
protected static string $resource = AnnouncementResource::class;

protected static bool $canCreateAnother = false;

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['end_at'] = $data['end_at'].'T23:59:59';

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class EditAnnouncement extends EditRecord
{
protected static string $resource = AnnouncementResource::class;

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
];
}
// protected function getHeaderActions(): array
// {
// return [
// Actions\ViewAction::make(),
// ];
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ListAnnouncements extends ListRecords
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
Actions\CreateAction::make()
->icon('heroicon-o-plus-circle'),
];
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-o-users';

public static function form(Form $form): Form
{
Expand Down

0 comments on commit a6a8d90

Please sign in to comment.