Skip to content

Commit

Permalink
fix: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth committed Oct 27, 2023
1 parent a481814 commit 409e66a
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 230 deletions.
40 changes: 21 additions & 19 deletions apps/dashboard/app/security/email/add/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use client";
import { getServerSession } from "next-auth";
import { authOptions } from "../../../api/auth/[...nextauth]/route";
import ContentContainer from "@/components/content-container";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
"use client"

// @ts-ignore-next-line no-implicit-any error
import { experimental_useFormStatus as useFormStatus } from "react-dom";
// @ts-ignore-next-line no-implicit-any error
import { experimental_useFormState as useFormState } from "react-dom";
import { emailRegisterInitiateServerAction } from "../../server-actions";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward"

import {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line no-implicit-any error
experimental_useFormStatus as useFormStatus,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line no-implicit-any error
experimental_useFormState as useFormState,
} from "react-dom"

import {
Box,
Expand All @@ -19,18 +20,19 @@ import {
FormHelperText,
Card,
Typography,
Link as MuiLink,
} from "@mui/joy";
import InfoOutlined from "@mui/icons-material/InfoOutlined";
import { CheckBox } from "@mui/icons-material";
import Link from "next/link";
} from "@mui/joy"
import InfoOutlined from "@mui/icons-material/InfoOutlined"
import Link from "next/link"

import { emailRegisterInitiateServerAction } from "../../server-actions"

export default function AddEmail() {
const [state, formAction] = useFormState(emailRegisterInitiateServerAction, {
error: null,
message: null,
responsePayload: {},
});
const { pending } = useFormStatus();
})
const { pending } = useFormStatus()
return (
<main
style={{
Expand Down Expand Up @@ -72,7 +74,7 @@ export default function AddEmail() {
{state.error ? (
<FormHelperText>
<InfoOutlined />
Opps! something is wrong.
Oops! something is wrong.
</FormHelperText>
) : null}

Expand Down Expand Up @@ -103,5 +105,5 @@ export default function AddEmail() {
</FormControl>
</Card>
</main>
);
)
}
52 changes: 24 additions & 28 deletions apps/dashboard/app/security/email/verify/page.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import VerfiyEmailForm from "./verify-form";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { getServerSession } from "next-auth"
import { redirect } from "next/navigation"

import VerifyEmailForm from "./verify-form"

import {
deleteEmail,
emailRegistrationInitiate,
} from "@/services/graphql/mutations/email";
import { useFormStatus } from "react-dom";
} from "@/services/graphql/mutations/email"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"

type VerifyEmailProp = {
emailRegistrationId: string | null | undefined;
};
emailRegistrationId: string | null | undefined
}

export default async function VerifyEmail({
searchParams,
}: {
searchParams: VerifyEmailProp;
searchParams: VerifyEmailProp
}) {
let { emailRegistrationId } = searchParams;
const session = await getServerSession(authOptions);
const token = session?.accessToken;
let { emailRegistrationId } = searchParams
const session = await getServerSession(authOptions)
const token = session?.accessToken

// this is if user has address but not verified
if (!emailRegistrationId || typeof emailRegistrationId !== "string") {
const email = session?.userData.data.me?.email?.address;
const email = session?.userData.data.me?.email?.address
if (!email || typeof email !== "string" || !token) {
redirect("/security");
redirect("/security")
}

await deleteEmail(token);
let data;
await deleteEmail(token)
let data
try {
data = await emailRegistrationInitiate(email, token);
data = await emailRegistrationInitiate(email, token)
} catch (err) {
console.log("error in emailRegistrationInitiate ", err);
redirect("/security");
console.log("error in emailRegistrationInitiate ", err)
redirect("/security")
}

if (data?.userEmailRegistrationInitiate.errors.length) {
redirect("/security");
redirect("/security")
}

emailRegistrationId =
data?.userEmailRegistrationInitiate.emailRegistrationId;
emailRegistrationId = data?.userEmailRegistrationInitiate.emailRegistrationId
}

if (!emailRegistrationId && typeof emailRegistrationId !== "string") {
redirect("/security");
redirect("/security")
}

return (
<VerfiyEmailForm
emailRegistrationId={emailRegistrationId}
></VerfiyEmailForm>
);
return <VerifyEmailForm emailRegistrationId={emailRegistrationId}></VerifyEmailForm>
}
50 changes: 23 additions & 27 deletions apps/dashboard/app/security/email/verify/verify-form.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use client";
import { getServerSession } from "next-auth";
import { authOptions } from "../../../api/auth/[...nextauth]/route";
import ContentContainer from "@/components/content-container";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
// @ts-ignore-next-line no-implicit-any error
import { experimental_useFormStatus as useFormStatus } from "react-dom";
// @ts-ignore-next-line no-implicit-any error
import { experimental_useFormState as useFormState } from "react-dom";
import { emailRegisterValidateServerAction } from "../../server-actions";
"use client"

import ArrowForwardIcon from "@mui/icons-material/ArrowForward"
import {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line no-implicit-any error
experimental_useFormStatus as useFormStatus,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line no-implicit-any error
experimental_useFormState as useFormState,
} from "react-dom"

import {
Box,
Expand All @@ -18,24 +19,23 @@ import {
FormHelperText,
Card,
Typography,
} from "@mui/joy";
import InfoOutlined from "@mui/icons-material/InfoOutlined";
import { CheckBox } from "@mui/icons-material";
import Link from "next/link";
} from "@mui/joy"
import InfoOutlined from "@mui/icons-material/InfoOutlined"
import Link from "next/link"

import { emailRegisterValidateServerAction } from "../../server-actions"

type VerifyEmailFormProps = {
emailRegistrationId: string;
};
export default function VerifyEmailForm({
emailRegistrationId,
}: VerifyEmailFormProps) {
const { pending } = useFormStatus();
emailRegistrationId: string
}
export default function VerifyEmailForm({ emailRegistrationId }: VerifyEmailFormProps) {
const { pending } = useFormStatus()

const [state, formAction] = useFormState(emailRegisterValidateServerAction, {
error: null,
message: null,
responsePayload: {},
});
})

return (
<main
Expand Down Expand Up @@ -64,11 +64,7 @@ export default function VerifyEmailForm({
>
<form action={formAction}>
<FormLabel>Code</FormLabel>
<input
type="hidden"
name="emailRegistrationId"
value={emailRegistrationId}
/>
<input type="hidden" name="emailRegistrationId" value={emailRegistrationId} />
<Input
name="code"
type="code"
Expand Down Expand Up @@ -113,5 +109,5 @@ export default function VerifyEmailForm({
</FormControl>
</Card>
</main>
);
)
}
18 changes: 9 additions & 9 deletions apps/dashboard/app/security/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import ContentContainer from "@/components/content-container";
import EmailSettings from "@/components/security/email/email";
import { Box } from "@mui/joy";
import { getServerSession } from "next-auth"
import { Box } from "@mui/joy"

import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import ContentContainer from "@/components/content-container"
import EmailSettings from "@/components/security/email/email"

export default async function Home() {
const session = await getServerSession(authOptions);
const totpEnabled = session?.userData.data.me?.totpEnabled;
const email = session?.userData.data.me?.email;
const session = await getServerSession(authOptions)
const email = session?.userData.data.me?.email
return (
<ContentContainer>
<Box
Expand All @@ -23,5 +23,5 @@ export default async function Home() {
{email ? <EmailSettings emailData={email}></EmailSettings> : null}
</Box>
</ContentContainer>
);
)
}
Loading

0 comments on commit 409e66a

Please sign in to comment.