fix:테넌트 자동선택 개선 - 전체 보기 제거, HQ 테넌트 자동선택

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-04 13:13:17 +09:00
parent 386558890b
commit be28b76872
4 changed files with 21 additions and 36 deletions

View File

@@ -56,7 +56,11 @@ public function switch(Request $request)
$tenantId = $request->input('tenant_id');
if ($tenantId === 'all') {
$request->session()->forget('selected_tenant_id');
// "전체 보기" 대신 사용자의 HQ 테넌트로 설정
$hqTenant = auth()->user()->getHQTenant();
if ($hqTenant) {
$request->session()->put('selected_tenant_id', $hqTenant->id);
}
} else {
$request->session()->put('selected_tenant_id', $tenantId);
}

View File

@@ -25,6 +25,14 @@ public function boot(): void
// 모든 뷰에 테넌트 목록 공유 (전역용)
View::composer('*', function ($view) {
if (auth()->check()) {
// 테넌트가 선택되지 않은 경우 자동으로 HQ 테넌트 설정
if (!session('selected_tenant_id')) {
$hqTenant = auth()->user()->getHQTenant();
if ($hqTenant) {
session(['selected_tenant_id' => $hqTenant->id]);
}
}
$globalTenants = Tenant::active()
->orderBy('company_name')
->get(['id', 'company_name', 'code']);

View File

@@ -17,28 +17,17 @@ class="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transi
<!-- 모바일 로고 + 테넌트 뱃지 (lg 미만에서만 표시) -->
<div class="flex items-center gap-2 lg:hidden">
<span class="text-lg font-bold text-gray-900">{{ config('app.name') }}</span>
@if(session('selected_tenant_id'))
@php
$mobileTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
@endphp
@if($mobileTenant)
<button
type="button"
onclick="openMobileSidebar()"
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-primary/10 text-primary"
title="테넌트 변경"
>
{{ Str::limit($mobileTenant->company_name, 8) }}
</button>
@endif
@else
@php
$mobileTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
@endphp
@if($mobileTenant)
<button
type="button"
onclick="openMobileSidebar()"
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-600"
title="테넌트 선택"
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-primary/10 text-primary"
title="테넌트 변경"
>
전체
{{ Str::limit($mobileTenant->company_name, 8) }}
</button>
@endif
</div>
@@ -59,12 +48,6 @@ class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-
onchange="document.getElementById('tenant-switch-form').submit()"
class="border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primary min-w-[200px]"
>
<option value="all" {{ session('selected_tenant_id') === null ? 'selected' : '' }}>
전체 보기
</option>
@if($globalTenants->isNotEmpty())
<option disabled>─────────</option>
@endif
@foreach($globalTenants as $tenant)
<option value="{{ $tenant->id }}" {{ session('selected_tenant_id') == $tenant->id ? 'selected' : '' }}>
{{ $tenant->company_name }}
@@ -74,8 +57,7 @@ class="border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primar
</form>
<!-- 현재 테넌트 정보 (데스크톱에서만 표시) -->
@if(session('selected_tenant_id'))
@php
@php
$currentTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
@endphp
@if($currentTenant)
@@ -90,9 +72,6 @@ class="border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primar
{{ $currentTenant->company_name }}
</span>
@endif
@else
<span class="hidden lg:inline text-xs text-gray-500">전체</span>
@endif
</div>
<!-- Right Side Actions -->

View File

@@ -90,12 +90,6 @@ class="absolute right-2 top-1/2 -translate-y-1/2 p-0.5 text-gray-400 hover:text-
onchange="document.getElementById('mobile-tenant-switch-form').submit()"
class="w-full border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primary"
>
<option value="all" {{ session('selected_tenant_id') === null ? 'selected' : '' }}>
전체 보기
</option>
@if($globalTenants->isNotEmpty())
<option disabled>─────────</option>
@endif
@foreach($globalTenants as $tenant)
<option value="{{ $tenant->id }}" {{ session('selected_tenant_id') == $tenant->id ? 'selected' : '' }}>
{{ $tenant->company_name }}