Skip to content

Commit d6ecaf3

Browse files
committed
feat: 회원 가입 폼에서 버튼 로딩 0.1 초 이하면 로딩 컴포넌트 보여주지 않도록 수정
1 parent a5cc5d5 commit d6ecaf3

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

src/pages/signup/components/AuthCodeInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface AuthCodeInputProps {
2222
}
2323
function AuthCodeInput({ emailSent, email, setValidation }: AuthCodeInputProps) {
2424
const [isLoading, setIsLoading] = useState(false);
25+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
2526

2627
const [authCode, setAuthCode] = useState(''); // 인증코드
2728
const [resendCount, setResendCount] = useState(0); // 재전송 횟수
@@ -45,7 +46,18 @@ function AuthCodeInput({ emailSent, email, setValidation }: AuthCodeInputProps)
4546
const handleEmailVerificationCheck = async () => {
4647
try {
4748
setIsLoading(true);
49+
50+
// 0.1초 뒤에 showLoading 활성화
51+
const loadingTimeout = setTimeout(() => {
52+
setShowLoading(true);
53+
}, 100);
54+
4855
const { code } = await postEmailVerificationCheck(email, authCode);
56+
57+
clearTimeout(loadingTimeout); // 불필요한 타이머 제거
58+
setIsLoading(false);
59+
setShowLoading(false); // 로딩 UI 숨기기
60+
4961
if (code === 200) {
5062
setMessage({ type: 'success', message: '이메일 인증이 완료되었습니다' });
5163
setButtonVariant('disabled');
@@ -86,7 +98,7 @@ function AuthCodeInput({ emailSent, email, setValidation }: AuthCodeInputProps)
8698
};
8799

88100
const renderButtonContent = () => {
89-
if (isLoading) {
101+
if (showLoading) {
90102
return <SpinLoading />;
91103
} else return <span>인증확인</span>;
92104
};
@@ -107,6 +119,7 @@ function AuthCodeInput({ emailSent, email, setValidation }: AuthCodeInputProps)
107119
onTimeout={onTimeout}
108120
onResendEmail={handlePostEmailVerificationRequest} // 재전송 요청
109121
resendCount={resendCount}
122+
disabled={isLoading ? true : false}
110123
/>
111124
);
112125
}

src/pages/signup/components/EmailInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface EmailInputProps {
1919

2020
function EmailInput({ value, setValue, validation, setValidation, onSendEmail }: EmailInputProps) {
2121
const [isLoading, setIsLoading] = useState(false);
22+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
2223
// 버튼 상태를 관리하는 state 추가
2324
const [buttonVariant, setButtonVariant] = useState<'primary' | 'secondary' | 'disabled'>(
2425
'primary',
@@ -47,7 +48,18 @@ function EmailInput({ value, setValue, validation, setValidation, onSendEmail }:
4748
const handleEmailCheck = async () => {
4849
try {
4950
setIsLoading(true);
51+
52+
// 0.1초 뒤에 showLoading 활성화
53+
const loadingTimeout = setTimeout(() => {
54+
setShowLoading(true);
55+
}, 100);
56+
5057
const { code } = await getEmailAvailability(value);
58+
59+
clearTimeout(loadingTimeout); // 불필요한 타이머 제거
60+
setIsLoading(false);
61+
setShowLoading(false); // 로딩 UI 숨기기
62+
5163
if (code === 200) {
5264
handlePostEmailVerificationRequest(); // 사용 가능한 이메일 경우에만 이메일 인증 요청 보내기
5365
} else if (code === 409) {
@@ -83,7 +95,7 @@ function EmailInput({ value, setValue, validation, setValidation, onSendEmail }:
8395
};
8496

8597
const renderButtonContent = () => {
86-
if (isLoading) {
98+
if (showLoading) {
8799
return <SpinLoading />;
88100
} else return <span>인증요청</span>;
89101
};
@@ -111,6 +123,7 @@ function EmailInput({ value, setValue, validation, setValidation, onSendEmail }:
111123
onChange={handleChange}
112124
validationMessages={validation}
113125
onClick={handleEmailCheck}
126+
disabled={isLoading ? true : false}
114127
/>
115128
);
116129
}

src/pages/signup/components/IdInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface IdInputProps {
1919

2020
function IdInput({ value, setValue, validation, setValidation }: IdInputProps) {
2121
const [isLoading, setIsLoading] = useState(false);
22+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
2223

2324
const [buttonVariant, setButtonVariant] = useState<ButtonType>('disabled'); // 버튼 상태를 관리하는 state 추가
2425
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -51,7 +52,18 @@ function IdInput({ value, setValue, validation, setValidation }: IdInputProps) {
5152
const handleIdCheck = async () => {
5253
try {
5354
setIsLoading(true);
55+
56+
// 0.1초 뒤에 showLoading 활성화
57+
const loadingTimeout = setTimeout(() => {
58+
setShowLoading(true);
59+
}, 100);
60+
5461
const { code } = await getIdAvailability(value);
62+
63+
clearTimeout(loadingTimeout); // 불필요한 타이머 제거
64+
setIsLoading(false);
65+
setShowLoading(false); // 로딩 UI 숨기기
66+
5567
if (code === 200) {
5668
setValidation({ type: 'success', message: '사용 가능한 아이디입니다' });
5769
} else if (code === 409) {
@@ -65,7 +77,7 @@ function IdInput({ value, setValue, validation, setValidation }: IdInputProps) {
6577
};
6678

6779
const renderButtonContent = () => {
68-
if (isLoading) {
80+
if (showLoading) {
6981
return <SpinLoading />;
7082
} else return <span>중복확인</span>;
7183
};
@@ -82,6 +94,7 @@ function IdInput({ value, setValue, validation, setValidation }: IdInputProps) {
8294
onChange={handleChange}
8395
validationMessages={validation}
8496
onClick={handleIdCheck}
97+
disabled={isLoading ? true : false}
8598
/>
8699
);
87100
}

src/pages/signup/components/NicknameInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface NicknameInputProps {
1818

1919
function NicknameInput({ value, setValue, validation, setValidation }: NicknameInputProps) {
2020
const [isLoading, setIsLoading] = useState(false);
21+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
2122

2223
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
2324
const newValue = e.target.value;
@@ -50,7 +51,18 @@ function NicknameInput({ value, setValue, validation, setValidation }: NicknameI
5051
const handleNicknameCheck = async () => {
5152
try {
5253
setIsLoading(true);
54+
55+
// 0.1초 뒤에 showLoading 활성화
56+
const loadingTimeout = setTimeout(() => {
57+
setShowLoading(true);
58+
}, 100);
59+
5360
const { code } = await getNicknameAvailability(value);
61+
62+
clearTimeout(loadingTimeout); // 불필요한 타이머 제거
63+
setIsLoading(false);
64+
setShowLoading(false); // 로딩 UI 숨기기
65+
5466
if (code === 200) {
5567
setValidation({ type: 'success', message: '사용 가능한 닉네임입니다' });
5668
} else if (code === 409) {
@@ -64,7 +76,7 @@ function NicknameInput({ value, setValue, validation, setValidation }: NicknameI
6476
};
6577

6678
const renderButtonContent = () => {
67-
if (isLoading) {
79+
if (showLoading) {
6880
return <SpinLoading />;
6981
} else return <span>중복확인</span>;
7082
};
@@ -81,6 +93,7 @@ function NicknameInput({ value, setValue, validation, setValidation }: NicknameI
8193
onChange={handleChange}
8294
validationMessages={validation}
8395
onClick={handleNicknameCheck}
96+
disabled={isLoading ? true : false}
8497
/>
8598
);
8699
}

0 commit comments

Comments
 (0)