From c405611039ba54b536d9902669abe4b03959c76d Mon Sep 17 00:00:00 2001 From: MartinSWDev Date: Sun, 30 Jun 2024 16:13:30 +0100 Subject: [PATCH 1/2] fix: lint error caused by useRouter being called conditionally --- components/ui/AuthForms/EmailSignIn.tsx | 5 +++-- components/ui/AuthForms/ForgotPassword.tsx | 5 +++-- components/ui/AuthForms/PasswordSignIn.tsx | 5 +++-- components/ui/AuthForms/Signup.tsx | 5 +++-- components/ui/AuthForms/UpdatePassword.tsx | 5 +++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/ui/AuthForms/EmailSignIn.tsx b/components/ui/AuthForms/EmailSignIn.tsx index 1860f729..2ef46514 100644 --- a/components/ui/AuthForms/EmailSignIn.tsx +++ b/components/ui/AuthForms/EmailSignIn.tsx @@ -19,12 +19,13 @@ export default function EmailSignIn({ redirectMethod, disableButton }: EmailSignInProps) { - const router = redirectMethod === 'client' ? useRouter() : null; + const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); + const routerMethod = redirectMethod === 'client' ? router : null; const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled - await handleRequest(e, signInWithEmail, router); + await handleRequest(e, signInWithEmail, routerMethod); setIsSubmitting(false); }; diff --git a/components/ui/AuthForms/ForgotPassword.tsx b/components/ui/AuthForms/ForgotPassword.tsx index bdf8f6b7..eb9c9db3 100644 --- a/components/ui/AuthForms/ForgotPassword.tsx +++ b/components/ui/AuthForms/ForgotPassword.tsx @@ -19,12 +19,13 @@ export default function ForgotPassword({ redirectMethod, disableButton }: ForgotPasswordProps) { - const router = redirectMethod === 'client' ? useRouter() : null; + const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); + const routerMethod = redirectMethod === 'client' ? router : null; const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled - await handleRequest(e, requestPasswordUpdate, router); + await handleRequest(e, requestPasswordUpdate, routerMethod); setIsSubmitting(false); }; diff --git a/components/ui/AuthForms/PasswordSignIn.tsx b/components/ui/AuthForms/PasswordSignIn.tsx index 3ec8297d..635dd73d 100644 --- a/components/ui/AuthForms/PasswordSignIn.tsx +++ b/components/ui/AuthForms/PasswordSignIn.tsx @@ -17,12 +17,13 @@ export default function PasswordSignIn({ allowEmail, redirectMethod }: PasswordSignInProps) { - const router = redirectMethod === 'client' ? useRouter() : null; + const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); + const routerMethod = redirectMethod === 'client' ? router : null; const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled - await handleRequest(e, signInWithPassword, router); + await handleRequest(e, signInWithPassword, routerMethod); setIsSubmitting(false); }; diff --git a/components/ui/AuthForms/Signup.tsx b/components/ui/AuthForms/Signup.tsx index cd98f040..0e45d7a0 100644 --- a/components/ui/AuthForms/Signup.tsx +++ b/components/ui/AuthForms/Signup.tsx @@ -15,12 +15,13 @@ interface SignUpProps { } export default function SignUp({ allowEmail, redirectMethod }: SignUpProps) { - const router = redirectMethod === 'client' ? useRouter() : null; + const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); + const routerMethod = redirectMethod === 'client' ? router : null; const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled - await handleRequest(e, signUp, router); + await handleRequest(e, signUp, routerMethod); setIsSubmitting(false); }; diff --git a/components/ui/AuthForms/UpdatePassword.tsx b/components/ui/AuthForms/UpdatePassword.tsx index cd51488e..b6fc8c58 100644 --- a/components/ui/AuthForms/UpdatePassword.tsx +++ b/components/ui/AuthForms/UpdatePassword.tsx @@ -13,12 +13,13 @@ interface UpdatePasswordProps { export default function UpdatePassword({ redirectMethod }: UpdatePasswordProps) { - const router = redirectMethod === 'client' ? useRouter() : null; + const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); + const routerMethod = redirectMethod === 'client' ? router : null; const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled - await handleRequest(e, updatePassword, router); + await handleRequest(e, updatePassword, routerMethod); setIsSubmitting(false); }; From 54b35965c00562535b8ab90c9e22df3e0086c245 Mon Sep 17 00:00:00 2001 From: MartinSWDev Date: Sun, 30 Jun 2024 16:41:18 +0100 Subject: [PATCH 2/2] fix: lint error caused by usePathname being called conditionally --- components/ui/Navbar/Navlinks.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/ui/Navbar/Navlinks.tsx b/components/ui/Navbar/Navlinks.tsx index 6608cd0a..9bfc3858 100644 --- a/components/ui/Navbar/Navlinks.tsx +++ b/components/ui/Navbar/Navlinks.tsx @@ -13,7 +13,9 @@ interface NavlinksProps { } export default function Navlinks({ user }: NavlinksProps) { - const router = getRedirectMethod() === 'client' ? useRouter() : null; + const router = useRouter() + const pathname = usePathname(); + const routerMethod = getRedirectMethod() === 'client' ? router : null; return (
@@ -34,8 +36,8 @@ export default function Navlinks({ user }: NavlinksProps) {
{user ? ( -
handleRequest(e, SignOut, router)}> - + handleRequest(e, SignOut, routerMethod)}> +