Aplikasi Keuangan yang mengatur lalu lintas transaksi antara bank dan aplikasi internal Kampus
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.
 
 
 
 
 

85 lines
2.6 KiB

<?php
use App\Domains\Academic\Actions\Curriculum\AdjustStudyProgramDetails;
use App\Domains\Academic\Actions\Curriculum\RegisterStudyProgram;
use App\Domains\Academic\DTOs\Curriculum\AdjustStudyProgramDTO;
use App\Domains\Academic\DTOs\Curriculum\RegisterStudyProgramDTO;
use App\Domains\Academic\Models\Faculty;
use App\Domains\Academic\Models\StudyProgram;
use App\Livewire\Concerns\WithModal;
use App\Livewire\Concerns\WithToast;
use App\Livewire\Forms\Academic\StudyProgramForm;
use Illuminate\Support\Collection;
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 StudyProgramForm $form;
protected string $resourceName = 'study_program';
#[Computed]
public function faculties(): Collection
{
return Faculty::all(['id', 'name']);
}
public function save(RegisterStudyProgram $create, AdjustStudyProgramDetails $update): void
{
$this->form->validate();
if ($this->mode === 'create') {
$create->execute(new RegisterStudyProgramDTO(
name: $this->form->name,
code: $this->form->code,
level: $this->form->level,
status: $this->form->status,
facultyId: (int) $this->form->faculty_id,
externalId: (int) $this->form->external_id,
));
} elseif ($this->mode === 'update') {
$update->execute($this->studyProgram, new AdjustStudyProgramDTO(
level: $this->form->level,
status: $this->form->status,
));
}
$this->success($this->message);
$this->dispatch('hide-studyprogram-form-modal');
$this->js("LaravelDataTables['studyprogram-table'].ajax.reload(null, false)");
$this->form->reset();
$this->form->resetValidation();
$this->reset('id', 'mode');
}
#[Computed]
public function studyProgram(): ?StudyProgram
{
return $this->id ? StudyProgram::where('ulid', $this->id)->first() : null;
}
public function show(int|string $id): void
{
$this->id = $id;
$this->mode = 'update';
$this->form->fill($this->studyProgram->only(['name', 'code', 'level', 'status', 'faculty_id', 'external_id']));
}
public function hide(): void
{
$this->form->reset();
$this->form->resetValidation();
$this->reset('id', 'mode');
}
};