Skip to content

Commit

Permalink
fix: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 13, 2023
1 parent 918b542 commit d520209
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 159 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
"plugin:tailwindcss/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
babelOptions: {
presets: [require.resolve("next/babel")],
},
project: "./tsconfig.json",
},
plugins: ["@typescript-eslint", "unused-imports"],
rules: {
Expand Down Expand Up @@ -65,6 +67,7 @@ module.exports = {
},
],
"max-params": ["error", 4],
"@typescript-eslint/no-unnecessary-condition": "error",
},
}

Expand Down
31 changes: 2 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@trpc/server": "^10.38.2",
"bcryptjs": "^2.4.3",
"class-variance-authority": "^0.7.0",
"client-only": "^0.0.1",
"clsx": "^2.0.0",
"crypto-js": "^4.1.1",
"dotenv": "^16.3.1",
Expand All @@ -70,8 +71,7 @@
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.6",
"ua-parser-js": "^1.0.35",
"zod": "^3.21.4",
"zustand": "^4.4.1"
"zod": "^3.21.4"
},
"devDependencies": {
"@babel/core": "^7.22.17",
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/(not-protected)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Locale } from "i18n-config"
import Link from "next/link"
import { ThemeSwitch } from "@/components/theme/theme-switch"
import { buttonVariants } from "@/components/ui/button"
import { authRoutes } from "@/lib/auth/constants"
import { getDictionary } from "@/lib/langs"
import { Locale } from "i18n-config"

export default async function Home({
params: { lang },
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/(sys-auth)/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Locale } from "i18n-config"
import Link from "next/link"
import { LoginUserAuthForm } from "@/components/auth/login-user-auth-form"
import { buttonVariants } from "@/components/ui/button"
import { authRoutes } from "@/lib/auth/constants"
import { getDictionary } from "@/lib/langs"
import { cn } from "@/lib/utils"
import { Locale } from "i18n-config"
import PrivacyAcceptance from "../privacy-acceptance"
import Providers from "../providers"

Expand Down
4 changes: 2 additions & 2 deletions src/app/[lang]/(sys-auth)/sign-up/credentials/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Locale } from "i18n-config"
import { redirect } from "next/navigation"
import { RegisterUserAuthForm } from "@/components/auth/register-user-auth-form"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { authRoutes } from "@/lib/auth/constants"
import { getDictionary } from "@/lib/langs"
import { Locale } from "i18n-config"

