Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
RudraPatel2003 committed Jan 21, 2025
1 parent ce48401 commit 46f40f1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
12 changes: 7 additions & 5 deletions src/app/dashboard/admin/programs/healthy-habits/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Box, Typography } from "@mui/material";

import HealthyHabitsDashboard from "@/components/AdminDashboard/HealthyHabitsDashboard";
import { getHealthHabitsProgramEnrollments } from "@/server/api/program-enrollments/queries";
import { getHealthyHabitsProgramEnrollments } from "@/server/api/program-enrollments/queries";

export default async function HealthyHabits() {
const [healthHabitsProgramEnrollments, error] =
await getHealthHabitsProgramEnrollments();
const [healthyHabitsProgramEnrollments, error] =
await getHealthyHabitsProgramEnrollments();

if (error !== null) {
return (
Expand All @@ -25,14 +25,16 @@ export default async function HealthyHabits() {
return (
<Box
sx={{
height: "100vh",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
marginTop: "100px",
padding: 4,
}}
>
<HealthyHabitsDashboard
healthHabitsProgramEnrollments={healthHabitsProgramEnrollments}
healthyHabitsProgramEnrollments={healthyHabitsProgramEnrollments}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ const createRowFromHealthyHabitsProgramEnrollment = (
let completed = false;

if (user.healthyHabitsTrackingForms.length > 0) {
const date = dayjsUtil(user.healthyHabitsTrackingForms[0]?.submittedDate);
const lastSunday = dayjsUtil()
.subtract(dayjsUtil().day(), "day")
.startOf("day");

const latestFormSubmission = user.healthyHabitsTrackingForms[0];
completed = date.isSame(lastSunday, "day");
}

Expand All @@ -50,42 +46,40 @@ function getRows(programEnrollments: ProgramEnrollment[]): Row[] {
}

type HealthyHabitsClientDashboardProps = {
healthHabitsProgramEnrollments: ProgramEnrollment[];
healthyHabitsProgramEnrollments: ProgramEnrollment[];
};

export default function HealthyHabitsClientDashboard({
healthHabitsProgramEnrollments,
healthyHabitsProgramEnrollments,
}: HealthyHabitsClientDashboardProps) {
const rows = getRows(healthHabitsProgramEnrollments);
const rows = getRows(healthyHabitsProgramEnrollments);
const [searchQuery, setSearchQuery] = useState("");

const columns: GridColDef<Row>[] = [
{
field: "firstName",
headerName: "First name",
width: 150,
flex: 1,
},
{
field: "lastName",
headerName: "Last name",
width: 150,
flex: 1,
},
{
field: "phoneNumber",
headerName: "Phone Number",
width: 125,
flex: 1,
},
{
field: "email",
headerName: "Email",
minWidth: 200,
flex: 1,
flex: 2,
},
{
field: "competed",
headerName: "Completed",
headerName: "Completed tracking form this week?",
sortable: false,
minWidth: 100,
flex: 1,
renderCell: (params) => {
const completed = params.row.completed;
Expand Down Expand Up @@ -120,7 +114,7 @@ export default function HealthyHabitsClientDashboard({
<>
<Box>
<Typography align="center" variant="h4" sx={{ m: 2 }}>
Health Habits
Healthy Habits Clients
</Typography>
<Box display="flex" alignItems="center" sx={{ py: 2 }}>
<TextField
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use client";

import { Typography } from "@mui/material";
import { Box, Typography } from "@mui/material";

export default function HealthyHabitsMetrics() {
return <Typography>Healthy Habits Metrics</Typography>;
return (
<Box sx={{ width: "100%", display: "flex", justifyContent: "center" }}>
<Typography variant="h6">Metrics</Typography>
</Box>
);
}
20 changes: 10 additions & 10 deletions src/components/AdminDashboard/HealthyHabitsDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { ProgramEnrollment } from "@/types";
type HealthyHabitsSections = "clients" | "metrics";

type HealthyHabitsDashboardProps = {
healthHabitsProgramEnrollments: ProgramEnrollment[];
healthyHabitsProgramEnrollments: ProgramEnrollment[];
};

export default function HealthyHabitsDashboard({
healthHabitsProgramEnrollments,
healthyHabitsProgramEnrollments,
}: HealthyHabitsDashboardProps) {
const [selectedSection, setSelectedSection] =
useState<HealthyHabitsSections>("clients");
Expand All @@ -31,7 +31,7 @@ export default function HealthyHabitsDashboard({
case "clients":
return (
<HealthyHabitsClientDashboard
healthHabitsProgramEnrollments={healthHabitsProgramEnrollments}
healthyHabitsProgramEnrollments={healthyHabitsProgramEnrollments}
/>
);
case "metrics":
Expand All @@ -46,17 +46,15 @@ export default function HealthyHabitsDashboard({
<Box
sx={{
display: "flex",
justifyContent: "flex-start",
alignItems: "center",
flexDirection: "column",
width: "95%",
height: "75%",
marginTop: "100px",
justifyContent: "center",
alignItems: "center",
width: "100%",
}}
>
<Box
sx={{
width: "100%",
alignSelf: "flex-start",
}}
>
<Tabs
Expand All @@ -69,7 +67,9 @@ export default function HealthyHabitsDashboard({
<Tab label="Metrics" value="metrics" />
</Tabs>
</Box>
<Box sx={{ marginTop: 3 }}>{getSectionContent(selectedSection)}</Box>
<Box sx={{ marginTop: 3, width: "100%" }}>
{getSectionContent(selectedSection)}
</Box>
</Box>
</>
);
Expand Down
6 changes: 3 additions & 3 deletions src/server/api/program-enrollments/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export async function getProgramEnrollmentForUser(
}
}

export async function getHealthHabitsProgramEnrollments(): Promise<
export async function getHealthyHabitsProgramEnrollments(): Promise<
ApiResponse<ProgramEnrollment[]>
> {
await dbConnect();
try {
const healthHabitsEnrollments = ProgramEnrollmentModel.find({
const healthyHabitsEnrollments = await ProgramEnrollmentModel.find({
status: "accepted",
program: "Healthy Habits For The Long Haul",
})
Expand All @@ -100,7 +100,7 @@ export async function getHealthHabitsProgramEnrollments(): Promise<
.lean<ProgramEnrollment[]>()
.exec();

return [await healthHabitsEnrollments, null];
return [serializeMongooseObject(healthyHabitsEnrollments), null];
} catch (error) {
console.error(error);
return [null, handleMongooseError(error)];
Expand Down

0 comments on commit 46f40f1

Please sign in to comment.