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

refactoring frontend (add eslint, absolute import) #38

Merged
merged 6 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"extends": "next/core-web-vitals",
"plugins": [
"simple-import-sort"
],
"rules": {
"react-hooks/exhaustive-deps": "off",
"simple-import-sort/exports": "warn",
"simple-import-sort/imports": [
"warn",
{
"groups": [
// Node.js builtins. You could also generate this regex if you use a `.js` config.
// For example: `^(${require("module").builtinModules.join("|")})(/|$)`
// Note that if you use the `node:` prefix for Node.js builtins,
// you can avoid this complexity: You can simply use "^node:".
[
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
],
// Packages `react` related packages
[
"^react",
"^next",
"^@?\\w"
],
// Internal packages.
[
"^~(/.*|$)"
],
// Relative imports
[
"^\\.\\.(?!/?$)",
"^\\.\\./?$",
"^\\./(?=.*/)(?!/?$)",
"^\\.(?!/?$)",
"^\\./?$"
],
// Style imports.
[
"^.+\\.?(css|scss)$"
]
]
}
]
}
}
17 changes: 10 additions & 7 deletions frontend/components/RouteGuard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import checkAuth from "../pages/api/auth/CheckAuth";
import { useEffect,useState } from "react";
import Image from "next/image";
import { useRouter } from "next/router";

import checkAuth from "~/pages/api/auth/CheckAuth";

import { publicPaths } from "../const";

// #TODO: finish spinner only when the data loads fully
Expand All @@ -11,9 +13,11 @@ export default function RouteGuard({ children }) {
const router = useRouter();
const [authorized, setAuthorized] = useState(false);

useEffect(async () => {
useEffect(() => {
// on initial load - run auth check
await authCheck(router.asPath);
(async () => {
await authCheck(router.asPath);
})();

// on route change start - hide page content by setting authorized to false
// #TODO: add the loading page when not yet authorized.
Expand All @@ -31,7 +35,6 @@ export default function RouteGuard({ children }) {
router.events.off("routeChangeComplete", authCheck);
// router.events.off("routeChangeError", onError);
};

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down Expand Up @@ -79,4 +82,4 @@ export default function RouteGuard({ children }) {
</div>
);
}
}
}
1 change: 1 addition & 0 deletions frontend/components/analytics/posthog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import posthog from "posthog-js";

import { ENV, POSTHOG_API_KEY, POSTHOG_HOST, TELEMETRY_ENABLED } from "../utilities/config";

export const initPostHog = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/basic/Error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

export default function Error({ text }) {
return (
Expand Down
9 changes: 5 additions & 4 deletions frontend/components/basic/InputField.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from "react";
import Error from "./Error";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useState } from "react";
import { useRouter } from "next/router";
import {
faCircle,
faCircleExclamation,
faE,
faEye,
faEyeSlash,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

import guidGenerator from "../utilities/randomId";
import { useState } from "react";
import { useRouter } from "next/router";
import Error from "./Error";

const InputField = (props) => {
const [passwordVisible, setPasswordVisible] = useState(false);
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/basic/Listbox.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { Listbox, Transition } from "@headlessui/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheck, faPlus, faAngleDown } from "@fortawesome/free-solid-svg-icons";
import { Fragment } from "react";
import { useRouter } from "next/router";
import { faAngleDown,faCheck, faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Listbox, Transition } from "@headlessui/react";

/**
* This is the component that we use for drop down lists.
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/basic/buttons/Button.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import Link from "next/link";
import Image from "next/image";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Link from "next/link";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

var classNames = require("classnames");

Expand Down
8 changes: 5 additions & 3 deletions frontend/components/basic/dialog/AddIncidentContactDialog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Dialog, Transition } from "@headlessui/react";
import { Fragment, useState } from "react";
import InputField from "../InputField";
import addIncidentContact from "../../../pages/api/organization/addIncidentContact";
import { Dialog, Transition } from "@headlessui/react";

import addIncidentContact from "~/pages/api/organization/addIncidentContact";

import Button from "../buttons/Button";
import InputField from "../InputField";

const AddIncidentContactDialog = ({
isOpen,
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/basic/dialog/AddProjectMemberDialog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Dialog, Transition } from "@headlessui/react";
import { Fragment, useState } from "react";
import ListBox from "../Listbox";
import { useRouter } from "next/router";
import { Dialog, Transition } from "@headlessui/react";

import Button from "../buttons/Button";
import ListBox from "../Listbox";

const AddProjectMemberDialog = ({
isOpen,
Expand Down
Loading