-
Notifications
You must be signed in to change notification settings - Fork 117
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
[황경수] week16 #1065
The head ref may contain hidden characters: "part3-\uD669\uACBD\uC218-week16"
[황경수] week16 #1065
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import { postSignIn } from "@src/api"; | |
import { useRouter } from "next/router"; | ||
import Input from "@src/components/sign/Input"; | ||
import ERROR from "@src/components/sign/ErrorMessages"; | ||
import { saveToLocalStorage } from "@src/utils/safeKey"; | ||
import { emailTextInputProps } from "@src/utils/formProps"; | ||
|
||
type FormType = { | ||
email: string; | ||
|
@@ -32,7 +34,7 @@ function SigninForm() { | |
console.log(accessToken); | ||
|
||
if (accessToken) { | ||
localStorage.setItem("accessToken", accessToken); | ||
saveToLocalStorage("accessToken", accessToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 반영 굳! 👍 |
||
} else { | ||
throw new Error("Access token이 없습니다."); | ||
} | ||
|
@@ -56,12 +58,8 @@ function SigninForm() { | |
<S.Label>이메일</S.Label> | ||
<div style={{ position: "relative" }}> | ||
<Input.TextInput | ||
type="text" | ||
register={register("email", { | ||
required: true, | ||
pattern: /^[a-z0-9]+@[a-z]+\.[a-z]{2,3}$/, | ||
})} | ||
placeholder="이메일을 입력해 주세요" | ||
{...emailTextInputProps} | ||
register={register("email", emailTextInputProps.registerOptions)} | ||
$hasError={!!errors.email} | ||
/> | ||
<S.ErrorMessage> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const emailTextInputProps = { | ||
type: "text", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 inputType 값은 email 값이 더 일반적입니다. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input |
||
registerOptions: { | ||
required: true, | ||
pattern: /^[a-z0-9]+@[a-z]+\.[a-z]{2,3}$/, | ||
}, | ||
placeholder: "이메일을 입력해 주세요", | ||
}; | ||
|
||
export const passwordTextInputProps = (inputType: string) => ({ | ||
type: inputType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 inputType 값은 password 값이 일반적입니다~ |
||
registerOptions: { | ||
required: true, | ||
pattern: /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/, | ||
}, | ||
placeholder: "영문, 숫자를 조합해 8자 이상 입력해 주세요", | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const safeGetItem = (key: string) => { | ||
try { | ||
return localStorage.getItem(key); | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
}; | ||
Comment on lines
+1
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 리턴값이 null로 되어있는 경우에는 키에 대한 값이 없어서 null 일때와 에러가 발생해서 받은 값인 null 경우 구분하기가 어렵기 때문에, 해당 키 값이 없을땐 null / 에러 발생 시 undefined 이렇게 구분해서 리턴해주면 좋습니다~ |
||
|
||
export const saveToLocalStorage = (key: string, value: string) => { | ||
try { | ||
localStorage.setItem(key, value); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; |
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.
지난번 리뷰 사항을 잘 반영해주셨네요 👍