|
1 | 1 | import Header, { DesktopHeader } from '@/components/ui/temp/Header'; |
2 | 2 | import Footer from '@/components/ui/temp/Footer'; |
3 | | -import { StatsCards } from '@/components/Center/Dashboard/StatsCards'; |
| 3 | +import StatsCards from '@/components/Center/Dashboard/StatsCards'; |
4 | 4 | import { Sidebar } from '@/components/ui/custom/Sidebar'; |
| 5 | +import { useDashboardStats } from '@/hooks/center/service/useDashboardStats'; |
| 6 | +import { TriangleAlert } from 'lucide-react'; |
5 | 7 |
|
6 | | -export default function Dashboard() { |
7 | | - return ( |
8 | | - <> |
9 | | - {/* Mobile Layout */} |
10 | | - <div className='flex flex-col h-screen lg:hidden'> |
11 | | - <Header hasBorder={false} /> |
12 | | - <main className='flex-1 bg-[var(--button-inactive)] p-5 min-h-0'> |
13 | | - <StatsCards /> |
14 | | - </main> |
15 | | - <Footer /> |
16 | | - </div> |
| 8 | +const ErrorFallback = ({ error, onRetry }) => ( |
| 9 | + <div className='flex flex-col items-center justify-center min-h-[50vh] p-8'> |
| 10 | + <div className='bg-red-50 border border-red-200 rounded-[1.25rem] p-6 max-w-md text-center'> |
| 11 | + <TriangleAlert className='mx-auto w-15 h-auto text-red-800' /> |
| 12 | + <h2 className='text-xl font-semibold text-red-800 mb-2'>오류가 발생했습니다</h2> |
| 13 | + <p className='text-red-600 text-base mb-4'> |
| 14 | + {error?.message || '페이지를 불러오는 중 문제가 발생했습니다.'} |
| 15 | + </p> |
| 16 | + <button |
| 17 | + onClick={onRetry} |
| 18 | + className='bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg text-base transition-colors cursor-pointer' |
| 19 | + > |
| 20 | + 다시 시도하기 |
| 21 | + </button> |
| 22 | + </div> |
| 23 | + </div> |
| 24 | +); |
17 | 25 |
|
18 | | - {/* Desktop Layout */} |
19 | | - <div className='hidden lg:flex lg:h-screen'> |
| 26 | +const MobileLayout = ({ statsData, isLoading, isError, fallbackProps }) => ( |
| 27 | + <div className='flex flex-col h-screen lg:hidden'> |
| 28 | + <header className='flex-shrink-0'> |
| 29 | + <Header hasBorder={false} /> |
| 30 | + </header> |
| 31 | + |
| 32 | + <main className='flex-1 bg-[var(--button-inactive)] p-5 min-h-0 overflow-y-auto'> |
| 33 | + {/* TODO: 추후 로딩 처리 */} |
| 34 | + {isLoading ? ( |
| 35 | + <div>로딩중...</div> |
| 36 | + ) : isError ? ( |
| 37 | + <ErrorFallback {...fallbackProps} /> |
| 38 | + ) : ( |
| 39 | + <StatsCards statsData={statsData} /> |
| 40 | + )} |
| 41 | + </main> |
| 42 | + |
| 43 | + <footer className='flex-shrink-0'> |
| 44 | + <Footer isManager={true} /> |
| 45 | + </footer> |
| 46 | + </div> |
| 47 | +); |
| 48 | + |
| 49 | +const DesktopLayout = ({ statsData, isLoading, isError, fallbackProps }) => { |
| 50 | + return ( |
| 51 | + <div className='hidden lg:flex lg:h-screen'> |
| 52 | + <aside className='flex-shrink-0'> |
20 | 53 | <Sidebar /> |
| 54 | + </aside> |
21 | 55 |
|
22 | | - <div className='flex-1 flex flex-col'> |
| 56 | + <div className='flex-1 flex flex-col min-w-0'> |
| 57 | + <header className='flex-shrink-0'> |
23 | 58 | <DesktopHeader onSidebarToggle={() => {}} isSidebarCollapsed={false} /> |
| 59 | + </header> |
24 | 60 |
|
25 | | - <main className='flex-1 bg-[var(--button-inactive)] lg:bg-[#f6f8fc] px-8 py-5 lg:py-20 lg:px-14 min-h-0'> |
26 | | - <StatsCards /> |
27 | | - </main> |
28 | | - </div> |
| 61 | + <main className='flex-1 bg-[var(--button-inactive)] lg:bg-[#f6f8fc] px-8 py-5 lg:py-20 lg:px-14 min-h-0 overflow-y-auto'> |
| 62 | + {/* TODO: 추후 로딩 처리 필요 */} |
| 63 | + {isLoading ? ( |
| 64 | + <div>로딩중..</div> |
| 65 | + ) : isError ? ( |
| 66 | + <ErrorFallback {...fallbackProps} /> |
| 67 | + ) : ( |
| 68 | + <StatsCards statsData={statsData} /> |
| 69 | + )} |
| 70 | + </main> |
29 | 71 | </div> |
| 72 | + </div> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export default function Dashboard() { |
| 77 | + const { data: statsData, isLoading, isError, error, refetch } = useDashboardStats(); |
| 78 | + |
| 79 | + const fallbackProps = { |
| 80 | + error, |
| 81 | + onRetry: refetch, |
| 82 | + }; |
| 83 | + |
| 84 | + return ( |
| 85 | + <> |
| 86 | + <MobileLayout |
| 87 | + statsData={statsData} |
| 88 | + isLoading={isLoading} |
| 89 | + isError={isError} |
| 90 | + fallbackProps={fallbackProps} |
| 91 | + /> |
| 92 | + <DesktopLayout |
| 93 | + statsData={statsData} |
| 94 | + isLoading={isLoading} |
| 95 | + isError={isError} |
| 96 | + fallbackProps={fallbackProps} |
| 97 | + /> |
30 | 98 | </> |
31 | 99 | ); |
32 | 100 | } |
0 commit comments