Files
investbrain/resources/views/livewire/import-portfolios-field.blade.php
T

79 lines
1.9 KiB
PHP
Raw Normal View History

2024-08-07 19:00:56 -05:00
<?php
2024-08-07 19:02:58 -05:00
use Livewire\WithFileUploads;
2024-08-07 19:00:56 -05:00
use Livewire\Volt\Component;
use Mary\Traits\Toast;
2024-08-27 22:41:13 -05:00
use App\Imports\BackupImport;
2024-08-29 23:36:44 -05:00
use App\Exports\BackupExport;
2024-08-27 22:49:01 -05:00
use Livewire\Attributes\Rule;
2024-08-07 19:00:56 -05:00
new class extends Component {
use Toast;
2024-08-07 19:02:58 -05:00
use WithFileUploads;
2024-08-07 19:00:56 -05:00
// props
2024-08-27 22:49:01 -05:00
#[Rule('required|file|mimes:xlsx|max:2048')]
2024-08-07 19:00:56 -05:00
public $file;
// methods
2024-08-27 22:41:13 -05:00
public function import()
2024-08-07 19:00:56 -05:00
{
2024-08-27 22:49:01 -05:00
$this->validate();
2024-09-19 21:26:29 -05:00
if (!RateLimiter::attempt('import:'.auth()->user()->id, $perMinute = 3, fn()=>null)) {
$this->error(__('Hang on! You\'re doing that too much.'));
return;
}
2024-08-29 21:39:59 -05:00
try {
$import = (new BackupImport)->import($this->file);
} catch (\Throwable $e) {
2024-08-29 23:36:44 -05:00
2024-08-29 21:39:59 -05:00
return $this->error($e->getMessage());
}
2024-08-27 22:41:13 -05:00
2024-08-30 20:22:28 -05:00
$this->success(__('Successfully imported!'), redirectTo: route('dashboard'));
2024-08-29 23:36:44 -05:00
}
2024-08-27 22:41:13 -05:00
2024-08-29 23:36:44 -05:00
public function downloadTemplate()
{
return Excel::download(new BackupExport(empty: true), now()->format('Y_m_d') . '_investbrain_template.xlsx');
2024-08-07 19:00:56 -05:00
}
}; ?>
2024-08-27 22:41:13 -05:00
<x-forms.form-section submit="import">
<x-slot name="title">
{{ __('Import') }}
</x-slot>
<x-slot name="description">
2024-08-29 23:36:44 -05:00
{{ __('Upload or recover your Investbrain portfolio and holdings.') }}
<a href="#" title="{{ __('Click to download import template.') }}" @click="$wire.downloadTemplate()"> {{ __('Download import template.') }}</a>
2024-08-27 22:41:13 -05:00
</x-slot>
<x-slot name="form">
<div class="col-span-6 sm:col-span-4">
<x-file wire:model="file" label="{{ __('Select a file') }}" hint="" accept=".xlsx" required />
</div>
</x-slot>
<x-slot name="actions">
2024-08-30 20:22:28 -05:00
<x-forms.action-message class="me-3" on="saved">
{{ __('Saved.') }}
</x-forms.action-message>
2024-08-27 22:41:13 -05:00
2024-08-30 20:22:28 -05:00
<x-button type="submit" spinner="import">
2024-08-27 22:41:13 -05:00
{{ __('Import') }}
</x-button>
</x-slot>
</x-forms.form-section>