-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] 모바일 비회원일 때 신고 버튼을 눌르면 알 수 없는 에러 메세지입니다라고 떠요 #781
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { ReportActionRequest } from '@type/report'; | ||
|
||
import { ToastContext } from '@hooks/context/toast'; | ||
|
||
import { reportAction } from '@api/report'; | ||
|
||
import { QUERY_KEY } from '@constants/queryKey'; | ||
|
||
export const useReportAction = () => { | ||
const queryClient = useQueryClient(); | ||
const { addMessage } = useContext(ToastContext); | ||
|
||
const { mutate, isLoading, isSuccess, isError, error } = useMutation({ | ||
mutationFn: async (reportActionData: ReportActionRequest) => | ||
|
@@ -16,7 +21,8 @@ export const useReportAction = () => { | |
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.REPORT] }); | ||
}, | ||
onError: () => { | ||
window.console.error('신고 조치를 실패했습니다.'); | ||
const message = error instanceof Error ? error.message : '신고 조치를 실패했습니다.'; | ||
addMessage(message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 복붙 때문인지 에러메시지 값이 이상해졌는데 복구해주실 수 있나요🤔 |
||
}, | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { ReportRequest } from '@type/report'; | ||
|
||
import { ToastContext } from '@hooks/context/toast'; | ||
|
||
import { reportContent } from '@api/report'; | ||
|
||
import { QUERY_KEY } from '@constants/queryKey'; | ||
|
||
export const useReportContent = () => { | ||
const queryClient = useQueryClient(); | ||
const { addMessage } = useContext(ToastContext); | ||
|
||
const { mutate, isLoading } = useMutation({ | ||
mutationFn: async (reportData: ReportRequest) => await reportContent(reportData), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.REPORT] }); | ||
addMessage('신고를 완료하였습니다.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 신고의 경우에는 성공했을 때 사용자에게 알려주는 것 너무 좋은데여🔥 |
||
}, | ||
onError: error => { | ||
const message = error instanceof Error ? error.message : '개인정보 등록을 실패했습니다.'; | ||
addMessage(message); | ||
}, | ||
}); | ||
|
||
return { mutate, isLoading }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { useState } from 'react'; | ||
import { useContext, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { PostAction, MenuItem } from '@type/menu'; | ||
import { ReportMessage } from '@type/report'; | ||
|
||
import { useToggle } from '@hooks'; | ||
import { AuthContext, useToggle } from '@hooks'; | ||
|
||
import DeleteModal from '@components/common/DeleteModal'; | ||
import HeaderTextButton from '@components/common/HeaderTextButton'; | ||
|
@@ -32,6 +32,7 @@ interface PostDetailPageChildProps { | |
reportPost: (reason: ReportMessage) => void; | ||
reportNickname: (reason: ReportMessage) => void; | ||
}; | ||
openToast: (text: string) => void; | ||
}; | ||
isEventLoading: Record<LoadingType, boolean>; | ||
} | ||
|
@@ -44,20 +45,25 @@ const menuList: MenuItem<PostAction>[] = [ | |
export default function InnerHeaderPart({ | ||
isWriter, | ||
isClosed, | ||
handleEvent: { movePage, controlPost }, | ||
handleEvent: { movePage, controlPost, openToast }, | ||
isEventLoading, | ||
}: PostDetailPageChildProps) { | ||
const navigate = useNavigate(); | ||
|
||
const { loggedInfo } = useContext(AuthContext); | ||
const { moveWritePostPage, moveVoteStatisticsPage } = movePage; | ||
const { setEarlyClosePost, deletePost, reportPost, reportNickname } = controlPost; | ||
const { isOpen, toggleComponent, closeComponent } = useToggle(); | ||
const [action, setAction] = useState<PostAction | null>(null); | ||
|
||
const { isDeletePostLoading, isReportNicknameLoading, isReportPostLoading } = isEventLoading; | ||
const { isOpen: isMenuOpen, toggleComponent, closeComponent } = useToggle(); | ||
const [action, setAction] = useState<PostAction | null>(null); | ||
|
||
const handleMenuClick = (action: PostAction) => { | ||
closeComponent(); | ||
|
||
if (!loggedInfo.isLoggedIn) { | ||
openToast('로그인 후에 기능을 이용해주세요.'); | ||
return; | ||
} | ||
|
||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 버그 해결 완료 👍👍👍 |
||
setAction(action); | ||
}; | ||
|
||
|
@@ -80,12 +86,12 @@ export default function InnerHeaderPart({ | |
{!isWriter ? ( | ||
<> | ||
<HeaderTextButton | ||
aria-label={isOpen ? '게시글 신고 메뉴 닫기' : '게시글 신고 메뉴 열기'} | ||
aria-label={isMenuOpen ? '게시글 신고 메뉴 닫기' : '게시글 신고 메뉴 열기'} | ||
onClick={toggleComponent} | ||
> | ||
신고 | ||
</HeaderTextButton> | ||
{isOpen && ( | ||
{isMenuOpen && ( | ||
<S.MenuWrapper> | ||
<Menu menuList={menuList} handleMenuClick={handleMenuClick} /> | ||
</S.MenuWrapper> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 가독성이 높아졌네요👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로딩이 끝나야만 action을 null로 세팅하도록 해서
말씀하신 이슈를 해결해볼 수 있을거 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 그럼 네트워크가 느린 사용자가 신고를 하고 기다리다가 오래 걸려서 취소를 누르면 나가지지 않게 될 것 같은데 제가 이해한 바가 맞을까요?? 아님 다르게 작동하나요??