diff --git a/frontend/src/components/pages/ResidentDirectory/ResidentDirectoryTable.tsx b/frontend/src/components/pages/ResidentDirectory/ResidentDirectoryTable.tsx index 4570f2c7..6ae3450d 100644 --- a/frontend/src/components/pages/ResidentDirectory/ResidentDirectoryTable.tsx +++ b/frontend/src/components/pages/ResidentDirectory/ResidentDirectoryTable.tsx @@ -16,7 +16,7 @@ import { } from "@chakra-ui/react"; import { VscKebabVertical } from "react-icons/vsc"; import { BuildingLabel } from "../../../types/BuildingTypes"; -import { Resident } from "../../../types/ResidentTypes"; +import { Resident, ResidentStatus } from "../../../types/ResidentTypes"; import EditResident from "../../forms/EditResident"; import ResidentAPIClient from "../../../APIClients/ResidentAPIClient"; import getFormattedDateAndTime from "../../../utils/DateUtils"; @@ -35,19 +35,44 @@ type Props = { countResidents: () => Promise; }; +const getStatusColor = (status: string): string => { + let color = ""; + + switch (status) { + case ResidentStatus.CURRENT: + color = "green.400"; + break; + case ResidentStatus.FUTURE: + color = "teal.400"; + break; + case ResidentStatus.PAST: + color = "gray.300"; + break; + default: + color = "black"; + } + + return color; +}; + const getFormattedDatesAndStatus = (resident: Resident) => { const startDateObj = convertToDate(resident.dateJoined); const startDate = getFormattedDateAndTime(startDateObj, true); let endDate; + let status = ResidentStatus.CURRENT; + const currentDate = new Date(); + currentDate.setHours(0,0,0,0); if (resident.dateLeft != null) { const endDateObj = convertToDate(resident.dateLeft); endDate = getFormattedDateAndTime(endDateObj, true); + if (endDateObj < currentDate) { + status = ResidentStatus.PAST; + } + } + if (currentDate < startDateObj) { + status = ResidentStatus.FUTURE; } - const status = - resident.dateJoined !== null && resident.dateLeft !== null - ? "Past" - : "Current"; return { startDate, endDate, @@ -67,7 +92,7 @@ const ResidentDirectoryTable = ({ getRecords, countResidents, }: Props): React.ReactElement => { - const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext); + const { authenticatedUser } = useContext(AuthContext); const [showAlert, setShowAlert] = useState(false); const newToast = CreateToast(); @@ -140,7 +165,7 @@ const ResidentDirectoryTable = ({ Resident - Status + Status Building Residency Start Date Residency End Date @@ -155,8 +180,20 @@ const ResidentDirectoryTable = ({ // TODO: Remove non-null assertion from residentId return ( - {resident.residentId!} - {status} + {resident.residentId!} + + + {status} + + {resident.building.name} {startDate.date} {endDate ? endDate.date : ""} diff --git a/frontend/src/types/ResidentTypes.ts b/frontend/src/types/ResidentTypes.ts index 1604f5c0..8bc21607 100644 --- a/frontend/src/types/ResidentTypes.ts +++ b/frontend/src/types/ResidentTypes.ts @@ -34,3 +34,9 @@ export type CreateResidentParams = Omit< export type EditResidentParams = Omit & { buildingId: number; }; + +export enum ResidentStatus { + FUTURE = "Future", + PAST = "Past", + CURRENT = "Current", +}