Skip to content

Commit

Permalink
feat: (#740) 단건 신고 처리 조회 api 및 query hook 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
chsua committed Oct 15, 2023
1 parent 9feb79d commit 4a4ba91
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
24 changes: 17 additions & 7 deletions frontend/src/api/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ export interface ReportAlarmList {
interface ReportAlarm {
id: number;
isRead: boolean;
info: {
id: number;
type: ReportType;
reason: ReportMessage[];
content: string;
createAt: StringDate;
};
info: ReportConfirmResult;
}

export interface ReportConfirmResult {
id: number;
type: ReportType;
reason: ReportMessage[];
content: string;
createAt: StringDate;
}

export const getContentAlarmList = async (page: number): Promise<ContentAlarmList> => {
Expand All @@ -55,3 +57,11 @@ export const getReportAlarmList = async (page: number): Promise<ReportAlarmList>
alarmList,
};
};

export const getReportConfirmResult = async (reportId: number): Promise<ReportConfirmResult> => {
const reportConfirmResult = await getFetch<ReportConfirmResult>(
`${BASE_URL}/alarms/report/${reportId}`
);

return reportConfirmResult;
};
1 change: 1 addition & 0 deletions frontend/src/constants/queryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const QUERY_KEY = {
VOTE_STATISTICS: 'voteStatistics',
ALARM_CONTENT: 'contentAlarm',
ALARM_REPORT: 'reportAlarm',
REPORT_CONFIRM_RESULT: 'reportConfirmResult',
};
28 changes: 28 additions & 0 deletions frontend/src/hooks/query/useReportConfirmResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useQuery } from '@tanstack/react-query';

import { ReportConfirmResult, getReportConfirmResult } from '@api/alarm';

import { QUERY_KEY } from '@constants/queryKey';

export const useReportConfirmResult = (reportId: number) => {
const { data } = useQuery<ReportConfirmResult>(
[QUERY_KEY.REPORT_CONFIRM_RESULT, reportId],
() => getReportConfirmResult(reportId),
{
cacheTime: 60 * 60 * 1000,
staleTime: 60 * 60 * 1000,
suspense: true,

retry: (failCount, error) => {
// const fetchError = error as Error;
// const status = JSON.parse(fetchError.message).status;
// if (status === 404) {
// return false;
// }
return failCount <= 3;
},
}
);

return { data };
};

0 comments on commit 4a4ba91

Please sign in to comment.