261022_03_ENH: 예약 취소 추가
This commit is contained in:
@@ -8,15 +8,19 @@ import type {
|
||||
ChannelType,
|
||||
KkoTemplateDetail,
|
||||
KkoTemplateListResponse,
|
||||
SendCancelResponse,
|
||||
SendResultInfo,
|
||||
SendResultSummaryRequest,
|
||||
SendResultSummaryResponse,
|
||||
} from "@kri/common/noti-hub";
|
||||
import { parseSendCancelResponse } from "@kri/common/noti-hub";
|
||||
import type { FileResponse, PageRequest, PageResponse } from "@kri/common";
|
||||
import { apiError, HttpError } from "@kri/common/http";
|
||||
import type { ProjectMainTemplateUpdateRequest } from "@/types/project";
|
||||
import type {
|
||||
MessageSendChannel,
|
||||
MessageSendSingleRequest,
|
||||
SendCancelRequest,
|
||||
SendSingleResponse,
|
||||
} from "@/types/message";
|
||||
import type { TemplateAttachmentImage, TemplateSummaryWithPurpose, TemplateWithPurpose } from "@/types/message";
|
||||
@@ -297,3 +301,37 @@ export function useSendResultBySidQuery(
|
||||
meta: { ignoreGlobalLoading: true },
|
||||
});
|
||||
}
|
||||
|
||||
export const formatSendCancelResult = (res: SendCancelResponse) =>
|
||||
`취소 ${res.canceledCount.toLocaleString()}건 / 이미 취소 ${res.alreadyCanceledCount.toLocaleString()}건 / 취소 불가 ${res.notCancelableCount.toLocaleString()}건`;
|
||||
|
||||
// 타임아웃·연결 오류·게이트웨이 오류는 서버에서 취소가 처리됐을 수 있으므로 실패로 확정하지 않는다.
|
||||
const UNCONFIRMED_CANCEL_STATUSES = new Set([0, 408, 502, 503, 504]);
|
||||
|
||||
export const resolveSendCancelErrorMessage = (error: unknown) => {
|
||||
if (error instanceof HttpError && !UNCONFIRMED_CANCEL_STATUSES.has(error.status)) {
|
||||
return apiError(error, { fallbackMessage: "예약 취소를 처리하지 못했습니다." }).message;
|
||||
}
|
||||
return "취소 처리 결과를 확인하지 못했습니다. 다시 조회된 목록에서 취소 상태를 확인해 주세요.";
|
||||
};
|
||||
|
||||
/**
|
||||
* 예약 취소 (POST /message-send/cancel/{single|bulk}, contactServer 경유)
|
||||
* 취소 불가 건이 있어도 200으로 응답하므로 건수로 결과를 안내하고, 성공·실패와 무관하게 발송 조회를 다시 불러온다.
|
||||
* 타임아웃 시 결과를 알 수 없으므로 자동 재시도하지 않는다.
|
||||
*/
|
||||
export function useCancelSendMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (req: SendCancelRequest) => {
|
||||
const body = req.type === "single" ? { sendIdx: req.sendIdx } : { bulkSendKey: req.bulkSendKey };
|
||||
const res = await nextApi.post<unknown>(`/message-send/cancel/${req.type}`, body, {
|
||||
skipResponseErrorHandler: true,
|
||||
});
|
||||
return parseSendCancelResponse(res);
|
||||
},
|
||||
retry: false,
|
||||
onSettled: () => queryClient.invalidateQueries({ queryKey: ["message-report"] }),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user