interim fix for drop downs

This commit is contained in:
Mark Gregory
2026-07-07 11:57:02 +01:00
parent fd63173736
commit 9cc2ce530e
9 changed files with 520 additions and 323 deletions
@@ -18,11 +18,11 @@ class CompanyController extends Controller
{ {
return view('company::index', [ return view('company::index', [
'companies' => Company::query() 'companies' => Company::query()
->with(['address.country', 'country']) ->with(['address.country'])
->withCount(['users', 'warehouses', 'licenseKeys', 'divisions']) ->withCount(['users', 'warehouses', 'licenseKeys', 'divisions'])
->latest('id') ->latest('id')
->paginate(20), ->paginate(20),
'countries' => $this->countries(), 'countries' => $this->countriesForSelect(),
]); ]);
} }
@@ -36,7 +36,7 @@ class CompanyController extends Controller
'status' => 'active', 'status' => 'active',
'timezone' => 'Europe/London', 'timezone' => 'Europe/London',
]), ]),
'countries' => $this->countries(), 'countries' => $this->countriesForSelect(),
]); ]);
} }
@@ -45,7 +45,10 @@ class CompanyController extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$company = Company::create($this->validated($request)); $validated = $this->validated($request);
$company = Company::create($validated['company']);
$this->syncAddressCountry($company, $validated['country_id']);
return redirect() return redirect()
->route('platform.companies.index') ->route('platform.companies.index')
@@ -73,7 +76,7 @@ class CompanyController extends Controller
'recentUsers' => $company->users()->latest('id')->limit(5)->get(), 'recentUsers' => $company->users()->latest('id')->limit(5)->get(),
'recentWarehouses' => $company->warehouses()->latest('id')->limit(5)->get(), 'recentWarehouses' => $company->warehouses()->latest('id')->limit(5)->get(),
'recentLicenseKeys' => $company->licenseKeys()->latest('id')->limit(5)->get(), 'recentLicenseKeys' => $company->licenseKeys()->latest('id')->limit(5)->get(),
'countries' => Country::query()->active()->orderBy('sort_order')->orderBy('name')->get(['id', 'alpha2', 'name', 'display_name', 'common_name']), 'countries' => $this->countriesForSelect(),
'companyUsers' => $company->users()->orderBy('name')->get(['id', 'name', 'email', 'company_id']), 'companyUsers' => $company->users()->orderBy('name')->get(['id', 'name', 'email', 'company_id']),
'unassignedWarehouses' => $company->warehouses()->whereNull('division_id')->orderBy('name')->get(), 'unassignedWarehouses' => $company->warehouses()->whereNull('division_id')->orderBy('name')->get(),
]); ]);
@@ -85,8 +88,8 @@ class CompanyController extends Controller
public function edit(Company $company) public function edit(Company $company)
{ {
return view('company::edit', [ return view('company::edit', [
'company' => $company->loadMissing(['address.country', 'country']), 'company' => $company->loadMissing('address.country'),
'countries' => $this->countries(), 'countries' => $this->countriesForSelect(),
]); ]);
} }
@@ -95,7 +98,10 @@ class CompanyController extends Controller
*/ */
public function update(Request $request, Company $company) public function update(Request $request, Company $company)
{ {
$company->update($this->validated($request, $company)); $validated = $this->validated($request, $company);
$company->update($validated['company']);
$this->syncAddressCountry($company, $validated['country_id']);
return redirect() return redirect()
->route('platform.companies.show', $company) ->route('platform.companies.show', $company)
@@ -122,20 +128,44 @@ class CompanyController extends Controller
'name' => ['required', 'string', 'max:255'], 'name' => ['required', 'string', 'max:255'],
'billing_email' => ['nullable', 'email', 'max:255'], 'billing_email' => ['nullable', 'email', 'max:255'],
'status' => ['required', Rule::in(['active', 'suspended', 'inactive'])], 'status' => ['required', Rule::in(['active', 'suspended', 'inactive'])],
'country_id' => ['nullable', Rule::exists('countries', 'id')->where('is_active', true)], 'country_id' => ['nullable', 'integer', Rule::exists('countries', 'id')],
]); ]);
$data['slug'] = Str::slug($data['name']); return [
$data['timezone'] = $company?->timezone ?: 'Europe/London'; 'company' => [
'name' => $data['name'],
return $data; 'billing_email' => $data['billing_email'] ?? null,
'status' => $data['status'],
'slug' => Str::slug($data['name']),
'timezone' => $company?->timezone ?: 'Europe/London',
],
'country_id' => $data['country_id'] ?? null,
];
} }
private function countries() private function countriesForSelect()
{ {
return Country::query() return Country::query()
->active() ->active()
->ordered() ->orderByRaw("LOWER(COALESCE(NULLIF(display_name, ''), NULLIF(common_name, ''), name)) ASC")
->get(['id', 'alpha2', 'name', 'display_name', 'common_name', 'sort_order']); ->get(['id', 'alpha2', 'name', 'display_name', 'common_name']);
}
private function syncAddressCountry(Company $company, ?int $countryId): void
{
if ($countryId === null) {
$company->address()?->delete();
return;
}
$company->address()->updateOrCreate(
[],
[
'country_id' => $countryId,
'label' => 'Registered address',
'is_primary' => true,
]
);
} }
} }
+199 -24
View File
@@ -1,13 +1,13 @@
@csrf @csrf
<div class="grid gap-6 md:grid-cols-2"> <div class="grid gap-6 lg:grid-cols-2">
<div> <div>
<label for="name" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Company name</label> <label for="name" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Company name</label>
<input <input
id="name" id="name"
name="name" name="name"
value="{{ old('name', $company->name) }}" value="{{ old('name', $company->name) }}"
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
required required
> >
@error('name') @error('name')
@@ -23,7 +23,7 @@
name="billing_email" name="billing_email"
value="{{ old('billing_email', $company->billing_email) }}" value="{{ old('billing_email', $company->billing_email) }}"
placeholder="billing@example.com" placeholder="billing@example.com"
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
> >
@error('billing_email') @error('billing_email')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p> <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@@ -35,7 +35,7 @@
<select <select
id="status" id="status"
name="status" name="status"
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
required required
> >
<option value="active" @selected(old('status', $company->status) === 'active')>Active</option> <option value="active" @selected(old('status', $company->status) === 'active')>Active</option>
@@ -47,25 +47,26 @@
@enderror @enderror
</div> </div>
<div class="wms-form-field wms-select2-field"> <div>
<label for="country_id" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Country</label> <label for="country_id" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Country</label>
<div class="mt-2"> <select
<select id="country_id"
id="country_id" name="country_id"
name="country_id" data-company-country-select2
data-wms-select2 data-placeholder="Search and select country"
data-placeholder="Search and select country" class="wms-country-select mt-2 w-full"
class="wms-country-select w-full" >
> <option value=""></option>
<option value="">Search and select country</option> @foreach($countries as $country)
@foreach ($countries as $country) <option
<option value="{{ $country->id }}" @selected((int) old('country_id', $company->country_id ?? $company->address?->country_id) === $country->id)> value="{{ $country->id }}"
{{ $country->effective_name ?? $country->name }} data-code="{{ $country->alpha2 }}"
</option> @selected(old('country_id', $company->address?->country_id) == $country->id)
@endforeach >
</select> {{ $country->display_name ?? $country->common_name ?? $country->name }}
</div> </option>
<p class="mt-2 text-xs font-medium text-zinc-500 dark:text-zinc-400">Start typing to filter the country list.</p> @endforeach
</select>
@error('country_id') @error('country_id')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p> <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror @enderror
@@ -73,14 +74,188 @@
</div> </div>
<div class="mt-8 flex flex-wrap items-center gap-3 border-t border-zinc-200 pt-6 dark:border-zinc-800"> <div class="mt-8 flex flex-wrap items-center gap-3 border-t border-zinc-200 pt-6 dark:border-zinc-800">
<button class="inline-flex items-center justify-center rounded-xl bg-green-600 px-5 py-2.5 text-sm font-bold text-white shadow-sm shadow-green-600/20 transition hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 dark:bg-green-500 dark:text-white dark:hover:bg-green-400 dark:focus:ring-offset-zinc-900"> <button class="rounded-xl bg-green-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm shadow-green-950/20 transition hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-green-500/40">
Save company Save company
</button> </button>
<a <a
href="{{ $company->exists ? route('platform.companies.show', $company) : route('platform.companies.index') }}" href="{{ $company->exists ? route('platform.companies.show', $company) : route('platform.companies.index') }}"
class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800" class="rounded-xl border border-zinc-300 px-5 py-2.5 text-sm font-semibold text-zinc-700 transition hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800"
> >
Cancel Cancel
</a> </a>
</div> </div>
@once
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
<style>
.wms-country-select.select2-hidden-accessible {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0, 0, 0, 0) !important;
white-space: nowrap !important;
border: 0 !important;
}
.wms-country-select + .select2-container {
display: block !important;
width: 100% !important;
margin-top: 0.5rem !important;
}
.wms-country-select + .select2-container .select2-selection--single {
height: 3rem !important;
min-height: 3rem !important;
display: flex !important;
align-items: center !important;
border-radius: 0.75rem !important;
border: 1px solid rgb(63 63 70) !important;
background: rgb(9 9 11) !important;
box-shadow: none !important;
transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease !important;
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__rendered {
width: 100% !important;
height: 3rem !important;
line-height: 3rem !important;
padding-left: 1rem !important;
padding-right: 2.75rem !important;
color: rgb(244 244 245) !important;
font-size: 0.875rem !important;
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__placeholder {
color: rgb(161 161 170) !important;
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__arrow {
height: 3rem !important;
right: 0.75rem !important;
top: 0 !important;
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__arrow b {
border-color: rgb(161 161 170) transparent transparent transparent !important;
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__clear {
margin-right: 0.5rem !important;
color: rgb(161 161 170) !important;
font-size: 1rem !important;
font-weight: 700 !important;
}
.wms-country-select + .select2-container.select2-container--focus .select2-selection--single,
.wms-country-select + .select2-container.select2-container--open .select2-selection--single {
border-color: rgb(59 130 246) !important;
box-shadow: 0 0 0 3px rgb(59 130 246 / 0.28) !important;
}
.select2-container--open .select2-dropdown.wms-country-select2-dropdown,
.wms-country-select2-dropdown {
border: 1px solid rgb(63 63 70) !important;
border-radius: 0.875rem !important;
overflow: hidden !important;
background: rgb(24 24 27) !important;
box-shadow: 0 20px 35px -15px rgb(0 0 0 / 0.7) !important;
}
.wms-country-select2-dropdown .select2-search--dropdown {
padding: 0.75rem !important;
border-bottom: 1px solid rgb(63 63 70) !important;
background: rgb(24 24 27) !important;
}
.wms-country-select2-dropdown .select2-search__field {
min-height: 2.5rem !important;
border-radius: 0.75rem !important;
border: 1px solid rgb(63 63 70) !important;
background: rgb(9 9 11) !important;
padding: 0.5rem 0.75rem !important;
color: rgb(244 244 245) !important;
outline: none !important;
}
.wms-country-select2-dropdown .select2-results__option {
padding: 0.7rem 0.9rem !important;
color: rgb(228 228 231) !important;
font-size: 0.875rem !important;
}
.wms-country-select2-dropdown .select2-results__option--highlighted.select2-results__option--selectable {
background: rgb(37 99 235) !important;
color: white !important;
}
.wms-country-select2-dropdown .select2-results__option--selected {
background: rgb(22 101 52) !important;
color: white !important;
}
</style>
<script>
(function () {
function loadScript(src, callback) {
var existing = document.querySelector('script[src="' + src + '"]');
if (existing) {
existing.addEventListener('load', callback, { once: true });
callback();
return;
}
var script = document.createElement('script');
script.src = src;
script.defer = true;
script.onload = callback;
document.head.appendChild(script);
}
function initCompanyCountrySelect2() {
if (!window.jQuery || !window.jQuery.fn || !window.jQuery.fn.select2) {
return;
}
window.jQuery('[data-company-country-select2]').each(function () {
var select = window.jQuery(this);
if (select.hasClass('select2-hidden-accessible')) {
return;
}
select.select2({
width: '100%',
placeholder: select.data('placeholder') || 'Search and select country',
allowClear: true,
dropdownAutoWidth: false,
dropdownCssClass: 'wms-country-select2-dropdown',
selectionCssClass: 'wms-country-select2-selection'
});
});
}
window.initialiseCompanyCountrySelect2 = initCompanyCountrySelect2;
function bootCompanyCountrySelect2() {
if (window.jQuery && window.jQuery.fn && window.jQuery.fn.select2) {
initCompanyCountrySelect2();
return;
}
loadScript('https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js', function () {
loadScript('https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', initCompanyCountrySelect2);
});
}
document.addEventListener('DOMContentLoaded', bootCompanyCountrySelect2);
document.addEventListener('livewire:navigated', bootCompanyCountrySelect2);
bootCompanyCountrySelect2();
})();
</script>
@endonce
+100 -45
View File
@@ -30,57 +30,86 @@
</a> </a>
</div> </div>
<form method="POST" action="{{ route('platform.companies.store') }}" class="mt-6 grid gap-5 lg:grid-cols-12 lg:items-end"> <form method="POST" action="{{ route('platform.companies.store') }}" class="mt-6">
@csrf @csrf
<div class="lg:col-span-3"> <div class="grid gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1.15fr)_minmax(12rem,.75fr)_minmax(18rem,1.15fr)_auto] xl:items-end">
<label for="quick_company_name" class="mb-2 block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Company</label> <div>
<input <label for="quick_company_name" class="block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Company</label>
id="quick_company_name" <input
name="name" id="quick_company_name"
value="{{ old('name') }}" name="name"
placeholder="Company name" value="{{ old('name') }}"
class="h-11 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" placeholder="Company name"
required class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
> required
</div> >
@error('name')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
</div>
<div class="lg:col-span-3"> <div>
<label for="quick_billing_email" class="mb-2 block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Billing email</label> <label for="quick_billing_email" class="block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Billing email</label>
<input <input
id="quick_billing_email" id="quick_billing_email"
name="billing_email" name="billing_email"
value="{{ old('billing_email') }}" value="{{ old('billing_email') }}"
placeholder="billing@example.com" placeholder="billing@example.com"
type="email" type="email"
class="h-11 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
> >
</div> @error('billing_email')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
</div>
<div class="lg:col-span-2"> <div>
<label for="quick_status" class="mb-2 block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Status</label> <label for="quick_status" class="block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Status</label>
<select id="quick_status" name="status" class="h-11 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white" required> <select
<option value="active" @selected(old('status', 'active') === 'active')>Active</option> id="quick_status"
<option value="suspended" @selected(old('status') === 'suspended')>Suspended</option> name="status"
<option value="inactive" @selected(old('status') === 'inactive')>Inactive</option> class="mt-2 h-12 w-full rounded-xl border-zinc-300 bg-white px-4 text-sm text-zinc-900 shadow-sm outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/30 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
</select> required
</div> >
<option value="active" @selected(old('status', 'active') === 'active')>Active</option>
<option value="suspended" @selected(old('status') === 'suspended')>Suspended</option>
<option value="inactive" @selected(old('status') === 'inactive')>Inactive</option>
</select>
@error('status')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
</div>
<div class="wms-select2-field lg:col-span-3"> <div>
<label for="quick_country_id" class="mb-2 block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Country</label> <label for="quick_country_id" class="block text-xs font-bold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">Country</label>
<select id="quick_country_id" name="country_id" data-wms-select2 data-placeholder="Search country" class="wms-country-select w-full"> <select
<option value="">Search country</option> id="quick_country_id"
@foreach ($countries as $country) name="country_id"
<option value="{{ $country->id }}" @selected((int) old('country_id') === $country->id)> data-company-country-select2
{{ $country->effective_name ?? $country->name }} data-placeholder="Search and select country"
</option> class="wms-country-select mt-2 w-full"
@endforeach >
</select> <option value=""></option>
</div> @foreach($countries as $country)
<option
value="{{ $country->id }}"
data-code="{{ $country->alpha2 }}"
@selected(old('country_id') == $country->id)
>
{{ $country->display_name ?? $country->common_name ?? $country->name }}
</option>
@endforeach
</select>
@error('country_id')
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
</div>
<button class="inline-flex h-11 items-center justify-center rounded-xl bg-green-600 px-5 text-sm font-bold text-white shadow-sm shadow-green-600/20 transition hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 dark:bg-green-500 dark:hover:bg-green-400 dark:focus:ring-offset-zinc-900 lg:col-span-1"> <button class="h-12 rounded-xl bg-green-600 px-6 text-sm font-bold text-white shadow-sm shadow-green-950/20 transition hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-green-500/40">
Create Create
</button> </button>
</div>
</form> </form>
</div> </div>
<div class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800"> <div class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
@@ -183,4 +212,30 @@
{{ $companies->links() }} {{ $companies->links() }}
</div> </div>
@push('scripts')
<script>
document.addEventListener('DOMContentLoaded', () => {
$('[data-company-country-select2]').select2({
width: '100%',
placeholder: 'Search and select country',
allowClear: true,
dropdownAutoWidth: false,
sorter: data => data.sort((a, b) => a.text.localeCompare(b.text)),
});
});
</script>
@endpush
</x-layouts::app> </x-layouts::app>
+7 -1
View File
@@ -1,6 +1,12 @@
latest: 1.2.0 latest: 1.2.1
versions: versions:
- version: 1.2.1
date: 2026-07-07
changes:
- Replaced company country inputs with a shared Select2-enhanced dropdown populated by the Countries module.
- Aligned the company create forms and changed the primary create/save action to green.
- Stored the selected country on the company address relationship during create and update.
- version: 1.2.0 - version: 1.2.0
date: 2026-07-02 date: 2026-07-02
changes: changes:
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "Company", "name": "Company",
"alias": "company", "alias": "company",
"version": "1.2.0", "version": "1.2.1",
"description": "", "description": "",
"keywords": [], "keywords": [],
"priority": 0, "priority": 0,
@@ -13,10 +13,7 @@ use Modules\Countries\Support\CountryUsageReport;
class CountriesController extends Controller class CountriesController extends Controller
{ {
/** public function __invoke(Request $request): View
* Display ISO 3166 country records.
*/
public function index(Request $request): View
{ {
$search = trim((string) $request->query('search', '')); $search = trim((string) $request->query('search', ''));
$status = (string) $request->query('status', 'all'); $status = (string) $request->query('status', 'all');
@@ -40,80 +37,78 @@ class CountriesController extends Controller
->when($status === 'active', fn ($query) => $query->where('is_active', true)) ->when($status === 'active', fn ($query) => $query->where('is_active', true))
->when($status === 'inactive', fn ($query) => $query->where('is_active', false)) ->when($status === 'inactive', fn ($query) => $query->where('is_active', false))
->when($region !== 'all' && $region !== '', fn ($query) => $query->where('region', $region)) ->when($region !== 'all' && $region !== '', fn ($query) => $query->where('region', $region))
->ordered() ->orderByRaw('LOWER(COALESCE(display_name, common_name, name)) ASC')
->paginate(50) ->paginate(50)
->withQueryString(); ->withQueryString();
$activeCount = Country::query()->where('is_active', true)->count(); $activeCount = Country::query()->where('is_active', true)->count();
$inactiveCount = Country::query()->where('is_active', false)->count(); $inactiveCount = Country::query()->where('is_active', false)->count();
$totalCount = Country::query()->count(); $totalCount = Country::query()->count();
$regions = Country::query()->whereNotNull('region')->distinct()->orderBy('region')->pluck('region');
return view('countries::index', compact('countries', 'activeCount', 'inactiveCount', 'totalCount', 'search', 'status', 'region', 'regions')); $regions = Country::query()
->whereNotNull('region')
->distinct()
->orderBy('region')
->pluck('region');
return view('countries::index', compact(
'countries',
'activeCount',
'inactiveCount',
'totalCount',
'search',
'status',
'region',
'regions'
));
} }
/**
* Show the country creation form.
*/
public function create(): View public function create(): View
{ {
return view('countries::create', ['country' => new Country]); return view('countries::create', ['country' => new Country]);
} }
/**
* Store a new ISO country record.
*/
public function store(StoreCountryRequest $request): RedirectResponse public function store(StoreCountryRequest $request): RedirectResponse
{ {
$country = Country::query()->create($this->payload($request)); $country = Country::query()->create($this->payload($request));
return redirect()->route('countries.show', $country)->with('success', 'Country created.'); return redirect()
->route('countries.show', $country)
->with('success', 'Country created.');
} }
/**
* Show a country record.
*/
public function show(Country $country, CountryUsageReport $usageReport): View public function show(Country $country, CountryUsageReport $usageReport): View
{ {
$country->load(['subdivisions' => fn ($query) => $query->ordered()->limit(250)]); $country->load(['subdivisions' => fn ($query) => $query->ordered()->limit(250)]);
$usageRows = $usageReport->forCountry($country); $usageRows = $usageReport->forCountry($country);
return view('countries::show', compact('country', 'usageRows')); return view('countries::show', compact('country', 'usageRows'));
} }
/**
* Show the edit form.
*/
public function edit(Country $country): View public function edit(Country $country): View
{ {
return view('countries::edit', compact('country')); return view('countries::edit', compact('country'));
} }
/**
* Update all editable ISO/support fields.
*/
public function update(UpdateCountryRequest $request, Country $country): RedirectResponse public function update(UpdateCountryRequest $request, Country $country): RedirectResponse
{ {
$country->update($this->payload($request)); $country->update($this->payload($request));
return redirect()->route('countries.show', $country)->with('success', 'Country updated.'); return redirect()
->route('countries.show', $country)
->with('success', 'Country updated.');
} }
/**
* Soft-delete a custom/retired country record.
*/
public function destroy(Country $country): RedirectResponse public function destroy(Country $country): RedirectResponse
{ {
$country->delete(); $country->delete();
return redirect()->route('countries.index')->with('success', 'Country archived.'); return redirect()
->route('countries.index')
->with('success', 'Country archived.');
} }
/**
* Build the database payload from validated request data.
*
* @return array<string, mixed>
*/
private function payload(StoreCountryRequest|UpdateCountryRequest $request): array private function payload(StoreCountryRequest|UpdateCountryRequest $request): array
{ {
$data = $request->validated(); $data = $request->validated();
@@ -130,7 +125,10 @@ class CountriesController extends Controller
foreach (['languages', 'timezones', 'metadata'] as $jsonField) { foreach (['languages', 'timezones', 'metadata'] as $jsonField) {
$value = $data[$jsonField] ?? null; $value = $data[$jsonField] ?? null;
$data[$jsonField] = blank($value) ? null : json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
$data[$jsonField] = blank($value)
? null
: json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
} }
foreach (['is_active', 'independent', 'un_member'] as $booleanField) { foreach (['is_active', 'independent', 'un_member'] as $booleanField) {
+1 -1
View File
@@ -6,7 +6,7 @@ use Modules\Countries\Http\Controllers\CountrySyncController;
use Modules\Countries\Http\Controllers\ReferenceDataController; use Modules\Countries\Http\Controllers\ReferenceDataController;
Route::prefix('countries')->name('countries.')->middleware(['web', 'auth'])->group(function (): void { Route::prefix('countries')->name('countries.')->middleware(['web', 'auth'])->group(function (): void {
Route::get('/', [CountriesController::class, 'index'])->name('index'); Route::get('/', CountriesController::class)->name('index');
Route::get('/create', [CountriesController::class, 'create'])->name('create'); Route::get('/create', [CountriesController::class, 'create'])->name('create');
Route::post('/', [CountriesController::class, 'store'])->name('store'); Route::post('/', [CountriesController::class, 'store'])->name('store');
Route::post('/sync', CountrySyncController::class)->name('sync'); Route::post('/sync', CountrySyncController::class)->name('sync');
+126 -195
View File
@@ -1410,199 +1410,130 @@ html[data-wms-sidebar="collapsed"] .wms-sidebar {
} }
/* Company country Select2 */
@layer components { .wms-country-select + .select2-container {
.wms-select2-field .select2-container { display: block;
width: 100% !important; width: 100% !important;
display: block; margin-top: 0.5rem;
} }
.wms-select2-field .select2-container--default .select2-selection--single { .wms-country-select + .select2-container .select2-selection--single {
position: relative; height: 3rem;
min-height: 2.75rem; min-height: 3rem;
border: 1px solid rgb(212 212 216); display: flex;
border-radius: 0.85rem; align-items: center;
background: linear-gradient(180deg, rgb(255 255 255), rgb(250 250 250)); border-radius: 0.75rem;
box-shadow: 0 1px 2px rgb(15 23 42 / 0.05); border: 1px solid rgb(212 212 216);
transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease; background: rgb(255 255 255);
} box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__rendered { }
min-height: 2.75rem;
padding-left: 0.95rem; .dark .wms-country-select + .select2-container .select2-selection--single {
padding-right: 3rem; border-color: rgb(63 63 70);
color: rgb(24 24 27); background: rgb(9 9 11);
font-size: 0.875rem; }
font-weight: 650;
line-height: 2.75rem; .wms-country-select + .select2-container .select2-selection--single .select2-selection__rendered {
} line-height: 3rem;
width: 100%;
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__placeholder { padding-left: 1rem;
color: rgb(113 113 122); padding-right: 2.75rem;
font-weight: 550; color: rgb(24 24 27);
} font-size: 0.875rem;
}
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__clear {
position: absolute; .dark .wms-country-select + .select2-container .select2-selection--single .select2-selection__rendered {
right: 2.6rem; color: rgb(244 244 245);
top: 0.62rem; }
z-index: 2;
width: 1.35rem; .wms-country-select + .select2-container .select2-selection--single .select2-selection__placeholder {
height: 1.35rem; color: rgb(113 113 122);
border-radius: 999px; }
color: rgb(113 113 122);
font-size: 1rem; .dark .wms-country-select + .select2-container .select2-selection--single .select2-selection__placeholder {
font-weight: 700; color: rgb(161 161 170);
line-height: 1.25rem; }
text-align: center;
} .wms-country-select + .select2-container .select2-selection--single .select2-selection__arrow {
height: 3rem;
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__clear:hover { right: 0.75rem;
background: rgb(244 244 245); top: 0;
color: rgb(39 39 42); }
}
.wms-country-select + .select2-container .select2-selection--single .select2-selection__arrow b {
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__arrow { border-color: rgb(113 113 122) transparent transparent transparent;
top: 0.45rem; }
right: 0.55rem;
width: 1.85rem; .wms-country-select + .select2-container .select2-selection--single .select2-selection__clear {
height: 1.85rem; order: 2;
border-radius: 0.65rem; margin-right: 0.5rem;
background: rgb(244 244 245); color: rgb(113 113 122);
border: 1px solid rgb(228 228 231); font-size: 1.125rem;
} font-weight: 700;
}
.wms-select2-field .select2-container--default .select2-selection--single .select2-selection__arrow b {
border-color: rgb(82 82 91) transparent transparent transparent; .wms-country-select + .select2-container.select2-container--focus .select2-selection--single,
border-width: 5px 4px 0 4px; .wms-country-select + .select2-container.select2-container--open .select2-selection--single {
margin-left: -4px; border-color: rgb(59 130 246);
margin-top: -2px; box-shadow: 0 0 0 3px rgb(59 130 246 / 0.28);
} }
.wms-select2-field .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b { .select2-container--open .select2-dropdown {
border-color: transparent transparent rgb(82 82 91) transparent; border: 1px solid rgb(63 63 70);
border-width: 0 4px 5px 4px; border-radius: 0.875rem;
} overflow: hidden;
background: rgb(255 255 255);
.wms-select2-field .select2-container--default.select2-container--focus .select2-selection--single, box-shadow: 0 20px 35px -15px rgb(0 0 0 / 0.45);
.wms-select2-field .select2-container--default.select2-container--open .select2-selection--single { }
border-color: rgb(22 163 74);
background: white; .dark .select2-container--open .select2-dropdown {
box-shadow: 0 0 0 4px rgb(34 197 94 / 0.14), 0 10px 24px rgb(15 23 42 / 0.08); background: rgb(24 24 27);
} border-color: rgb(63 63 70);
}
.select2-container--default .select2-dropdown {
overflow: hidden; .select2-container--default .select2-search--dropdown {
margin-top: 0.35rem; padding: 0.75rem;
border: 1px solid rgb(212 212 216); border-bottom: 1px solid rgb(228 228 231);
border-radius: 1rem; }
background: white;
box-shadow: 0 24px 60px rgb(15 23 42 / 0.18); .dark .select2-container--default .select2-search--dropdown {
} border-bottom-color: rgb(63 63 70);
}
.select2-container--default .select2-search--dropdown {
padding: 0.75rem; .select2-container--default .select2-search--dropdown .select2-search__field {
border-bottom: 1px solid rgb(244 244 245); min-height: 2.5rem;
} border-radius: 0.75rem;
border: 1px solid rgb(212 212 216);
.select2-container--default .select2-search--dropdown .select2-search__field { padding: 0.5rem 0.75rem;
min-height: 2.5rem; color: rgb(24 24 27);
border: 1px solid rgb(212 212 216); outline: none;
border-radius: 0.75rem; }
padding: 0.55rem 0.8rem;
background: rgb(250 250 250); .dark .select2-container--default .select2-search--dropdown .select2-search__field {
color: rgb(24 24 27); border-color: rgb(63 63 70);
font-size: 0.875rem; background: rgb(9 9 11);
font-weight: 600; color: rgb(244 244 245);
outline: none; }
}
.select2-container--default .select2-results__option {
.select2-container--default .select2-search--dropdown .select2-search__field:focus { padding: 0.7rem 0.9rem;
border-color: rgb(22 163 74); font-size: 0.875rem;
background: white; color: rgb(39 39 42);
box-shadow: 0 0 0 4px rgb(34 197 94 / 0.14); }
}
.dark .select2-container--default .select2-results__option {
.select2-container--default .select2-results > .select2-results__options { color: rgb(228 228 231);
max-height: 16rem; }
padding: 0.35rem;
} .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable,
.select2-container--default .select2-results__option--highlighted[aria-selected] {
.select2-container--default .select2-results__option { background: rgb(37 99 235);
margin: 0.1rem 0; color: white;
border-radius: 0.65rem; }
padding: 0.65rem 0.8rem;
color: rgb(39 39 42); .select2-container--default .select2-results__option--selected,
font-size: 0.875rem; .select2-container--default .select2-results__option[aria-selected="true"] {
font-weight: 650; background: rgb(22 101 52);
} color: white;
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
background: rgb(22 163 74);
color: white;
}
.select2-container--default .select2-results__option--selected {
background: rgb(240 253 244);
color: rgb(21 128 61);
}
.dark .wms-select2-field .select2-container--default .select2-selection--single {
border-color: rgb(63 63 70);
background: linear-gradient(180deg, rgb(24 24 27), rgb(9 9 11));
}
.dark .wms-select2-field .select2-container--default .select2-selection--single .select2-selection__rendered {
color: white;
}
.dark .wms-select2-field .select2-container--default .select2-selection--single .select2-selection__placeholder {
color: rgb(161 161 170);
}
.dark .wms-select2-field .select2-container--default .select2-selection--single .select2-selection__arrow {
border-color: rgb(63 63 70);
background: rgb(39 39 42);
}
.dark .wms-select2-field .select2-container--default .select2-selection--single .select2-selection__arrow b {
border-color: rgb(212 212 216) transparent transparent transparent;
}
.dark .wms-select2-field .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
border-color: transparent transparent rgb(212 212 216) transparent;
}
.dark .wms-select2-field .select2-container--default.select2-container--focus .select2-selection--single,
.dark .wms-select2-field .select2-container--default.select2-container--open .select2-selection--single {
border-color: rgb(34 197 94);
background: rgb(9 9 11);
box-shadow: 0 0 0 4px rgb(34 197 94 / 0.16);
}
.dark .select2-container--default .select2-dropdown {
border-color: rgb(63 63 70);
background: rgb(24 24 27);
color: rgb(244 244 245);
box-shadow: 0 24px 60px rgb(0 0 0 / 0.35);
}
.dark .select2-container--default .select2-search--dropdown {
border-bottom-color: rgb(39 39 42);
}
.dark .select2-container--default .select2-search--dropdown .select2-search__field {
border-color: rgb(63 63 70);
background: rgb(9 9 11);
color: white;
}
.dark .select2-container--default .select2-results__option {
color: rgb(244 244 245);
}
.dark .select2-container--default .select2-results__option--selected {
background: rgb(20 83 45);
color: rgb(220 252 231);
}
} }
+8 -6
View File
@@ -167,7 +167,7 @@ function initialiseSelect2() {
return; return;
} }
$('[data-helpdesk-select2], [data-wms-select2]').each(function () { $('[data-helpdesk-select2], [data-company-country-select2]').each(function () {
const $select = $(this); const $select = $(this);
if ($select.hasClass('select2-hidden-accessible')) { if ($select.hasClass('select2-hidden-accessible')) {
@@ -176,15 +176,17 @@ function initialiseSelect2() {
const isMultiple = $select.prop('multiple'); const isMultiple = $select.prop('multiple');
const placeholder =
$select.data('placeholder') ||
$select.find('option[value=""]').first().text() ||
(isMultiple ? 'Select options' : 'Select option');
$select.select2({ $select.select2({
width: '100%', width: '100%',
allowClear: !isMultiple, allowClear: !isMultiple,
closeOnSelect: !isMultiple, closeOnSelect: !isMultiple,
dropdownAutoWidth: true, dropdownAutoWidth: false,
placeholder: placeholder,
$select.data('placeholder') ||
$select.find('option[value=""]').first().text() ||
(isMultiple ? 'Select options' : 'Select option'),
}); });
$select.off('change.select2-livewire'); $select.off('change.select2-livewire');