-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Feat/#67] 펫 이름 뷰 구현 #68
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
const Onboarding = () => { | ||
return ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
|
||
export const layout = style({ | ||
display: "flex", | ||
flexDirection: "column", | ||
padding: "8rem 2rem", | ||
gap: "9rem", | ||
}); | ||
|
||
export const imgStyle = style({ | ||
width: "16.5rem", | ||
height: "9.3rem", | ||
marginBottom: "1.6rem", | ||
}); | ||
|
||
export const btnWrapper = style({ | ||
maxWidth: "76.8rem", | ||
width: "100%", | ||
position: "fixed", | ||
bottom: 0, | ||
|
||
display: "grid", | ||
gridTemplateColumns: "9.6rem calc(100% - 9.6rem)", | ||
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. p5) 이런 계산 식이라니.. 멋있다 |
||
gap: "1.2rem", | ||
whiteSpace: "nowrap", | ||
padding: "1.2rem 2rem 3.2rem 2rem", | ||
}); | ||
|
||
export const errorLayout = style({ | ||
marginTop: "0.8rem", | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useState, ChangeEvent } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import * as styles from "./PetName.css"; | ||
import onboardingImg from "@asset/image/image 1730.png"; | ||
import { ONBOARDING_GUIDE } from "@page/onboarding/index/constant/onboardingGuide"; | ||
import Title from "@page/onboarding/index/common/title/Title"; | ||
import Docs from "@page/onboarding/index/common/docs/Docs"; | ||
import { TextField } from "@common/component/TextField"; | ||
import { Button } from "@common/component/Button"; | ||
import { validatePetName } from "../../util/validatePetName"; | ||
|
||
const PetName = () => { | ||
// 상태 하나로 관리 | ||
const [petName, setPetName] = useState(""); | ||
|
||
// 펫이름 입력 처리 | ||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setPetName(e.target.value); | ||
}; | ||
|
||
// 유효성 검사 결과 | ||
const validationMessages = petName ? validatePetName(petName) : []; | ||
const isValid = petName && validationMessages.length === 0; | ||
Comment on lines
+21
to
+23
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. p5) 유효성 검사 좋아요 🫠❤️ |
||
|
||
// 뒤로 가기 | ||
const navigate = useNavigate(); | ||
const handleGoBack = () => { | ||
navigate(-1); | ||
}; | ||
Comment on lines
+27
to
+29
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. p3) 전에 논의 많이 하기로는 -1 은 지양하기로 했던 거 같은데, 이걸 사용해야만 이유가 있었을까요? 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. 아! 해당 pr은 논의 이전에 올린 pr입니다..! |
||
|
||
// 다음 버튼 | ||
const handleNext = () => { | ||
console.log("다음 pr에서 구현할래욥."); | ||
}; | ||
|
||
return ( | ||
<> | ||
{/* 상단 영역 */} | ||
<div className={styles.layout}> | ||
<div> | ||
<img src={onboardingImg} alt="onboarding-character" className={styles.imgStyle} /> | ||
<Title text={ONBOARDING_GUIDE.petName.title} /> | ||
<Docs text={ONBOARDING_GUIDE.petName.docs} /> | ||
</div> | ||
|
||
{/* 펫이름 입력 영역 */} | ||
<div> | ||
<TextField | ||
state={petName === "" ? "default" : isValid ? "default" : "error"} | ||
value={petName} | ||
onChange={handleChange} | ||
placeholder="닉네임을 입력해주세요." | ||
/> | ||
<div className={styles.errorLayout}> | ||
{validationMessages.map((message) => ( | ||
<Docs key={`error-${message}`} state="lError" text={message} /> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{/* 하단 버튼 */} | ||
<div className={styles.btnWrapper}> | ||
<Button label="돌아가기" size="large" variant="solidNeutral" disabled={false} onClick={handleGoBack} /> | ||
<Button label="다음" size="large" variant="solidPrimary" disabled={!isValid} onClick={handleNext} /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default PetName; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ERROR_MSG } from "../constant/errorMsg"; | ||
|
||
export function validatePetName(petName: string): string[] { | ||
const errors: string[] = []; | ||
|
||
// 영어 또는 숫자 하나라도 포함되면 오류 | ||
const alphanumericPattern = /[a-zA-Z0-9]/; | ||
if (alphanumericPattern.test(petName)) { | ||
errors.push(ERROR_MSG.petName.enNum); // 영어 또는 숫자가 포함된 경우 | ||
} | ||
Comment on lines
+4
to
+10
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. p4) error 라는 state 를 두고 setState 로 이전 상태 값에 에러를 추가하는 방법으로 세팅하는 방법이 있는데, 해당 방법으로 구현한 이유가 있을까용?? 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. 가장 큰 이유는 개인적인 취향이긴 한데, 상태 안두고 유틸 함수 작성하는 것을 좋아해서 입니도..호홍 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. p5) 아주 좋은 생각! 상태 많이 둬봤자 신경쓸 것만 많아져요~ 유틸함수 지향 잘 배웠네요! 좋습니다 |
||
|
||
// 펫이름 길이 | ||
if (petName.length < 2 || petName.length > 8) { | ||
errors.push(ERROR_MSG.petName.length); | ||
} | ||
|
||
// 공백 특수문자 | ||
if (/[^a-zA-Z0-9가-힣ㄱ-ㅎㅏ-ㅣ]/.test(petName)) { | ||
errors.push(ERROR_MSG.petName.spaceSymbol); | ||
} | ||
// 완성된 한글 | ||
if (/[ㄱ-ㅎㅏ-ㅣ]/.test(petName)) { | ||
errors.push(ERROR_MSG.petName.ko); | ||
} | ||
|
||
return errors; | ||
} |
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.
p5) 미리 미리 고려해서 구현해두는 예림 누나 굿 ~