Refactor DashboardCard component: add active prop handling and improve option click logic

This commit is contained in:
2025-05-29 09:55:31 +05:30
parent 0184abdd7a
commit c8627e0249
4 changed files with 34 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ interface DashBoardCardProps {
projectId: string;
handleDeleteProject?: (projectId: string) => Promise<void>;
handleRestoreProject?: (projectId: string) => Promise<void>;
active?: string;
}
const DashboardCard: React.FC<DashBoardCardProps> = ({
@@ -21,6 +22,7 @@ const DashboardCard: React.FC<DashBoardCardProps> = ({
thumbnail,
projectId,
handleRestoreProject,
active
}) => {
const navigate = useNavigate();
const { setProjectName } = useProjectName();
@@ -42,7 +44,6 @@ const DashboardCard: React.FC<DashBoardCardProps> = ({
};
const handleOptionClick = async (option: string) => {
console.log('option: ', option);
switch (option) {
case "delete":
if (handleDeleteProject) {
@@ -54,7 +55,13 @@ const DashboardCard: React.FC<DashBoardCardProps> = ({
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<DashBoardCardProps> = ({
</div>
</div>
{isKebabOpen && (
{isKebabOpen && active !== "trash" && (
<div className="kebab-options-wrapper">
{["rename", "restore", "delete", "duplicate", "open in new tab"].map((option) => (
{["rename", "delete", "duplicate", "open in new tab"].map((option) => (
<button
key={option}
className="option"
@@ -128,7 +135,25 @@ const DashboardCard: React.FC<DashBoardCardProps> = ({
))}
</div>
)}
</button>
{isKebabOpen && active && active == "trash" && (
< div className="kebab-options-wrapper">
{["restore", "delete"].map((option) => (
<button
key={option}
className="option"
onClick={(e) => {
console.log(option);
e.stopPropagation();
handleOptionClick(option);
}}
>
{option}
</button>
))}
</div>
)
}
</button >
);
};