-
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.
feat(livewire): add FormBranchOption component
- Added FormBranchOption component to handle branch selection in the user form - Included blade file for FormBranchOption component in the user form view - Implemented functionality to fetch and display branches based on selected company code - Updated UserForm component to include branch ID in user detail data - Updated FormCompanyOption component to dispatch 'getBranch' event when company code is set - Updated FormDepartmentOption component to handle cases where company is not found See the changes for more details.
- Loading branch information
Mahatma Mahardhika
committed
Aug 6, 2024
1 parent
02bb103
commit be1796d
Showing
6 changed files
with
125 additions
and
14 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,75 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\Branch; | ||
use App\Models\Company; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\On; | ||
use Livewire\Attributes\Url; | ||
use Livewire\Component; | ||
|
||
class FormBranchOption extends Component | ||
{ | ||
|
||
public $companyId; | ||
|
||
#[Url(keep:true)] | ||
public $companyCode = "all"; | ||
|
||
public $branchCode; | ||
|
||
public $option = 'disabled'; | ||
|
||
public $branches; | ||
|
||
public function mount(): void | ||
{ | ||
$this->reset(); | ||
|
||
if($this->companyCode != "all") { | ||
$company = Company::where('code', $this->companyCode)->first(); | ||
|
||
if($company) { | ||
$this->option = ""; | ||
$this->companyId = $company->id; | ||
$this->branches = $company->branches; | ||
} | ||
} | ||
} | ||
|
||
#[On('getBranch')] | ||
public function getBranch($companyCode): void | ||
{ | ||
$this->reset([ | ||
'branches', | ||
'option' | ||
]); | ||
|
||
$company = Company::where('code', $companyCode)->first(); | ||
|
||
if(!$company) { | ||
$this->option = "disabled"; | ||
return; | ||
} | ||
|
||
$this->option = ""; | ||
$this->companyId = $company->id; | ||
|
||
if($company->branches()->count() > 0) { | ||
$this->option = ""; | ||
$this->branches = $company->branches; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Render the view for the Livewire component. | ||
* | ||
* @return View | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.form-branch-option'); | ||
} | ||
} |
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
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,24 @@ | ||
<div class="flex flex-col gap-3"> | ||
<label for="branchCode" class="block text-sm font-medium text-gray-700">Branch</label> | ||
<select | ||
wire:model.live="branchCode" | ||
id="branchCode" | ||
class="mt-1 shadow-sm focus:ring-indigo-500 | ||
focus:border-indigo-500 block w-full | ||
sm:text-sm border border-gray-300 | ||
rounded-md p-2" | ||
{{$option}} | ||
> | ||
<option value="all">Select Branch</option> | ||
@if($branches) | ||
@foreach ($branches as $branch) | ||
<option value="{{ $branch->code }}">{{ $branch->name }}</option> | ||
@endforeach | ||
@endif | ||
</select> | ||
@error('branchCode') | ||
<div class="p-4 mb-4 text-sm text-red-700 bg-red-100 rounded-lg dark:bg-red-200 dark:text-red-800" role="alert"> | ||
<span class="font-medium">Error!</span> {{ $message }} | ||
</div> | ||
@enderror | ||
</div> |
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