Skip to content

Commit

Permalink
add styles for resident status
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-sellner committed Nov 29, 2023
1 parent 8796389 commit 4d3da4c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -35,19 +35,43 @@ type Props = {
countResidents: () => Promise<void>;
};

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();
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,
Expand All @@ -67,7 +91,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();

Expand Down Expand Up @@ -156,7 +180,18 @@ const ResidentDirectoryTable = ({
return (
<Tr key={resident.id} style={{ verticalAlign: "middle" }}>
<Td width="20%">{resident.residentId!}</Td>
<Td width="15%">{status}</Td>
<Td width="15%"
textStyle="user-status-label"
textAlign="center"
>
<Box
backgroundColor={getStatusColor(status)}
borderRadius="40px"
padding="6px 0px"
>
{status}
</Box>
</Td>
<Td width="20%">{resident.building.name}</Td>
<Td width="20%">{startDate.date}</Td>
<Td width="15%">{endDate ? endDate.date : ""}</Td>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/types/ResidentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ export type CreateResidentParams = Omit<
export type EditResidentParams = Omit<Resident, "residentId" | "building"> & {
buildingId: number;
};

export enum ResidentStatus {
FUTURE = "Future",
PAST = "Past",
CURRENT = "Current",
}

0 comments on commit 4d3da4c

Please sign in to comment.