|
| 1 | +import useMutationError from "../hooks/useMutationError"; |
| 2 | +import { RouteId } from "../data/types/route"; |
| 3 | +import { CautionIssueType, DangerIssueType } from "../data/types/enum"; |
| 4 | +import { postFetch } from "../utils/fetch/fetch"; |
| 5 | +import { postReportRoute } from "../api/route"; |
| 6 | + |
| 7 | +const postReport = ( |
| 8 | + univId: number, |
| 9 | + routeId: RouteId, |
| 10 | + body: { dangerTypes: DangerIssueType[]; cautionTypes: CautionIssueType[] }, |
| 11 | +): Promise<boolean> => { |
| 12 | + return postFetch<void, string>(`/${univId}/route/risk/${routeId}`, body); |
| 13 | +}; |
| 14 | + |
| 15 | +export default function Errortest() { |
| 16 | + const [Modal400, result400] = useMutationError( |
| 17 | + { |
| 18 | + //@ts-expect-error 강제 에러 발생 |
| 19 | + mutationFn: () => postReport(1001, 1, { cautionTypes: ["TEST"], dangerTypes: [] }), |
| 20 | + }, |
| 21 | + undefined, |
| 22 | + { |
| 23 | + 400: { mainTitle: "400 제목", subTitle: "400 부제목" }, |
| 24 | + 404: { mainTitle: "404 제목", subTitle: "404 부제목" }, |
| 25 | + }, |
| 26 | + ); |
| 27 | + |
| 28 | + const [Modal404, result404] = useMutationError( |
| 29 | + { |
| 30 | + mutationFn: () => postReport(1, 1, { cautionTypes: [], dangerTypes: [] }), |
| 31 | + }, |
| 32 | + undefined, |
| 33 | + { |
| 34 | + 400: { mainTitle: "400 제목", subTitle: "400 부제목" }, |
| 35 | + 404: { mainTitle: "404 제목", subTitle: "404 부제목" }, |
| 36 | + }, |
| 37 | + ); |
| 38 | + |
| 39 | + const [Modal500, result500] = useMutationError( |
| 40 | + { |
| 41 | + //@ts-expect-error 강제 에러 발생 |
| 42 | + mutationFn: () => postReportRoute(1001, {}), |
| 43 | + }, |
| 44 | + undefined, |
| 45 | + { |
| 46 | + 400: { mainTitle: "400 제목", subTitle: "400 부제목" }, |
| 47 | + 404: { mainTitle: "404 제목", subTitle: "404 부제목" }, |
| 48 | + }, |
| 49 | + ); |
| 50 | + |
| 51 | + const { mutate: mutate400 } = result400; |
| 52 | + const { mutate: mutate404 } = result404; |
| 53 | + const { mutate: mutate500 } = result500; |
| 54 | + |
| 55 | + return ( |
| 56 | + <div> |
| 57 | + <div className="rounded-sm border border-dashed border-[#9747FF] flex flex-col justify-start space-y-5 p-5"> |
| 58 | + <button className="border border-system-red" onClick={mutate400}> |
| 59 | + 400 발생 |
| 60 | + </button> |
| 61 | + <button className="border border-system-red" onClick={mutate404}> |
| 62 | + 404 발생 |
| 63 | + </button> |
| 64 | + <button className="border border-system-red" onClick={mutate500}> |
| 65 | + 500 발생 |
| 66 | + </button> |
| 67 | + </div> |
| 68 | + <Modal400 /> |
| 69 | + <Modal404 /> |
| 70 | + <Modal500 /> |
| 71 | + </div> |
| 72 | + ); |
| 73 | +} |
0 commit comments