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