Skip to content

Commit

Permalink
Fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timwekkenbc committed Oct 2, 2024
1 parent fe7d67d commit ec8a93f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/components/GithubAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface GithubAuthContextType {

const GithubAuthContext = createContext<GithubAuthContextType | undefined>(undefined);

export const GithubAuthProvider: React.FC<{ authInfo?: GithubAuthContextType; children: React.ReactNode }> = ({
export const GithubAuthProvider: React.FC<{ authInfo: GithubAuthContextType | null; children: React.ReactNode }> = ({
authInfo,
children,
}) => {
Expand Down
1 change: 1 addition & 0 deletions app/components/RuleViewerEditor/RuleViewerEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export default function RuleViewerEditor({
),
}),
],
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);

Expand Down
2 changes: 2 additions & 0 deletions app/components/SavePublish/SavePublishWarnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function SavePublishWarnings({ filePath, ruleContent, isSaving }:

useEffect(() => {
getMisconnectedFields();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ruleContent]);

useEffect(() => {
Expand All @@ -91,6 +92,7 @@ export default function SavePublishWarnings({ filePath, ruleContent, isSaving }:
if (misconnectedFieldsPanelOpen) {
warnOfMisconnectedFields();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [misconnectedFields, misconnectedFieldsPanelOpen]);

return (
Expand Down
16 changes: 12 additions & 4 deletions app/errors/noorgaccess/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use client";
import { useEffect } from "react";
import { Suspense, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import axios from "axios";
import Image from "next/image";
import { Alert, Button } from "antd";

export default function NoOrgAccess() {
function NoOrgAccessComponent() {
const searchParams = useSearchParams();
const returnUrl = searchParams.get("returnUrl");

Expand All @@ -22,8 +22,8 @@ export default function NoOrgAccess() {
<div>
<p>Your account has no organization authorization.</p>
<p>
Hit the "Re-Login" button below and then make sure to hit the "Authorize" button shown below before
continuing.
Hit the &quot;Re-Login&quot; button below and then make sure to hit the &quot;Authorize&quot; button shown
below before continuing.
</p>
<div>
<Image src="/images/github-authorize-screen.png" alt="GitHub Authorize Screen" width={500} height={370} />
Expand All @@ -40,3 +40,11 @@ export default function NoOrgAccess() {
</div>
);
}

export default function NoOrgAccess() {
return (
<Suspense fallback={<div>Loading...</div>}>
<NoOrgAccessComponent />
</Suspense>
);
}
10 changes: 9 additions & 1 deletion app/hooks/useGithubAuth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { redirect } from "next/navigation";
import { headers, cookies } from "next/headers";
import { isGithubAuthTokenValid, AuthFailureReasons } from "../utils/githubApi";
import { GithubAuthContextType } from "../components/GithubAuthProvider";

export default async function useGithubAuth(
redirectPath: string,
required: boolean = true
): Promise<GithubAuthContextType | null> {
if (!required) {
return null;
}

export default async function useGithubAuth(redirectPath: string) {
const githubAuthToken = cookies().get("github-authentication-token")?.value;
const githubAuthUsername = cookies().get("github-authentication-username")?.value;
const { valid, reason } = await isGithubAuthTokenValid(githubAuthToken);
Expand Down
10 changes: 4 additions & 6 deletions app/rule/[ruleId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ export default async function Rule({
// Get version of rule to use
const { version } = searchParams;

let githubAuthInfo: GithubAuthContextType | undefined;
if (version === RULE_VERSION.draft) {
// Ensure user is first logged into github so they can save what they edit
// If they are not, redirect them to the oauth flow
githubAuthInfo = (await useGithubAuth(`rule/${ruleId}?version=${version}`)) as GithubAuthContextType;
}
// Ensure user is first logged into github so they can save what they edit
// If they are not, redirect them to the oauth flow
const oAuthRequired = version === RULE_VERSION.draft; // only require oauth if editing a draft
const githubAuthInfo = await useGithubAuth(`rule/${ruleId}?version=${version}`, oAuthRequired);

// Get rule details and json content for the rule id
const { ruleInfo, ruleContent } = await getRuleDataForVersion(ruleId, version);
Expand Down
4 changes: 2 additions & 2 deletions app/rule/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import NewRule from "./NewRule";
export default async function NewRuleWrapper() {
// Ensure user is first logged into github so they can save what they edit
// If they are not, redirect them to the oauth flow
const { githubAuthToken, githubAuthUsername } = await useGithubAuth("rule/new");
const githubAuthInfo = await useGithubAuth("rule/new");

return (
<GithubAuthProvider authInfo={{ githubAuthToken, githubAuthUsername }}>
<GithubAuthProvider authInfo={githubAuthInfo}>
<NewRule />
</GithubAuthProvider>
);
Expand Down

0 comments on commit ec8a93f

Please sign in to comment.