Skip to content

Commit 0153a87

Browse files
committed
feat: setting 페이지 프로젝트 정보 수정 API 연결
1 parent 46e02fb commit 0153a87

File tree

4 files changed

+77
-64
lines changed

4 files changed

+77
-64
lines changed

frontend/src/components/setting/InformationSettingSection.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import { useOutletContext } from "react-router-dom";
44
import { Socket } from "socket.io-client";
55
import useSettingProjectInfoSocket from "../../hooks/pages/setting/useSettingProjectInfoSocket";
66

7-
interface InformationSettingSectionProps {}
8-
9-
const InformationSettingSection = ({}: InformationSettingSectionProps) => {
7+
interface InformationSettingSectionProps {
8+
title: string;
9+
subject: string;
10+
}
11+
12+
const InformationSettingSection = ({
13+
title,
14+
subject,
15+
}: InformationSettingSectionProps) => {
1016
const { socket }: { socket: Socket } = useOutletContext();
11-
const {
12-
projectInfo: { title, subject },
13-
} = useSettingProjectInfoSocket(socket);
14-
const [titleValue, setTitleValue] = useState("");
17+
const { emitProjectInfoUpdateEvent } = useSettingProjectInfoSocket(socket);
18+
const [titleValue, setTitleValue] = useState(title);
1519
const [titleErrorMessage, setTitleErrorMessage] = useState("");
16-
const [subjectValue, setSubjectValue] = useState("");
20+
const [subjectValue, setSubjectValue] = useState(subject);
1721
const [subjectErrorMessage, setSubjectErrorMessage] = useState("");
1822
const submitActivated = useMemo(
1923
() =>
@@ -22,7 +26,7 @@ const InformationSettingSection = ({}: InformationSettingSectionProps) => {
2226
!subjectValue ||
2327
(titleValue === title && subjectValue === subject)
2428
),
25-
[titleValue, subjectValue]
29+
[title, subject, titleValue, subjectValue]
2630
);
2731

2832
const handleTitleChange = (event: ChangeEvent<HTMLInputElement>) => {
@@ -61,7 +65,9 @@ const InformationSettingSection = ({}: InformationSettingSectionProps) => {
6165
setSubjectErrorMessage("");
6266
};
6367

64-
const handleSubmit = () => {};
68+
const handleSubmit = () => {
69+
emitProjectInfoUpdateEvent({ title: titleValue, subject: subjectValue });
70+
};
6571

6672
useEffect(() => {
6773
setTitleValue(title);
Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,14 @@
1-
import { useEffect, useState } from "react";
21
import { Socket } from "socket.io-client";
3-
import { SettingDTO, SettingProjectDTO } from "../../../types/DTO/settingDTO";
4-
import {
5-
SettingSocketData,
6-
SettingSocketDomain,
7-
SettingSocketProjectInfoAction,
8-
} from "../../../types/common/setting";
92

103
const useSettingProjectInfoSocket = (socket: Socket) => {
11-
const [projectInfo, setProjectInfo] = useState<SettingProjectDTO>({
12-
title: "",
13-
subject: "",
14-
});
15-
16-
const handleInitEvent = (content: SettingDTO) => {
17-
const { project } = content;
18-
setProjectInfo(project);
19-
};
20-
21-
const handleProjectInfoEvent = (
22-
action: SettingSocketProjectInfoAction,
23-
content: SettingProjectDTO
24-
) => {
25-
switch (action) {
26-
case SettingSocketProjectInfoAction.UPDATE:
27-
setProjectInfo(content);
28-
break;
29-
}
4+
const emitProjectInfoUpdateEvent = (content: {
5+
title: string;
6+
subject: string;
7+
}) => {
8+
socket.emit("projectInfo", { action: "update", content });
309
};
3110

32-
const handleOnProjectInfoSetting = ({
33-
domain,
34-
action,
35-
content,
36-
}: SettingSocketData) => {
37-
switch (domain) {
38-
case SettingSocketDomain.INIT:
39-
handleInitEvent(content);
40-
break;
41-
case SettingSocketDomain.PROJECT_INFO:
42-
handleProjectInfoEvent(action, content);
43-
break;
44-
}
45-
};
46-
47-
useEffect(() => {
48-
socket.on("setting", handleOnProjectInfoSetting);
49-
50-
return () => {
51-
socket.off("setting", handleOnProjectInfoSetting);
52-
};
53-
}, []);
54-
55-
return { projectInfo };
11+
return { emitProjectInfoUpdateEvent };
5612
};
5713

5814
export default useSettingProjectInfoSocket;
Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
1-
import { useEffect } from "react";
1+
import { useEffect, useState } from "react";
22
import { Socket } from "socket.io-client";
3+
import {
4+
SettingSocketData,
5+
SettingSocketDomain,
6+
SettingSocketProjectInfoAction,
7+
} from "../../../types/common/setting";
8+
import { SettingDTO, SettingProjectDTO } from "../../../types/DTO/settingDTO";
39

410
const useSettingSocket = (socket: Socket) => {
11+
const [projectInfo, setProjectInfo] = useState<SettingProjectDTO>({
12+
title: "",
13+
subject: "",
14+
});
15+
16+
const handleInitEvent = (content: SettingDTO) => {
17+
const { project } = content;
18+
setProjectInfo(project);
19+
};
20+
21+
const handleProjectInfoEvent = (
22+
action: SettingSocketProjectInfoAction,
23+
content: SettingProjectDTO
24+
) => {
25+
switch (action) {
26+
case SettingSocketProjectInfoAction.UPDATE:
27+
setProjectInfo(content);
28+
break;
29+
}
30+
};
31+
32+
const handleOnProjectInfoSetting = ({
33+
domain,
34+
action,
35+
content,
36+
}: SettingSocketData) => {
37+
switch (domain) {
38+
case SettingSocketDomain.INIT:
39+
handleInitEvent(content);
40+
break;
41+
case SettingSocketDomain.PROJECT_INFO:
42+
handleProjectInfoEvent(action, content);
43+
break;
44+
}
45+
};
46+
547
useEffect(() => {
6-
socket.emit("joinLanding");
48+
socket.emit("joinSetting");
49+
socket.on("setting", handleOnProjectInfoSetting);
50+
51+
return () => {
52+
socket.off("setting", handleOnProjectInfoSetting);
53+
};
754
}, []);
55+
56+
return { projectInfo };
857
};
958

1059
export default useSettingSocket;

frontend/src/pages/setting/SettingPage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ const memberList: LandingMemberDTO[] = [
2626

2727
const SettingPage = () => {
2828
const { socket }: { socket: Socket } = useOutletContext();
29-
useSettingSocket(socket);
29+
const {
30+
projectInfo: { title, subject },
31+
} = useSettingSocket(socket);
3032

3133
return (
3234
<div className="w-full h-full">
33-
<InformationSettingSection />
35+
<InformationSettingSection {...{ title, subject }} />
3436
<MemberSettingSection memberList={memberList} />
3537
<ProjectDeleteSection projectTitle="프로젝트 이름" />
3638
</div>

0 commit comments

Comments
 (0)