-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charlie ⚡️
committed
Oct 26, 2022
1 parent
889cec1
commit 862ceb7
Showing
14 changed files
with
384 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ node_modules | |
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
/apps/ui/coverage | ||
|
||
# next.js | ||
.next/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useRouter } from "next/router"; | ||
import z from "zod"; | ||
import { Label, Input, TextLabel } from "./ui/input"; | ||
import { login } from "../lib/graphql"; | ||
import { useAuthAtom } from "../hooks/useAuth"; | ||
import { useForm } from "./ui/forms/core"; | ||
|
||
const validationSchema = z.object({ | ||
email: z.string().email("Invalid email"), | ||
password: z.string().min(8), | ||
}); | ||
|
||
export function LoginForm() { | ||
const [, , { loginWithToken }] = useAuthAtom(); | ||
const router = useRouter(); | ||
const { errors, isSubmitting, getFieldProps, getFormProps, getErrorProps } = useForm( | ||
{ | ||
initialValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
validationSchema, | ||
onSubmit(values) { | ||
login(values.email, values.password).then(({ login: { user, token } }) => { | ||
if (user && token) { | ||
loginWithToken(token); | ||
router.push("/dashboard"); | ||
} | ||
}); | ||
}, | ||
}, | ||
{ | ||
validateOnEvent: "blur", | ||
} | ||
); | ||
|
||
return ( | ||
<form {...getFormProps()} className="space-y-6"> | ||
<div> | ||
<Label htmlFor="email"> | ||
<TextLabel>Email</TextLabel> | ||
<Input | ||
disabled={isSubmitting} | ||
type="email" | ||
id="email" | ||
autoComplete="email" | ||
required | ||
data-testid="login-email-input" | ||
{...getFieldProps("email")} | ||
/> | ||
{errors["email"] && <div {...getErrorProps("email")}>{errors["email"]}</div>} | ||
</Label> | ||
</div> | ||
|
||
<div> | ||
<Label htmlFor="password"> | ||
<TextLabel>Password</TextLabel> | ||
<Input | ||
disabled={isSubmitting} | ||
id="password" | ||
type="password" | ||
autoComplete="current-password" | ||
required | ||
data-testid="login-password-input" | ||
{...getFieldProps("password")} | ||
/> | ||
{errors["password"] && ( | ||
<div {...getErrorProps("password")}>{errors["password"]}</div> | ||
)} | ||
</Label> | ||
</div> | ||
|
||
<div> | ||
<button | ||
type="submit" | ||
disabled={isSubmitting || Object.keys(errors).length > 0} | ||
className="flex w-full justify-center rounded-md border border-transparent bg-sky-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2"> | ||
Login | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
} |
Oops, something went wrong.
862ceb7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
reubin – ./
pre-alpha.reubin.app
reubin-hephaestus.vercel.app
reubin-git-main-hephaestus.vercel.app
reubin.app
reubin-site.vercel.app
alpha.reubin.app