Skip to content

Commit

Permalink
Merge pull request #229 from oreumi-dreamer/jinhui
Browse files Browse the repository at this point in the history
🎨 회원가입 중 중복 아이디 체크 validation 추가
  • Loading branch information
jini0012 authored Dec 20, 2024
2 parents 3efa26c + b481757 commit 243eb6c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/components/signup/BasicInfoForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function BasicInfoForm({ onSubmit, formData, setters }) {
const [isNameValid, setIsNameValid] = useState(false);
const [isBirthValid, setIsBirthValid] = useState(false);
const [isAgree, setIsAgree] = useState(false);
const [idError, setIdError] = useState("");

const router = useRouter();

Expand Down Expand Up @@ -52,6 +53,9 @@ export default function BasicInfoForm({ onSubmit, formData, setters }) {
const inputClass = e.target.classList;

if (type === "userId") {
if (userId !== "") {
checkId();
}
if (!valid) {
inputClass.add(`${styles.invalid}`);
} else {
Expand All @@ -68,6 +72,24 @@ export default function BasicInfoForm({ onSubmit, formData, setters }) {
}
};

async function checkId() {
try {
const idRes = await fetch("/api/join/check-userid", {
method: "POST",
body: JSON.stringify({ userId: userId }),
});
const idData = await idRes.json();
if (idData.isDuplicate) {
setIsIdValid(false);
setIdError("이미 사용중인 아이디입니다.");
} else {
setIdError("");
}
} catch (error) {
console.error(error);
}
}

const todayYear = new Date().getFullYear();

const handleAgree = () => {
Expand Down Expand Up @@ -101,8 +123,10 @@ export default function BasicInfoForm({ onSubmit, formData, setters }) {
required
/>
<span className={styles["invalid-text"]}>
{!isIdValid &&
{!idError &&
!isIdValid &&
"아이디는 4~20자의 영문 소문자와 숫자로 입력해주세요."}
{idError && idError}
</span>
<img
src={isIdValid ? "/images/valid.svg" : "/images/invalid.svg"}
Expand Down

0 comments on commit 243eb6c

Please sign in to comment.