Skip to content

Commit 77aec7b

Browse files
authored
Merge pull request #105 from oodd-team/feat/OD-149
[OD-149] 회원가입 페이지 & 이용약관 동의 페이지 변수 명명 규칙 점검 및 코드 순서 정리
2 parents 34c1fd7 + a572ad4 commit 77aec7b

6 files changed

Lines changed: 79 additions & 63 deletions

File tree

src/apis/user/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { newRequest } from '../core';
33
import { EmptySuccessResponse } from '../core/dto';
44

55
// 유저 정보 수정 api
6-
export const patchUserInfoApi = (data: PatchUserInfoRequest, userId: number) =>
6+
export const patchUserInfoApi = (data: Partial<PatchUserInfoRequest>, userId: number) =>
77
newRequest.patch<PatchUserInfoResponse>(`/user/${userId}`, data);
88

99
// 유저 탈퇴 api

src/components/TopBar/styles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const TopbarLayout = styled.header<TopbarLayoutProps>`
66
display: flex;
77
position: sticky;
88
top: 0; /* 부모 요소의 상단에 붙도록 설정 */
9-
z-index: 1;
9+
z-index: 99;
1010
background-color: white;
1111
width: 100%; /* 부모 너비에 맞춤 */
1212
align-items: center;

src/pages/SignUp/index.tsx

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
import React, { useState } from 'react';
22
import { useNavigate } from 'react-router-dom';
33

4-
import { OODDFrame } from '../../components/Frame/Frame';
5-
import BottomButton from '../../components/BottomButton';
6-
import Modal from '../../components/Modal';
4+
import { patchUserInfoApi } from '@/apis/user';
5+
import type { PatchUserInfoRequest } from '@/apis/user/dto';
6+
import { handleError } from '@/apis/util/handleError';
77

8-
import { StyledText } from '../../components/Text/StyledText';
9-
import { SignUpContainer, LogoWrapper, IntroWrapper, NickNameContainer, NickName, TapStyled, LogoImg } from './style';
8+
import OODDlogo from '@/assets/default/oodd.svg';
109

11-
import OODDlogo from '../../assets/default/oodd.svg';
10+
import { OODDFrame } from '@/components/Frame/Frame';
11+
import { StyledText } from '@/components/Text/StyledText';
12+
import BottomButton from '@/components/BottomButton';
13+
import Modal from '@/components/Modal';
1214

13-
import { patchUserInfoApi } from '../../apis/user';
14-
import { handleError } from '../../apis/util/handleError';
15-
import { PatchUserInfoRequest } from '../../apis/user/dto';
15+
import { getCurrentUserId } from '@/utils/getCurrentUserId';
16+
17+
import {
18+
SignUpLayout,
19+
LogoWrapper,
20+
SignupStepContainer,
21+
InputContainer,
22+
InputValue,
23+
TapToEdit,
24+
LogoImg,
25+
} from './style';
1626

1727
type PartialUserInfoRequest = Pick<PatchUserInfoRequest, 'name' | 'birthDate' | 'phoneNumber' | 'nickname'>;
1828

1929
const SignUp: React.FC = () => {
20-
const navigate = useNavigate();
21-
22-
const my_id = Number(localStorage.getItem('my_id'));
23-
const token = localStorage.getItem('new_jwt_token');
24-
2530
const [isModalOpen, setIsModalOpen] = useState(false);
2631
const [modalMessage, setModalMessage] = useState('');
2732
const [modalType, setModalType] = useState('');
2833

2934
const [currentStep, setCurrentStep] = useState(1);
3035
const [formData, setFormData] = useState<PartialUserInfoRequest>({
31-
// 이름, 생년월일 등 개별적으로 상태 관리하지 않고 통합
3236
name: '',
3337
birthDate: '',
3438
phoneNumber: '',
3539
nickname: '', //초기 값
3640
});
3741

42+
const navigate = useNavigate();
43+
44+
const currentUserId = getCurrentUserId();
45+
const token = localStorage.getItem('new_jwt_token');
46+
3847
const handleInputChange = (field: keyof PatchUserInfoRequest) => (e: React.ChangeEvent<HTMLInputElement>) => {
3948
setFormData((prevData) => ({ ...prevData, [field]: e.target.value }));
4049
};
@@ -106,19 +115,20 @@ const SignUp: React.FC = () => {
106115

107116
if (currentStep < steps.length) {
108117
setCurrentStep(currentStep + 1);
109-
} else if (my_id && token) {
118+
} else if (currentUserId && token) {
110119
const requestData: PartialUserInfoRequest = {
111120
name: formData.name,
112121
nickname: formData.nickname,
113122
birthDate: formData.birthDate,
114123
phoneNumber: formData.phoneNumber,
115124
};
116-
await patchUserInfo(requestData, my_id);
125+
await patchUserInfo(requestData, currentUserId);
117126
}
118127
};
119-
const patchUserInfo = async (requestData: any, my_id: number) => {
128+
129+
const patchUserInfo = async (requestData: PartialUserInfoRequest, currentUserId: number) => {
120130
try {
121-
const response = await patchUserInfoApi(requestData, my_id);
131+
const response = await patchUserInfoApi(requestData, currentUserId);
122132
console.log('수정 성공:', response.data);
123133
setModalMessage('회원가입에 성공했습니다!');
124134
setIsModalOpen(true);
@@ -135,11 +145,12 @@ const SignUp: React.FC = () => {
135145
const handleModalClose = () => {
136146
setIsModalOpen(false);
137147
if (modalType === 'success') {
138-
navigate('/terms-agreement'); // 회원가입 정보 입력 되면, 이용약관 동의 페이지로
148+
navigate('/signup/terms-agreement'); // 회원가입 정보 입력 되면, 이용약관 동의 페이지로
139149
} else if (modalType === 'fail') {
140150
navigate('/login');
141151
}
142152
};
153+
143154
const handleKeyDown = (event: React.KeyboardEvent) => {
144155
if (event.key === 'Enter') {
145156
handleNextClick();
@@ -148,36 +159,36 @@ const SignUp: React.FC = () => {
148159

149160
return (
150161
<OODDFrame>
151-
<SignUpContainer>
162+
<SignUpLayout>
152163
<LogoWrapper>
153164
<LogoImg src={OODDlogo} />
154165
</LogoWrapper>
155-
<IntroWrapper>
166+
<SignupStepContainer>
156167
<StyledText $textTheme={{ style: { mobile: 'title3-bold', tablet: 'title2-bold', desktop: 'title1-bold' } }}>
157168
{label}
158169
</StyledText>
159-
<NickNameContainer>
160-
<NickName
170+
<InputContainer>
171+
<InputValue
161172
type={type}
162173
value={value}
163174
onChange={onChange}
164175
placeholder={placeholder}
165176
onKeyDown={handleKeyDown}
166177
/>
167178
{value === '' && (
168-
<TapStyled
179+
<TapToEdit
169180
$textTheme={{
170181
style: { mobile: 'body1-regular', tablet: 'heading1-medium', desktop: 'heading1-medium' },
171182
}}
172183
>
173184
탭하여 수정해 주세요!
174-
</TapStyled>
185+
</TapToEdit>
175186
)}
176-
</NickNameContainer>
177-
</IntroWrapper>
187+
</InputContainer>
188+
</SignupStepContainer>
178189
<BottomButton content={currentStep < steps.length ? '다음' : '완료'} onClick={handleNextClick} />
179190
{isModalOpen && <Modal content={modalMessage} onClose={handleModalClose} />}
180-
</SignUpContainer>
191+
</SignUpLayout>
181192
</OODDFrame>
182193
);
183194
};

src/pages/SignUp/style.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components';
2-
import { StyledText } from '../../components/Text/StyledText';
2+
import { StyledText } from '@/components/Text/StyledText';
33

4-
export const SignUpContainer = styled.main`
4+
export const SignUpLayout = styled.main`
55
display: flex;
66
flex-direction: column;
77
align-items: center;
@@ -35,7 +35,7 @@ export const LogoImg = styled.img`
3535
width: 100%;
3636
`;
3737

38-
export const IntroWrapper = styled.div`
38+
export const SignupStepContainer = styled.div`
3939
display: flex;
4040
flex-direction: column;
4141
max-width: 21.875rem;
@@ -44,7 +44,7 @@ export const IntroWrapper = styled.div`
4444
text-align: center;
4545
`;
4646

47-
export const NickNameContainer = styled.section`
47+
export const InputContainer = styled.section`
4848
display: flex;
4949
flex-direction: column;
5050
align-items: center;
@@ -53,7 +53,7 @@ export const NickNameContainer = styled.section`
5353
margin: 5rem auto 0; /* 중앙 정렬을 위한 auto */
5454
`;
5555

56-
export const NickName = styled.input`
56+
export const InputValue = styled.input`
5757
width: 100%;
5858
max-width: 300px;
5959
height: 3.25rem;
@@ -68,7 +68,7 @@ export const NickName = styled.input`
6868
margin: 0 auto; /* 중앙 정렬 */
6969
`;
7070

71-
export const TapStyled = styled(StyledText)`
71+
export const TapToEdit = styled(StyledText)`
7272
width: 100%;
7373
height: 1.3125rem;
7474
margin: 1.25rem auto 0; /* 중앙 정렬을 위한 auto */

src/pages/TermsAgreement/index.tsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import React, { useState } from 'react';
22
import { useNavigate } from 'react-router-dom';
33

4-
import { OODDFrame } from '../../components/Frame/Frame';
5-
import BottomButton from '../../components/BottomButton';
6-
import TopBar from '../../components/TopBar';
7-
import Modal from '../../components/Modal';
4+
import { postTermsAgreementApi } from '@/apis/user';
5+
import { handleError } from '@/apis/util/handleError';
86

9-
import { LogoWrapper, LogoImg } from '../SignUp/style';
10-
import { TermsAgreementContainer, StyledTitle, CheckboxWrapper, CheckboxItem, CheckboxInput, Divider } from './styles';
11-
import { StyledText } from '../../components/Text/StyledText';
7+
import Back from '@/assets/arrow/left.svg';
8+
import OODDlogo from '@/assets/default/oodd.svg';
129

13-
import Back from '../../assets/arrow/left.svg';
14-
import OODDlogo from '../../assets/default/oodd.svg';
10+
import { OODDFrame } from '@/components/Frame/Frame';
11+
import { StyledText } from '@/components/Text/StyledText';
12+
import BottomButton from '@/components/BottomButton';
13+
import TopBar from '@/components/TopBar';
14+
import Modal from '@/components/Modal';
1515

16-
import { postTermsAgreementApi } from '../../apis/user';
17-
import { handleError } from '../../apis/util/handleError';
16+
import { getCurrentUserId } from '@/utils/getCurrentUserId';
1817

19-
const TermsAgreement: React.FC = () => {
20-
const my_id = Number(localStorage.getItem('my_id'));
21-
const navigate = useNavigate();
18+
import { LogoWrapper, LogoImg } from '@/pages/SignUp/style';
2219

20+
import { TermsAgreementLayout, StyledTitle, CheckboxList, CheckboxItem, CheckboxInput, Divider } from './styles';
21+
22+
const TermsAgreement: React.FC = () => {
2323
const [isModalOpen, setIsModalOpen] = useState(false);
2424
const [modalMessage, setModalMessage] = useState('');
2525

26+
const navigate = useNavigate();
27+
const currentUserId = getCurrentUserId();
28+
2629
const [agreements, setAgreements] = useState({
2730
all: false,
2831
terms: false,
@@ -55,15 +58,16 @@ const TermsAgreement: React.FC = () => {
5558
});
5659
};
5760

58-
const handleFinalClick = async () => {
59-
if (!my_id) {
61+
// 완료 버튼을 눌렀을 때 실행되는 함수
62+
const handleCompletedClick = async () => {
63+
if (!currentUserId) {
6064
setModalMessage('회원 정보가 없습니다.\n로그인 해 주세요!');
6165
setIsModalOpen(true);
6266
return;
6367
}
6468

6569
try {
66-
const response = await postTermsAgreementApi(my_id);
70+
const response = await postTermsAgreementApi(currentUserId);
6771
console.log(response);
6872
navigate('/'); // 성공 시 홈으로 이동
6973
} catch (error) {
@@ -73,14 +77,15 @@ const TermsAgreement: React.FC = () => {
7377
setIsModalOpen(true);
7478
}
7579
};
80+
7681
const navigateToLogin = () => {
7782
navigate('/login');
7883
};
7984

8085
return (
8186
<OODDFrame>
8287
<TopBar LeftButtonSrc={Back} onLeftClick={navigateToLogin} />
83-
<TermsAgreementContainer>
88+
<TermsAgreementLayout>
8489
<LogoWrapper>
8590
<LogoImg src={OODDlogo} />
8691
</LogoWrapper>
@@ -91,7 +96,7 @@ const TermsAgreement: React.FC = () => {
9196
>
9297
OODD에 오신 것을 환영해요 🥳
9398
</StyledTitle>
94-
<CheckboxWrapper>
99+
<CheckboxList>
95100
<CheckboxItem>
96101
<CheckboxInput
97102
type="checkbox"
@@ -103,7 +108,7 @@ const TermsAgreement: React.FC = () => {
103108
<StyledText $textTheme={{ style: 'body1-medium' }}>약관 전체 동의</StyledText>
104109
</label>
105110
</CheckboxItem>
106-
111+
{/*전체 동의와 개별 동의 구분*/}
107112
<Divider />
108113
{checkboxData.map(({ key, label }) => (
109114
<CheckboxItem key={key}>
@@ -118,14 +123,14 @@ const TermsAgreement: React.FC = () => {
118123
</label>
119124
</CheckboxItem>
120125
))}
121-
</CheckboxWrapper>
126+
</CheckboxList>
122127
<BottomButton
123128
content="OODD 시작하기"
124-
onClick={handleFinalClick}
129+
onClick={handleCompletedClick}
125130
disabled={!agreements.terms || !agreements.privacy}
126131
/>
127132
{isModalOpen && <Modal content={modalMessage} onClose={navigateToLogin} />}
128-
</TermsAgreementContainer>
133+
</TermsAgreementLayout>
129134
</OODDFrame>
130135
);
131136
};

src/pages/TermsAgreement/styles.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components';
2-
import { StyledText } from '../../components/Text/StyledText';
2+
import { StyledText } from '@/components/Text/StyledText';
33

4-
export const TermsAgreementContainer = styled.main`
4+
export const TermsAgreementLayout = styled.main`
55
display: flex;
66
flex-direction: column;
77
padding: 1.875rem;
@@ -13,7 +13,7 @@ export const BackButton = styled.img`
1313
cursor: pointer;
1414
`;
1515

16-
export const CheckboxWrapper = styled.div`
16+
export const CheckboxList = styled.div`
1717
margin-top: 1.25rem;
1818
`;
1919

0 commit comments

Comments
 (0)