fix: [approvals] 뱃지 데이터 View::share 덮어쓰기 문제 수정

- AppServiceProvider와 ViewServiceProvider에서 각각 View::share 호출하여 덮어쓰기 발생
- ViewServiceProvider 한 곳에서 영업+결재 뱃지를 통합 관리하도록 수정
- AppServiceProvider에서 뱃지 로직 제거
This commit is contained in:
김보곤
2026-02-28 15:21:16 +09:00
parent b6b16fcbd1
commit 350394820b
2 changed files with 16 additions and 33 deletions

View File

@@ -7,7 +7,6 @@
use App\Models\Tenants\Department;
use App\Models\User;
use App\Observers\FileObserver;
use App\Services\ApprovalService;
use App\Services\SidebarMenuService;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Cache;
@@ -57,32 +56,6 @@ public function boot(): void
$menuService = app(SidebarMenuService::class);
$menusBySection = $menuService->getMenusBySection();
// 결재 뱃지 건수
$menuBadges = ['byRoute' => [], 'byUrl' => []];
if (auth()->check()) {
try {
$counts = app(ApprovalService::class)->getBadgeCounts(auth()->id());
$menuBadges = [
'byRoute' => [
'approvals.pending' => ['count' => $counts['pending'], 'color' => '#ef4444'],
'approvals.drafts' => ['count' => $counts['draft'], 'color' => '#3b82f6'],
'approvals.references' => ['count' => $counts['reference_unread'], 'color' => '#10b981'],
],
'byUrl' => [
'/approval-mgmt/pending' => ['count' => $counts['pending'], 'color' => '#ef4444'],
'/approval-mgmt/drafts' => ['count' => $counts['draft'], 'color' => '#3b82f6'],
'/approval-mgmt/references' => ['count' => $counts['reference_unread'], 'color' => '#10b981'],
],
];
} catch (\Throwable $e) {
// 테이블 미존재 등 예외 무시
}
}
// menuBadges는 Blade 컴포넌트(<x-sidebar.menu-item>)에서도 접근 필요
// $view->with()는 컴포넌트 격리 스코프에 전달 안 되므로 View::share 사용
View::share('menuBadges', $menuBadges);
$view->with([
'mainMenus' => $menusBySection['main'],
'toolsMenus' => $menusBySection['tools'],

View File

@@ -3,6 +3,7 @@
namespace App\Providers;
use App\Models\Tenants\Tenant;
use App\Services\ApprovalService;
use App\Services\Sales\BusinessCardRequestService;
use App\Services\Sales\SalesManagerService;
use Illuminate\Support\Facades\View;
@@ -42,25 +43,25 @@ public function boot(): void
}
});
// 사이드바 메뉴 뱃지 데이터 (전역 공유 - 컴포넌트에서도 접근 가능)
// 사이드바 메뉴 뱃지 데이터 (전역 공유 - Blade 컴포넌트에서도 접근 가능)
// ⚠️ 모든 뱃지를 이 한 곳에서 통합 관리 (View::share 덮어쓰기 방지)
View::composer('partials.sidebar', function ($view) {
$menuBadges = [
'byRoute' => [], // 라우트명 기준
'byUrl' => [], // URL 기준
'byRoute' => [],
'byUrl' => [],
];
if (auth()->check()) {
// ── 영업 뱃지 ──
try {
$salesManagerService = app(SalesManagerService::class);
$approvalStats = $salesManagerService->getApprovalStats();
// 영업파트너 승인 대기 건수
if ($approvalStats['pending'] > 0) {
$menuBadges['byRoute']['sales.managers.approvals'] = $approvalStats['pending'];
$menuBadges['byUrl']['/sales/managers/approvals'] = $approvalStats['pending'];
}
// 명함신청 대기 건수 (관리자용 처리 메뉴에 표시)
$businessCardService = app(BusinessCardRequestService::class);
$businessCardPending = $businessCardService->getPendingCount();
if ($businessCardPending > 0) {
@@ -70,9 +71,18 @@ public function boot(): void
} catch (\Exception $e) {
// 서비스 오류 시 무시
}
// ── 결재 뱃지 (색상별) ──
try {
$counts = app(ApprovalService::class)->getBadgeCounts(auth()->id());
$menuBadges['byUrl']['/approval-mgmt/pending'] = ['count' => $counts['pending'], 'color' => '#ef4444'];
$menuBadges['byUrl']['/approval-mgmt/drafts'] = ['count' => $counts['draft'], 'color' => '#3b82f6'];
$menuBadges['byUrl']['/approval-mgmt/references'] = ['count' => $counts['reference_unread'], 'color' => '#10b981'];
} catch (\Throwable $e) {
// 테이블 미존재 등 예외 무시
}
}
// View::share로 전역 공유 (Blade 컴포넌트에서도 접근 가능)
View::share('menuBadges', $menuBadges);
});
}