init: SR System — Helpdesk & ITAM Portal

This commit is contained in:
pray4skylark
2026-06-02 13:50:39 +09:00
commit 832c9f096f
262 changed files with 30470 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
'use client';
import React, { useEffect, useState } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { ShieldAlert } from 'lucide-react';
import { useAuthStore } from '@/stores';
import { getCookie } from '@/lib/cookie';
const publicPaths = ['/login'];
export default function AuthGuard({ children }: { children: React.ReactNode }) {
const router = useRouter();
const pathname = usePathname();
const { isAuthenticated, fetchMe, tryRefresh, accessToken } = useAuthStore();
const [loading, setLoading] = useState(true);
useEffect(() => {
if (publicPaths.includes(pathname)) {
setLoading(false);
return;
}
const init = async () => {
const token = accessToken || localStorage.getItem('accessToken') || getCookie('accessToken');
if (!token) {
const hasRefresh = localStorage.getItem('refreshToken');
if (hasRefresh) {
const renewed = await tryRefresh();
if (renewed) {
await fetchMe().catch(() => {
router.replace('/login');
return;
});
setLoading(false);
return;
}
}
router.replace('/login');
return;
}
if (!isAuthenticated) {
await fetchMe().catch(() => {
router.replace('/login');
return;
});
}
setLoading(false);
};
init();
}, [pathname]);
if (publicPaths.includes(pathname)) return <>{children}</>;
if (loading) {
return (
<div className="h-screen flex items-center justify-center bg-canvas">
<div className="text-center">
<ShieldAlert className="w-10 h-10 text-primary mx-auto mb-3 animate-pulse" />
<p className="text-text-muted text-sm">인증 확인 중...</p>
</div>
</div>
);
}
return <>{children}</>;
}
+93
View File
@@ -0,0 +1,93 @@
"use client";
import React, { useEffect, useState } from 'react';
import { Search, Calendar, MessageSquare, Bell, ChevronsRight, ChevronsLeft, Plus, Menu } from 'lucide-react';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
import { useAuthStore, useNotificationStore } from '@/stores';
import NotificationDropdown from './NotificationDropdown';
import UserDropdown from './UserDropdown';
const Header = ({ toggleSidebar, isCollapsed, onOpenMobile }: { toggleSidebar: () => void, isCollapsed: boolean, onOpenMobile?: () => void }) => {
const router = useRouter();
const unreadCount = useNotificationStore((s) => s.unreadCount);
const startPolling = useNotificationStore((s) => s.startPolling);
const [searchVal, setSearchVal] = useState('');
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
useEffect(() => {
startPolling();
}, []);
const handleSearch = (e: React.FormEvent) => {
e.preventDefault();
if (searchVal.trim()) {
router.push(`/issues?search=${encodeURIComponent(searchVal.trim())}`);
}
};
return (
<header className="h-16 bg-surface border-b border-border flex items-center justify-between px-6 shrink-0 z-30 shadow-sm">
<div className="flex items-center flex-1">
<button
onClick={toggleSidebar}
className="mr-4 lg:mr-6 text-text-muted hover:text-text-main transition-colors p-1 hover:bg-gray-100 rounded-lg lg:block hidden"
>
{isCollapsed ? <ChevronsRight className="w-5 h-5" /> : <ChevronsLeft className="w-5 h-5" />}
</button>
<button
onClick={() => onOpenMobile?.()}
className="mr-4 lg:mr-6 text-text-muted hover:text-text-main transition-colors p-1 hover:bg-gray-100 rounded-lg lg:hidden block"
>
<Menu className="w-5 h-5" />
</button>
<form onSubmit={handleSearch} className="relative w-full max-w-md">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<Search className="w-4 h-4 text-gray-400" />
</div>
<input
type="text"
value={searchVal}
onChange={(e) => setSearchVal(e.target.value)}
placeholder="Search issues, assets, employees..."
className="block w-full pl-10 pr-3 py-2 border-none rounded-xl bg-gray-100 text-sm focus:outline-none focus:ring-2 focus:ring-primary focus:bg-white transition-all text-text-main"
/>
</form>
</div>
<div className="flex items-center space-x-4">
<button onClick={() => router.push('/calendar')} className="p-2 text-text-muted hover:bg-gray-100 rounded-full transition-colors" title="일정 보기">
<Calendar className="w-5 h-5" />
</button>
<button className="p-2 text-text-muted hover:bg-gray-100 rounded-full transition-colors relative" title="메시지 보기">
<MessageSquare className="w-5 h-5" />
</button>
<div className="relative">
<button
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
className="p-2 text-text-muted hover:bg-gray-100 rounded-full transition-colors relative mr-2"
>
<Bell className="w-5 h-5" />
{unreadCount > 0 && (
<span className="absolute -top-0.5 -right-0.5 w-5 h-5 bg-status-critical-text text-white text-[10px] font-bold rounded-full flex items-center justify-center border-2 border-white">
{unreadCount > 99 ? '99+' : unreadCount}
</span>
)}
</button>
<NotificationDropdown isOpen={isDropdownOpen} onClose={() => setIsDropdownOpen(false)} />
</div>
<Link href="/issues" className="bg-primary hover:bg-primary-hover text-white px-4 py-2 rounded-xl text-xs font-semibold shadow-soft transition-all flex items-center">
<Plus className="w-3.5 h-3.5 mr-1.5" />
New SR
</Link>
<div className="h-8 w-px bg-gray-200"></div>
<UserDropdown />
</div>
</header>
);
};
export default Header;
+44
View File
@@ -0,0 +1,44 @@
"use client";
import React, { useState } from 'react';
import Sidebar from './Sidebar';
import Header from './Header';
import AuthGuard from './AuthGuard';
import MobileBottomNav from './MobileBottomNav';
export default function MainShell({ children }: { children: React.ReactNode }) {
const [isCollapsed, setIsCollapsed] = useState(false);
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const toggleSidebar = () => setIsCollapsed(!isCollapsed);
return (
<AuthGuard>
<div className="h-full flex overflow-hidden">
{/* Desktop Sidebar - hidden on mobile */}
<div className="hidden lg:block">
<Sidebar isCollapsed={isCollapsed} />
</div>
{/* Mobile sidebar overlay (drawer) */}
{mobileMenuOpen && (
<div className="fixed inset-0 z-50 lg:hidden" onClick={() => setMobileMenuOpen(false)}>
<div className="absolute inset-0 bg-black/40" />
<div className="absolute left-0 top-0 bottom-0 w-[250px] bg-white shadow-xl" onClick={(e) => e.stopPropagation()}>
<Sidebar isCollapsed={false} />
</div>
</div>
)}
<div className="flex-1 flex flex-col min-w-0 bg-canvas">
<Header toggleSidebar={toggleSidebar} isCollapsed={isCollapsed} onOpenMobile={() => setMobileMenuOpen(true)} />
<main className="flex-1 overflow-auto pb-16 lg:pb-0">
{children}
</main>
</div>
</div>
{/* Mobile bottom navigation */}
<MobileBottomNav />
</AuthGuard>
);
}
+32
View File
@@ -0,0 +1,32 @@
'use client';
import React from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { LayoutDashboard, Ticket, Link2, Monitor, FileText } from 'lucide-react';
const navItems = [
{ name: 'Dashboard', href: '/', icon: LayoutDashboard },
{ name: 'Issues', href: '/issues', icon: Ticket },
{ name: 'Dispatch', href: '/dispatch', icon: Link2 },
{ name: 'ITAM', href: '/itam', icon: Monitor },
{ name: 'Reports', href: '/work-reports', icon: FileText },
];
export default function MobileBottomNav() {
const pathname = usePathname();
return (
<nav className="fixed bottom-0 inset-x-0 z-50 bg-white border-t border-border flex items-center justify-around py-1 safe-area-bottom lg:hidden shadow-[0_-2px_10px_rgba(0,0,0,0.06)]">
{navItems.map((item) => {
const Icon = item.icon;
const isActive = pathname === item.href || pathname.startsWith(item.href + '/');
return (
<Link key={item.name} href={item.href} className={`flex flex-col items-center py-1 px-3 rounded-xl transition-colors ${isActive ? 'text-primary' : 'text-text-muted'}`}>
<Icon className="w-5 h-5" />
<span className="text-[10px] font-medium mt-0.5">{item.name}</span>
</Link>
);
})}
</nav>
);
}
@@ -0,0 +1,167 @@
"use client";
import React, { useEffect, useRef } from 'react';
import { Bell, Check, AlertCircle, Info, AlertTriangle, XCircle } from 'lucide-react';
import { useNotificationStore } from '@/stores';
const formatTimeAgo = (dateString: string): string => {
const date = new Date(dateString);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffSec = Math.floor(diffMs / 1000);
const diffMin = Math.floor(diffSec / 60);
const diffHour = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHour / 24);
if (diffSec < 60) return '방금 전';
if (diffMin < 60) return `${diffMin}분 전`;
if (diffHour < 24) return `${diffHour}시간 전`;
if (diffDay < 7) return `${diffDay}일 전`;
if (diffDay < 30) return `${Math.floor(diffDay / 7)}주 전`;
return date.toLocaleDateString('ko-KR');
};
const getTypeIcon = (type: string) => {
switch (type) {
case 'SR_TICKET':
return <AlertCircle className="w-4 h-4 text-blue-500" />;
case 'SR_UPDATE':
return <Info className="w-4 h-4 text-indigo-500" />;
case 'SLA_WARNING':
return <AlertTriangle className="w-4 h-4 text-amber-500" />;
case 'REPORT_APPROVED':
case 'REPORT_REJECTED':
return <Check className="w-4 h-4 text-emerald-500" />;
case 'EQUIPMENT':
return <Bell className="w-4 h-4 text-purple-500" />;
case 'ERROR':
return <XCircle className="w-4 h-4 text-red-500" />;
default:
return <Bell className="w-4 h-4 text-gray-500" />;
}
};
interface NotificationDropdownProps {
isOpen: boolean;
onClose: () => void;
}
const NotificationDropdown = ({ isOpen, onClose }: NotificationDropdownProps) => {
const dropdownRef = useRef<HTMLDivElement>(null);
const notifications = useNotificationStore((s) => s.notifications);
const markAsRead = useNotificationStore((s) => s.markAsRead);
const fetchNotifications = useNotificationStore((s) => s.fetchNotifications);
useEffect(() => {
const handleClickOutside = (e: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
onClose();
}
};
if (isOpen) {
document.addEventListener('mousedown', handleClickOutside);
fetchNotifications();
}
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [isOpen, onClose, fetchNotifications]);
const handleNotificationClick = async (id: number) => {
await markAsRead(id);
};
const handleMarkAllRead = async () => {
const unreadIds = notifications.filter((n) => !n.isRead).map((n) => n.notificationId);
for (const id of unreadIds) {
await markAsRead(id);
}
};
if (!isOpen) return null;
const unreadNotifications = notifications.filter((n) => !n.isRead);
return (
<div
ref={dropdownRef}
className="absolute right-0 top-full mt-2 w-96 bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden z-50"
style={{ maxHeight: '500px' }}
>
{/* Header */}
<div className="px-4 py-3 border-b border-gray-100 flex items-center justify-between bg-gray-50">
<h3 className="text-sm font-semibold text-text-main">알림</h3>
{unreadNotifications.length > 0 && (
<button
onClick={handleMarkAllRead}
className="text-xs text-primary hover:text-primary-hover font-medium transition-colors"
>
모두 읽음
</button>
)}
</div>
{/* Notification List */}
<div className="overflow-y-auto" style={{ maxHeight: '420px' }}>
{notifications.length === 0 ? (
<div className="px-4 py-8 text-center">
<Bell className="w-8 h-8 text-gray-300 mx-auto mb-2" />
<p className="text-sm text-text-muted">알림이 없습니다</p>
</div>
) : (
<ul className="divide-y divide-gray-50">
{notifications.map((notification) => (
<li
key={notification.notificationId}
onClick={() => handleNotificationClick(notification.notificationId)}
className={`px-4 py-3 cursor-pointer transition-colors hover:bg-gray-50 ${
!notification.isRead ? 'bg-blue-50/50 hover:bg-blue-50' : ''
}`}
>
<div className="flex items-start gap-3">
<div className="shrink-0 mt-0.5">{getTypeIcon(notification.type)}</div>
<div className="flex-1 min-w-0">
<div className="flex items-center justify-between gap-2 mb-1">
<p
className={`text-sm font-medium truncate ${
!notification.isRead ? 'text-text-main' : 'text-text-muted'
}`}
>
{notification.title}
</p>
{!notification.isRead && (
<span className="w-2 h-2 bg-primary rounded-full shrink-0" />
)}
</div>
<p className="text-xs text-text-muted line-clamp-2 mb-1">
{notification.message}
</p>
<span className="text-[10px] text-text-muted">
{formatTimeAgo(notification.createdAt)}
</span>
</div>
</div>
</li>
))}
</ul>
)}
</div>
{/* Footer */}
{notifications.length > 0 && (
<div className="px-4 py-2 border-t border-gray-100 bg-gray-50 text-center">
<button
onClick={onClose}
className="text-xs text-text-muted hover:text-text-main transition-colors"
>
닫기
</button>
</div>
)}
</div>
);
};
export default NotificationDropdown;
+87
View File
@@ -0,0 +1,87 @@
"use client";
import { useEffect, useState, useCallback, useRef } from 'react';
import { Moon, RefreshCw, Clock } from 'lucide-react';
const BACKOFF_MS = [5_000, 10_000, 20_000, 40_000, 60_000];
export default function ParkingGuard({ children }: { children: React.ReactNode }) {
const [status, setStatus] = useState<'loading' | 'parked' | 'online'>('loading');
const backoffIdx = useRef(0);
const timerRef = useRef<number | undefined>(undefined);
const checkHealth = useCallback(async () => {
try {
const res = await fetch('/api/v1/health');
if (!res.ok) { setStatus('parked'); return; }
const body = await res.json();
setStatus(body.data?.parked ? 'parked' : 'online');
} catch {
setStatus('parked');
}
}, []);
useEffect(() => {
checkHealth();
const onVisible = () => {
if (document.visibilityState === 'visible') {
clearTimeout(timerRef.current);
backoffIdx.current = 0;
checkHealth();
}
};
document.addEventListener('visibilitychange', onVisible);
return () => {
document.removeEventListener('visibilitychange', onVisible);
clearTimeout(timerRef.current);
};
}, [checkHealth]);
useEffect(() => {
if (status !== 'parked') return;
const delay = BACKOFF_MS[Math.min(backoffIdx.current, BACKOFF_MS.length - 1)];
if (backoffIdx.current < BACKOFF_MS.length - 1) backoffIdx.current++;
timerRef.current = window.setTimeout(checkHealth, delay);
return () => clearTimeout(timerRef.current);
}, [status, checkHealth]);
if (status === 'loading') return null;
if (status === 'parked') {
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
<div className="bg-surface rounded-2xl shadow-xl max-w-md w-full mx-4 p-8 text-center">
<div className="w-16 h-16 mx-auto mb-4 rounded-full bg-amber-50 flex items-center justify-center">
<Moon className="w-8 h-8 text-amber-500" />
</div>
<h2 className="text-xl font-semibold text-text-main mb-2 font-outfit">
서버 점검 시간입니다
</h2>
<div className="bg-amber-50 rounded-xl px-4 py-3 mb-5 text-sm text-amber-800">
<div className="flex items-center justify-center gap-2">
<Clock className="w-4 h-4" />
<span>점검 시간: 토/일요일 · 평일 20:00~08:00</span>
</div>
</div>
<p className="text-sm text-text-muted mb-4">
백엔드 서버가 절전 모드입니다. 서버가 기동되면 자동으로 접속됩니다.
</p>
<button
onClick={() => { backoffIdx.current = 0; checkHealth(); }}
className="w-full flex items-center justify-center gap-2 bg-primary hover:bg-primary-hover text-white px-5 py-2.5 rounded-xl text-sm font-semibold transition-all shadow-soft"
>
<RefreshCw className="w-4 h-4" />
서버 상태 확인
</button>
</div>
</div>
);
}
return <>{children}</>;
}
+102
View File
@@ -0,0 +1,102 @@
"use client";
import React, { useState, useEffect } from 'react';
import { Moon, Sun, Clock, Send, CheckCircle, Power } from 'lucide-react';
import { useParkingStore } from '@/stores';
const RESUME_SCHEDULE = '월요일 08:00';
const ParkingOverlay = () => {
const { parked, checking, wakeLoading, wakeSent, wakeMessage, requestWake, dismissWake } = useParkingStore();
const [reason, setReason] = useState('');
if (checking || !parked) return null;
const now = new Date();
const day = now.getDay();
const hour = now.getHours();
const isWeekend = day === 0 || day === 6;
const resumeTime = isWeekend
? '월요일 08:00'
: `오늘 ${hour < 8 ? '08:00' : '다음 영업일 08:00'}`;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
<div className="bg-surface rounded-2xl shadow-xl max-w-md w-full mx-4 p-8 text-center">
<div className="w-16 h-16 mx-auto mb-4 rounded-full bg-amber-50 flex items-center justify-center">
<Moon className="w-8 h-8 text-amber-500" />
</div>
<h2 className="text-xl font-semibold text-text-main mb-2 font-outfit">
서버 점검 시간입니다
</h2>
<div className="bg-amber-50 rounded-xl px-4 py-3 mb-5 text-sm text-amber-800 space-y-1">
<div className="flex items-center justify-center gap-2">
<Clock className="w-4 h-4" />
<span>예상 재기동: <strong>{resumeTime}</strong></span>
</div>
<div className="text-amber-600 text-xs">
점검 시간: 토/일요일 (주말) · 평일 20:00~08:00
</div>
</div>
{!wakeSent ? (
<>
<p className="text-sm text-text-muted mb-4">
긴급하게 서버가 필요하면 아래 버튼으로 관리자에게 기동 요청을 보낼 수 있습니다.
</p>
<input
type="text"
value={reason}
onChange={(e) => setReason(e.target.value)}
placeholder="요청 사유 (예: 긴급 SR 처리)"
className="w-full px-4 py-2.5 border border-border rounded-xl text-sm mb-3 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent bg-white"
maxLength={100}
/>
<button
onClick={() => requestWake(reason || '긴급 서버 기동 요청')}
disabled={wakeLoading}
className="w-full flex items-center justify-center gap-2 bg-primary hover:bg-primary-hover text-white px-5 py-2.5 rounded-xl text-sm font-semibold transition-all disabled:opacity-50 disabled:cursor-not-allowed shadow-soft"
>
{wakeLoading ? (
<span className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" />
) : (
<>
<Power className="w-4 h-4" />
서버 기동 요청
</>
)}
</button>
</>
) : (
<div className="bg-emerald-50 rounded-xl px-4 py-5">
<CheckCircle className="w-8 h-8 text-emerald-500 mx-auto mb-2" />
<p className="text-sm text-emerald-800 font-medium mb-1">요청이 전송되었습니다</p>
<p className="text-xs text-emerald-600">{wakeMessage}</p>
<button
onClick={dismissWake}
className="mt-3 text-xs text-text-muted hover:text-text-main underline"
>
다시 요청하기
</button>
</div>
)}
<div className="mt-5 pt-4 border-t border-border">
<a
href="mailto:admin@example.com"
className="text-xs text-text-muted hover:text-primary transition-colors"
>
관리자 직접 연락: admin@example.com
</a>
</div>
</div>
</div>
);
};
export default ParkingOverlay;
+315
View File
@@ -0,0 +1,315 @@
"use client";
import React, { useState } from 'react';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import {
LayoutDashboard,
Ticket,
Link2,
Monitor,
FileText,
Plus,
Lightbulb,
ChevronDown,
PlusCircle,
ArrowUpRight,
ArrowDownLeft,
History,
BookOpen,
Users,
ClipboardCheck,
CalendarDays,
Settings,
CheckSquare,
Briefcase,
} from 'lucide-react';
import { useAuthStore } from '@/stores';
/**
* SR 시스템의 메인 사이드바 컴포넌트
* ITAM 하위 메뉴를 포함하도록 고도화되었습니다.
*/
const Sidebar = ({ isCollapsed }: { isCollapsed?: boolean }) => {
const pathname = usePathname();
const router = useRouter();
const [isItamOpen, setIsItamOpen] = useState(pathname.startsWith('/itam'));
const user = useAuthStore((s) => s.user);
const role = user?.roleCode;
const isMgmt = role === 'MANAGER' || role === 'ADMIN';
const menuItems = [
{ name: 'Dashboard', href: '/', icon: LayoutDashboard },
{ name: 'SR Issues', href: '/issues', icon: Ticket },
{ name: 'Dispatch', href: '/dispatch', icon: Link2 },
];
const itamSubItems = [
{ name: 'Asset Hub', href: '/itam', icon: Monitor },
{ name: 'Register', href: '/itam/register', icon: PlusCircle },
{ name: 'Check-out', href: '/itam/checkout', icon: ArrowUpRight },
{ name: 'Check-in', href: '/itam/checkin', icon: ArrowDownLeft },
{ name: 'History', href: '/itam', icon: History },
];
const projects = [
{ name: 'Samsung Pay SI', dot: 'bg-dot-green' },
{ name: 'LG CNS SM', dot: 'bg-dot-orange' },
{ name: 'Kakao Maintenance', dot: 'bg-dot-blue' },
];
return (
<aside
className={`bg-surface border-r border-border flex flex-col justify-between flex-shrink-0 transition-all duration-300 relative z-20 overflow-hidden ${
isCollapsed ? 'w-[64px]' : 'w-[250px]'
}`}
>
<div className="flex-1 overflow-y-auto no-scrollbar">
{/* 로고 영역 */}
<div className={`h-16 flex items-center border-b border-border transition-all sticky top-0 bg-surface z-10 ${isCollapsed ? 'justify-center' : 'px-6'}`}>
<div className="w-6 h-6 rounded-full bg-gradient-to-tr from-primary to-purple-400 flex-shrink-0 shadow-lg shadow-primary/20"></div>
{!isCollapsed && (
<h1 className="font-outfit font-semibold text-lg text-text-main tracking-wide ml-3 whitespace-nowrap">SR System.</h1>
)}
</div>
{/* 메인 메뉴 */}
<div className={`py-6 ${isCollapsed ? 'px-1' : 'px-4'}`}>
{!isCollapsed && (
<p className="text-[10px] font-bold text-text-muted tracking-[0.12em] mb-4 px-2 uppercase whitespace-nowrap">Main Menu</p>
)}
<nav className="space-y-1">
{menuItems.map((item) => {
const Icon = item.icon;
const isActive = pathname === item.href;
return (
<Link
key={item.name}
href={item.href}
title={isCollapsed ? item.name : ''}
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
isActive
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<Icon className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">{item.name}</span>}
</Link>
);
})}
{/* Projects link (management only) */}
{isMgmt && (
<Link
href="/projects"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/projects'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<Briefcase className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Projects</span>}
</Link>
)}
{/* ITAM Group Menu */}
<div className="space-y-1">
<button
onClick={() => !isCollapsed && setIsItamOpen(!isItamOpen)}
className={`w-full flex items-center justify-between rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname.startsWith('/itam') && !isCollapsed
? 'text-primary'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<div className="flex items-center">
<Monitor className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">ITAM (Assets)</span>}
</div>
{!isCollapsed && (
<ChevronDown className={`w-3.5 h-3.5 transition-transform duration-300 ${isItamOpen ? 'rotate-180' : ''}`} />
)}
</button>
{/* ITAM Sub Items */}
{isItamOpen && !isCollapsed && (
<div className="pl-6 space-y-1 mt-1 animate-in slide-in-from-top-2 duration-300">
{itamSubItems.map((sub) => {
const SubIcon = sub.icon;
const isActive = pathname === sub.href;
return (
<Link
key={sub.name}
href={sub.href}
className={`flex items-center px-3 py-2 rounded-lg text-[11px] font-bold transition-all ${
isActive
? 'text-primary bg-indigo-50/50'
: 'text-text-muted hover:text-text-main hover:bg-gray-50'
}`}
>
<SubIcon className="w-3.5 h-3.5 mr-2.5" />
<span className="whitespace-nowrap">{sub.name}</span>
</Link>
);
})}
</div>
)}
</div>
<Link
href="/work-reports"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/work-reports'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<FileText className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Work Reports</span>}
</Link>
<Link
href="/daily-reports"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/daily-reports'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<ClipboardCheck className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Daily Report</span>}
</Link>
{isMgmt && (
<Link
href="/work-reports/review"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/work-reports/review'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<CheckSquare className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Report Review</span>}
</Link>
)}
{role === 'ADMIN' && (
<Link
href="/settings/codes"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/settings/codes'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<Settings className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Settings</span>}
</Link>
)}
<Link
href="/calendar"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/calendar'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<CalendarDays className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Calendar</span>}
</Link>
{isMgmt && (
<Link
href="/employees"
className={`flex items-center rounded-xl font-bold text-xs transition-all ${
isCollapsed ? 'justify-center py-3' : 'px-3 py-2.5'
} ${
pathname === '/employees'
? 'bg-primary text-white shadow-lg shadow-primary/20'
: 'text-text-muted hover:bg-gray-50 hover:text-text-main'
}`}
>
<Users className={`w-4.5 h-4.5 flex-shrink-0 ${isCollapsed ? '' : 'mr-3'}`} />
{!isCollapsed && <span className="whitespace-nowrap">Employees</span>}
</Link>
)}
</nav>
</div>
{/* 내 프로젝트 */}
<div className={`border-t border-border mt-4 pt-6 ${isCollapsed ? 'px-1 py-2' : 'px-4 py-2'}`}>
<div className={`flex items-center justify-between mb-4 ${isCollapsed ? 'justify-center' : 'px-2'}`}>
{!isCollapsed ? (
<>
<p className="text-[10px] font-bold text-text-muted tracking-[0.12em] uppercase whitespace-nowrap">My Projects</p>
<button onClick={() => router.push('/dispatch')} className="text-text-muted hover:text-text-main">
<Plus className="w-3.5 h-3.5" />
</button>
</>
) : (
<p className="text-[10px] font-bold text-text-muted uppercase">MY</p>
)}
</div>
<nav className="space-y-1">
{projects.map((project) => (
<Link
key={project.name}
href="/dispatch"
title={isCollapsed ? project.name : ''}
className={`flex items-center hover:bg-gray-50 rounded-xl text-xs font-bold text-text-muted transition-colors ${
isCollapsed ? 'justify-center py-2' : 'px-3 py-2'
}`}
>
<span className={`w-2 h-2 rounded-full flex-shrink-0 ${project.dot} ${isCollapsed ? '' : 'mr-3'}`}></span>
{!isCollapsed && <span className="whitespace-nowrap">{project.name}</span>}
</Link>
))}
</nav>
</div>
</div>
{/* 하단 정보 카드 */}
<div className={`${isCollapsed ? 'p-2' : 'p-6'}`}>
{isCollapsed ? (
<button className="w-10 h-10 mx-auto bg-primary rounded-xl flex items-center justify-center text-white shadow-soft hover:bg-primary-hover transition-colors">
<Lightbulb className="w-5 h-5" />
</button>
) : (
<div className="bg-indigo-50/50 rounded-2xl p-4 border border-indigo-100/50 text-center relative overflow-hidden group">
<div className="absolute -top-4 -right-4 w-12 h-12 bg-primary/10 rounded-full opacity-50 blur-xl group-hover:scale-150 transition-transform duration-700"></div>
<div className="w-8 h-8 mx-auto bg-white rounded-full flex items-center justify-center shadow-sm mb-3">
<span className="text-lg"><Lightbulb className="w-4.5 h-4.5 text-primary" /></span>
</div>
<h4 className="font-bold text-xs text-slate-800 mb-1.5 whitespace-nowrap">Need Assistance?</h4>
<p className="text-[10px] text-slate-500 leading-relaxed mb-4">현장 장비 부족이나 기술적 이슈는 즉시 보고하세요.</p>
<button onClick={() => router.push('/issues')} className="w-full py-2 bg-white rounded-xl text-[10px] font-bold text-primary shadow-sm hover:shadow-md transition-all border border-indigo-100">
HQ에 긴급 메시지
</button>
</div>
)}
</div>
</aside>
);
};
export default Sidebar;
+75
View File
@@ -0,0 +1,75 @@
'use client';
import React, { useState, useRef, useEffect } from 'react';
import Link from 'next/link';
import { UserCircle, Settings, LogOut, ChevronDown } from 'lucide-react';
import { useAuthStore } from '@/stores';
export default function UserDropdown() {
const user = useAuthStore((s) => s.user);
const logout = useAuthStore((s) => s.logout);
const [open, setOpen] = useState(false);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const handler = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
};
if (open) document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
}, [open]);
const roleLabel: Record<string, string> = {
ADMIN: '최고관리자',
MANAGER: '본사관리자',
EMPLOYEE: '파견직원',
};
return (
<div className="relative" ref={ref}>
<button
onClick={() => setOpen(!open)}
className="flex items-center gap-3 pl-2 pr-1.5 py-1 rounded-xl hover:bg-gray-50 transition-all"
>
<div className="text-right hidden md:block">
<p className="text-sm font-medium text-text-main leading-tight">{user?.name || 'User'}</p>
<p className="text-xs text-text-muted">{roleLabel[user?.roleCode || ''] || user?.roleCode || 'HQ Center'}</p>
</div>
<div className="w-9 h-9 rounded-full bg-gradient-to-br from-primary to-purple-400 flex items-center justify-center text-white text-sm font-semibold shadow-sm flex-shrink-0">
{user?.name?.[0] || 'U'}
</div>
<ChevronDown className={`w-4 h-4 text-text-muted transition-transform ${open ? 'rotate-180' : ''}`} />
</button>
{open && (
<div className="absolute right-0 top-12 w-56 bg-white rounded-xl shadow-lg border border-border overflow-hidden z-50">
<div className="px-4 py-3 border-b border-border">
<p className="text-sm font-semibold text-text-main">{user?.name || 'User'}</p>
<p className="text-xs text-text-muted mt-0.5">{user?.email || ''}</p>
</div>
<div className="py-1">
<Link href="/profile" onClick={() => setOpen(false)} className="flex items-center gap-3 px-4 py-2.5 text-sm text-text-main hover:bg-gray-50 transition-colors">
<UserCircle className="w-4 h-4 text-text-muted" />
프로필 정보
</Link>
{user?.roleCode === 'ADMIN' && (
<Link href="/settings/codes" onClick={() => setOpen(false)} className="flex items-center gap-3 px-4 py-2.5 text-sm text-text-main hover:bg-gray-50 transition-colors">
<Settings className="w-4 h-4 text-text-muted" />
설정 (공통코드)
</Link>
)}
</div>
<div className="border-t border-border py-1">
<button onClick={() => { logout(); setOpen(false); window.location.href = '/login'; }} className="flex items-center gap-3 px-4 py-2.5 text-sm text-status-critical-text hover:bg-red-50 transition-colors w-full text-left">
<LogOut className="w-4 h-4" />
로그아웃
</button>
</div>
</div>
)}
</div>
);
}