2024-08-01 13:53:10 -05:00
< ? php
use App\Models\Portfolio ;
use Illuminate\Support\Collection ;
use Livewire\Attributes\Rule ;
use Livewire\Volt\Component ;
use Mary\Traits\Toast ;
new class extends Component {
use Toast ;
2024-08-06 20:41:52 -05:00
// props
2024-08-01 13:53:10 -05:00
public ? Portfolio $portfolio ;
2024-08-01 20:44:41 -05:00
public Bool $hideCancel = false ;
2024-08-01 13:53:10 -05:00
#[Rule('required|min:5')]
2024-08-06 20:41:52 -05:00
public String $title ;
2024-08-01 13:53:10 -05:00
#[Rule('sometimes|nullable')]
2024-08-06 20:41:52 -05:00
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
2024-08-06 20:41:52 -05:00
public Bool $confirmingPortfolioDeletion = false ;
// methods
public function mount ()
{
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-ib-form wire:submit="{{ $portfolio ? 'update' : 'save' }}" >
2024-08-06 22:59:17 -05:00
<x-input label="{{ __('Title') }}" wire:model="title" required />
2024-08-01 13:53:10 -05:00
2024-10-31 12:09:06 -05:00
<x-ib-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
2024-10-22 16:48:53 -05:00
<x-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-toggle>
2024-08-01 13:53:10 -05:00
<x-slot:actions>
2024-08-06 20:41:52 -05:00
@if ($portfolio)
2024-09-18 19:51:05 -05:00
<x-button
wire:click="$toggle('confirmingPortfolioDeletion')"
wire:loading.attr="disabled"
2024-10-28 19:32:04 -05:00
class="btn text-error"
2024-09-18 19:51:05 -05:00
title="{{ __('Delete Portfolio') }}"
2024-10-28 19:32:04 -05:00
label="{{ __('Delete Portfolio') }}"
2024-09-18 19:51:05 -05:00
/>
2024-08-06 20:41:52 -05:00
@endif
2024-08-01 20:44:41 -05:00
@if (!$hideCancel)
2024-09-18 19:51:05 -05:00
<x-button label="{{ __('Cancel') }}" link="/dashboard" />
2024-08-01 20:44:41 -05:00
@endif
2024-10-18 20:46:22 -05:00
<x-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>
2024-09-18 19:51:05 -05:00
</x-ib-form>
2024-08-06 20:41:52 -05:00
<x-confirmation-modal wire:model.live="confirmingPortfolioDeletion">
<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-button class="btn-outline" wire:click="$toggle('confirmingPortfolioDeletion')" wire:loading.attr="disabled">
{{ __('Cancel') }}
</x-secondary-button>
<x-button class="ms-3 btn-error text-white" wire:click="delete" wire:loading.attr="disabled">
{{ __('Delete Portfolio') }}
</x-button>
</x-slot>
</x-confirmation-modal>
2024-08-01 13:53:10 -05:00
</div>