Skip to content

Commit

Permalink
feat: Refactor sidebar into multiple components
Browse files Browse the repository at this point in the history
  • Loading branch information
RudraPatel2003 committed Dec 29, 2024
1 parent 7af38b9 commit 7c1f07c
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 177 deletions.
16 changes: 16 additions & 0 deletions src/app/dashboard/admin/programs/diabetes-prevention/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from "@mui/material";

export default function DiabetesPreventionProgramPage() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Typography>Diabetes Prevention Program</Typography>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from "@mui/material";

export default function GetPreventativeScreeningsProgramPage() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Typography>Get Preventative Screenings Program</Typography>
</Box>
);
}
16 changes: 16 additions & 0 deletions src/app/dashboard/admin/programs/healthy-habits/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from "@mui/material";

export default function HealthyHabitsProgramPage() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Typography>Healthy Habits Program</Typography>
</Box>
);
}
16 changes: 16 additions & 0 deletions src/app/dashboard/admin/programs/rigs-without-cigs/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from "@mui/material";

export default function RigsWithoutCigsProgramPage() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Typography>Rigs Without Cigs Program</Typography>
</Box>
);
}
16 changes: 16 additions & 0 deletions src/app/dashboard/admin/programs/vaccine-voucher/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from "@mui/material";

export default function VaccineVoucherProgramPage() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Typography>Vaccine Voucher Program</Typography>
</Box>
);
}
58 changes: 58 additions & 0 deletions src/components/AdminDashboard/Sidebar/CollapsibleSidebarButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use client";

import { ExpandLess, ExpandMore } from "@mui/icons-material";
import {
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
Theme,
} from "@mui/material";
import { ReactNode } from "react";

import getButtonStyles from "@/components/AdminDashboard/Sidebar/getButtonStyles";

type CollapsibleSidebarButtonProps = {
pathname: string;
theme: Theme;
href: string;
icon: ReactNode;
label: string;
onClick: () => void;
open?: boolean;
};

export default function CollapsibleSidebarButton({
pathname,
theme,
href,
icon,
label,
onClick,
open = false,
}: CollapsibleSidebarButtonProps) {
const { color, backgroundColor, hoverBackgroundColor } = getButtonStyles(
theme,
pathname,
href,
);

return (
<ListItem disablePadding onClick={onClick}>
<ListItemButton
sx={{
backgroundColor: backgroundColor,
"&:hover": { backgroundColor: hoverBackgroundColor },
}}
>
<ListItemIcon sx={{ color: color }}>{icon}</ListItemIcon>
<ListItemText primary={label} sx={{ color: color }} />
{open ? (
<ExpandLess sx={{ color: color }} />
) : (
<ExpandMore sx={{ color: color }} />
)}
</ListItemButton>
</ListItem>
);
}
54 changes: 54 additions & 0 deletions src/components/AdminDashboard/Sidebar/SidebarButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";

import {
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
Theme,
} from "@mui/material";
import Link from "next/link";
import { ReactNode } from "react";

import getButtonStyles from "@/components/AdminDashboard/Sidebar/getButtonStyles";

type SidebarButtonProps = {
pathname: string;
theme: Theme;
href: string;
icon: ReactNode;
label: string;
padLeft?: boolean;
};

export default function SidebarButton({
pathname,
theme,
href,
icon,
label,
padLeft,
}: SidebarButtonProps) {
const { color, backgroundColor, hoverBackgroundColor } = getButtonStyles(
theme,
pathname,
href,
);

return (
<Link href={href} style={{ textDecoration: "none" }}>
<ListItem disablePadding>
<ListItemButton
sx={{
backgroundColor: backgroundColor,
"&:hover": { backgroundColor: hoverBackgroundColor },
paddingLeft: padLeft ? 4 : undefined,
}}
>
<ListItemIcon sx={{ color: color }}>{icon}</ListItemIcon>
<ListItemText primary={label} sx={{ color: color }} />
</ListItemButton>
</ListItem>
</Link>
);
}
17 changes: 17 additions & 0 deletions src/components/AdminDashboard/Sidebar/getButtonStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Theme } from "@mui/material";

export default function getButtonStyles(
theme: Theme,
pathname: string,
href: string,
) {
const isCurrentPage = pathname === href;

return {
backgroundColor: isCurrentPage ? theme.palette.primary.main : "inherit",
hoverBackgroundColor: isCurrentPage
? theme.palette.primary.light
: "lightgray",
color: isCurrentPage ? theme.palette.primary.contrastText : "black",
};
}
Loading

0 comments on commit 7c1f07c

Please sign in to comment.