From edb6ee8bb08b564a2b4dbdef081a77b7ff438dff Mon Sep 17 00:00:00 2001
From: Rudra Patel <85089368+RudraPatel2003@users.noreply.github.com>
Date: Sat, 11 Jan 2025 17:17:25 -0500
Subject: [PATCH] feat: Store week of submission and submission date separately
(#96)
---
src/app/layout.tsx | 2 +-
.../AcceptPendingApplicationButton.tsx | 3 ++-
.../GeneralInformationResponses.tsx | 3 ++-
.../ProgramSelectionResponses.tsx | 5 +++--
.../GetPreventativeScreeningResponses.tsx | 3 ++-
...thyHabitsAndDiabetesPreventionResponses.tsx | 5 +++--
.../RigsWithoutCigsResponses.tsx | 5 +++--
.../VaccineVoucherResponses.tsx | 5 +++--
.../ProgramSpecificResponses/index.tsx | 11 ++++++-----
.../QualifyingQuestionResponses.tsx | 5 +++--
.../PendingApplicationInfoModal/index.tsx | 9 +++++----
.../RejectPendingApplicationButton.tsx | 3 ++-
.../PendingApplicationDashboard/index.tsx | 7 ++++---
.../Sidebar/CollapsibleSidebarButton.tsx | 2 +-
.../AdminDashboard/Sidebar/SidebarButton.tsx | 2 +-
.../AdminDashboard/Sidebar/index.tsx | 4 ++--
.../ChangePassword/ChangePasswordForm.tsx | 3 ++-
.../HealthyHabitsTrackingFormListItem.tsx | 5 +++--
.../HealthyHabitsTrackingFormModal.tsx | 6 +++++-
.../HealthyHabitsTrackingFormList/index.tsx | 5 +++--
.../HealthyHabitsHistory/ModularBarChart.tsx | 6 ++++--
.../HealthyHabitsHistory/ModularLineChart.tsx | 4 ++--
.../HealthyHabitsHistory/index.tsx | 7 ++++---
.../HealthyHabits/HealthyHabitsTracking.tsx | 18 +++++++++++-------
.../ClientDashboard/HealthyHabits/index.tsx | 11 ++++++-----
.../GeneralInformationFormSection.tsx | 5 +++--
.../ProgramSelectionFormSection.tsx | 2 +-
.../ProgramSpecificQuestionsFormSection.tsx | 11 ++++++-----
.../QualifyingQuestionsFormSection.tsx | 5 +++--
.../ForgotPassword/ForgotPasswordForm.tsx | 3 ++-
.../ForgotPassword/ResetPasswordForm.tsx | 3 ++-
src/components/Header/index.tsx | 4 ++--
src/components/LoginForm/index.tsx | 2 +-
src/components/Settings/AdminSettings.tsx | 5 +++--
src/components/Settings/ClientSettings.tsx | 5 +++--
.../private-mutations.ts | 2 +-
.../public-mutations.ts | 5 +----
.../healthy-habits-tracking-forms/queries.ts | 4 ++--
src/server/api/users/queries.ts | 2 +-
src/server/models/HealthyHabitsTrackingForm.ts | 1 +
src/types/HealthyHabitsTrackingForm.ts | 1 +
src/utils/getClosestPastSunday.ts | 14 ++++++++++----
42 files changed, 126 insertions(+), 87 deletions(-)
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index e22794c..3df9aa1 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -4,7 +4,7 @@ import { AppRouterCacheProvider } from "@mui/material-nextjs/v14-appRouter";
import type { Metadata } from "next";
import { Roboto } from "next/font/google";
-import Header from "@/components/Header";
+import { Header } from "@/components/Header";
import NextAuthProvider from "@/providers/NextAuthProvider";
import theme from "@/styles/theme";
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/AcceptPendingApplicationButton.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/AcceptPendingApplicationButton.tsx
index ae9ff8e..82da09a 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/AcceptPendingApplicationButton.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/AcceptPendingApplicationButton.tsx
@@ -4,10 +4,11 @@ import { Check } from "@mui/icons-material";
import Button from "@mui/material/Button";
import React, { Dispatch, SetStateAction } from "react";
-import { Row } from "@/components/AdminDashboard/PendingApplicationDashboard";
import { handleApproveProgramApplication } from "@/server/api/program-enrollments/public-mutations";
import { ProgramEnrollment } from "@/types";
+import { Row } from ".";
+
type AcceptPendingApplicationButtonProps = {
programEnrollment: ProgramEnrollment;
rows: Row[];
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/GeneralInformationResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/GeneralInformationResponses.tsx
index 8c414c3..7fb87b7 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/GeneralInformationResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/GeneralInformationResponses.tsx
@@ -1,8 +1,9 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
import { GeneralInformationSection } from "@/types/EnrollmentForm";
+import FormResponse from "./FormResponse";
+
type GeneralInformationResponsesProps = {
generalInformationSection: GeneralInformationSection;
};
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSelectionResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSelectionResponses.tsx
index 1805a58..93988e2 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSelectionResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSelectionResponses.tsx
@@ -1,7 +1,8 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
-import { ProgramSelectionSection } from "@/types/EnrollmentForm";
+import { ProgramSelectionSection } from "@/types";
+
+import FormResponse from "./FormResponse";
type ProgramSelectionResponsesProps = {
programSelectionSection: ProgramSelectionSection;
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/GetPreventativeScreeningResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/GetPreventativeScreeningResponses.tsx
index 0accd4c..e80a710 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/GetPreventativeScreeningResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/GetPreventativeScreeningResponses.tsx
@@ -1,8 +1,9 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
import { ProgramSpecificQuestionsSection } from "@/types/EnrollmentForm";
+import FormResponse from "../FormResponse";
+
type GetPreventativeScreeningResponsesProps = {
programSpecificQuestionsSection: ProgramSpecificQuestionsSection;
};
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/HealthyHabitsAndDiabetesPreventionResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/HealthyHabitsAndDiabetesPreventionResponses.tsx
index 9be5326..eef07fa 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/HealthyHabitsAndDiabetesPreventionResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/HealthyHabitsAndDiabetesPreventionResponses.tsx
@@ -1,9 +1,10 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
-import { ProgramSpecificQuestionsSection } from "@/types/EnrollmentForm";
+import { ProgramSpecificQuestionsSection } from "@/types";
import getBmiClassification from "@/utils/getBmiClassification";
+import FormResponse from "../FormResponse";
+
type HealthyHabitsAndDiabetesPreventionResponsesProps = {
programSpecificQuestionsSection: ProgramSpecificQuestionsSection;
};
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/RigsWithoutCigsResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/RigsWithoutCigsResponses.tsx
index 95b8079..c6110d7 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/RigsWithoutCigsResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/RigsWithoutCigsResponses.tsx
@@ -1,7 +1,8 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
-import { ProgramSpecificQuestionsSection } from "@/types/EnrollmentForm";
+import { ProgramSpecificQuestionsSection } from "@/types";
+
+import FormResponse from "../FormResponse";
type RigsWithoutCigsResponsesProps = {
programSpecificQuestionsSection: ProgramSpecificQuestionsSection;
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/VaccineVoucherResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/VaccineVoucherResponses.tsx
index 74ac655..6af7eda 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/VaccineVoucherResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/VaccineVoucherResponses.tsx
@@ -1,7 +1,8 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
-import { ProgramSpecificQuestionsSection } from "@/types/EnrollmentForm";
+import { ProgramSpecificQuestionsSection } from "@/types";
+
+import FormResponse from "../FormResponse";
type VaccineVoucherResponsesProps = {
programSpecificQuestionsSection: ProgramSpecificQuestionsSection;
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/index.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/index.tsx
index d1aa272..47edc9b 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/index.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/index.tsx
@@ -1,10 +1,11 @@
import { Box, Typography } from "@mui/material";
-import GetPreventativeScreeningResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/GetPreventativeScreeningResponses";
-import HealthyHabitsAndDiabetesPreventionResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/HealthyHabitsAndDiabetesPreventionResponses";
-import RigsWithoutCigsResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/RigsWithoutCigsResponses";
-import VaccineVoucherResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses/VaccineVoucherResponses";
-import { ProgramSpecificQuestionsSection } from "@/types/EnrollmentForm";
+import { ProgramSpecificQuestionsSection } from "@/types";
+
+import GetPreventativeScreeningResponses from "./GetPreventativeScreeningResponses";
+import HealthyHabitsAndDiabetesPreventionResponses from "./HealthyHabitsAndDiabetesPreventionResponses";
+import RigsWithoutCigsResponses from "./RigsWithoutCigsResponses";
+import VaccineVoucherResponses from "./VaccineVoucherResponses";
type ProgramSpecificResponsesProps = {
programSpecificQuestionsSection: ProgramSpecificQuestionsSection;
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/QualifyingQuestionResponses.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/QualifyingQuestionResponses.tsx
index cab8c93..e677638 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/QualifyingQuestionResponses.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/QualifyingQuestionResponses.tsx
@@ -1,7 +1,8 @@
import { Box, Typography } from "@mui/material";
-import FormResponse from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/FormResponse";
-import { QualifyingQuestionsSection } from "@/types/EnrollmentForm";
+import { QualifyingQuestionsSection } from "@/types";
+
+import FormResponse from "./FormResponse";
type QualifyingQuestionResponsesProps = {
qualifyingQuestionsSection: QualifyingQuestionsSection;
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/index.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/index.tsx
index 7bc1761..1506998 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/index.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/index.tsx
@@ -4,12 +4,13 @@ import InfoIcon from "@mui/icons-material/Info";
import { Box, Button, Fade, Modal, Typography } from "@mui/material";
import { useState } from "react";
-import GeneralInformationResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/GeneralInformationResponses";
-import ProgramSelectionResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSelectionResponses";
-import ProgramSpecificResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/ProgramSpecificResponses";
-import QualifyingQuestionResponses from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal/QualifyingQuestionResponses";
import { EnrollmentForm } from "@/types";
+import GeneralInformationResponses from "./GeneralInformationResponses";
+import ProgramSelectionResponses from "./ProgramSelectionResponses";
+import ProgramSpecificResponses from "./ProgramSpecificResponses";
+import QualifyingQuestionResponses from "./QualifyingQuestionResponses";
+
const style = {
position: "absolute",
top: "50%",
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/RejectPendingApplicationButton.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/RejectPendingApplicationButton.tsx
index f019a1f..24d0e6a 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/RejectPendingApplicationButton.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/RejectPendingApplicationButton.tsx
@@ -11,11 +11,12 @@ import React, { Dispatch, SetStateAction, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
-import { Row } from "@/components/AdminDashboard/PendingApplicationDashboard";
import ControlledTextField from "@/components/controlled/ControlledTextField";
import { handleRejectProgramApplication } from "@/server/api/program-enrollments/public-mutations";
import { ProgramEnrollment } from "@/types";
+import { Row } from ".";
+
const rejectionReasonSchema = z.object({
rejectionReason: z.string().min(1, { message: "Reason is required" }),
});
diff --git a/src/components/AdminDashboard/PendingApplicationDashboard/index.tsx b/src/components/AdminDashboard/PendingApplicationDashboard/index.tsx
index 5386cad..a3d9b61 100644
--- a/src/components/AdminDashboard/PendingApplicationDashboard/index.tsx
+++ b/src/components/AdminDashboard/PendingApplicationDashboard/index.tsx
@@ -5,11 +5,12 @@ import { Box, Snackbar, TextField, Typography } from "@mui/material";
import { DataGrid, GridColDef } from "@mui/x-data-grid";
import { useState } from "react";
-import AcceptPendingApplicationButton from "@/components/AdminDashboard/PendingApplicationDashboard/AcceptPendingApplicationButton";
-import PendingApplicationInfoModal from "@/components/AdminDashboard/PendingApplicationDashboard/PendingApplicationInfoModal";
-import RejectPendingApplicationButton from "@/components/AdminDashboard/PendingApplicationDashboard/RejectPendingApplicationButton";
import { ClientUser, Program, ProgramEnrollment } from "@/types";
+import AcceptPendingApplicationButton from "./AcceptPendingApplicationButton";
+import PendingApplicationInfoModal from "./PendingApplicationInfoModal";
+import RejectPendingApplicationButton from "./RejectPendingApplicationButton";
+
export type Row = {
id?: string;
lastName: string;
diff --git a/src/components/AdminDashboard/Sidebar/CollapsibleSidebarButton.tsx b/src/components/AdminDashboard/Sidebar/CollapsibleSidebarButton.tsx
index 4dd4755..9621fc7 100644
--- a/src/components/AdminDashboard/Sidebar/CollapsibleSidebarButton.tsx
+++ b/src/components/AdminDashboard/Sidebar/CollapsibleSidebarButton.tsx
@@ -10,7 +10,7 @@ import {
} from "@mui/material";
import { ReactNode } from "react";
-import getButtonStyles from "@/components/AdminDashboard/Sidebar/getButtonStyles";
+import getButtonStyles from "./getButtonStyles";
type CollapsibleSidebarButtonProps = {
pathname: string;
diff --git a/src/components/AdminDashboard/Sidebar/SidebarButton.tsx b/src/components/AdminDashboard/Sidebar/SidebarButton.tsx
index ed5f6f9..146ba35 100644
--- a/src/components/AdminDashboard/Sidebar/SidebarButton.tsx
+++ b/src/components/AdminDashboard/Sidebar/SidebarButton.tsx
@@ -10,7 +10,7 @@ import {
import Link from "next/link";
import { ReactNode } from "react";
-import getButtonStyles from "@/components/AdminDashboard/Sidebar/getButtonStyles";
+import getButtonStyles from "./getButtonStyles";
type SidebarButtonProps = {
pathname: string;
diff --git a/src/components/AdminDashboard/Sidebar/index.tsx b/src/components/AdminDashboard/Sidebar/index.tsx
index 66dd68a..99f9377 100644
--- a/src/components/AdminDashboard/Sidebar/index.tsx
+++ b/src/components/AdminDashboard/Sidebar/index.tsx
@@ -13,8 +13,8 @@ import { Box, Collapse, Drawer, List, Toolbar, useTheme } from "@mui/material";
import { usePathname } from "next/navigation";
import { useState } from "react";
-import CollapsibleSidebarButton from "@/components/AdminDashboard/Sidebar/CollapsibleSidebarButton";
-import SidebarButton from "@/components/AdminDashboard/Sidebar/SidebarButton";
+import CollapsibleSidebarButton from "./CollapsibleSidebarButton";
+import SidebarButton from "./SidebarButton";
const drawerWidth = 200;
diff --git a/src/components/ChangePassword/ChangePasswordForm.tsx b/src/components/ChangePassword/ChangePasswordForm.tsx
index 4d7b7bf..b06384c 100644
--- a/src/components/ChangePassword/ChangePasswordForm.tsx
+++ b/src/components/ChangePassword/ChangePasswordForm.tsx
@@ -8,9 +8,10 @@ import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
import { handleChangePassword } from "@/server/api/users/public-mutations";
+import ControlledTextField from "../controlled/ControlledTextField";
+
const changePasswordFormSchema = z
.object({
oldPassword: z.string().min(8, {
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormListItem.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormListItem.tsx
index 1f627d8..19350af 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormListItem.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormListItem.tsx
@@ -12,10 +12,11 @@ import {
} from "@mui/material";
import { useState } from "react";
-import HealthyHabitsTrackingFormModal from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormModal";
import { HealthyHabitsTrackingForm } from "@/types";
import dayjsUtil from "@/utils/dayjsUtil";
+import HealthyHabitsTrackingFormModal from "./HealthyHabitsTrackingFormModal";
+
type HealthyHabitsTrackingFormListItemProps = {
form: HealthyHabitsTrackingForm;
handleDelete: (form: HealthyHabitsTrackingForm) => void;
@@ -50,7 +51,7 @@ export default function HealthyHabitsTrackingFormListItem({
);
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormModal.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormModal.tsx
index ec2e49f..460fb91 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormModal.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList/HealthyHabitsTrackingFormModal.tsx
@@ -49,10 +49,14 @@ export default function HealthyHabitsTrackingFormModal({
- {dayjsUtil.utc(form.submittedDate).format("MM/DD/YYYY")}
+ {`Week of ${dayjsUtil.utc(form.weekOfSubmission).format("MM/DD/YYYY")}`}
+
>;
@@ -23,7 +24,7 @@ export default function HealthyHabitsTrackingFormList({
const handleDelete = async (form: HealthyHabitsTrackingForm) => {
const confirm = window.confirm(
- "Are you sure you want to delete this health tracking record?",
+ "Are you sure you want to delete this tracking form?",
);
if (!confirm) {
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularBarChart.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularBarChart.tsx
index 72500c7..5dea884 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularBarChart.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularBarChart.tsx
@@ -23,11 +23,13 @@ export default function ModularBarChart({
const getChartData = () => {
return trackingForms
.sort((a, b) =>
- dayjsUtil.utc(a.submittedDate).diff(dayjsUtil.utc(b.submittedDate)),
+ dayjsUtil
+ .utc(a.weekOfSubmission)
+ .diff(dayjsUtil.utc(b.weekOfSubmission)),
)
.map((form) => ({
value: Number(form[dataKey]) || 0,
- label: `Week of ${dayjsUtil.utc(form.submittedDate).format("MM/DD/YY")}`,
+ label: `Week of ${dayjsUtil.utc(form.weekOfSubmission).format("MM/DD/YY")}`,
}));
};
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularLineChart.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularLineChart.tsx
index a7e01b1..4377305 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularLineChart.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularLineChart.tsx
@@ -42,11 +42,11 @@ export default function ModularLineChart({
const getChartDataAndSeries = (): ChartConfig => {
const sortedData = trackingForms.sort((a, b) =>
- dayjsUtil.utc(a.submittedDate).diff(dayjsUtil.utc(b.submittedDate)),
+ dayjsUtil.utc(a.weekOfSubmission).diff(dayjsUtil.utc(b.weekOfSubmission)),
);
const chartData: RegularChartDataPoint[] = sortedData.map((entry) => ({
- x: dayjsUtil.utc(entry.submittedDate).toDate(),
+ x: dayjsUtil.utc(entry.weekOfSubmission).toDate(),
y: entry[dataKey] as number,
...(dataKey2 && { y2: entry[dataKey2] as number }),
}));
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/index.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/index.tsx
index 1b06fef..5e17537 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/index.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/index.tsx
@@ -3,11 +3,12 @@
import { Box, Typography } from "@mui/material";
import { useState } from "react";
-import HealthyHabitsTrackingFormList from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/HealthyHabitsTrackingFormList";
-import ModularBarChart from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularBarChart";
-import ModularLineChart from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory/ModularLineChart";
import { ClientUser, HealthyHabitsTrackingForm } from "@/types";
+import HealthyHabitsTrackingFormList from "./HealthyHabitsTrackingFormList";
+import ModularBarChart from "./ModularBarChart";
+import ModularLineChart from "./ModularLineChart";
+
type HealthyHabitsHistoryProps = {
initialForms: HealthyHabitsTrackingForm[];
user: ClientUser;
diff --git a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsTracking.tsx b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsTracking.tsx
index cd69d5c..7728173 100644
--- a/src/components/ClientDashboard/HealthyHabits/HealthyHabitsTracking.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/HealthyHabitsTracking.tsx
@@ -24,12 +24,12 @@ import { Controller, useForm } from "react-hook-form";
import ControlledTextField from "@/components/controlled/ControlledTextField";
import { handleHealthyHabitsTrackingFormSubmission } from "@/server/api/healthy-habits-tracking-forms/public-mutations";
-import { ClientUser } from "@/types";
import {
+ ClientUser,
HealthyHabitsFormValues,
HealthyHabitsTrackingForm,
healthyHabitsValidator,
-} from "@/types/HealthyHabitsTrackingForm";
+} from "@/types";
import apiErrors from "@/utils/constants/apiErrors";
import dayjsUtil from "@/utils/dayjsUtil";
import getClosestPastSunday from "@/utils/getClosestPastSunday";
@@ -53,7 +53,8 @@ export default function HealthyHabitsTracking({
} = useForm({
resolver: zodResolver(healthyHabitsValidator),
defaultValues: {
- submittedDate: getClosestPastSunday(),
+ submittedDate: dayjsUtil().utc().format("MM/DD/YYYY"),
+ weekOfSubmission: "",
healthConditions: "",
devices: {
hasScale: false,
@@ -86,6 +87,9 @@ export default function HealthyHabitsTracking({
const healthyHabitsTrackingForm: HealthyHabitsTrackingForm = {
...data,
submittedDate: dayjsUtil(data.submittedDate).utc().toISOString(),
+ weekOfSubmission: getClosestPastSunday(
+ dayjsUtil(data.submittedDate, "MM/DD/YYYY"),
+ ),
user,
};
@@ -99,7 +103,9 @@ export default function HealthyHabitsTracking({
error ===
apiErrors.healthyHabitsTrackingForm.healthyHabitsTrackingFormAlreadyExists
) {
- setSnackbarMessage("You have already submitted the form for this week.");
+ setSnackbarMessage(
+ "You have already submitted the form for the selected week.",
+ );
} else {
setSnackbarMessage("An unknown error occurred");
}
@@ -141,9 +147,7 @@ export default function HealthyHabitsTracking({
}
label="Date"
format="MM/DD/YYYY"
- shouldDisableDate={(day) => {
- return day.day() !== 0;
- }}
+ disableFuture={true}
/>
{errors.submittedDate?.message}
diff --git a/src/components/ClientDashboard/HealthyHabits/index.tsx b/src/components/ClientDashboard/HealthyHabits/index.tsx
index 9a27fbb..9e8e986 100644
--- a/src/components/ClientDashboard/HealthyHabits/index.tsx
+++ b/src/components/ClientDashboard/HealthyHabits/index.tsx
@@ -1,12 +1,13 @@
"use client";
import { Box, Divider, Tab, Tabs, Typography } from "@mui/material";
-import { useState } from "react";
+import { SyntheticEvent, useState } from "react";
-import HealthyHabitsHistory from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsHistory";
-import HealthyHabitsInfo from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsInfo";
-import HealthyHabitsTracking from "@/components/ClientDashboard/HealthyHabits/HealthyHabitsTracking";
import { ClientUser } from "@/types";
+import HealthyHabitsHistory from "./HealthyHabitsHistory";
+import HealthyHabitsInfo from "./HealthyHabitsInfo";
+import HealthyHabitsTracking from "./HealthyHabitsTracking";
+
type HealthyHabitsSections = "tracking" | "history" | "info";
type HealthyHabitsProps = {
@@ -18,7 +19,7 @@ export default function HealthyHabits({ user }: HealthyHabitsProps) {
useState("tracking");
const handleTabChange = (
- _event: React.SyntheticEvent,
+ _event: SyntheticEvent,
newValue: HealthyHabitsSections,
) => {
setSelectedSection(newValue);
diff --git a/src/components/EnrollmentForm/GeneralInformationFormSection.tsx b/src/components/EnrollmentForm/GeneralInformationFormSection.tsx
index d86b578..88c4390 100644
--- a/src/components/EnrollmentForm/GeneralInformationFormSection.tsx
+++ b/src/components/EnrollmentForm/GeneralInformationFormSection.tsx
@@ -26,15 +26,16 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import { Controller, useFieldArray, useForm } from "react-hook-form";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
import useEnrollmentForm from "@/hooks/useEnrollmentForm";
import {
Doctor,
GeneralInformationSection,
generalInformationSectionValidator,
-} from "@/types/EnrollmentForm";
+} from "@/types";
import dayjsUtil from "@/utils/dayjsUtil";
+import ControlledTextField from "../controlled/ControlledTextField";
+
function isDisqualified(generalInformationSection: GeneralInformationSection) {
if (!generalInformationSection.hasClassACdl) {
return true;
diff --git a/src/components/EnrollmentForm/ProgramSelectionFormSection.tsx b/src/components/EnrollmentForm/ProgramSelectionFormSection.tsx
index 7b36ca3..937e9a8 100644
--- a/src/components/EnrollmentForm/ProgramSelectionFormSection.tsx
+++ b/src/components/EnrollmentForm/ProgramSelectionFormSection.tsx
@@ -18,7 +18,7 @@ import {
EnrollmentForm,
ProgramSelectionSection,
programSelectionSectionValidator,
-} from "@/types/EnrollmentForm";
+} from "@/types";
import calculateAge from "@/utils/calculateAge";
function shouldShowDiabetesPreventionButton(enrollmentForm: EnrollmentForm) {
diff --git a/src/components/EnrollmentForm/ProgramSpecificQuestions/ProgramSpecificQuestionsFormSection.tsx b/src/components/EnrollmentForm/ProgramSpecificQuestions/ProgramSpecificQuestionsFormSection.tsx
index 0b8a646..9f0c83e 100644
--- a/src/components/EnrollmentForm/ProgramSpecificQuestions/ProgramSpecificQuestionsFormSection.tsx
+++ b/src/components/EnrollmentForm/ProgramSpecificQuestions/ProgramSpecificQuestionsFormSection.tsx
@@ -7,18 +7,19 @@ import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
-import GetPreventativeScreeningsProgramSpecificQuestions from "@/components/EnrollmentForm/ProgramSpecificQuestions/GetPreventativeScreeningsProgramSpecificQuestions";
-import HealthyHabitsProgramSpecificQuestions from "@/components/EnrollmentForm/ProgramSpecificQuestions/HealthyHabitsProgramSpecificQuestions";
-import RigsWithoutCigsProgramSpecificQuestions from "@/components/EnrollmentForm/ProgramSpecificQuestions/RigsWithoutCigsProgramSpecificQuestions";
-import VaccineVoucherProgramSpecificQuestions from "@/components/EnrollmentForm/ProgramSpecificQuestions/VaccineVoucherProgramSpecificQuestions";
import useEnrollmentForm from "@/hooks/useEnrollmentForm";
import { handleEnrollmentFormSubmission } from "@/server/api/enrollment-forms/public-mutations";
import {
ProgramSpecificQuestionsSection,
programSpecificQuestionsSectionValidator,
-} from "@/types/EnrollmentForm";
+} from "@/types";
import apiErrors from "@/utils/constants/apiErrors";
+import GetPreventativeScreeningsProgramSpecificQuestions from "./GetPreventativeScreeningsProgramSpecificQuestions";
+import HealthyHabitsProgramSpecificQuestions from "./HealthyHabitsProgramSpecificQuestions";
+import RigsWithoutCigsProgramSpecificQuestions from "./RigsWithoutCigsProgramSpecificQuestions";
+import VaccineVoucherProgramSpecificQuestions from "./VaccineVoucherProgramSpecificQuestions";
+
export default function ProgramSpecificQuestionsFormSection() {
const [snackbarOpen, setSnackbarOpen] = useState(false);
const [snackbarMessage, setSnackbarMessage] = useState("");
diff --git a/src/components/EnrollmentForm/QualifyingQuestionsFormSection.tsx b/src/components/EnrollmentForm/QualifyingQuestionsFormSection.tsx
index e9d2e05..e872f2b 100644
--- a/src/components/EnrollmentForm/QualifyingQuestionsFormSection.tsx
+++ b/src/components/EnrollmentForm/QualifyingQuestionsFormSection.tsx
@@ -18,12 +18,13 @@ import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
import useEnrollmentForm from "@/hooks/useEnrollmentForm";
import {
QualifyingQuestionsSection,
qualifyingQuestionsSectionValidator,
-} from "@/types/EnrollmentForm";
+} from "@/types";
+
+import ControlledTextField from "../controlled/ControlledTextField";
export default function QualifyingQuestionsFormSection() {
const [isLoading, setIsLoading] = useState(false);
diff --git a/src/components/ForgotPassword/ForgotPasswordForm.tsx b/src/components/ForgotPassword/ForgotPasswordForm.tsx
index 681dd7d..a8be225 100644
--- a/src/components/ForgotPassword/ForgotPasswordForm.tsx
+++ b/src/components/ForgotPassword/ForgotPasswordForm.tsx
@@ -7,9 +7,10 @@ import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
import handlePasswordResetRequest from "@/server/api/password-reset-tokens/public-mutations";
+import ControlledTextField from "../controlled/ControlledTextField";
+
const forgotPasswordFormSchema = z.object({
email: z.string().email({ message: "Invalid email" }),
});
diff --git a/src/components/ForgotPassword/ResetPasswordForm.tsx b/src/components/ForgotPassword/ResetPasswordForm.tsx
index edf823d..ca2a229 100644
--- a/src/components/ForgotPassword/ResetPasswordForm.tsx
+++ b/src/components/ForgotPassword/ResetPasswordForm.tsx
@@ -8,9 +8,10 @@ import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
import { resetPasswordWithToken } from "@/server/api/users/public-mutations";
+import ControlledTextField from "../controlled/ControlledTextField";
+
const resetPasswordFormSchema = z
.object({
newPassword: z.string().min(8, {
diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx
index 219728c..0c12871 100644
--- a/src/components/Header/index.tsx
+++ b/src/components/Header/index.tsx
@@ -5,9 +5,9 @@ import { Button } from "@mui/material";
import Link from "next/link";
import { useSession } from "next-auth/react";
-import Logo from "@/components/Logo";
+import Logo from "../Logo";
-export default function Header() {
+export function Header() {
const { data: session } = useSession();
return (
diff --git a/src/components/LoginForm/index.tsx b/src/components/LoginForm/index.tsx
index 9eb97f7..b607ca8 100644
--- a/src/components/LoginForm/index.tsx
+++ b/src/components/LoginForm/index.tsx
@@ -10,7 +10,7 @@ import { Suspense, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
-import ControlledTextField from "@/components/controlled/ControlledTextField";
+import ControlledTextField from "../controlled/ControlledTextField";
function LoginFormLoadingSkeleton() {
return ;
diff --git a/src/components/Settings/AdminSettings.tsx b/src/components/Settings/AdminSettings.tsx
index 95916d8..defbf10 100644
--- a/src/components/Settings/AdminSettings.tsx
+++ b/src/components/Settings/AdminSettings.tsx
@@ -1,9 +1,10 @@
import { Box, Typography } from "@mui/material";
-import ChangePasswordButton from "@/components/Settings/ChangePasswordButton";
-import SignOutButton from "@/components/Settings/SignOutButton";
import { User } from "@/types";
+import ChangePasswordButton from "./ChangePasswordButton";
+import SignOutButton from "./SignOutButton";
+
type AdminSettingsProps = {
user: User;
};
diff --git a/src/components/Settings/ClientSettings.tsx b/src/components/Settings/ClientSettings.tsx
index 0e76776..453363d 100644
--- a/src/components/Settings/ClientSettings.tsx
+++ b/src/components/Settings/ClientSettings.tsx
@@ -1,9 +1,10 @@
import { Box, Typography } from "@mui/material";
-import ChangePasswordButton from "@/components/Settings/ChangePasswordButton";
-import SignOutButton from "@/components/Settings/SignOutButton";
import { User } from "@/types";
+import ChangePasswordButton from "./ChangePasswordButton";
+import SignOutButton from "./SignOutButton";
+
type ClientSettingsProps = {
user: User;
};
diff --git a/src/server/api/healthy-habits-tracking-forms/private-mutations.ts b/src/server/api/healthy-habits-tracking-forms/private-mutations.ts
index d6ae1a9..7690c59 100644
--- a/src/server/api/healthy-habits-tracking-forms/private-mutations.ts
+++ b/src/server/api/healthy-habits-tracking-forms/private-mutations.ts
@@ -16,7 +16,7 @@ export async function createHealthyHabitsTrackingForm(
const [existingHealthyHabitsTrackingForm] =
await getHealthyHabitsTrackingForm(
healthyHabitsTrackingForm.user.email,
- healthyHabitsTrackingForm.submittedDate,
+ healthyHabitsTrackingForm.weekOfSubmission,
);
if (existingHealthyHabitsTrackingForm) {
diff --git a/src/server/api/healthy-habits-tracking-forms/public-mutations.ts b/src/server/api/healthy-habits-tracking-forms/public-mutations.ts
index a93c212..7787680 100644
--- a/src/server/api/healthy-habits-tracking-forms/public-mutations.ts
+++ b/src/server/api/healthy-habits-tracking-forms/public-mutations.ts
@@ -46,10 +46,7 @@ export async function handleHealthyHabitsTrackingFormDeletion(
return [null, authError];
}
- if (
- session.user.role === "client" &&
- session.user.email !== healthyHabitsTrackingForm.user.email
- ) {
+ if (session.user.role === "client" && session.user.email !== user.email) {
return [null, apiErrors.unauthorized];
}
diff --git a/src/server/api/healthy-habits-tracking-forms/queries.ts b/src/server/api/healthy-habits-tracking-forms/queries.ts
index 0cc9b10..0ed522f 100644
--- a/src/server/api/healthy-habits-tracking-forms/queries.ts
+++ b/src/server/api/healthy-habits-tracking-forms/queries.ts
@@ -9,7 +9,7 @@ import { getUserByEmail } from "../users/queries";
export async function getHealthyHabitsTrackingForm(
email: string,
- submittedDate: string,
+ weekOfSubmission: string,
): Promise> {
await dbConnect();
@@ -26,7 +26,7 @@ export async function getHealthyHabitsTrackingForm(
const healthyHabitsTrackingForm =
await HealthyHabitsTrackingFormModel.findOne({
user: user._id,
- submittedDate,
+ weekOfSubmission,
})
.lean()
.exec();
diff --git a/src/server/api/users/queries.ts b/src/server/api/users/queries.ts
index 45ac4bd..5883f98 100644
--- a/src/server/api/users/queries.ts
+++ b/src/server/api/users/queries.ts
@@ -24,7 +24,7 @@ async function getUser(
if (options?.populateHealthyHabitsTrackingForms) {
userQuery.populate({
path: "healthyHabitsTrackingForms",
- options: { sort: { submittedDate: -1 } },
+ options: { sort: { weekOfSubmission: -1 } },
});
}
diff --git a/src/server/models/HealthyHabitsTrackingForm.ts b/src/server/models/HealthyHabitsTrackingForm.ts
index 81df595..67bfd73 100644
--- a/src/server/models/HealthyHabitsTrackingForm.ts
+++ b/src/server/models/HealthyHabitsTrackingForm.ts
@@ -10,6 +10,7 @@ const HealthyHabitsTrackingFormSchema = new Schema(
required: true,
},
submittedDate: { type: String, required: true },
+ weekOfSubmission: { type: String, required: true },
healthConditions: { type: String, required: true },
devices: {
hasScale: { type: Boolean, required: true },
diff --git a/src/types/HealthyHabitsTrackingForm.ts b/src/types/HealthyHabitsTrackingForm.ts
index 3b9be95..f5ece9b 100644
--- a/src/types/HealthyHabitsTrackingForm.ts
+++ b/src/types/HealthyHabitsTrackingForm.ts
@@ -4,6 +4,7 @@ import { User } from ".";
export const healthyHabitsValidator = z.object({
submittedDate: z.string(),
+ weekOfSubmission: z.string(),
healthConditions: z.string(),
devices: z.object({
hasScale: z.boolean(),
diff --git a/src/utils/getClosestPastSunday.ts b/src/utils/getClosestPastSunday.ts
index 85f5e75..9982b04 100644
--- a/src/utils/getClosestPastSunday.ts
+++ b/src/utils/getClosestPastSunday.ts
@@ -1,14 +1,20 @@
+import { Dayjs } from "dayjs";
+
import dayjsUtil from "./dayjsUtil";
-export default function getClosestPastSunday() {
- const today = dayjsUtil();
+/**
+ * @param date The date to get the closest past sunday for. Defaults to the current date.
+ * @returns The closest past sunday to the current date in ISO date format
+ */
+export default function getClosestPastSunday(date?: Dayjs) {
+ const today = dayjsUtil(date).utc().startOf("day");
const dayOfWeek = today.day();
if (dayOfWeek === 0) {
- return today.format("MM/DD/YYYY");
+ return today.toISOString();
}
const closestSunday = today.subtract(dayOfWeek, "day");
- return closestSunday.format("MM/DD/YYYY");
+ return closestSunday.toISOString();
}