Skip to content

Commit 6798908

Browse files
authored
Merge pull request #185 from prgrms-web-devcourse-final-project/feat/184-signup-button-loading
[feat] 회원 가입 폼에서 버튼 로딩 0.1 초 이하면 로딩 컴포넌트 보여주지 않도록 수정
2 parents c818c16 + 4d34326 commit 6798908

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

dev-dist/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict';
7979
*/
8080
workbox.precacheAndRoute([{
8181
"url": "index.html",
82-
"revision": "0.08jje88gm9"
82+
"revision": "0.mu5kaq0e0jg"
8383
}], {});
8484
workbox.cleanupOutdatedCaches();
8585
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {

src/pages/signup/components/AuthCodeInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface AuthCodeInputProps {
1515
function AuthCodeInput({ email, emailvalidity, validity, setValidity }: AuthCodeInputProps) {
1616
const [resendCount, setResendCount] = useState(0); // 재전송 횟수
1717
// 유효성 검사
18+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
19+
1820
const handleValidation = (value: string) => {
1921
if (value == '') {
2022
return { success: false, message: '인증번호가 오지 않았나요?' };
@@ -63,8 +65,19 @@ function AuthCodeInput({ email, emailvalidity, validity, setValidity }: AuthCode
6365
});
6466
};
6567

66-
const renderButtonContent = () => {
68+
// 0.1초 후 로딩 UI 표시
69+
useEffect(() => {
70+
let loadingTimeout: NodeJS.Timeout;
6771
if (isLoading) {
72+
loadingTimeout = setTimeout(() => setShowLoading(true), 100);
73+
} else {
74+
setShowLoading(false);
75+
}
76+
return () => clearTimeout(loadingTimeout);
77+
}, [isLoading]);
78+
79+
const renderButtonContent = () => {
80+
if (showLoading) {
6881
return <SpinLoading />;
6982
} else return <span>인증확인</span>;
7083
};

src/pages/signup/components/EmailInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SpinLoading from '@/components/loading/SpinLoading';
33
import { EMAIL_REGEX } from '@/constants';
44
import { useEmailCheck } from '@/hooks/useEmailCheck';
55
import { useValidationWithButton } from '@/hooks/useValidationWithButton';
6+
import { useEffect, useState } from 'react';
67

78
interface EmailInputProps {
89
setValue: (val: string) => void;
@@ -12,6 +13,7 @@ interface EmailInputProps {
1213
}
1314

1415
function EmailInput({ setValue, validity, setValidity, authcodeValidity }: EmailInputProps) {
16+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
1517
// 유효성 검사
1618
const handleValidation = (value: string) => {
1719
if (!EMAIL_REGEX.test(value)) {
@@ -44,8 +46,19 @@ function EmailInput({ setValue, validity, setValidity, authcodeValidity }: Email
4446
setButtonVariant,
4547
);
4648

47-
const renderButtonContent = () => {
49+
// 0.1초 후 로딩 UI 표시
50+
useEffect(() => {
51+
let loadingTimeout: NodeJS.Timeout;
4852
if (isChecking) {
53+
loadingTimeout = setTimeout(() => setShowLoading(true), 100);
54+
} else {
55+
setShowLoading(false);
56+
}
57+
return () => clearTimeout(loadingTimeout);
58+
}, [isChecking]);
59+
60+
const renderButtonContent = () => {
61+
if (showLoading) {
4962
return <SpinLoading />;
5063
} else return <span>인증요청</span>;
5164
};

src/pages/signup/components/IdInput.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SpinLoading from '@/components/loading/SpinLoading';
33
import { ID_REGEX } from '@/constants';
44
import { useIdAvailability } from '@/hooks/useIdAvailability';
55
import { useValidationWithButton } from '@/hooks/useValidationWithButton';
6+
import { useEffect, useState } from 'react';
67

78
interface IdInputProps {
89
setValue: (val: string) => void;
@@ -11,6 +12,8 @@ interface IdInputProps {
1112
}
1213

1314
function IdInput({ setValue, validity, setValidity }: IdInputProps) {
15+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
16+
1417
// 유효성 검사
1518
const handleValidation = (value: string) => {
1619
if (!ID_REGEX.test(value)) {
@@ -34,8 +37,19 @@ function IdInput({ setValue, validity, setValidity }: IdInputProps) {
3437
setValidationMessage,
3538
);
3639

37-
const renderButtonContent = () => {
40+
// 0.1초 후 로딩 UI 표시
41+
useEffect(() => {
42+
let loadingTimeout: NodeJS.Timeout;
3843
if (isPending) {
44+
loadingTimeout = setTimeout(() => setShowLoading(true), 100);
45+
} else {
46+
setShowLoading(false);
47+
}
48+
return () => clearTimeout(loadingTimeout);
49+
}, [isPending]);
50+
51+
const renderButtonContent = () => {
52+
if (showLoading) {
3953
return <SpinLoading />;
4054
} else return <span>중복확인</span>;
4155
};

src/pages/signup/components/NicknameInput.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SpinLoading from '@/components/loading/SpinLoading';
33
import { MAX_NICKNAME_LENGTH, MIN_NICKNAME_LENGTH, NICKNAME_REGEX } from '@/constants';
44
import { useNicknameAvailability } from '@/hooks/useNicknameAvailability';
55
import { useValidationWithButton } from '@/hooks/useValidationWithButton';
6+
import { useEffect, useState } from 'react';
67

78
interface NicknameInputProps {
89
initialValue?: string; // 초기값
@@ -12,6 +13,7 @@ interface NicknameInputProps {
1213
}
1314

1415
function NicknameInput({ initialValue, setValue, validity, setValidity }: NicknameInputProps) {
16+
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
1517
// 유효성 검사
1618
const handleValidation = (value: string) => {
1719
if (value.length < MIN_NICKNAME_LENGTH || value.length > MAX_NICKNAME_LENGTH) {
@@ -43,8 +45,19 @@ function NicknameInput({ initialValue, setValue, validity, setValidity }: Nickna
4345
setValidationMessage,
4446
);
4547

46-
const renderButtonContent = () => {
48+
// 0.1초 후 로딩 UI 표시
49+
useEffect(() => {
50+
let loadingTimeout: NodeJS.Timeout;
4751
if (isPending) {
52+
loadingTimeout = setTimeout(() => setShowLoading(true), 100);
53+
} else {
54+
setShowLoading(false);
55+
}
56+
return () => clearTimeout(loadingTimeout);
57+
}, [isPending]);
58+
59+
const renderButtonContent = () => {
60+
if (showLoading) {
4861
return <SpinLoading />;
4962
} else return <span>중복확인</span>;
5063
};

0 commit comments

Comments
 (0)