Skip to content

Commit

Permalink
resolve yarn lint warnings (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Bechthold authored Jan 25, 2024
1 parent d5f0dcc commit 8382e84
Show file tree
Hide file tree
Showing 32 changed files with 121 additions and 185 deletions.
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";
Expand All @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
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";
Expand Down
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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/APIClients/TagAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/APIClients/UserAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
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";
Expand Down
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 {
Expand Down Expand Up @@ -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} />;
};

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/auth/TwoFa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Redirect } from "react-router-dom";
import {
Box,
Button,
Center,
Flex,
Input,
Spinner,
Expand All @@ -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";

Expand All @@ -28,6 +26,7 @@ type TwoFaProps = {
const TwoFa = ({
email,
password,
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
token,
toggle,
}: TwoFaProps): React.ReactElement => {
Expand Down
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";
Expand Down
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,
Expand Down
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,
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/forms/CreateEmployee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
33 changes: 4 additions & 29 deletions frontend/src/components/forms/CreateLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/CreateResident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 8382e84

Please sign in to comment.