Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lint error caused by useRouter being called conditionally #355

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/ui/AuthForms/EmailSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
setIsSubmitting(true); // Disable the button while the request is being handled
await handleRequest(e, signInWithEmail, router);
await handleRequest(e, signInWithEmail, routerMethod);
setIsSubmitting(false);
};

Expand Down
5 changes: 3 additions & 2 deletions components/ui/AuthForms/ForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
setIsSubmitting(true); // Disable the button while the request is being handled
await handleRequest(e, requestPasswordUpdate, router);
await handleRequest(e, requestPasswordUpdate, routerMethod);
setIsSubmitting(false);
};

Expand Down
5 changes: 3 additions & 2 deletions components/ui/AuthForms/PasswordSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
setIsSubmitting(true); // Disable the button while the request is being handled
await handleRequest(e, signInWithPassword, router);
await handleRequest(e, signInWithPassword, routerMethod);
setIsSubmitting(false);
};

Expand Down
5 changes: 3 additions & 2 deletions components/ui/AuthForms/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
setIsSubmitting(true); // Disable the button while the request is being handled
await handleRequest(e, signUp, router);
await handleRequest(e, signUp, routerMethod);
setIsSubmitting(false);
};

Expand Down
5 changes: 3 additions & 2 deletions components/ui/AuthForms/UpdatePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
setIsSubmitting(true); // Disable the button while the request is being handled
await handleRequest(e, updatePassword, router);
await handleRequest(e, updatePassword, routerMethod);
setIsSubmitting(false);
};

Expand Down
8 changes: 5 additions & 3 deletions components/ui/Navbar/Navlinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="relative flex flex-row justify-between py-4 align-center md:py-6">
Expand All @@ -34,8 +36,8 @@ export default function Navlinks({ user }: NavlinksProps) {
</div>
<div className="flex justify-end space-x-8">
{user ? (
<form onSubmit={(e) => handleRequest(e, SignOut, router)}>
<input type="hidden" name="pathName" value={usePathname()} />
<form onSubmit={(e) => handleRequest(e, SignOut, routerMethod)}>
<input type="hidden" name="pathName" value={pathname} />
<button type="submit" className={s.link}>
Sign out
</button>
Expand Down