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.
74 lines
2.1 KiB
74 lines
2.1 KiB
<?php
|
|
|
|
use App\Domains\Admission\Actions\StudyModeProvisioning\DefineProgramTrack;
|
|
use App\Domains\Admission\DTOs\StudyModeProvisioning\DefineProgramTrackDTO;
|
|
use App\Domains\Admission\Models\ProgramTrack;
|
|
use App\Domains\System\Enums\LifecycleStatus;
|
|
use App\Livewire\Concerns\WithModal;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use App\Livewire\Forms\Admission\ProgramTrackForm;
|
|
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 ProgramTrackForm $form;
|
|
|
|
protected string $resourceName = 'program-track';
|
|
|
|
public function save(DefineProgramTrack $create): void
|
|
{
|
|
$this->form->validate();
|
|
|
|
if ($this->mode === 'create') {
|
|
$create->execute(new DefineProgramTrackDTO(
|
|
name: $this->form->name,
|
|
code: $this->form->code,
|
|
status: $this->form->status,
|
|
));
|
|
} elseif ($this->mode === 'update') {
|
|
$this->programTrack->update([
|
|
'name' => $this->form->name,
|
|
'code' => $this->form->code,
|
|
'status' => $this->form->status,
|
|
]);
|
|
}
|
|
|
|
$this->success($this->message);
|
|
$this->dispatch('hide-programtrack-form-modal');
|
|
$this->js("LaravelDataTables['programtrack-table'].ajax.reload(null, false)");
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
|
|
#[Computed]
|
|
public function programTrack(): ?ProgramTrack
|
|
{
|
|
return $this->id ? ProgramTrack::where('ulid', $this->id)->first() : null;
|
|
}
|
|
|
|
public function show(int|string $id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->mode = 'update';
|
|
$this->form->fill($this->programTrack->only(['name', 'code', 'status']));
|
|
}
|
|
|
|
public function hide(): void
|
|
{
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
};
|
|
|