Feat: Adds multi currency support (#88)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Livewire\Volt\Component;
|
||||
use Mary\Traits\Toast;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\BackupExport;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
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-button type="submit" @click="$wire.export" spinner="export">
|
||||
{{ __('Download Export') }}
|
||||
</x-button>
|
||||
</div>
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
use App\Exports\BackupExport;
|
||||
use App\Models\BackupImport as BackupImportModel;
|
||||
use Livewire\Attributes\Rule;
|
||||
use Livewire\Volt\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Mary\Traits\Toast;
|
||||
|
||||
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.') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot:form>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-file wire:model="file" label="{{ __('Select a file') }}" hint="" accept=".xlsx" required />
|
||||
<p class="mt-4 text-xs text-secondary leading-tight"><a href="#" title="{{ __('Click to download import template.') }}" @click="$wire.downloadTemplate()"> {{ __('Download import template.') }}</a></p>
|
||||
</div>
|
||||
|
||||
<x-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-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-button wire:click="$toggle('importStatusDialog')"> {{ __('Try again') }} </x-button>
|
||||
@else
|
||||
<div wire:poll="checkImportStatus" class="text-gray-400 text-sm">{{ __('Your import will continue in the background') }}</div>
|
||||
<x-ib-flex-spacer />
|
||||
<x-button wire:click="$toggle('importStatusDialog')"> {{ __('Close') }} </x-button>
|
||||
@endif
|
||||
</x-slot>
|
||||
</x-dialog-modal>
|
||||
|
||||
</x-slot:form>
|
||||
|
||||
<x-slot name="actions">
|
||||
|
||||
<x-forms.action-message class="me-3" on="saved">
|
||||
{{ __('Saved.') }}
|
||||
</x-forms.action-message>
|
||||
|
||||
<x-button type="submit" wire:loading.attr="disabled" spinner="import">
|
||||
{{ __('Import') }}
|
||||
</x-button>
|
||||
</x-slot>
|
||||
</x-forms.form-section>
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Currency;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
// props
|
||||
|
||||
public Collection $currencies;
|
||||
|
||||
public string $display_currency;
|
||||
|
||||
public ?string $locale;
|
||||
|
||||
public ?User $user;
|
||||
|
||||
// methods
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'locale' => ['required', 'in:'.implode(',', Arr::pluck(config('app.available_locales'), 'locale'))],
|
||||
'display_currency' => ['required', 'exists:currencies,currency'],
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->currencies = Currency::get();
|
||||
$this->display_currency = auth()->user()->getCurrency();
|
||||
$this->locale = auth()->user()->getLocale();
|
||||
$this->user = auth()->user();
|
||||
}
|
||||
|
||||
public function updateProfileInformation()
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
$this->validate();
|
||||
|
||||
$this->user->options = array_merge($this->user->options ?? [], [
|
||||
'locale' => $this->locale,
|
||||
'display_currency' => $this->display_currency,
|
||||
]);
|
||||
|
||||
$this->user->save();
|
||||
|
||||
cache()->tags(['metrics-'.$this->user->id])->flush();
|
||||
|
||||
$this->dispatch('saved');
|
||||
|
||||
//$this->js('window.location.reload();');
|
||||
}
|
||||
}; ?>
|
||||
<x-forms.form-section submit="updateProfileInformation">
|
||||
<x-slot name="title">
|
||||
{{ __('Locale Options') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="description">
|
||||
{{ __('Adjust localization options for your preferred region.') }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="form">
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-select
|
||||
label="{{ __('Locale') }}"
|
||||
class="select block mt-1 w-full"
|
||||
:options="config('app.available_locales')"
|
||||
option-value="locale"
|
||||
option-label="label"
|
||||
placeholder="Choose a locale"
|
||||
wire:model="locale"
|
||||
id="locale"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-select
|
||||
label="{{ __('Display Currency') }}"
|
||||
class="select block mt-1 w-full"
|
||||
:options="$currencies"
|
||||
option-value="currency"
|
||||
option-label="label"
|
||||
placeholder="Choose a display currency"
|
||||
wire:model="display_currency"
|
||||
id="display_currency"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="actions">
|
||||
<x-forms.action-message class="me-3" on="saved">
|
||||
{{ __('Saved.') }}
|
||||
</x-forms.action-message>
|
||||
|
||||
<x-button type="submit">
|
||||
{{ __('Save') }}
|
||||
</x-button>
|
||||
</x-slot>
|
||||
</x-forms.form-section>
|
||||
@@ -7,7 +7,13 @@
|
||||
|
||||
<x-section-border hide-on-mobile />
|
||||
@endif
|
||||
|
||||
<div class="mt-10 sm:mt-0">
|
||||
@livewire('localization-form')
|
||||
</div>
|
||||
|
||||
<x-section-border hide-on-mobile />
|
||||
|
||||
@if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()))
|
||||
<div class="mt-10 sm:mt-0">
|
||||
@livewire('profile.update-password-form')
|
||||
|
||||
Reference in New Issue
Block a user