diff --git a/src/app/panel/OthersProfile.tsx b/src/app/panel/OthersProfile.tsx index 99645a4c2..fd718bcc5 100644 --- a/src/app/panel/OthersProfile.tsx +++ b/src/app/panel/OthersProfile.tsx @@ -1,7 +1,9 @@ 'use client' +import ReportModal from '@/components/ReportModal' import { Box, Button, Popover, Typography } from '@mui/material' import { MouseEvent, ReactNode, useState } from 'react' +import useModal from '@/hook/useModal' interface IOthersProfile { name: string @@ -11,6 +13,7 @@ interface IOthersProfile { const OthersProfile = ({ name, userId, children }: IOthersProfile) => { const [anchorEl, setAnchorEl] = useState(null) + const { isOpen, openModal, closeModal } = useModal() const handleClick = (event: MouseEvent) => { setAnchorEl(event.currentTarget) @@ -55,9 +58,14 @@ const OthersProfile = ({ name, userId, children }: IOthersProfile) => { 아이디: {userId} - + + ) } diff --git a/src/app/report/page.tsx b/src/app/report/page.tsx deleted file mode 100644 index 3c7e14b2b..000000000 --- a/src/app/report/page.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react' -import ReportForm from './panel/ReportForm' -import { Typography, Container } from '@mui/material' - -const Report = () => { - return ( - - 신고하기 페이지 - - - ) -} - -export default Report diff --git a/src/app/report/panel/ReportForm.tsx b/src/app/report/panel/ReportForm.tsx deleted file mode 100644 index 57abc07d7..000000000 --- a/src/app/report/panel/ReportForm.tsx +++ /dev/null @@ -1,143 +0,0 @@ -'use client' -import React, { useState } from 'react' -import { Box, Typography, Button } from '@mui/material' -import { useSearchParams } from 'next/navigation' -import { useForm, Controller, SubmitHandler } from 'react-hook-form' -import CuTextFieldLabel from '@/components/CuTextFieldLabel' -import CuTextField from '@/components/CuTextField' -import useAxiosWithAuth from '@/api/config' -import { useRouter } from 'next/navigation' -import ReportTypeSelect from './ReportTypeSelect' - -interface IReportFormInput { - targetUrl: string - reportType: string - content: string -} - -const ReportForm = () => { - const [isSubmitting, setIsSubmitting] = useState(false) - const router = useRouter() - const useParams = useSearchParams() - // 모집글, 사용자 등 신고 종류 구분 - const targetUrl = useParams.get('url') - //console.log(targetUrl) - // 신고 대상의 id(글, 사용자) - - const axiosInstance = useAxiosWithAuth() - - const onSubmit: SubmitHandler = (data) => { - console.log(data) - setIsSubmitting(true) - axiosInstance - .post(`/report`, { - data, - }) - .then((res) => { - console.log(res) - }) - .catch((error) => { - console.log(error.message) - }) - setIsSubmitting(false) - } - - const { - handleSubmit, - control, - formState: { errors }, - } = useForm({ - defaultValues: { - targetUrl: targetUrl ? targetUrl : '', - reportType: '', - content: '', - }, - }) - - return ( - - ( - <> - - - 신고 대상 url - - - - {errors.targetUrl && ( - {errors.targetUrl?.message} - )} - - )} - /> - ( - <> - - {errors.reportType && ( - {errors.reportType?.message} - )} - - )} - /> - ( - - - 신고 내용 - - - {errors.content && ( - {errors.content.message} - )} - - )} - /> - - - - ) -} - -export default ReportForm diff --git a/src/components/ReportModal.tsx b/src/components/ReportModal.tsx new file mode 100644 index 000000000..d0b3bf768 --- /dev/null +++ b/src/components/ReportModal.tsx @@ -0,0 +1,151 @@ +import CuModal from './CuModal' +import React, { useState } from 'react' +import { useForm, Controller, SubmitHandler } from 'react-hook-form' +import CuTextFieldLabel from '@/components/CuTextFieldLabel' +import CuTextField from '@/components/CuTextField' +import useAxiosWithAuth from '@/api/config' +import { Box, Typography } from '@mui/material' +import ReportTypeSelect from '@/components/ReportTypeSelect' +import useToast from '@/hook/useToast' +import IToastProps from '@/types/IToastProps' + +interface IReportModalProps { + isModalOpen: boolean + handleClose: () => void + targetId: string +} + +interface IReportFormInput { + userId: string + type: string + content: string +} + +const ReportModal = ({ + isModalOpen, + handleClose, + targetId, +}: IReportModalProps) => { + const [isSubmitting, setIsSubmitting] = useState(false) + const [toastProps, setToastProps] = useState({ + severity: 'info', + message: '', + }) + const { CuToast, isOpen, openToast, closeToast } = useToast() + + const axiosInstance = useAxiosWithAuth() + const { + handleSubmit, + control, + formState: { errors }, + } = useForm({ + defaultValues: { + userId: targetId ? targetId : '', + type: '', + content: '', + }, + }) + + const onSubmit: SubmitHandler = (data) => { + //console.log(data) + setIsSubmitting(true) + axiosInstance + .post(`api/v1/report`, data) + .then(() => { + setToastProps({ + severity: 'success', + message: '신고가 접수되었습니다.', + }) + handleClose() + openToast() + }) + .catch((error) => { + if (error.response.status !== 401) { + setToastProps({ + severity: 'error', + message: '신고 접수 중 오류가 발생했습니다.', + }) + openToast() + } + }) + setIsSubmitting(false) + } + + return ( + <> + + +
+ ( + <> + + + {errors.type?.message || '\u00A0'} + + + )} + /> + ( + + + + 이 유저를 신고하시겠습니까? + + + + + {errors.content?.message || '\u00A0'} + + + )} + /> + +
+
+ + + ) +} + +export default ReportModal diff --git a/src/app/report/panel/ReportTypeSelect.tsx b/src/components/ReportTypeSelect.tsx similarity index 66% rename from src/app/report/panel/ReportTypeSelect.tsx rename to src/components/ReportTypeSelect.tsx index 6197ef0b8..7040aacd0 100644 --- a/src/app/report/panel/ReportTypeSelect.tsx +++ b/src/components/ReportTypeSelect.tsx @@ -1,27 +1,24 @@ import React from 'react' -import { Select, MenuItem, Box } from '@mui/material' +import { Select, MenuItem, Box, Typography } from '@mui/material' import CuTextFieldLabel from '@/components/CuTextFieldLabel' interface IReportTypeSelectProps { field: any label: string - options: string[] } -const ReportTypeSelect = ({ - field, - label, - options, -}: IReportTypeSelectProps) => { +const ReportTypeSelect = ({ field, label }: IReportTypeSelectProps) => { + const options = ['광고', '비방', '선전성', '도배', '기타'] return ( - {label} + {label}