Chore: Upgrade to Laravel 12 + remove Mary and Jetstream dependencies (#141)
* docs: remove requirement for setting APP_KEY manually * optimize date picker * clean up modals * spot light working * reorganization * add lazy load * wip * remove filament * styling
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use App\Exports\BackupExport;
|
||||
use App\Traits\Toast;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Livewire\Volt\Component;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
use Toast;
|
||||
|
||||
// props
|
||||
|
||||
// methods
|
||||
public function export()
|
||||
{
|
||||
if (! RateLimiter::attempt('export:'.auth()->user()->id, $perMinute = 3, fn () => null)) {
|
||||
|
||||
$this->error(__('Hang on! You\'re doing that too much.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return Excel::download(new BackupExport, now()->format('Y_m_d').'_investbrain_backup.xlsx');
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div>
|
||||
<x-ui.button type="submit" @click="$wire.export" spinner="export">
|
||||
{{ __('Download Export') }}
|
||||
</x-ui.button>
|
||||
</div>
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
use App\Exports\BackupExport;
|
||||
use App\Models\BackupImport as BackupImportModel;
|
||||
use App\Traits\Toast;
|
||||
use Livewire\Attributes\Rule;
|
||||
use Livewire\Volt\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
use Toast;
|
||||
use WithFileUploads;
|
||||
|
||||
// props
|
||||
#[Rule('required|extensions:xlsx|mimes:xlsx|max:2048')]
|
||||
public $file;
|
||||
|
||||
public bool $importStatusDialog = false;
|
||||
|
||||
public ?BackupImportModel $backupImport = null;
|
||||
|
||||
public int $percent = 10;
|
||||
|
||||
// methods
|
||||
public function import()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
if (! RateLimiter::attempt('import:'.auth()->user()->id, $perMinute = 3, fn () => null)) {
|
||||
|
||||
$this->error(__('Hang on! You\'re doing that too much.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->backupImport = BackupImportModel::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'path' => $this->file->getPathname(),
|
||||
]);
|
||||
|
||||
$this->importStatusDialog = true;
|
||||
|
||||
}
|
||||
|
||||
public function checkImportStatus()
|
||||
{
|
||||
if (Str::contains($this->backupImport?->message, 'portfolios')) {
|
||||
|
||||
$this->percent = (1 / 2) * 100;
|
||||
}
|
||||
|
||||
if (Str::contains($this->backupImport?->message, 'transactions')) {
|
||||
|
||||
$this->percent = (3 / 4) * 100;
|
||||
}
|
||||
|
||||
if (Str::contains($this->backupImport?->message, 'daily changes')) {
|
||||
|
||||
$this->percent = (7 / 8) * 100;
|
||||
}
|
||||
|
||||
if ($this->backupImport?->status == 'failed') {
|
||||
|
||||
unset($this->file);
|
||||
$this->percent = 100;
|
||||
}
|
||||
|
||||
if ($this->backupImport?->status == 'success') {
|
||||
|
||||
$this->importStatusDialog = false;
|
||||
$this->backupImport = null;
|
||||
|
||||
$this->success(__('Successfully imported!'), redirectTo: route('dashboard'));
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadTemplate()
|
||||
{
|
||||
return Excel::download(new BackupExport(empty: true), now()->format('Y_m_d').'_investbrain_template.xlsx');
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<x-forms.form-section submit="import">
|
||||
<x-slot name="title">
|
||||
{{ __('Import') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="description">
|
||||
{{ __('Upload or recover your Investbrain portfolio and holdings.') }}
|
||||
<span class="text-xs text-secondary"><a href="#" title="{{ __('Click to download import template.') }}" @click="$wire.downloadTemplate()"> {{ __('Download import template.') }}</a></span>
|
||||
</x-slot>
|
||||
|
||||
<x-slot:form>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-ui.file wire:model="file" label="{{ __('Select a file') }}" hint="" accept=".xlsx" required />
|
||||
</div>
|
||||
|
||||
<x-ui.dialog-modal wire:model.live="importStatusDialog" persistent>
|
||||
<x-slot name="title">
|
||||
|
||||
@if($backupImport?->status)
|
||||
<div
|
||||
class="{{ $backupImport?->status == 'failed' ? 'text-error' : '' }}"
|
||||
>
|
||||
{{ $backupImport?->message }}
|
||||
</div>
|
||||
@endif
|
||||
</x-slot>
|
||||
<x-slot name="content">
|
||||
@if($backupImport?->status != 'failed')
|
||||
<x-ui.progress
|
||||
:indeterminate="$backupImport?->status == 'pending'"
|
||||
class="progress-primary h-3"
|
||||
value="{{ $percent }}"
|
||||
max="100"
|
||||
/>
|
||||
@endif
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="footer">
|
||||
@if($backupImport?->status == 'failed')
|
||||
|
||||
<x-ui.button wire:click="$toggle('importStatusDialog')"> {{ __('Try again') }} </x-ui.button>
|
||||
@else
|
||||
<div wire:poll="checkImportStatus" class="text-gray-400 text-sm">{{ __('Your import will continue in the background') }}</div>
|
||||
<x-ui.flex-spacer />
|
||||
<x-ui.button wire:click="$toggle('importStatusDialog')"> {{ __('Dismiss') }} </x-ui.button>
|
||||
@endif
|
||||
</x-slot>
|
||||
</x-ui.dialog-modal>
|
||||
|
||||
</x-slot:form>
|
||||
|
||||
<x-slot name="actions">
|
||||
|
||||
<x-forms.action-message class="me-3" on="saved">
|
||||
{{ __('Saved.') }}
|
||||
</x-forms.action-message>
|
||||
|
||||
<x-ui.button type="submit" wire:loading.attr="disabled" spinner="import">
|
||||
{{ __('Import') }}
|
||||
</x-ui.button>
|
||||
</x-slot>
|
||||
</x-forms.form-section>
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<x-layouts.app>
|
||||
|
||||
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
|
||||
|
||||
@livewire('import-portfolios-field')
|
||||
|
||||
<x-ui.section-border hide-on-mobile />
|
||||
|
||||
<x-forms.action-section>
|
||||
<x-slot name="title">
|
||||
{{ __('Export') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="description">
|
||||
{{ __('Download all of your portfolios and transactions.') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="content">
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
@livewire('export-portfolios-button')
|
||||
|
||||
</div>
|
||||
|
||||
</x-slot>
|
||||
|
||||
</x-forms.form-section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</x-layouts.app>
|
||||
Reference in New Issue
Block a user