Skip to content

Commit 0b66882

Browse files
committed
refact: 이벤트 데이터 공통 필드 추출 함수 추가
1 parent 1d8691c commit 0b66882

File tree

7 files changed

+66
-108
lines changed

7 files changed

+66
-108
lines changed

src/entities/event/model/event.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
1-
export type OnlineType = 'ONLINE' | 'OFFLINE';
2-
export type CategoryType = 'DEVELOPMENT_STUDY' | 'NETWORKING' | 'HACKATHON' | 'CONFERENCE';
1+
import { BaseEvent } from '../../../shared/types/baseEventType';
32

43
export interface EventDetailRequest {
54
eventId: number;
65
}
76

87
export interface EventDetailResponse {
9-
result: {
8+
result: BaseEvent & {
109
id: number;
11-
bannerImageUrl: string;
12-
title: string;
1310
participantCount: number;
14-
startDate: string;
15-
endDate: string;
16-
startTime: string;
17-
endTime: string;
18-
address: string;
19-
location: {
20-
lat: number;
21-
lng: number;
22-
};
23-
description: string;
2411
hostChannelName: string;
2512
hostChannelDescription: string;
26-
organizerEmail: string;
27-
organizerPhoneNumber: string;
28-
referenceLinks: {
29-
title: string;
30-
url: string;
31-
}[];
32-
category: CategoryType;
33-
onlineType: OnlineType;
3413
status: string;
35-
hashtags: string[];
3614
};
3715
}
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
1-
export type OnlineType = 'ONLINE' | 'OFFLINE';
2-
export type CategoryType = 'DEVELOPMENT_STUDY' | 'NETWORKING' | 'HACKATHON' | 'CONFERENCE';
1+
import { BaseEvent } from '../../../shared/types/baseEventType';
32

4-
export interface UpdateEventRequest {
3+
export interface UpdateEventRequest extends BaseEvent {
54
hostChannelId: number;
6-
bannerImageUrl: string;
7-
title: string;
8-
participantCount: number;
9-
startDate: string;
10-
endDate: string;
11-
startTime: string;
12-
endTime: string;
13-
address: string;
14-
location: {
15-
lat: number;
16-
lng: number;
17-
};
18-
description: string;
19-
hostChannelName: string;
20-
hostChannelDescription: string;
21-
organizerEmail: string;
22-
organizerPhoneNumber: string;
23-
referenceLinks: {
24-
title: string;
25-
url: string;
26-
}[];
27-
category: CategoryType;
28-
onlineType: OnlineType;
29-
status: string;
30-
hashtags: string[];
315
}
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
export interface CreateEventRequest {
1+
import { BaseEvent } from '../../../../shared/types/baseEventType';
2+
3+
export interface CreateEventRequest extends BaseEvent {
24
hostChannelId: number;
3-
title: string;
4-
startDate: string;
5-
endDate: string;
6-
startTime: string;
7-
endTime: string;
8-
bannerImageUrl: string;
9-
description: string;
10-
referenceLinks: { address: string; detailAddress: string; title: string; url: string }[];
11-
onlineType: 'ONLINE' | 'OFFLINE';
12-
address: string;
13-
location: { lat: number; lng: number };
14-
category: string;
15-
hashtags: string[];
16-
organizerEmail: string;
17-
organizerPhoneNumber: string;
185
}

src/pages/dashboard/ui/EventDetailPage.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TextEditor from '../../../features/event-manage/event-create/ui/TextEdito
77
import DashboardLayout from '../../../shared/ui/backgrounds/DashboardLayout';
88
import useEventDetail from '../../../entities/event/hook/useEventHook';
99
import { useUpdateEventHook } from '../../../features/dashboard/hook/useEventHook';
10+
import { formatEventRequest } from '../../../shared/lib/formatEventRequest';
1011

1112
const EventDetailPage = () => {
1213
const navigate = useNavigate();
@@ -27,30 +28,16 @@ const EventDetailPage = () => {
2728

2829
const handleSave = () => {
2930
if (!data?.result.id) return;
30-
const existing = data.result;
31+
32+
const formatData = formatEventRequest(data.result);
3133

3234
mutate(
3335
{
34-
title: existing.title,
35-
organizerEmail: existing.organizerEmail,
36-
organizerPhoneNumber: existing.organizerPhoneNumber,
37-
onlineType: existing.onlineType,
38-
address: existing.address,
36+
...formatData,
37+
bannerImageUrl,
38+
description,
39+
referenceLinks,
3940
hostChannelId: 1,
40-
bannerImageUrl: bannerImageUrl || existing.bannerImageUrl,
41-
startDate: existing.startDate,
42-
endDate: existing.endDate,
43-
startTime: existing.startTime,
44-
endTime: existing.endTime,
45-
location: existing.location,
46-
description: description || existing.description,
47-
referenceLinks: referenceLinks || existing.referenceLinks,
48-
category: existing.category,
49-
hashtags: existing.hashtags,
50-
status: existing.status,
51-
hostChannelName: existing.hostChannelName,
52-
hostChannelDescription: existing.hostChannelDescription,
53-
participantCount: existing.participantCount,
5441
},
5542
{
5643
onSuccess: () => {

src/pages/dashboard/ui/EventInfoPage.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { useNavigate } from 'react-router-dom';
88
import Button from '../../../../design-system/ui/Button';
99
import useEventDetail from '../../../entities/event/hook/useEventHook';
1010
import { useUpdateEventHook } from '../../../features/dashboard/hook/useEventHook';
11-
import { OnlineType } from '../../../features/dashboard/model/event';
11+
import { formatEventRequest } from '../../../shared/lib/formatEventRequest';
12+
import { OnlineType } from '../../../shared/types/baseEventType';
1213

1314
const EventInfoPage = () => {
1415
const navigate = useNavigate();
@@ -29,30 +30,17 @@ const EventInfoPage = () => {
2930

3031
const handleSave = () => {
3132
if (!data?.result.id) return;
32-
const existing = data.result;
33+
34+
const formatData = formatEventRequest(data.result);
3335

3436
mutate(
3537
{
38+
...formatData,
3639
title,
37-
organizerEmail: email || existing.organizerEmail,
38-
organizerPhoneNumber: phone || existing.organizerPhoneNumber,
40+
organizerEmail: email,
41+
organizerPhoneNumber: phone,
3942
onlineType: selectedOption as OnlineType,
40-
address: address || existing.address,
41-
hostChannelId: 1,
42-
bannerImageUrl: existing.bannerImageUrl,
43-
startDate: existing.startDate,
44-
endDate: existing.endDate,
45-
startTime: existing.startTime,
46-
endTime: existing.endTime,
47-
location: existing.location,
48-
description: existing.description,
49-
referenceLinks: existing.referenceLinks,
50-
category: existing.category,
51-
hashtags: existing.hashtags,
52-
status: existing.status,
53-
hostChannelName: existing.hostChannelName,
54-
hostChannelDescription: existing.hostChannelDescription,
55-
participantCount: existing.participantCount,
43+
address,
5644
},
5745
{
5846
onSuccess: () => {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BaseEvent } from '../types/baseEventType';
2+
3+
export const formatEventRequest = (data: any): BaseEvent => ({
4+
title: data.title,
5+
startDate: data.startDate,
6+
endDate: data.endDate,
7+
startTime: data.startTime,
8+
endTime: data.endTime,
9+
bannerImageUrl: data.bannerImageUrl,
10+
description: data.description,
11+
referenceLinks: data.referenceLinks,
12+
onlineType: data.onlineType,
13+
address: data.address,
14+
location: data.location,
15+
category: data.category,
16+
hashtags: data.hashtags,
17+
organizerEmail: data.organizerEmail,
18+
organizerPhoneNumber: data.organizerPhoneNumber,
19+
});

src/shared/types/baseEventType.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type OnlineType = 'ONLINE' | 'OFFLINE';
2+
export type CategoryType = 'DEVELOPMENT_STUDY' | 'NETWORKING' | 'HACKATHON' | 'CONFERENCE';
3+
4+
export interface BaseEvent {
5+
title: string;
6+
startDate: string;
7+
endDate: string;
8+
startTime: string;
9+
endTime: string;
10+
bannerImageUrl: string;
11+
description: string;
12+
referenceLinks: {
13+
title: string;
14+
url: string;
15+
address?: string;
16+
detailAddress?: string;
17+
}[];
18+
onlineType: OnlineType;
19+
address: string;
20+
location: { lat: number; lng: number };
21+
category: CategoryType;
22+
hashtags: string[];
23+
organizerEmail: string;
24+
organizerPhoneNumber: string;
25+
}

0 commit comments

Comments
 (0)