[st] WIP: 대시보드 페이지
This commit is contained in:
@@ -1,9 +1,96 @@
|
||||
const Dashboard = () => {
|
||||
return (
|
||||
<div>
|
||||
Dashboard
|
||||
</div>
|
||||
);
|
||||
};
|
||||
"use client";
|
||||
|
||||
export default Dashboard;
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { closestCenter, DndContext } from "@dnd-kit/core";
|
||||
import { rectSortingStrategy, SortableContext } from "@dnd-kit/sortable";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { useUserStore } from "@/shared/lib";
|
||||
import { Skeleton } from "@common/components";
|
||||
|
||||
import { useDndSensors } from "@/pages/statistics/lib/hooks/use-dnd-sensors";
|
||||
import { usePanelOrder } from "@/pages/statistics/lib/hooks/use-panel-order";
|
||||
import { getInitialPanels } from "@/pages/statistics/model/panel-config";
|
||||
import { SortablePanel } from "@/pages/statistics/ui/sortable-panel";
|
||||
|
||||
interface PanelItem {
|
||||
id: string;
|
||||
component: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function Dashboard() {
|
||||
const userInfo = useUserStore((state) => state.userInfo);
|
||||
const [initialPanels, setInitialPanels] = useState<PanelItem[]>([]);
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
const sensors = useDndSensors();
|
||||
|
||||
const { panels, handleDragEnd } = usePanelOrder({
|
||||
initialPanels,
|
||||
storageKey: "statistics-dashboard-panels-order",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!userInfo) return;
|
||||
const initialPanels = getInitialPanels({
|
||||
dashboardParams: {
|
||||
statsYr: String(dayjs().year() - 1),
|
||||
dtlInstCd: userInfo.dtlInstCd,
|
||||
enoCd: userInfo.enoCd,
|
||||
laeSeCd: userInfo.laeSeCd,
|
||||
},
|
||||
scheduleInfoParams: {
|
||||
statsYr: String(dayjs().year() - 1),
|
||||
},
|
||||
});
|
||||
setInitialPanels(initialPanels);
|
||||
}, [userInfo]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isMounted && initialPanels.length > 0 ? (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={panels.map((p) => p.id)}
|
||||
strategy={rectSortingStrategy}
|
||||
>
|
||||
{/* TBD: 그리드 레이아웃 비율 정의 필요
|
||||
현재: 3열 그리드, 반응형 브레이크포인트 적용
|
||||
SPEC 레이아웃에 따라 조정 필요 */}
|
||||
<div className="grid grid-cols-1 gap-4 p-2 md:grid-cols-2 lg:grid-cols-3">
|
||||
{panels.map((panel) => (
|
||||
<SortablePanel
|
||||
key={panel.id}
|
||||
id={panel.id}
|
||||
className={panel.className}
|
||||
>
|
||||
{panel.component}
|
||||
</SortablePanel>
|
||||
))}
|
||||
</div>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4 p-2 md:grid-cols-2 lg:grid-cols-3">
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
<Skeleton className="h-[20rem] rounded-xl" />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Dashboard;
|
||||
|
||||
Reference in New Issue
Block a user