Skip to content

Commit ecf916f

Browse files
authored
Merge pull request #23 from YAPP-Github/refactor/YS-176
[YS-176] 회원가입 로직 리팩토링 (연구자)
2 parents dee2e72 + 7c8985d commit ecf916f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+858
-712
lines changed

src/apis/login.ts

+15
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,27 @@ export interface ResearcherResponse {
4949
univName: string;
5050
}
5151

52+
export interface NaverLoginParams {
53+
code: string;
54+
role: string;
55+
state: string;
56+
}
57+
5258
export const googleLogin = async (code: string, role: string) => {
5359
const res = await API.post<LoginResponse>(API_URL.google(role), { authorizationCode: code });
5460

5561
return res.data;
5662
};
5763

64+
export const naverLogin = async ({ code, role, state }: NaverLoginParams) => {
65+
const res = await API.post<LoginResponse>(API_URL.naver(role), {
66+
authorizationCode: code,
67+
state,
68+
});
69+
70+
return res.data;
71+
};
72+
5873
export const sendUnivAuthCode = async (univEmail: string) => {
5974
const res = await API.post<UnivAuthCodeResponse>(API_URL.send, { univEmail });
6075

src/apis/post.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { Area } from '@/app/home/home.types';
44
import { API_URL } from '@/constants/url';
55
import { Post } from '@/types/post';
66

7-
type PostResponse = Post[];
7+
interface PostResponse {
8+
content: Post[];
9+
isLast: boolean;
10+
page: number;
11+
size: number;
12+
totalCount: number;
13+
}
814

915
export type AreaResponse = PostAreaResponse | PostSubAreaResponse;
1016

@@ -24,7 +30,7 @@ interface PostArea {
2430
}
2531

2632
export interface PostListParams {
27-
recruitDone: boolean;
33+
recruitStatus: 'ALL' | 'OPEN';
2834
matchType?: 'ONLINE' | 'OFFLINE' | 'ALL';
2935
gender?: '' | 'MALE' | 'FEMALE' | 'ALL';
3036
age?: number;
@@ -34,7 +40,7 @@ export interface PostListParams {
3440
count?: number;
3541
}
3642

37-
export const fetchPostList = async (params: PostListParams) => {
43+
export const fetchPostList = async (params: PostListParams = { recruitStatus: 'ALL' }) => {
3844
const queryParams = new URLSearchParams();
3945

4046
Object.entries(params).forEach(([key, value]) => {

src/app/home/components/PostCard/PostCard.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from './PostCard.styles';
1717

1818
import Icon from '@/components/Icon';
19-
import theme from '@/styles/theme';
2019
import { Post } from '@/types/post';
2120

2221
interface PostCardProps {
@@ -30,9 +29,6 @@ const PostCard = ({ post }: PostCardProps) => {
3029
href={`/post/${post.postInfo.experimentPostId}`}
3130
key={post.postInfo.experimentPostId}
3231
css={postCardLayout}
33-
style={{
34-
backgroundColor: post.recruitDone ? theme.colors.field01 : theme.colors.field01,
35-
}}
3632
>
3733
<div css={postHeader}>
3834
<div css={postCardHeader}>
@@ -45,7 +41,7 @@ const PostCard = ({ post }: PostCardProps) => {
4541
<h3 css={postTitle}>{post.postInfo.title}</h3>
4642
</div>
4743
<div>
48-
{post.recruitDone ? (
44+
{post.recruitStatus ? (
4945
<div css={contactedPostTag}>
5046
<span>모집 완료</span>
5147
</div>

src/app/home/components/PostContainer/PostContainer.tsx

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { useState } from 'react';
4+
45
import usePostListQuery from '../../hooks/usePostListQuery';
56
import PostCardList from '../PostCardList/PostCardList';
67
import FilterContainer from './FilterContainer/FilterContainer';
@@ -11,20 +12,16 @@ import {
1112
postContainerTitle,
1213
totalPostCount,
1314
} from './PostContainer.styles';
14-
import JoinCheckbox from '@/app/join/components/JoinCheckboxContainer/JoinCheckbox/JoinCheckbox';
15+
1516
import { PostListParams } from '@/apis/post';
17+
import JoinCheckbox from '@/app/join/components/JoinEmailStep/JoinCheckboxContainer/JoinCheckbox/JoinCheckbox';
1618

1719
const PostContainer = () => {
1820
const [filters, setFilters] = useState<PostListParams>({
19-
matchType: 'ALL' as 'ALL' | 'ONLINE' | 'OFFLINE',
20-
gender: '' as '' | 'ALL' | 'MALE' | 'FEMALE',
21-
region: '',
22-
areas: '',
23-
age: 20,
24-
recruitDone: false,
21+
recruitStatus: 'ALL',
2522
});
2623

27-
const { data: postList } = usePostListQuery(filters);
24+
const { data } = usePostListQuery(filters);
2825

2926
const handleFilterChange = (key: string, value: string | number | boolean) => {
3027
setFilters((prev) => ({
@@ -33,9 +30,11 @@ const PostContainer = () => {
3330
}));
3431
};
3532

36-
// TODO: 개선 필요.
33+
const isRecruiting = filters.recruitStatus === 'OPEN';
34+
3735
const handleChange = () => {
38-
handleFilterChange('recruitDone', !filters.recruitDone);
36+
const toggleChecked = isRecruiting ? 'ALL' : 'OPEN';
37+
handleFilterChange('recruitStatus', toggleChecked);
3938
};
4039

4140
return (
@@ -45,14 +44,14 @@ const PostContainer = () => {
4544
<FilterContainer handleFilterChange={handleFilterChange} />
4645
<JoinCheckbox
4746
label="모집 중인 공고만 보기"
48-
isChecked={filters.recruitDone}
47+
isChecked={isRecruiting}
4948
onChange={handleChange}
5049
isArrow={false}
5150
/>
5251
</div>
5352
<div css={postCardContainer}>
54-
<span css={totalPostCount}>{postList?.length}</span>
55-
<PostCardList postList={postList} />
53+
<span css={totalPostCount}>{data?.content.length}</span>
54+
<PostCardList postList={data?.content} />
5655
</div>
5756
</div>
5857
);

src/app/home/hooks/usePostListQuery.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { fetchPostList, PostListParams } from '@/apis/post';
44
import { QUERY_KEY } from '@/constants/queryKey';
55

66
const usePostListQuery = (params: PostListParams) => {
7-
const { matchType, gender, age, region, areas, recruitDone } = params;
7+
const { matchType, gender, age, region, areas, recruitStatus } = params;
88

99
return useQuery({
10-
queryKey: [QUERY_KEY.post, matchType, gender, age, region, areas, recruitDone],
10+
queryKey: [QUERY_KEY.post, matchType, gender, age, region, areas, recruitStatus],
1111
queryFn: () => fetchPostList(params),
1212
});
1313
};
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { getResearcherInfo } from '@/apis/login';
21
import { useQuery } from '@tanstack/react-query';
32

3+
import { getResearcherInfo } from '@/apis/login';
4+
45
export const useResearcherInfoQuery = () => {
56
const role = sessionStorage.getItem('role');
67
const userRole = role === 'RESEARCHER' ? 'researchers' : 'participants';
78

89
return useQuery({
910
queryKey: ['researcherInfo'],
1011
queryFn: getResearcherInfo,
11-
enabled: !!role,
12+
enabled: !!userRole,
1213
retry: 1,
1314
});
1415
};

src/app/join/JoinEmailStep.tsx

-121
This file was deleted.

src/app/join/JoinInfoStep.tsx

-66
This file was deleted.

0 commit comments

Comments
 (0)