Skip to content

Commit

Permalink
feat: login시 route처리, error message 스타일링
Browse files Browse the repository at this point in the history
  • Loading branch information
codefug committed Jun 14, 2024
1 parent e837462 commit fcf5f1e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/pages/login/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useStore } from "@/app/store";
import { postSignIn } from "@/shared/api/api";
import { zodResolver } from "@hookform/resolvers/zod";
import { FieldValues, useForm } from "react-hook-form";
import { Link } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import { z } from "zod";

const schema = z.object({
Expand All @@ -12,6 +12,7 @@ const schema = z.object({
// 네트워크 요청을 보내기 전에 형식 검사
export function LoginPage() {
const { login } = useStore();
const navigate = useNavigate();
const {
register,
handleSubmit,
Expand All @@ -25,20 +26,26 @@ export function LoginPage() {
password: d.password,
});
if (!data) return;
console.log(d);
login(data.accessToken);
navigate("/");
})();
};

return (
<>
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("email")} />
{errors.email?.message && <p>{errors.email?.message as string}</p>}
<input {...register("password")} />
{errors.password?.message && (
<p>{errors.password?.message as string}</p>
)}
<div>
<input {...register("email")} />
{errors.email?.message && (
<p style={{ color: "red" }}>{errors.email?.message as string}</p>
)}
</div>
<div>
<input {...register("password")} type="password" />
{errors.password?.message && (
<p style={{ color: "red" }}>{errors.password?.message as string}</p>
)}
</div>
<input type="submit" />
</form>
<Link to="/signup">회원가입</Link>
Expand Down

0 comments on commit fcf5f1e

Please sign in to comment.