From a6c81da7bf0ea2dcfabb3f4b4086ffe0b57dffb9 Mon Sep 17 00:00:00 2001 From: G-hoon Date: Fri, 27 Sep 2024 04:16:15 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#58]=20=EC=9D=98=EA=B2=AC=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EA=B8=B0=20=EB=B0=8F=20=EC=95=BD=EA=B4=80=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A7=81=ED=81=AC=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 1 + src/api/report.ts | 29 +++++++ src/components/Modal/Modals.tsx | 2 + src/components/Modal/ReportModal.tsx | 117 +++++++++++++++++++++++++++ src/components/SideNav.tsx | 23 +++++- src/pages/HomePage.tsx | 8 +- 6 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 src/api/report.ts create mode 100644 src/components/Modal/ReportModal.tsx diff --git a/src/api/index.ts b/src/api/index.ts index 6554a24..aae0a28 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,3 +1,4 @@ export * from "./auth" export * from "./snapshot" export * from "./group" +export * from "./report" diff --git a/src/api/report.ts b/src/api/report.ts new file mode 100644 index 0000000..e2d2219 --- /dev/null +++ b/src/api/report.ts @@ -0,0 +1,29 @@ +import axiosInstance from "./axiosInstance" + +interface ReportResData { + data: { + id: number + uid: number + email: string + type: string + title: string + content: string + createdAt: string + modifiedAt: string + } +} + +interface ReportParam { + email: string + title: string + content: string +} + +export const requestSendReportAPI = async (param: ReportParam): Promise => { + try { + const res = await axiosInstance.post(`/discussion`, { ...param, type: "QNA" }) + return res.data + } catch (e) { + throw e + } +} diff --git a/src/components/Modal/Modals.tsx b/src/components/Modal/Modals.tsx index 0765d63..0719b29 100644 --- a/src/components/Modal/Modals.tsx +++ b/src/components/Modal/Modals.tsx @@ -5,6 +5,7 @@ import CreateCrewModal from "./CreateCrewModal" import GoodPostureGuidePopupModal from "./GoodPostureGuideModal" import InviteCrewModal from "./InviteCrewModal" import JoinCrewModal from "./JoinCrewModal" +import ReportModal from "./ReportModal" import ToWithdrawModal from "./ToWithdrawModal" import WithdrawCrewModal from "./WithdrawCrewModal" @@ -15,6 +16,7 @@ export const modals = { withdrawCrewModal: WithdrawCrewModal, ToWithdrawModal: ToWithdrawModal, postureGuideModal: GoodPostureGuidePopupModal, + reportModal: ReportModal, } const Modals = (): React.ReactNode => { diff --git a/src/components/Modal/ReportModal.tsx b/src/components/Modal/ReportModal.tsx new file mode 100644 index 0000000..1a12d57 --- /dev/null +++ b/src/components/Modal/ReportModal.tsx @@ -0,0 +1,117 @@ +import { requestSendReportAPI } from "@/api" +import { ModalProps } from "@/contexts/ModalsContext" +import ModalContainer from "@components/ModalContainer" +import { useState } from "react" + +const ReportModal = (props: ModalProps): React.ReactElement => { + const { onClose, onSubmit } = props + + const [title, setTitle] = useState("") + const [email, setEmail] = useState("") + const [isValidEmail, setIsValidEmail] = useState(false) + const [description, setDescription] = useState("") + + const onChangeName = (e: React.ChangeEvent): void => { + setTitle(e.target.value) + } + + const onChangeDescription = (e: React.ChangeEvent): void => { + if (e.target.value.length <= 500) setDescription(e.target.value) + } + + const isValidForm = (): boolean => { + return Boolean(title.trim() && email.trim() && description.trim()) && isValidEmail + } + + const handleSubmit = (): void => { + if (!isValidForm()) { + return + } + + requestSendReportAPI({ + title, + email, + content: description, + }).then(({ data }) => { + if (onSubmit && typeof onSubmit === "function") onSubmit() + }) + } + + const onChangeEmail = (event: any) => { + setEmail(event.target.value.trim()) + + const emailRegex = /^[\w-\.]+@([\w-]+)\.?([\w-]+)\.+[\w-]{2,4}$/ + const validEmail = emailRegex.test(event.target.value) + setIsValidEmail(validEmail) + } + + return ( + +
+ {/* header */} +
+
의견 보내기
+
+ +
+ {/* crew owner */} +
+
제목
+
+ +
+
+ +
+
이메일
+
+ +
+ {email && !isValidEmail && ( +
올바른 이메일을 입력해주세요.
+ )} +
+ + {/* crew description */} +
+
상세 내용
+
+