-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from urther/develop
kakako login,member signUp
- Loading branch information
Showing
10 changed files
with
261 additions
and
127 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
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,8 @@ | ||
export interface usertype { | ||
nickname?: string; | ||
name?: string; | ||
email: string; | ||
gender: boolean; | ||
city: string; | ||
district: string; | ||
} |
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,92 @@ | ||
import { throttle } from 'lodash'; | ||
import React, { useState } from 'react'; | ||
|
||
import { checkIsNicknameDuplicated } from 'api/firebase'; | ||
import Image from 'next/image'; | ||
import correct from '@assets/signUp/correct.svg'; | ||
import incorrect from '@assets/signUp/incorrect.svg'; | ||
|
||
export const CheckIsValidNickname = ({ | ||
nickname, | ||
onSetNickname, | ||
isCheckNickname, | ||
}: CheckIsValid) => { | ||
const [isValid, setIsValid] = useState(false); | ||
const [isDuplicated, setIsDuplicated] = useState(false); | ||
|
||
const onChangeNickName = throttle((e: React.SyntheticEvent) => { | ||
if (!(e.target instanceof HTMLInputElement)) return; | ||
|
||
const nickname = e.target.value; | ||
onSetNickname(nickname); | ||
|
||
if (nickname.length < 1 || nickname.length >= 5) setIsValid(false); | ||
else { | ||
const reg = /[!?@#$%^&*():;+-=~{}<>\_\[\]\|\\\"\'\,\.\/\`\₩\s]/g; | ||
|
||
if (reg.test(nickname)) { | ||
// 특수문자 있는 경우 | ||
setIsValid(false); | ||
} else { | ||
setIsValid(true); | ||
checkDuplicated(nickname); | ||
} | ||
} | ||
}, 200); | ||
|
||
const checkDuplicated = async (nickname: string) => { | ||
try { | ||
const result = await checkIsNicknameDuplicated(nickname); | ||
if (!result) { | ||
isCheckNickname(true); | ||
setIsDuplicated(true); | ||
} else { | ||
setIsDuplicated(false); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{isValid && isDuplicated ? ( | ||
<> | ||
<span className="correct-nickname">좋은 닉네임이에요!</span> | ||
<div className="nickname-img"> | ||
<Image src={correct} alt="옳음" width={'17px'} height={'17px'} /> | ||
</div> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
|
||
{isValid ? ( | ||
<></> | ||
) : ( | ||
<> | ||
<span className="incorrect-nickname">닉네임은 특수문자 제외 5자 이내에요.</span> | ||
<div className="nickname-img"> | ||
<Image src={incorrect} alt="틀림" width={'17px'} height={'17px'} /> | ||
</div> | ||
</> | ||
)} | ||
{isValid && !isDuplicated ? ( | ||
<> | ||
<span className="duplicate-nickname">중복된 닉네임이 있습니다!</span> | ||
<div className="nickname-img"> | ||
<Image src={incorrect} alt="틀림" width={'17px'} height={'17px'} /> | ||
</div> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
<input | ||
onChange={onChangeNickName} | ||
value={nickname || ''} | ||
type="text" | ||
placeholder="특수 문자 제외 5자 이내" | ||
/> | ||
</> | ||
); | ||
}; |
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,5 @@ | ||
interface CheckIsValid { | ||
nickname: string; | ||
onSetNickname: Dispatch<SetStateAction<string>>; | ||
isCheckNickname: Dispatch<SetStateAction<boolean>>; | ||
} |
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
Oops, something went wrong.