Skip to content

Commit

Permalink
Merge pull request #101 from WASSUP-Project/develop
Browse files Browse the repository at this point in the history
[close #100] 개별 공지사항 작성 기능 구현
  • Loading branch information
YehyeokBang authored Jun 11, 2024
2 parents c68ba73 + 18f430a commit ef47569
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/containers/group/detail/GroupDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function GroupDetail() {
function renderComponent(id: number, groupData: groupInfo | null) {
switch (selectedAction) {
case "manage":
return <MemberManage id={id} />;
return <MemberManage id={id} groupData={groupData} />;
case "attendance":
return <Attendance id={id} />;
case "notice":
Expand Down
36 changes: 34 additions & 2 deletions src/containers/group/detail/contents/MemberManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ import {
import usePagination from "@/hooks/usePagination";
import MemberInvite from "./MemberInvite";
import { getGroupMembers } from "@/services/member/member";
import { groupInfo } from "@/types/group/group";
import { createNoticeToMember } from "@/services/notice/notice";

type ManageType = "info" | "invite";

type MemberManageProps = {
id: number;
groupData: groupInfo | null;
};

export default function MemberManage(props: MemberManageProps) {
const [members, setMembers] = useState<member[]>([]);
const [currentMembers, setCurrentMembers] = useState<member[]>([]);
const [selectedMember, setSelectedMember] = useState<member | null>(null);
const [searchKeyword, setSearchKeyword] = useState("");
const [message, setMessage] = useState("");
const { isOpen, onOpen, onOpenChange } = useDisclosure();
const [selectedModal, setSelectedModal] = useState<string>("");
const [selectedPage, setSelectedPage] = useState<ManageType>("info");
Expand Down Expand Up @@ -83,6 +87,19 @@ export default function MemberManage(props: MemberManageProps) {
console.log(`Send message to member ${id}`);
};

const requestSendMessageToMember = (id: number, message: string) => {
const data = createNoticeToMember({
memberId: id,
groupId: props.id,
title: `[${props.groupData?.name}]에서 메시지가 도착했습니다.`,
content: message,
});
data.then(() => {
alert("메시지가 전송되었습니다.");
setMessage("");
});
};

return (
<>
<div className={styles.title}>인원 관리</div>
Expand Down Expand Up @@ -237,15 +254,30 @@ export default function MemberManage(props: MemberManageProps) {
<textarea
className={styles.message_textarea}
placeholder="메시지를 입력해주세요."
value={message}
onChange={(e) => setMessage(e.target.value)}
></textarea>
</>
)}
</ModalBody>
<ModalFooter>
<Button color="secondary" onPress={onClose}>
<Button
color="secondary"
onPress={onClose}
onClick={() => setMessage("")}
>
돌아가기
</Button>
<Button color="primary" onPress={onClose}>
<Button
color="primary"
onPress={onClose}
onClick={() =>
requestSendMessageToMember(
selectedMember!.id,
message!
)
}
>
전송하기
</Button>
</ModalFooter>
Expand Down
24 changes: 24 additions & 0 deletions src/services/notice/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,28 @@ export const createNotice = async (request: RequestCreateNotice) => {
} catch (error) {
console.error(error);
}
};

export type RequestCreateNoticeToMember = {
memberId: number;
groupId: number;
title: string;
content: string;
};

export const createNoticeToMember = async (request: RequestCreateNoticeToMember) => {
try {
const response = await axios.post(`/api/announcements/${request.memberId}?groupId=${request.groupId}`, {
title: request.title,
content: request.content,
}, {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${localStorage.getItem("accessToken")}`,
}
});
return response.data;
} catch (error) {
console.error(error);
}
};

0 comments on commit ef47569

Please sign in to comment.