Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve yarn lint warnings #228

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions frontend/src/APIClients/AuthAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
FetchResult,
MutationFunctionOptions,
OperationVariables,
} from "@apollo/client";
import { AxiosError } from "axios";
import { getAuthErrMessage } from "../helper/error";
import AUTHENTICATED_USER_KEY from "../constants/AuthConstants";
@@ -26,7 +21,7 @@ const login = async (
);
return data;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;
if (axiosErr.response && axiosErr.response.status === 401) {
return {
errCode: axiosErr.response.status,
@@ -53,7 +48,7 @@ const twoFa = async (
);
return data;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;
if (axiosErr.response && axiosErr.response.status === 401) {
return {
errMessage:
@@ -114,7 +109,7 @@ const register = async (
);
return data;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;
if (axiosErr.response && axiosErr.response.status === 409) {
return {
errCode: axiosErr.response.status,
1 change: 0 additions & 1 deletion frontend/src/APIClients/BuildingAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios, { AxiosError } from "axios";
import AUTHENTICATED_USER_KEY from "../constants/AuthConstants";
import { getLocalStorageObjProperty } from "../utils/LocalStorageUtils";
import baseAPIClient from "./BaseAPIClient";
11 changes: 5 additions & 6 deletions frontend/src/APIClients/ResidentAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios, { AxiosError } from "axios";
import { AxiosError } from "axios";
import AUTHENTICATED_USER_KEY from "../constants/AuthConstants";
import {
Resident,
GetResidentsReponse,
CountResidentsResponse,
CreateResidentParams,
@@ -99,7 +98,7 @@ const createResident = async ({
);
return true;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 409) {
return {
@@ -122,8 +121,8 @@ const deleteResident = async (residentId: number): Promise<number> => {
headers: { Authorization: bearerToken },
});
return 200;
} catch (error: any) {
const axiosErr = (error as any) as AxiosError;
} catch (error) {
const axiosErr = error as AxiosError;
if (axiosErr.response) {
return axiosErr.response.status;
}
@@ -151,7 +150,7 @@ const editResident = async ({
);
return true;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 409) {
return {
8 changes: 4 additions & 4 deletions frontend/src/APIClients/TagAPIClient.ts
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ const createTag = async ({
);
return true;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 409) {
return {
@@ -94,7 +94,7 @@ const editTag = async ({
);
return true;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 409) {
return {
@@ -117,8 +117,8 @@ const deleteTag = async (tagId: number): Promise<number> => {
headers: { Authorization: bearerToken },
});
return 200;
} catch (error: any) {
const axiosErr = (error as any) as AxiosError;
} catch (error) {
const axiosErr = error as AxiosError;
if (axiosErr.response) {
return axiosErr.response.status;
}
19 changes: 10 additions & 9 deletions frontend/src/APIClients/UserAPIClient.ts
Original file line number Diff line number Diff line change
@@ -8,14 +8,15 @@ import {
UpdateUserParams,
UserStatus,
GetUserStatusResponse,
GetUserParams,
} from "../types/UserTypes";
import { ErrorResponse } from "../types/ErrorTypes";

const getUsers = async ({
returnAll = false,
pageNumber = 1,
resultsPerPage = 10,
}): Promise<GetUsersResponse> => {
}: GetUserParams): Promise<GetUsersResponse> => {
try {
const bearerToken = `Bearer ${getLocalStorageObjProperty(
AUTHENTICATED_USER_KEY,
@@ -72,8 +73,8 @@ const updateUser = async ({
},
);
return res.status;
} catch (error: any) {
const axiosErr = (error as any) as AxiosError;
} catch (error) {
const axiosErr = error as AxiosError;
if (axiosErr.response) {
return axiosErr.response.status;
}
@@ -98,8 +99,8 @@ const updateUserStatus = async (
},
);
return res.status;
} catch (error: any) {
const axiosErr = (error as any) as AxiosError;
} catch (error) {
const axiosErr = error as AxiosError;
if (axiosErr.response) {
return axiosErr.response.status;
}
@@ -117,8 +118,8 @@ const deleteUser = async (userId: number): Promise<number> => {
headers: { Authorization: bearerToken },
});
return res.status;
} catch (error: any) {
const axiosErr = (error as any) as AxiosError;
} catch (error) {
const axiosErr = error as AxiosError;
if (axiosErr.response) {
return axiosErr.response.status;
}
@@ -144,7 +145,7 @@ const inviteUser = async (
);
return true;
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 409) {
return {
@@ -182,7 +183,7 @@ const getUserStatus = async (
"This email address has not been invited. Please try again with a different email.",
};
} catch (error) {
const axiosErr = (error as any) as AxiosError;
const axiosErr = error as AxiosError;

if (axiosErr.response && axiosErr.response.status === 403) {
return {
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "bootstrap/dist/css/bootstrap.min.css";
import React, { useState, useReducer } from "react";
import React, { useState } from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";

import { ChakraProvider } from "@chakra-ui/react";
5 changes: 1 addition & 4 deletions frontend/src/components/auth/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useState, useEffect } from "react";
import React, { useContext } from "react";
import { Route, Redirect, useLocation } from "react-router-dom";
import AuthContext from "../../contexts/AuthContext";
import {
@@ -44,9 +44,6 @@ const PrivateRoute: React.FC<PrivateRouteProps> = ({
) {
return <Redirect to={HOME_PAGE} />;
}

console.log(path, currentPath);

return <Route path={path} exact={exact} component={component} />;
};

3 changes: 1 addition & 2 deletions frontend/src/components/auth/TwoFa.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { Redirect } from "react-router-dom";
import {
Box,
Button,
Center,
Flex,
Input,
Spinner,
@@ -14,7 +13,6 @@ import authAPIClient from "../../APIClients/AuthAPIClient";
import AUTHENTICATED_USER_KEY from "../../constants/AuthConstants";
import { HOME_PAGE } from "../../constants/Routes";
import AuthContext from "../../contexts/AuthContext";
import { AuthenticatedUser } from "../../types/AuthTypes";
import CreateToast from "../common/Toasts";
import { isErrorResponse } from "../../helper/error";

@@ -28,6 +26,7 @@ type TwoFaProps = {
const TwoFa = ({
email,
password,
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
token,
toggle,
}: TwoFaProps): React.ReactElement => {
2 changes: 1 addition & 1 deletion frontend/src/components/auth/Verification.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useContext } from "react";
import { useHistory } from "react-router-dom";
import { Box, Button, Flex, Spinner, Text, VStack } from "@chakra-ui/react";
import { Box, Button, Flex, Spinner, Text } from "@chakra-ui/react";
import authAPIClient from "../../APIClients/AuthAPIClient";
import CreateToast from "../common/Toasts";
import AuthContext from "../../contexts/AuthContext";
2 changes: 1 addition & 1 deletion frontend/src/components/common/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import {
Box,
Modal,
3 changes: 2 additions & 1 deletion frontend/src/components/common/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import {
Menu,
MenuButton,
@@ -60,6 +60,7 @@ const Pagination = ({
};

// Treat the enter key as an alt method of triggering onBlur (lose focus)
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const handleKeyUp = (event: any) => {
if (event.keyCode === 13) {
event.target.blur();
1 change: 0 additions & 1 deletion frontend/src/components/forms/CreateEmployee.tsx
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import {
Text,
} from "@chakra-ui/react";
import { AddIcon } from "@chakra-ui/icons";
import { INVITE_EMPLOYEE_ERROR } from "../../constants/ErrorMessages";
import CreateToast from "../common/Toasts";
import UserAPIClient from "../../APIClients/UserAPIClient";
import { isErrorResponse } from "../../helper/error";
33 changes: 4 additions & 29 deletions frontend/src/components/forms/CreateLog.tsx
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@ import LogRecordAPIClient from "../../APIClients/LogRecordAPIClient";
import BuildingAPIClient from "../../APIClients/BuildingAPIClient";
import { selectStyle } from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
import { Resident } from "../../types/ResidentTypes";
import { SelectLabel } from "../../types/SharedTypes";
import { combineDateTime, getFormattedTime } from "../../helper/dateHelpers";

@@ -76,25 +75,6 @@ const ALERT_DATA: AlertDataOptions = {
},
};

// Replace this with the tags from the db once the API and table are made
const TAGS = [
{ label: "Tag A", value: "A" },
{ label: "Tag B", value: "B" },
{ label: "Tag C", value: "C" },
];

// Changes the border of the Select components if the input is invalid
function getBorderStyle(state: any, error: boolean): string {
if (state.isFocused) {
return "2px solid #3182ce";
}
if (error) {
return "2px solid #e53e3e";
}

return "1px solid #cbd5e0";
}

// Helper to get the currently logged in user
const getCurUserSelectOption = () => {
const curUser: AuthenticatedUser | null = getLocalStorageObj(
@@ -107,8 +87,9 @@ const getCurUserSelectOption = () => {
return { label: "", value: -1 };
};

const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {
const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props): React.ReactElement => {
// currently, the select for employees is locked and should default to current user. Need to check if admins/regular staff are allowed to change this
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const [employee, setEmployee] = useState<SelectLabel>(getCurUserSelectOption());
const [date, setDate] = useState(new Date());
const [time, setTime] = useState(
@@ -133,8 +114,6 @@ const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {
const [isCreateOpen, setCreateOpen] = React.useState(false);

// error states for non-nullable inputs
const [employeeError, setEmployeeError] = useState(false);
const [dateError, setDateError] = useState(false);
const [timeError, setTimeError] = useState(false);
const [buildingError, setBuildingError] = useState(false);
const [residentError, setResidentError] = useState(false);
@@ -219,7 +198,7 @@ const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {

if (buildingsData && buildingsData.buildings.length !== 0) {
const buildingLabels: SelectLabel[] = buildingsData.buildings.map(
(building) => ({ label: building.name!, value: building.id! }),
(building) => ({ label: building.name, value: building.id }),
);
setBuildingOptions(buildingLabels);
}
@@ -231,7 +210,7 @@ const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {
if (residentsData && residentsData.residents.length !== 0) {
// TODO: Remove the type assertions here
const residentLabels: SelectLabel[] = residentsData.residents.map(
(r) => ({ label: r.residentId!, value: r.id! }),
(r) => ({ label: r.residentId, value: r.id }),
);
setResidentOptions(residentLabels);
}
@@ -272,8 +251,6 @@ const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {
setNotes("");

// reset all error states
setEmployeeError(false);
setDateError(false);
setTimeError(false);
setBuildingError(false);
setResidentError(false);
@@ -289,8 +266,6 @@ const CreateLog = ({ getRecords, countRecords, setUserPageNum }: Props) => {

const handleSubmit = async () => {
// Update error states
setEmployeeError(!employee.label);
setDateError(date === null);
setTimeError(time === "");
setBuildingError(buildingId === -1);
setResidentError(residents.length === 0);
2 changes: 1 addition & 1 deletion frontend/src/components/forms/CreateResident.tsx
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ const CreateResident = ({

if (buildingsData && buildingsData.buildings.length !== 0) {
const buildingLabels: SelectLabel[] = buildingsData.buildings.map(
(building) => ({ label: building.name!, value: building.id! }),
(building) => ({ label: building.name, value: building.id }),
);
setBuildingOptions(buildingLabels);
}
Loading