refactor: update NavbarLinkResource to improve form handling and error fallback logic, ensuring better data management and user experience
This commit is contained in:
@@ -4,17 +4,12 @@ namespace Paymenter\Extensions\Others\NavbarManager\Admin\Resources;
|
||||
|
||||
use Paymenter\Extensions\Others\NavbarManager\Models\NavbarLink;
|
||||
use Paymenter\Extensions\Others\NavbarManager\Admin\Resources\NavbarLinkResource\Pages;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class NavbarLinkResource extends Resource
|
||||
{
|
||||
@@ -100,7 +95,7 @@ class NavbarLinkResource extends Resource
|
||||
|
||||
// Add pricing info if available
|
||||
if ($product->price > 0) {
|
||||
$label .= " (${$product->price})";
|
||||
$label .= " (\${$product->price})";
|
||||
}
|
||||
|
||||
// Add description if available
|
||||
@@ -114,11 +109,7 @@ class NavbarLinkResource extends Resource
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Fallback if there's an error
|
||||
$products = [
|
||||
1 => 'Minecraft Server - 1GB RAM',
|
||||
2 => 'Minecraft Server - 6GB RAM',
|
||||
3 => 'Rust Server - 4GB RAM',
|
||||
];
|
||||
$products = [];
|
||||
}
|
||||
|
||||
return $products;
|
||||
@@ -150,19 +141,15 @@ class NavbarLinkResource extends Resource
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Fallback if there's an error
|
||||
$categories = [
|
||||
1 => 'Gaming Servers',
|
||||
2 => 'Web Hosting',
|
||||
3 => 'VPS Hosting',
|
||||
];
|
||||
$categories = [];
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $schema
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Link Name')
|
||||
@@ -186,7 +173,7 @@ class NavbarLinkResource extends Resource
|
||||
->preload()
|
||||
->placeholder('Select parent (optional)'),
|
||||
|
||||
Section::make('Link Destination')
|
||||
Forms\Components\Section::make('Link Destination')
|
||||
->description('Configure the link destination')
|
||||
->schema([
|
||||
Forms\Components\Select::make('link_type')
|
||||
@@ -435,12 +422,12 @@ class NavbarLinkResource extends Resource
|
||||
Tables\Filters\TernaryFilter::make('is_active')
|
||||
->label('Active Status'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->defaultSort('sort_order');
|
||||
|
||||
Reference in New Issue
Block a user