Skip to content

Commit

Permalink
Merge pull request #35 from vidyaaKhandekar/metabase-dashboard
Browse files Browse the repository at this point in the history
Task #234692-Integrate Public Metabase URL in Profile Section
  • Loading branch information
gouravmore authored Feb 11, 2025
2 parents 59ecce3 + 407570f commit 6b6c9ff
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/layouts/header/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { firstLetterInUpperCase } from "@/utils/Helper";
import useSubmittedButtonStore from "@/utils/useSharedState";
import LogoutIcon from "@mui/icons-material/Logout";
import MailIcon from "@mui/icons-material/Mail";
import DatasetIcon from "@mui/icons-material/Dataset";
import PhoneIcon from "@mui/icons-material/Phone";
import { Box, Button, Divider, Menu, Typography } from "@mui/material";
import { useRouter } from "next/router";
Expand Down Expand Up @@ -205,6 +206,12 @@ const Profile = () => {
}
})();

const handleDashboard = () => {
const id = localStorage.getItem("userId");
setAnchorEl4(null);
router.push(`/dashboard?userId=${id}`);
};

return (
<>
<Button
Expand Down Expand Up @@ -355,6 +362,21 @@ const Profile = () => {
{adminInfo?.email}
</Typography>
</Box>
<Box
sx={{
display: "flex",
alignItems: "center",
marginBottom: "20px",
px: "20px",
cursor: "pointer",
}}
onClick={handleDashboard}
>
<DatasetIcon sx={{ marginRight: "10px" }} />
<Typography variant="body1" sx={{ fontSize: "14px" }}>
Dashboard
</Typography>
</Box>

<Divider sx={{ color: "#D0C5B4" }} />
<Box sx={{ px: "20px" }}>
Expand Down
52 changes: 52 additions & 0 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";

const Dashboard = () => {
const router = useRouter();
const { userId } = router.query;
const [isError, setIsError] = useState(false);

// Validate userId
useEffect(() => {
if (!userId) {
setIsError(true);
}
}, [userId]);

const metabaseUrl = `${process.env.NEXT_PUBLIC_METABASE_URL}${userId}`;

return (
<div>
{isError ? (
<p style={{ fontWeight: "bold" }}>
User ID is missing. Please go back and try again.
</p>
) : (
<iframe
src={metabaseUrl}
width="100%"
height="600px"
style={{ border: "none" }}
onError={() => setIsError(true)} // Handle iframe load failure
title="metabase-dashboard"
/>
)}

{isError && (
<p>
Dashboard not available. Please check your access or try again later.
</p>
)}
</div>
);
};
export async function getStaticProps({ locale }: any) {
return {
props: {
...(await serverSideTranslations(locale, ["common"])),
},
};
}

export default Dashboard;

0 comments on commit 6b6c9ff

Please sign in to comment.