init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Tenancy;
|
||||
|
||||
use App\Jobs\SyncCafeBazaarApp;
|
||||
use App\Models\MobileApp;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Tenancy\EditTenantProfile;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
class EditMobileAppProfile extends EditTenantProfile
|
||||
{
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return 'App settings';
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('App identity and availability')->schema([
|
||||
TextInput::make('name')->required()->maxLength(255),
|
||||
TextInput::make('package_name')->required()->regex('/^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/')->unique(MobileApp::class, ignoreRecord: true)->maxLength(255),
|
||||
Toggle::make('is_active')->required(),
|
||||
Toggle::make('maintenance_mode')->required(),
|
||||
TextInput::make('latest_version_name')->maxLength(255),
|
||||
TextInput::make('latest_version_code')->numeric()->minValue(1),
|
||||
TextInput::make('minimum_version_code')->numeric()->minValue(1),
|
||||
TextInput::make('store_url')->url(),
|
||||
TextInput::make('privacy_url')->url(),
|
||||
TextInput::make('support_email')->email(),
|
||||
])->columns(2)->columnSpanFull(),
|
||||
Section::make('API access')->description('Use the client key in Android requests. Keep the management key only on trusted servers and in this panel.')->schema([
|
||||
TextInput::make('client_key')->password()->revealable()->required(),
|
||||
TextInput::make('management_key')->password()->revealable()->required(),
|
||||
])->columns(2)->columnSpanFull(),
|
||||
Section::make('Remote configuration')->schema([
|
||||
KeyValue::make('configuration')->keyLabel('Key')->valueLabel('Value')->columnSpanFull(),
|
||||
KeyValue::make('feature_flags')->keyLabel('Feature')->valueLabel('Enabled or value')->columnSpanFull(),
|
||||
])->columnSpanFull(),
|
||||
Section::make('Cafe Bazaar server API')->description('Per-app tokens from Pishkhan. Secrets are encrypted in the database.')->schema([
|
||||
TextInput::make('bazaar_api_secret')->password()->revealable()->label('Billing and Pishkhan API secret'),
|
||||
TextInput::make('bazaar_comments_header')->label('Comments API header name')->default('CAFEBAZAAR-PISHKHAN-API-SECRET'),
|
||||
TextInput::make('bazaar_comments_secret')->password()->revealable()->label('Comments API secret'),
|
||||
Textarea::make('bazaar_billing_public_key')->rows(5)->label('RSA billing public key')->columnSpanFull(),
|
||||
])->columns(2)->columnSpanFull(),
|
||||
Section::make('Cafe Bazaar synchronization')->description('Refreshes known purchases and subscriptions, imports reviews, and reconciles release state in the background.')->schema([
|
||||
Toggle::make('bazaar_sync_enabled')->label('Automatic synchronization')->required(),
|
||||
TextInput::make('bazaar_sync_interval_minutes')->label('Subscription sync interval (minutes)')->numeric()->minValue(5)->maxValue(1440)->required(),
|
||||
Placeholder::make('bazaar_sync_status')->label('Last result')->content(fn (?MobileApp $record): string => ucfirst($record?->bazaar_sync_status ?? 'idle')),
|
||||
Placeholder::make('bazaar_last_synced_at')->label('Last completed')->content(fn (?MobileApp $record): string => $record?->bazaar_last_synced_at?->diffForHumans() ?? 'Never'),
|
||||
Placeholder::make('bazaar_sync_error')->label('Last error')->content(fn (?MobileApp $record): string => $record?->bazaar_sync_error ?? 'None')->columnSpanFull(),
|
||||
])->columns(2)->columnSpanFull(),
|
||||
Section::make('Login with Bazaar')->schema([
|
||||
TextInput::make('bazaar_login_client_id')->label('Client ID'),
|
||||
TextInput::make('bazaar_login_client_secret')->password()->revealable()->label('Client secret'),
|
||||
TextInput::make('bazaar_login_redirect_url')->url()->label('Registered redirect URL')->columnSpanFull(),
|
||||
])->columns(2)->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('syncBazaar')
|
||||
->label('Sync Bazaar now')
|
||||
->icon(Heroicon::ArrowPath)
|
||||
->requiresConfirmation()
|
||||
->action(function (): void {
|
||||
/** @var MobileApp $app */
|
||||
$app = Filament::getTenant();
|
||||
SyncCafeBazaarApp::dispatch($app->id, true);
|
||||
|
||||
Notification::make()
|
||||
->title('Cafe Bazaar synchronization queued')
|
||||
->body('The dashboard status will update when the background worker finishes.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Tenancy;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Tenancy\RegisterTenant;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RegisterMobileApp extends RegisterTenant
|
||||
{
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return 'Add Android app';
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->required()->maxLength(255),
|
||||
TextInput::make('package_name')->required()->regex('/^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/')->unique(MobileApp::class)->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleRegistration(array $data): MobileApp
|
||||
{
|
||||
$mobileApp = MobileApp::create([
|
||||
...$data,
|
||||
'client_key' => Str::random(48),
|
||||
'management_key' => Str::random(64),
|
||||
'store_url' => 'https://cafebazaar.ir/app/'.$data['package_name'],
|
||||
]);
|
||||
|
||||
$mobileApp->users()->attach(auth()->user(), ['role' => 'owner']);
|
||||
|
||||
return $mobileApp;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user