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\Academic\Actions\Curriculum\EstablishFaculty;
|
|
use App\Domains\Academic\Actions\Curriculum\ModifyFacultyDetails;
|
|
use App\Domains\Academic\DTOs\Curriculum\EstablishFacultyDTO;
|
|
use App\Domains\Academic\DTOs\Curriculum\ModifyFacultyDetailsDTO;
|
|
use App\Domains\Academic\Models\Faculty;
|
|
use App\Livewire\Concerns\WithModal;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use App\Livewire\Forms\Academic\FacultyForm;
|
|
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 FacultyForm $form;
|
|
|
|
protected string $resourceName = 'faculty';
|
|
|
|
public function save(EstablishFaculty $create, ModifyFacultyDetails $update): void
|
|
{
|
|
$this->form->validate();
|
|
|
|
if ($this->mode === 'create') {
|
|
$create->execute(new EstablishFacultyDTO(
|
|
name: $this->form->name,
|
|
code: $this->form->code,
|
|
externalId: $this->form->external_id,
|
|
));
|
|
} elseif ($this->mode === 'update') {
|
|
$update->execute($this->faculty, new ModifyFacultyDetailsDTO(
|
|
name: $this->form->name,
|
|
code: $this->form->code,
|
|
));
|
|
}
|
|
|
|
$this->success($this->message);
|
|
$this->dispatch('hide-faculty-form-modal');
|
|
$this->js("LaravelDataTables['faculty-table'].ajax.reload(null, false)");
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
|
|
#[Computed]
|
|
public function faculty(): ?Faculty
|
|
{
|
|
return $this->id ? Faculty::where('ulid', $this->id)->first() : null;
|
|
}
|
|
|
|
public function show(int|string $id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->mode = 'update';
|
|
$this->form->fill($this->faculty->only(['name', 'code', 'external_id']));
|
|
}
|
|
|
|
public function hide(): void
|
|
{
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
};
|
|
|