export default async function SignupByCredentials({
searchParams,
Expand All @@ -17,7 +17,7 @@ export default async function SignupByCredentials({
const dictionary = await getDictionary(lang)

//? If there is no email in the search params, redirect to the sign-up page
if (!searchParams?.email) {
if (!searchParams.email) {
redirect(authRoutes.signUp[0])
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/(sys-auth)/sign-up/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Locale } from "i18n-config"
import Link from "next/link"
import { RegisterUserAuthForm } from "@/components/auth/register-user-auth-form"
import { buttonVariants } from "@/components/ui/button"
import { authRoutes } from "@/lib/auth/constants"
import { getDictionary } from "@/lib/langs"
import { cn } from "@/lib/utils"
import { Locale } from "i18n-config"
import PrivacyAcceptance from "../privacy-acceptance"
import Providers from "../providers"

Expand Down
2 changes: 1 addition & 1 deletion src/app/[lang]/[...not-found]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Locale } from "i18n-config"
import Link from "next/link"
import React from "react"
import { buttonVariants } from "@/components/ui/button"
import { getDictionary } from "@/lib/langs"
import { Locale } from "i18n-config"

export default async function Page404({
params: { lang },
Expand Down
20 changes: 0 additions & 20 deletions src/app/api/me/route.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/app/api/sessions/[id]/route.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/app/api/sessions/active/route.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/auth/github-sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function GithubSignIn({
logger.debug("SignIn result", res)

if (res?.error) {
if (res?.error === "OAuthAccountNotLinked") {
if (res.error === "OAuthAccountNotLinked") {
} else {
throw new Error(dictionary.errors.unknownError)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/auth/login-user-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export type IForm = z.infer<ReturnType<typeof formSchema>>
export function LoginUserAuthForm({ dictionary, searchParams, ...props }: UserAuthFormProps) {
const router = useRouter()

const callbackUrl = ensureRelativeUrl(searchParams?.callbackUrl?.toString()) || authRoutes.redirectAfterSignIn
const error = searchParams?.error?.toString()
const callbackUrl = ensureRelativeUrl(searchParams.callbackUrl?.toString()) || authRoutes.redirectAfterSignIn
const error = searchParams.error?.toString()

const [isLoading, setIsLoading] = React.useState<boolean>(false)
const [errorDisplayed, setErrorDisplayed] = React.useState<string | null>(null)
Expand Down
12 changes: 5 additions & 7 deletions src/components/auth/require-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { validateSession } from "@/lib/server-utils"

export default async function requireAuth(callbackUrl?: string) {
const session = await getServerSession(nextAuthOptions)
if (!session || !session.user || !session.user.id) {
if (!session || !session.user.id) {
let searchParams = ""
if (callbackUrl) {
searchParams = "?" + new URLSearchParams({ callbackUrl }).toString()
Expand All @@ -22,15 +22,13 @@ export default async function requireAuth(callbackUrl?: string) {

export async function getAuthApi() {
const session = await getServerSession(nextAuthOptions)
if (!session || !session.user || !session.user.id) {
if (!session || !session.user.id) {
return { session: null, error: NextResponse.json({ error: "Unauthorized" }, { status: 401 }) }
}

if (session) {
const sessionValidationError = await validateSession(session)
if (sessionValidationError) {
return { session: null, error: NextResponse.json({ error: sessionValidationError }, { status: 403 }) }
}
const sessionValidationError = await validateSession(session)
if (sessionValidationError) {
return { session: null, error: NextResponse.json({ error: sessionValidationError }, { status: 403 }) }
}

return { session, error: null }
Expand Down
2 changes: 1 addition & 1 deletion src/components/locale-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client"

import { i18n } from "i18n-config"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { i18n } from "i18n-config"

export default function LocaleSwitcher() {
const pathName = usePathname()
Expand Down
2 changes: 1 addition & 1 deletion src/components/profile/get-device-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function GetDeviceIcon({ name }: { name?: string }) {
return <Icons.mobile />
}

if (["Windows"]) {
if (["Windows"].includes(name)) {
// return 'windows-logo';
return <Icons.desktop />
}
Expand Down
14 changes: 7 additions & 7 deletions src/components/profile/sessions/sessions-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export default function SessionsTable({ dictionary }: { dictionary: TDictionary
(prev) =>
prev && {
...prev,
data: prev?.data?.filter((session) => session.id !== selectedSession),
data: prev.data?.filter((session) => session.id !== selectedSession),
}
)

//? Delete from DB
deleteSessionMutation.mutate({ id: selectedSession })
}

const rows = activeSessions?.data?.data?.map((session) => (
const rows = activeSessions.data?.data?.map((session) => (
<SessionRow session={session} setSelectedSession={setSelectedSession} key={session.id} />
))

Expand All @@ -72,7 +72,7 @@ export default function SessionsTable({ dictionary }: { dictionary: TDictionary
)

const showPagination = Boolean(
activeSessions?.data && (activeSessions?.data.meta.totalPages > 1 || itemsPerPageInitial !== itemsPerPage)
activeSessions.data && (activeSessions.data.meta.totalPages > 1 || itemsPerPageInitial !== itemsPerPage)
)

return (
Expand All @@ -81,11 +81,11 @@ export default function SessionsTable({ dictionary }: { dictionary: TDictionary
{activeSessions.isFetched ? rows : skelRows}
<Pagination
show={showPagination}
currentNumberOfItems={activeSessions?.data?.data?.length ?? 0}
currentPage={activeSessions?.data?.meta.page}
totalPages={activeSessions?.data?.meta.totalPages}
currentNumberOfItems={activeSessions.data?.data?.length ?? 0}
currentPage={activeSessions.data?.meta.page}
totalPages={activeSessions.data?.meta.totalPages}
setCurrentPage={setCurrentPage}
itemsPerPage={activeSessions?.data?.meta.perPage}
itemsPerPage={activeSessions.data?.meta.perPage}
setItemsPerPage={setItemsPerPage}
/>
<AlertDialogContent>
Expand Down
10 changes: 5 additions & 5 deletions src/components/profile/update-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export default function UpdateAccount({ dictionary }: { dictionary: TDictionary
const form = useForm<INonSensibleForm>({
resolver: zodResolver(nonSensibleSchema(dictionary)),
defaultValues: {
username: account?.data?.user?.name || "",
username: account.data?.user.name || "",
},
})

const resetForm = useCallback(() => {
logger.debug("Resetting form with", account?.data?.user)
logger.debug("Resetting form with", account.data?.user)
form.reset({
username: account?.data?.user.username ?? "",
username: account.data?.user.username ?? "",
})
}, [account?.data?.user, form])
}, [account.data?.user, form])

useEffect(() => {
resetForm()
Expand All @@ -76,7 +76,7 @@ export default function UpdateAccount({ dictionary }: { dictionary: TDictionary
label={dictionary.profilePage.profileDetails.username.label}
placeholder={dictionary.profilePage.profileDetails.username.placeholder}
type="text"
disabled={updateUserMutation.isLoading || !account?.isFetched}
disabled={updateUserMutation.isLoading || !account.isFetched}
form={form}
name="username"
/>
Expand Down
Loading

0 comments on commit d520209

Please sign in to comment.