Files
investbrain/resources/views/portfolio/manage-portfolio-form.blade.php
T

124 lines
3.7 KiB
PHP
Raw Normal View History

2024-08-01 13:53:10 -05:00
<?php
use App\Models\Portfolio;
use App\Traits\Toast;
use App\Traits\WithTrimStrings;
2024-08-01 13:53:10 -05:00
use Livewire\Attributes\Rule;
use Livewire\Volt\Component;
new class extends Component
{
2024-08-01 13:53:10 -05:00
use Toast;
2024-11-06 10:49:12 -06:00
use WithTrimStrings;
2024-08-01 13:53:10 -05:00
2024-08-06 20:41:52 -05:00
// props
2024-08-01 13:53:10 -05:00
public ?Portfolio $portfolio;
public bool $hideCancel = false;
2024-08-01 13:53:10 -05:00
#[Rule('required|min:5')]
public string $title;
2024-08-01 13:53:10 -05:00
#[Rule('sometimes|nullable')]
public ?string $notes;
2024-08-01 13:53:10 -05:00
2024-08-06 20:41:52 -05:00
#[Rule('sometimes|nullable|boolean')]
public bool $wishlist = false;
2024-08-04 18:27:47 -05:00
public bool $confirmingPortfolioDeletion = false;
2024-08-06 20:41:52 -05:00
// methods
public function mount()
2024-08-06 20:41:52 -05:00
{
2024-08-01 13:53:10 -05:00
if (isset($this->portfolio)) {
$this->title = $this->portfolio->title;
$this->notes = $this->portfolio->notes;
2024-08-04 18:27:47 -05:00
$this->wishlist = $this->portfolio->wishlist;
2024-08-01 13:53:10 -05:00
}
}
public function update()
{
2024-10-21 22:23:20 -05:00
$this->authorize('fullAccess', $this->portfolio);
2024-10-21 23:02:18 -05:00
2024-08-01 13:53:10 -05:00
$this->portfolio->update($this->validate());
$this->portfolio->save();
2024-08-06 22:59:17 -05:00
$this->success(__('Portfolio updated'), redirectTo: "/portfolio/{$this->portfolio->id}");
2024-08-01 13:53:10 -05:00
}
public function save()
{
$portfolio = (new Portfolio)->fill($this->validate());
2024-10-21 22:23:20 -05:00
2024-08-01 13:53:10 -05:00
$portfolio->save();
2024-08-06 22:59:17 -05:00
$this->success(__('Portfolio created'), redirectTo: "/portfolio/{$portfolio->id}");
2024-08-01 13:53:10 -05:00
}
2024-08-06 20:41:52 -05:00
public function delete()
2024-08-01 13:53:10 -05:00
{
2024-10-21 22:23:20 -05:00
$this->authorize('fullAccess', $this->portfolio);
2024-08-06 20:41:52 -05:00
$this->portfolio->delete();
2024-08-15 21:35:43 -05:00
$this->success(__('Portfolio deleted'), redirectTo: route('dashboard'));
2024-08-01 13:53:10 -05:00
}
}; ?>
2024-10-22 16:48:53 -05:00
<div class="w-full md:w-3/4">
<x-ui.form wire:submit="{{ $portfolio ? 'update' : 'save' }}" >
<x-ui.input label="{{ __('Title') }}" wire:model="title" required />
2024-08-01 13:53:10 -05:00
<x-ui.textarea class="mt-1" label="{{ __('Notes') }}" wire:model="notes" rows="4" />
2024-10-21 22:23:20 -05:00
2024-10-22 16:48:53 -05:00
@if (isset($this->portfolio))
2024-10-21 22:23:20 -05:00
@livewire('share-portfolio-form', ['portfolio' => $portfolio])
2024-10-22 16:48:53 -05:00
@endif
2024-08-04 18:27:47 -05:00
<x-ui.toggle label="{{ __('Wishlist') }}" wire:model="wishlist" >
2024-08-07 13:06:40 -05:00
<x-slot:hint>
{{ __('Treat this portfolio as a "wishlist" (holdings will be excluded from realized gains, unrealized gains, and dividends)') }}
</x-slot:hint>
</x-ui.toggle>
2024-08-01 13:53:10 -05:00
<x-slot:actions>
2024-08-06 20:41:52 -05:00
@if ($portfolio)
<x-ui.button
wire:click="$toggle('confirmingPortfolioDeletion')"
wire:loading.attr="disabled"
class="btn text-error"
title="{{ __('Delete Portfolio') }}"
label="{{ __('Delete Portfolio') }}"
/>
2024-08-06 20:41:52 -05:00
@endif
2024-08-01 20:44:41 -05:00
@if (!$hideCancel)
<x-ui.button label="{{ __('Cancel') }}" link="/dashboard" />
2024-08-01 20:44:41 -05:00
@endif
<x-ui.button label="{{ $portfolio ? __('Update') : __('Create') }}" type="submit" icon="o-paper-airplane" class="btn-primary" spinner="save" />
2024-08-01 13:53:10 -05:00
</x-slot:actions>
</x-ui.form>
2024-08-06 20:41:52 -05:00
<x-ui.confirmation-modal wire:model.live="confirmingPortfolioDeletion">
2024-08-06 20:41:52 -05:00
<x-slot name="title">
{{ __('Delete Portfolio') }}
</x-slot>
<x-slot name="content">
{{ __('Are you sure you want to delete this portfolio? Once a portfolio is deleted, all of its holdings and other data will be permanently deleted.') }}
</x-slot>
<x-slot name="footer">
<x-ui.button class="btn-outline" wire:click="$toggle('confirmingPortfolioDeletion')" wire:loading.attr="disabled">
2024-08-06 20:41:52 -05:00
{{ __('Cancel') }}
</x-secondary-button>
<x-ui.button class="ms-3 btn-error text-white" wire:click="delete" wire:loading.attr="disabled">
2024-08-06 20:41:52 -05:00
{{ __('Delete Portfolio') }}
</x-ui.button>
2024-08-06 20:41:52 -05:00
</x-slot>
</x-ui.confirmation-modal>
2024-08-01 13:53:10 -05:00
</div>