You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.0 KiB
71 lines
2.0 KiB
<?php
|
|
|
|
use App\Domains\Admission\Actions\IntakeSourcing\InitializeAdmissionTrack;
|
|
use App\Domains\Admission\DTOs\IntakeSourcing\InitializeAdmissionTrackDTO;
|
|
use App\Domains\Admission\Models\AdmissionTrack;
|
|
use App\Livewire\Concerns\WithModal;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use App\Livewire\Forms\Admission\AdmissionTrackForm;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
use WithModal;
|
|
use WithToast;
|
|
|
|
#[Locked]
|
|
public ?string $id = null;
|
|
|
|
#[Locked]
|
|
public string $mode = 'create';
|
|
|
|
public AdmissionTrackForm $form;
|
|
|
|
protected string $resourceName = 'admission_track';
|
|
|
|
public function save(InitializeAdmissionTrack $create): void
|
|
{
|
|
$this->form->validate();
|
|
|
|
if ($this->mode === 'create') {
|
|
$create->execute(new InitializeAdmissionTrackDTO(
|
|
name: $this->form->name,
|
|
status: $this->form->status,
|
|
));
|
|
} elseif ($this->mode === 'update') {
|
|
$this->admissionTrack->update([
|
|
'name' => $this->form->name,
|
|
'status' => $this->form->status,
|
|
]);
|
|
}
|
|
|
|
$this->success($this->message);
|
|
$this->dispatch('hide-admissiontrack-form-modal');
|
|
$this->js("LaravelDataTables['admissiontrack-table'].ajax.reload(null, false)");
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
|
|
#[Computed]
|
|
public function admissionTrack(): ?AdmissionTrack
|
|
{
|
|
return $this->id ? AdmissionTrack::where('ulid', $this->id)->first() : null;
|
|
}
|
|
|
|
public function show(int|string $id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->mode = 'update';
|
|
$this->form->fill($this->admissionTrack->only(['name', 'status']));
|
|
}
|
|
|
|
public function hide(): void
|
|
{
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
};
|
|
|