Add all files
This commit is contained in:
11
app/Admin/Resources/UserResource/Pages/CreateUser.php
Normal file
11
app/Admin/Resources/UserResource/Pages/CreateUser.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
}
|
||||
36
app/Admin/Resources/UserResource/Pages/EditUser.php
Normal file
36
app/Admin/Resources/UserResource/Pages/EditUser.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('tickets')
|
||||
->label('All Tickets')
|
||||
->icon('ri-customer-service-fill')
|
||||
->url(fn ($record) => "/admin/tickets?tableSearch={$record->email}&activeTab=all", true)
|
||||
->openUrlInNewTab(),
|
||||
Actions\DeleteAction::make()
|
||||
->icon('ri-delete-back-2-fill')
|
||||
->label('Delete User')
|
||||
->hidden(fn ($record) => Auth::user()->id == $record->id),
|
||||
Actions\Action::make('impersonate')
|
||||
->label('Impersonate User')
|
||||
->icon('heroicon-s-user-circle')
|
||||
->action(function ($record) {
|
||||
session()->put('impersonating', $record->id);
|
||||
$this->redirect('/dashboard');
|
||||
})
|
||||
->hidden(fn ($record) => Auth::user()->hasPermission('impersonate', $record) == false || Auth::user()->id == $record->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Admin/Resources/UserResource/Pages/ListUsers.php
Normal file
19
app/Admin/Resources/UserResource/Pages/ListUsers.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
79
app/Admin/Resources/UserResource/Pages/ShowCredits.php
Normal file
79
app/Admin/Resources/UserResource/Pages/ShowCredits.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\UserResource;
|
||||
use App\Models\Currency;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Pages\ManageRelatedRecords;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ShowCredits extends ManageRelatedRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected static string $relationship = 'credits';
|
||||
|
||||
protected static ?string $navigationIcon = 'ri-bill-line';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Credits';
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('currency_code')
|
||||
->options(function () {
|
||||
$existing_currencies = $this->getOwnerRecord()->credits->pluck('currency_code');
|
||||
|
||||
return Currency::whereNotIn('code', $existing_currencies)->pluck('code', 'code');
|
||||
})
|
||||
->live()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('amount')
|
||||
->required()
|
||||
->label('Amount')
|
||||
// Suffix based on chosen currency
|
||||
->prefix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->prefix)
|
||||
->suffix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->suffix)
|
||||
->live(onBlur: true)
|
||||
->mask(RawJs::make(
|
||||
<<<'JS'
|
||||
$money($input, '.', '', 2)
|
||||
JS
|
||||
))
|
||||
->numeric()
|
||||
->minValue(0),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('currency.code')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('currency.code'),
|
||||
Tables\Columns\TextColumn::make('formattedAmount')->label('Formatted Amount'),
|
||||
Tables\Columns\TextInputColumn::make('amount')->label('Amount'),
|
||||
])
|
||||
->filters([])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make()->disabled(function () {
|
||||
$existing_currencies = $this->getOwnerRecord()->credits->pluck('currency_code');
|
||||
|
||||
return count(Currency::whereNotIn('code', $existing_currencies)->pluck('code', 'code')) <= 0;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
56
app/Admin/Resources/UserResource/Pages/ShowInvoices.php
Normal file
56
app/Admin/Resources/UserResource/Pages/ShowInvoices.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\InvoiceResource;
|
||||
use App\Admin\Resources\UserResource;
|
||||
use Filament\Resources\Pages\ManageRelatedRecords;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ShowInvoices extends ManageRelatedRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected static string $relationship = 'invoices';
|
||||
|
||||
protected static ?string $navigationIcon = 'ri-bill-line';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Invoices';
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('product.name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('formattedTotal')->label('Total'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label('Status')
|
||||
// Make first letter uppercase
|
||||
->formatStateUsing(fn (string $state): string => ucfirst($state))
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'paid' => 'success',
|
||||
'pending' => 'warning',
|
||||
default => 'danger',
|
||||
}),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label('Status')
|
||||
->options([
|
||||
'paid' => 'Paid',
|
||||
'pending' => 'Pending',
|
||||
'cancelled' => 'Cancelled',
|
||||
]),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make()->url(fn ($record) => InvoiceResource::getUrl('edit', ['record' => $record])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
40
app/Admin/Resources/UserResource/Pages/ShowServices.php
Normal file
40
app/Admin/Resources/UserResource/Pages/ShowServices.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ServiceResource;
|
||||
use App\Admin\Resources\UserResource;
|
||||
use Filament\Resources\Pages\ManageRelatedRecords;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ShowServices extends ManageRelatedRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected static string $relationship = 'services';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-shopping-cart';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Products/Services';
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('product.name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('product.name'),
|
||||
Tables\Columns\TextColumn::make('quantity'),
|
||||
Tables\Columns\TextColumn::make('formattedPrice')->label('Price'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make()->url(fn ($record) => ServiceResource::getUrl('edit', ['record' => $record])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user