-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: apply flex layout and add page filter component
- Applied flex layout and added the page filter component to the employee, division, and level pages for better UI/UX.
- Loading branch information
Mahatma Mahardhika
committed
Aug 6, 2024
1 parent
be1796d
commit a271606
Showing
23 changed files
with
574 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
class SubDivisionController extends Controller | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\Department; | ||
use App\Models\SubDivision; | ||
use DB; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Validation\ValidationException; | ||
use Livewire\Attributes\On; | ||
use Livewire\Attributes\Validate; | ||
use Livewire\Component; | ||
|
||
class SubDivisionForm extends Component | ||
{ | ||
public $departmentId; | ||
|
||
#[Validate('required|unique:sub_divisions|min:3')] | ||
public $code; | ||
|
||
#[Validate('required|min:3')] | ||
public $name; | ||
|
||
public $subDivision; | ||
|
||
public $actionForm = 'save'; | ||
|
||
/** | ||
* Updates the specified property with the given value and performs validation if the property is 'code', | ||
* 'email', or 'phone'. | ||
* | ||
* @param string $key The name of the property to be updated. | ||
* @param mixed $value The new value for the property. | ||
* @return void | ||
* @throws ValidationException | ||
*/ | ||
public function updated(string $key, mixed $value): void | ||
{ | ||
$this->resetErrorBag(); | ||
|
||
if($key == 'code' || $key == 'name'){ | ||
$this->validateOnly($key); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the department ID based on the provided department code. | ||
* | ||
* @param string $departmentCode The code of the department. | ||
* @return void | ||
*/ | ||
#[On('setDepartment')] | ||
public function setDepartment(string $departmentCode): void | ||
{ | ||
$department = Department::where('code', $departmentCode)->first(); | ||
|
||
if(!$department){ | ||
$this->dispatch('setErrorDepartment'); | ||
return; | ||
} | ||
|
||
$this->departmentId = $department->id; | ||
} | ||
|
||
/** | ||
* The default data for the form. | ||
* | ||
* @return array | ||
*/ | ||
public function subDivisionData(): array | ||
{ | ||
return [ | ||
'company_id' => auth()->user()->details->company_id, | ||
'branch_id' => auth()->user()->details->branch_id, | ||
'department_id' => $this->departmentId, | ||
'code' => $this->code, | ||
'name' => $this->name, | ||
]; | ||
} | ||
|
||
/** | ||
* Saves the subDivision details to the database and dispatches a 'sub-division-created' event. | ||
* | ||
* @return void | ||
*/ | ||
public function save(): void | ||
{ | ||
if(!$this->departmentId){ | ||
$this->dispatch('setErrorDepartment'); | ||
return; | ||
} | ||
|
||
$this->validate(); | ||
|
||
DB::transaction(function () { | ||
$this->subDivision = SubDivision::create($this->subDivisionData()); | ||
}, 5); | ||
|
||
$this->dispatch('sub-division-created', subDivisionId: $this->subDivision->id); | ||
|
||
$this->reset(); | ||
} | ||
|
||
/** | ||
* Edit the subDivision details. | ||
*/ | ||
#[On('edit')] | ||
public function edit($code): void | ||
{ | ||
$this->subDivision = SubDivision::where('code',$code)->first(); | ||
$this->departmentId = $this->subDivision->department_id; | ||
|
||
$this->dispatch('selectDepartment', departmentId: $this->departmentId ); | ||
|
||
$this->code = $this->subDivision->code; | ||
$this->name = $this->subDivision->name; | ||
|
||
$this->actionForm = 'update'; | ||
|
||
$this->dispatch('show-form'); | ||
} | ||
|
||
/** | ||
* Updates the subDivision details in the database. | ||
*/ | ||
public function update(): void | ||
{ | ||
if(!$this->departmentId){ | ||
$this->dispatch('setErrorDepartment'); | ||
return; | ||
} | ||
|
||
DB::transaction(function () { | ||
$this->subDivision->update($this->subDivisionData()); | ||
}, 5); | ||
|
||
$this->dispatch('sub-division-updated', subDivisionId: $this->subDivision->id); | ||
|
||
$this->reset(); | ||
} | ||
|
||
/** | ||
* Deletes the subDivision from the database. | ||
*/ | ||
#[On('delete')] | ||
public function destroy($code): void | ||
{ | ||
$this->subDivision = SubDivision::where('code',$code)->first(); | ||
$this->subDivision->code = $code . '-deleted'; | ||
$this->subDivision->save(); | ||
|
||
$this->subDivision->delete(); | ||
|
||
$this->dispatch('sub-division-deleted', refreshCompanies: true); | ||
} | ||
|
||
/** | ||
* Render the livewire component. | ||
* | ||
* @return View | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.sub-division-form', [ | ||
'departments' => Department::all(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use Illuminate\Contracts\View\View; | ||
use Livewire\Component; | ||
|
||
class SubDivisionPage extends Component | ||
{ | ||
public $moduleLabel = 'Sub Division'; | ||
|
||
/** | ||
* Renders the view for the unit page. | ||
* | ||
* @return View The rendered view. | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.sub-division-page') | ||
->layout('components.layouts.dashboard'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\SubDivision; | ||
use Illuminate\Contracts\Pagination\LengthAwarePaginator; | ||
use Illuminate\Contracts\View\View; | ||
use Livewire\Attributes\On; | ||
use Livewire\Attributes\Url; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class SubDivisionTable extends Component | ||
{ | ||
use withPagination; | ||
public $showForm = false; | ||
|
||
#[Url] | ||
public $search; | ||
|
||
/** | ||
* Handles the event when a subDivision is created. | ||
* | ||
* @param int $subDivisionId The ID of the created subDivision. | ||
* @return void | ||
*/ | ||
#[On('sub-division-created')] | ||
public function subDivisionAdded(int $subDivisionId): void | ||
{ | ||
$this->showForm = false; | ||
} | ||
|
||
/** | ||
* Handles the event when a subDivision is updated. | ||
* | ||
* @param int $subDivisionId The ID of the updated subDivision. | ||
* @return void | ||
*/ | ||
#[On('sub-division-updated')] | ||
public function subDivisionUpdated(int $subDivisionId): void | ||
{ | ||
$this->showForm = false; | ||
} | ||
|
||
/** | ||
* Handles the event when a subDivision is deleted. | ||
* @return void | ||
*/ | ||
#[On('sub-division-deleted')] | ||
public function subDivisionDeleted(): void | ||
{ | ||
$this->showForm = false; | ||
$this->resetPage(); | ||
$this->getSubDivisions(); | ||
} | ||
|
||
/** | ||
* Shows the form subDivision. | ||
* | ||
* @return void | ||
*/ | ||
#[On('show-form')] | ||
public function showForm(): void | ||
{ | ||
$this->showForm = true; | ||
} | ||
|
||
/** | ||
* Retrieves a paginated list of subDivisions based on a search query. | ||
* | ||
* @return LengthAwarePaginator The paginated list of subDivisions. | ||
*/ | ||
public function getSubDivisions(): LengthAwarePaginator | ||
{ | ||
return SubDivision::where(function ($query){ | ||
$query->where('name', 'like', '%' . $this->search . '%') | ||
->orWhere('code', 'like', '%' . $this->search . '%'); | ||
}) | ||
->orderBy('id', 'asc') | ||
->paginate(5); | ||
} | ||
|
||
/** | ||
* Render the livewire component. | ||
* | ||
* @return View | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.sub-division-table',[ | ||
'subDivisions' => self::getSubDivisions() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.