Refactor Dashboard Management to Use Tab Store for Navigation
- Removed the useRouter hook and replaced it with the useTabStore for managing tab navigation in the Dashboard List and Dashboard Designer pages. - Updated button and row click handlers to utilize the openTab function, enhancing the user experience by allowing for tabbed navigation instead of direct routing. - This change improves the overall structure and maintainability of the dashboard management functionality, aligning with the new tab management system.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import React, { useState, useRef, useCallback } from "react";
|
||||
import { use } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { DashboardCanvas } from "@/components/admin/dashboard/DashboardCanvas";
|
||||
import { DashboardTopMenu } from "@/components/admin/dashboard/DashboardTopMenu";
|
||||
import { WidgetConfigSidebar } from "@/components/admin/dashboard/WidgetConfigSidebar";
|
||||
@@ -12,6 +11,7 @@ import { GRID_CONFIG, snapToGrid, snapSizeToGrid, calculateCellSize, calculateBo
|
||||
import { Resolution, RESOLUTIONS, detectScreenResolution } from "@/components/admin/dashboard/ResolutionSelector";
|
||||
import { DashboardProvider } from "@/contexts/DashboardContext";
|
||||
import { useMenu } from "@/contexts/MenuContext";
|
||||
import { useTabStore } from "@/stores/tabStore";
|
||||
import { useKeyboardShortcuts } from "@/components/admin/dashboard/hooks/useKeyboardShortcuts";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -51,8 +51,8 @@ export default function DashboardDesignerPage({ params }: { params: Promise<{ id
|
||||
// "new"면 생성 모드, 아니면 편집 모드
|
||||
const initialDashboardId = paramId === "new" ? undefined : paramId;
|
||||
|
||||
const router = useRouter();
|
||||
const { refreshMenus } = useMenu();
|
||||
const openTab = useTabStore((s) => s.openTab);
|
||||
const [elements, setElements] = useState<DashboardElement[]>([]);
|
||||
const [selectedElement, setSelectedElement] = useState<string | null>(null);
|
||||
const [selectedElements, setSelectedElements] = useState<string[]>([]); // 다중 선택
|
||||
@@ -650,7 +650,7 @@ export default function DashboardDesignerPage({ params }: { params: Promise<{ id
|
||||
open={successModalOpen}
|
||||
onOpenChange={() => {
|
||||
setSuccessModalOpen(false);
|
||||
router.push("/admin/screenMng/dashboardList");
|
||||
openTab({ type: "admin", title: "대시보드 관리", adminUrl: "/admin/screenMng/dashboardList" });
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
@@ -667,7 +667,7 @@ export default function DashboardDesignerPage({ params }: { params: Promise<{ id
|
||||
<Button
|
||||
onClick={() => {
|
||||
setSuccessModalOpen(false);
|
||||
router.push("/admin/screenMng/dashboardList");
|
||||
openTab({ type: "admin", title: "대시보드 관리", adminUrl: "/admin/screenMng/dashboardList" });
|
||||
}}
|
||||
>
|
||||
확인
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { dashboardApi } from "@/lib/api/dashboard";
|
||||
import { Dashboard } from "@/lib/api/dashboard";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -18,6 +17,7 @@ import { DeleteConfirmModal } from "@/components/common/DeleteConfirmModal";
|
||||
import { ResponsiveDataView, RDVColumn, RDVCardField } from "@/components/common/ResponsiveDataView";
|
||||
import { ScrollToTop } from "@/components/common/ScrollToTop";
|
||||
import { Plus, Search, Edit, Trash2, Copy, MoreVertical, AlertCircle, RefreshCw } from "lucide-react";
|
||||
import { useTabStore } from "@/stores/tabStore";
|
||||
|
||||
/**
|
||||
* 대시보드 관리 페이지
|
||||
@@ -26,8 +26,8 @@ import { Plus, Search, Edit, Trash2, Copy, MoreVertical, AlertCircle, RefreshCw
|
||||
* - 대시보드 생성/수정/삭제/복사
|
||||
*/
|
||||
export default function DashboardListPage() {
|
||||
const router = useRouter();
|
||||
const { toast } = useToast();
|
||||
const openTab = useTabStore((s) => s.openTab);
|
||||
|
||||
// 상태 관리
|
||||
const [dashboards, setDashboards] = useState<Dashboard[]>([]);
|
||||
@@ -145,7 +145,7 @@ export default function DashboardListPage() {
|
||||
label: "제목",
|
||||
render: (_v, row) => (
|
||||
<button
|
||||
onClick={() => router.push(`/admin/screenMng/dashboardList/${row.id}`)}
|
||||
onClick={(e) => { e.stopPropagation(); openTab({ type: "admin", title: row.title, adminUrl: `/admin/screenMng/dashboardList/${row.id}` }); }}
|
||||
className="hover:text-primary cursor-pointer text-left font-medium transition-colors hover:underline"
|
||||
>
|
||||
{row.title}
|
||||
@@ -217,7 +217,7 @@ export default function DashboardListPage() {
|
||||
총 <span className="text-foreground font-semibold">{totalCount.toLocaleString()}</span> 건
|
||||
</div>
|
||||
</div>
|
||||
<Button onClick={() => router.push("/admin/screenMng/dashboardList/new")} className="h-10 gap-2 text-sm font-medium">
|
||||
<Button onClick={() => openTab({ type: "admin", title: "새 대시보드", adminUrl: "/admin/screenMng/dashboardList/new" })} className="h-10 gap-2 text-sm font-medium">
|
||||
<Plus className="h-4 w-4" />
|
||||
새 대시보드 생성
|
||||
</Button>
|
||||
@@ -251,7 +251,7 @@ export default function DashboardListPage() {
|
||||
cardTitle={(d) => d.title}
|
||||
cardSubtitle={(d) => d.id}
|
||||
cardFields={cardFields}
|
||||
onRowClick={(d) => router.push(`/admin/screenMng/dashboardList/${d.id}`)}
|
||||
onRowClick={(d) => openTab({ type: "admin", title: d.title, adminUrl: `/admin/screenMng/dashboardList/${d.id}` })}
|
||||
renderActions={(d) => (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -261,7 +261,7 @@ export default function DashboardListPage() {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => router.push(`/admin/screenMng/dashboardList/${d.id}`)}
|
||||
onClick={() => openTab({ type: "admin", title: d.title, adminUrl: `/admin/screenMng/dashboardList/${d.id}` })}
|
||||
className="gap-2 text-sm"
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
|
||||
Reference in New Issue
Block a user