-
Notifications
You must be signed in to change notification settings - Fork 5
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
[FE] 계좌번호 입력 제한 추가 #634
[FE] 계좌번호 입력 제한 추가 #634
Changes from 3 commits
0294b81
f6d95fd
c595c69
4c46a99
aa8d6c7
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ const RULE = { | |
maxEventPasswordLength: 4, | ||
maxMemberNameLength: 4, | ||
maxPrice: 10000000, | ||
minAccountNumberLength: 8, | ||
maxAccountNumberLength: 30, | ||
Comment on lines
+6
to
+7
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. 상수화 굿굿 |
||
}; | ||
|
||
export default RULE; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,15 +2,20 @@ import type {Event} from 'types/serviceType'; | |||||
|
||||||
import {useEffect, useState} from 'react'; | ||||||
|
||||||
import validateAccountNumber from '@utils/validate/validateAccountNumber'; | ||||||
|
||||||
import RULE from '@constants/rule'; | ||||||
|
||||||
import useRequestPatchEvent from './queries/event/useRequestPatchEvent'; | ||||||
import useRequestGetEvent from './queries/event/useRequestGetEvent'; | ||||||
|
||||||
const useAccount = () => { | ||||||
const {bankName, accountNumber} = useRequestGetEvent(); | ||||||
|
||||||
const [bankNameState, setBankName] = useState(bankName); | ||||||
const [accountNumberState, setAccountNumber] = useState(accountNumber); | ||||||
const [accountNumberErrorMessage, setAccountNumberErrorMessage] = useState<string | null>(null); | ||||||
const [canSubmit, setCanSubmit] = useState(false); | ||||||
const [isPasting, setIsPasting] = useState(false); | ||||||
|
||||||
useEffect(() => { | ||||||
setBankName(bankName); | ||||||
|
@@ -24,7 +29,32 @@ const useAccount = () => { | |||||
}; | ||||||
|
||||||
const handleAccount = (event: React.ChangeEvent<HTMLInputElement>) => { | ||||||
setAccountNumber(event.target.value); | ||||||
if (isPasting) return; | ||||||
|
||||||
const newValue = event.target.value; | ||||||
const {isValid, errorMessage} = validateAccountNumber(newValue); | ||||||
setAccountNumberErrorMessage(errorMessage); | ||||||
|
||||||
const isValidMinLength = newValue.length >= RULE.minAccountNumberLength; | ||||||
|
||||||
if (isValid) { | ||||||
setAccountNumber(event.target.value); | ||||||
} else if (!isValid && !isValidMinLength) { | ||||||
setAccountNumber(event.target.value.replace(/[^0-9\s\-]/g, '').trim()); | ||||||
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. 어차피 허용되는 문자인데 slice 를 사용하면 안되는 이유가 있었을까요?
Suggested change
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. 8자보다 작을 때 숫자 공백 하이픈 외의 문자가 허용되지 않도록 하기 위해서입니다! |
||||||
} | ||||||
}; | ||||||
|
||||||
const handleAccountOnPaste = (event: React.ClipboardEvent<HTMLInputElement>) => { | ||||||
setIsPasting(true); | ||||||
|
||||||
const value = `${accountNumberState}${event.clipboardData.getData('text')}`; | ||||||
const newValue = value.replace(/[^0-9\s\-]/g, '').trim(); | ||||||
const {isValid, errorMessage} = validateAccountNumber(newValue); | ||||||
|
||||||
setAccountNumberErrorMessage(errorMessage); | ||||||
if (isValid) setAccountNumber(newValue); | ||||||
|
||||||
setTimeout(() => setIsPasting(false), 0); | ||||||
}; | ||||||
|
||||||
const getChangedField = () => { | ||||||
|
@@ -49,15 +79,17 @@ const useAccount = () => { | |||||
const existEmptyField = bankName.trim() === '' && accountNumber.trim() === ''; | ||||||
const isChanged = bankName !== bankNameState || accountNumber !== accountNumberState; | ||||||
|
||||||
setCanSubmit(!existEmptyField && isChanged); | ||||||
}, [bankName, accountNumber, bankNameState, accountNumberState]); | ||||||
setCanSubmit(!existEmptyField && isChanged && accountNumberErrorMessage === null); | ||||||
}, [bankName, accountNumber, bankNameState, accountNumberState, accountNumberErrorMessage]); | ||||||
|
||||||
return { | ||||||
bankName: bankNameState, | ||||||
accountNumber: accountNumberState, | ||||||
accountNumberErrorMessage, | ||||||
canSubmit, | ||||||
selectBank, | ||||||
handleAccount, | ||||||
handleAccountOnPaste, | ||||||
enrollAccount, | ||||||
}; | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,16 @@ const Account = () => { | |
|
||
const [isBottomSheetOpen, setIsBottomSheetOpen] = useState(false); | ||
|
||
const {bankName, accountNumber, canSubmit, selectBank, handleAccount, enrollAccount} = useAccount(); | ||
const { | ||
bankName, | ||
accountNumber, | ||
accountNumberErrorMessage, | ||
canSubmit, | ||
selectBank, | ||
handleAccount, | ||
handleAccountOnPaste, | ||
enrollAccount, | ||
} = useAccount(); | ||
|
||
const enrollAccountAndNavigateAdmin = async () => { | ||
await enrollAccount(); | ||
|
@@ -40,19 +49,19 @@ const Account = () => { | |
errorText={null} | ||
autoFocus={false} | ||
isAlwaysOnLabel | ||
isAlwaysOnInputBorder | ||
readOnly | ||
onClick={() => setIsBottomSheetOpen(true)} | ||
/> | ||
<LabelInput | ||
labelText="계좌번호" | ||
placeholder="030302-04-191806" | ||
errorText={null} | ||
placeholder="ex) 030302-04-191806" | ||
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. 올바른 placeholder 최고 |
||
errorText={accountNumberErrorMessage} | ||
isError={accountNumberErrorMessage !== null} | ||
value={accountNumber ?? ''} | ||
onChange={handleAccount} | ||
onPaste={handleAccountOnPaste} | ||
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. 저도 이번에 처음 알게 됐어요! 혹시나 있을까 해서 봤는데 진짜 있었던 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. ㄹㅇ 갓갓 onPaste |
||
autoFocus={false} | ||
isAlwaysOnLabel | ||
isAlwaysOnInputBorder | ||
/> | ||
{isBottomSheetOpen && ( | ||
<BankSelectModal | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {ERROR_MESSAGE} from '@constants/errorMessage'; | ||
import REGEXP from '@constants/regExp'; | ||
import RULE from '@constants/rule'; | ||
|
||
import {ValidateResult} from './type'; | ||
|
||
const validateAccountNumber = (accountNumber: string): ValidateResult => { | ||
const isValidateType = () => { | ||
return REGEXP.accountNumber.test(accountNumber); | ||
}; | ||
|
||
const isValidateLength = () => { | ||
return accountNumber.length >= RULE.minAccountNumberLength && accountNumber.length <= RULE.maxAccountNumberLength; | ||
}; | ||
|
||
if (isValidateType() && isValidateLength()) { | ||
return {isValid: true, errorMessage: null}; | ||
} | ||
|
||
return {isValid: false, errorMessage: ERROR_MESSAGE.invalidAccountNumber}; | ||
}; | ||
|
||
export default validateAccountNumber; |
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.
로 사용하면 연속된 -나 공백을 걸러줄 수 있어요~
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.
토다리는 정(규표현식의)신