From 3bfda85545fe578a44cb77f12df18d7b3a6d08fb Mon Sep 17 00:00:00 2001 From: Aamir Azad Date: Wed, 19 Jun 2024 12:01:39 +0530 Subject: [PATCH] refactor: fix eslint issues --- src/app/paperless/page.tsx | 10 +++++----- src/app/settings/page.tsx | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx index 2bb6118..adcd8ae 100644 --- a/src/app/paperless/page.tsx +++ b/src/app/paperless/page.tsx @@ -23,7 +23,7 @@ import { QueryClient, } from "@tanstack/react-query"; import LoadingSpinner from "@/components/loading-spinner"; -import { PaperlessDocumentsType } from "@/types"; +import type { PaperlessDocumentsType } from "@/types"; const queryClient = new QueryClient(); @@ -34,7 +34,7 @@ function DocumentsSearch() { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); - const givenQuery = searchParams.get("query") || ""; + const givenQuery = searchParams.get("query") ?? ""; // 1. Define your form. const form = useForm>({ resolver: zodResolver(formSchema), @@ -54,9 +54,9 @@ function DocumentsSearch() { ); function onSubmit(values: z.infer) { - if (values["query"]) + if (values.query) router.replace( - pathname + "?" + createQueryString("query", values["query"]), + pathname + "?" + createQueryString("query", values.query), ); } @@ -91,7 +91,7 @@ function DocumentsPage() { queryKey: ["key", query], queryFn: async () => { const response = await fetch("/api/paperless?query=" + query); - const data = (await response.json()) as PaperlessDocumentsType; + const data = await response.json() as PaperlessDocumentsType; return data; }, }); diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index c8c7f17..44b2893 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -14,7 +14,8 @@ import { Input } from "@/components/ui/input"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { useForm } from "react-hook-form"; -import { Dispatch, SetStateAction, useState } from "react"; +import type { Dispatch, SetStateAction } from "react"; +import { useState } from "react"; import { useUser } from "@clerk/nextjs"; import { redirect, usePathname } from "next/navigation"; import LoadingSpinner from "@/components/loading-spinner"; @@ -56,7 +57,7 @@ function FullName({ async function onSubmit(values: z.infer) { setActiveTab((prevTab) => prevTab + 1); // Increment activeTab try { - await setFullUserName(values["FullName"], user!.id); + await setFullUserName(values.FullName); // Operation succeeded, show success toast toast("Your name preferences was saved"); // Optionally, move to a new tab or take another action to indicate success @@ -120,13 +121,13 @@ function PaperlessURL({ } async function onSubmit(values: z.infer) { - if (values["URL"] == "") { + if (values.URL == "") { setActiveTab((prevTab) => prevTab + 2); // Skip api key form } else { setActiveTab((prevTab) => prevTab + 1); // Increment activeTab } try { - await setPaperlessURL(values["URL"], user!.id); + await setPaperlessURL(values.URL); // Operation succeeded, show success toast toast("Your paperless URL preferences was saved"); // Optionally, move to a new tab or take another action to indicate success @@ -193,7 +194,7 @@ function PaperlessToken({ setActiveTab((prevTab) => prevTab + 1); // Increment activeTab try { - await setPaperlessToken(values["token"], user!.id); + await setPaperlessToken(values.token); // Operation succeeded, show success toast toast("Your paperless token preferences was saved"); } catch { @@ -221,9 +222,9 @@ function PaperlessToken({ - You can create (or re-create) an API token by opening the "My - Profile" link in the user dropdown found in the web UI and - clicking the circular arrow button. + You can create (or re-create) an API token by opening the + "My Profile" link in the user dropdown found in the + web UI and clicking the circular arrow button. )} @@ -271,10 +272,10 @@ export default function SettingsPage() { const [activeTab, setActiveTab] = useState(0); const formElements = [ - , - , - , - , + , + , + , + , ]; return ( <>