Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
Add loading state to sign in button
Browse files Browse the repository at this point in the history
  • Loading branch information
NicHaley committed Jan 23, 2024
1 parent f23d35a commit 712ff56
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions apps/app/src/app/signin/form.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
"use client";

import { useState } from "react";
import { signIn } from "next-auth/react";
import { Button, Input } from "@floe/ui";
import Image from "next/image";
import type { FormEvent } from "react";
import { Spinner } from "@floe/ui";
import { useSearchParams } from "next/navigation";
import logo from "public/logo.png";

function Form() {
const searchParams = useSearchParams();
const [loading, setLoading] = useState(false);
const callbackUrl = searchParams.get("callbackUrl") || "/";

function handleSubmit(event: FormEvent<HTMLFormElement>) {
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();

if (loading) {
return;
}

const email = event.currentTarget.email.value;
void signIn("sendgrid", { email, callbackUrl });
setLoading(true);
await signIn("sendgrid", { email, callbackUrl }).finally(() => {
setLoading(false);
});
}

return (
Expand All @@ -39,8 +49,8 @@ function Form() {
type="email"
/>
</div>
<Button className="w-full" type="submit">
Continue with email
<Button className="w-full" disabled={loading} type="submit">
{loading ? <Spinner /> : "Continue with email"}
</Button>
</form>
</div>
Expand Down

0 comments on commit 712ff56

Please sign in to comment.