261029_01_ENH: 이메일·문자·알림톡 템플릿 삭제 기능 추가 및 삭제
This commit is contained in:
@@ -91,6 +91,42 @@ export function useSaveTemplateMutation(chnnlTy: ChannelType, itrntPrjctCd: stri
|
||||
});
|
||||
}
|
||||
|
||||
export const resolveDeleteTemplateErrorMessage = (error: unknown) => {
|
||||
if (error instanceof HttpError) {
|
||||
const { code, message } = apiError(error, { fallbackMessage: "템플릿을 삭제하지 못했습니다." });
|
||||
if (error.status === 409 || code === "TEMPLATE_IN_USE") return "사용 중인 템플릿이라 삭제할 수 없습니다.";
|
||||
if (error.status === 403 || code === "MESSAGE_TEMPLATE_FORBIDDEN") return "템플릿 관리 권한이 없습니다.";
|
||||
return message;
|
||||
}
|
||||
return "템플릿을 삭제하지 못했습니다.";
|
||||
};
|
||||
|
||||
/**
|
||||
* 템플릿 삭제 (DELETE /message-template/{tmplatIdx})
|
||||
* 403으로 전역 로그아웃되지 않도록 기본 오류 처리를 건너뛰고, 화면에서 resolveDeleteTemplateErrorMessage로 안내한다.
|
||||
* 해당 템플릿의 대표 연결은 서버에서 제거하므로 성공 시 목록과 대표 템플릿을 다시 불러온다.
|
||||
*/
|
||||
export function useDeleteTemplateMutation(chnnlTy: ChannelType, itrntPrjctCd: string, prjctIdx: number) {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (tmplatIdx: number) => {
|
||||
await nextApi.del(`/message-template/${tmplatIdx}`, {
|
||||
expectText: true,
|
||||
skipForbiddenHandler: true,
|
||||
skipResponseErrorHandler: true,
|
||||
});
|
||||
},
|
||||
retry: false,
|
||||
onSuccess: (_data, tmplatIdx) => {
|
||||
qc.removeQueries({ queryKey: qk.template(tmplatIdx) });
|
||||
qc.removeQueries({ queryKey: qk.templateAttachments(tmplatIdx) });
|
||||
qc.invalidateQueries({ queryKey: qk.templateList(chnnlTy, itrntPrjctCd) });
|
||||
qc.invalidateQueries({ queryKey: qk.mainTemplate(prjctIdx, chnnlTy) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 템플릿 첨부파일 단건 다운로드 (GET /message-template/{tmplatIdx}/attachment?fileName=...)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user