From c8627e0249e0a6e45f779709582ac0f998cb0eaf Mon Sep 17 00:00:00 2001 From: Poovizhi99 Date: Thu, 29 May 2025 09:55:31 +0530 Subject: [PATCH] Refactor DashboardCard component: add active prop handling and improve option click logic --- .../components/Dashboard/DashboardCard.tsx | 35 ++++++++++++++++--- .../components/Dashboard/DashboardTrash.tsx | 1 + app/src/services/dashboard/recentlyViewed.ts | 6 ++-- app/src/services/dashboard/restoreTrash.ts | 2 +- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/src/components/Dashboard/DashboardCard.tsx b/app/src/components/Dashboard/DashboardCard.tsx index 75378b1..7ff0caf 100644 --- a/app/src/components/Dashboard/DashboardCard.tsx +++ b/app/src/components/Dashboard/DashboardCard.tsx @@ -13,6 +13,7 @@ interface DashBoardCardProps { projectId: string; handleDeleteProject?: (projectId: string) => Promise; handleRestoreProject?: (projectId: string) => Promise; + active?: string; } const DashboardCard: React.FC = ({ @@ -21,6 +22,7 @@ const DashboardCard: React.FC = ({ thumbnail, projectId, handleRestoreProject, + active }) => { const navigate = useNavigate(); const { setProjectName } = useProjectName(); @@ -42,7 +44,6 @@ const DashboardCard: React.FC = ({ }; const handleOptionClick = async (option: string) => { - console.log('option: ', option); switch (option) { case "delete": if (handleDeleteProject) { @@ -54,7 +55,13 @@ const DashboardCard: React.FC = ({ await handleRestoreProject(projectId); } break; - case "openInNewTab": + case "open in new tab": + try { + await viewProject(organization, projectId, userId); + setProjectName(projectName); // optional depending on scope + } catch (error) { + console.error("Error opening project in new tab:", error); + } window.open(`/${projectId}`, "_blank"); break; case "rename": @@ -111,9 +118,9 @@ const DashboardCard: React.FC = ({ - {isKebabOpen && ( + {isKebabOpen && active !== "trash" && (
- {["rename", "restore", "delete", "duplicate", "open in new tab"].map((option) => ( + {["rename", "delete", "duplicate", "open in new tab"].map((option) => (
)} - + {isKebabOpen && active && active == "trash" && ( + < div className="kebab-options-wrapper"> + {["restore", "delete"].map((option) => ( + + ))} + + ) + } + ); }; diff --git a/app/src/components/Dashboard/DashboardTrash.tsx b/app/src/components/Dashboard/DashboardTrash.tsx index 17de39b..06bf179 100644 --- a/app/src/components/Dashboard/DashboardTrash.tsx +++ b/app/src/components/Dashboard/DashboardTrash.tsx @@ -96,6 +96,7 @@ const DashboardTrash: React.FC = () => { thumbnail={project.thumbnail} projectId={project._id} handleRestoreProject={handleRestoreProject} + active={"trash"} /> )); }; diff --git a/app/src/services/dashboard/recentlyViewed.ts b/app/src/services/dashboard/recentlyViewed.ts index 0b42c08..78a0696 100644 --- a/app/src/services/dashboard/recentlyViewed.ts +++ b/app/src/services/dashboard/recentlyViewed.ts @@ -7,9 +7,9 @@ export const recentlyViewed = async (organization: string, userId: string) => { { method: "GET", headers: { - Authorization: "Bearer ", // Replace with actual token + Authorization: "Bearer ", // Replace with actual token "Content-Type": "application/json", - token: localStorage.getItem("token") || "", // Coerce null to empty string + token: localStorage.getItem("token") || "", // Coerce null to empty string refresh_token: localStorage.getItem("refreshToken") || "", }, } @@ -18,9 +18,7 @@ export const recentlyViewed = async (organization: string, userId: string) => { if (!response.ok) { throw new Error("Failed to fetch project"); } - - console.log('response: ', response); return await response.json(); } catch (error: any) { console.error("Failed to get project"); diff --git a/app/src/services/dashboard/restoreTrash.ts b/app/src/services/dashboard/restoreTrash.ts index 8e234b1..2af5d06 100644 --- a/app/src/services/dashboard/restoreTrash.ts +++ b/app/src/services/dashboard/restoreTrash.ts @@ -4,7 +4,7 @@ const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_ export const restoreTrash = async (organization: string, projectId: string) => { try { const response = await fetch( - `${url_Backend_dwinzo}api/v2/Trash/restore?projectId=${projectId}`, + `${url_Backend_dwinzo}/api/v2/Trash/restore?projectId=${projectId}`, { method: "PATCH", headers: {