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