[as] refactor: 버튼 로직 중복 코드 제거
This commit is contained in:
@@ -5,6 +5,7 @@ import { useRouter } from "next/navigation";
|
||||
|
||||
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import { useAlertStore, useUserStore } from "@/shared/lib";
|
||||
import { type ElaprDmndSaveRequestDto, elaprDmndService, type ElaprTmplt } from "@/entities/elapr";
|
||||
@@ -120,7 +121,13 @@ function FloatingActionButtons({
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
alert(error.message || "처리 중 오류가 발생했습니다.");
|
||||
let errorMessage = "";
|
||||
if (error instanceof AxiosError) {
|
||||
errorMessage = error.response?.data?.message ?? "";
|
||||
} else {
|
||||
errorMessage = error.message ?? "처리 중 오류가 발생했습니다.";
|
||||
}
|
||||
alert(errorMessage);
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
@@ -436,23 +443,15 @@ function FloatingActionButtons({
|
||||
결재(회신)
|
||||
</Button>
|
||||
)}
|
||||
{shouldShowButton(INSTL_SNCN_VIEW_BUTTON_ACTION.grndsChck) && (
|
||||
<Button
|
||||
onClick={() =>
|
||||
void executeAction({ action: INSTL_SNCN_VIEW_BUTTON_ACTION.grndsChck })
|
||||
}
|
||||
disabled={isProcessing}
|
||||
>
|
||||
기술검토
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ElaprTmpltPickerDialog
|
||||
open={activeDialog === "elaprTmplt"}
|
||||
onClose={() => setActiveDialog(null)}
|
||||
onSelect={handleElaprTmpltSelect}
|
||||
/>
|
||||
|
||||
<TextInputDialog
|
||||
open={activeDialog === "dmndSplmnt"}
|
||||
onOpenChange={() => setActiveDialog(null)}
|
||||
@@ -461,6 +460,7 @@ function FloatingActionButtons({
|
||||
isSubmitting={isProcessing}
|
||||
onConfirm={(value) => void handleDmndSplmntConfirm(value)}
|
||||
/>
|
||||
|
||||
<ElaprApprovalDialog
|
||||
open={activeDialog === "elaprApproval"}
|
||||
onOpenChange={(open) => setActiveDialog(open ? "elaprApproval" : null)}
|
||||
@@ -480,18 +480,7 @@ function FloatingActionButtons({
|
||||
|
||||
export { FloatingActionButtons };
|
||||
|
||||
async function handleStrg(
|
||||
context: ActionHandlerContext<InstlSncnApplySaveRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.saveApply(context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAply(
|
||||
async function handleSaveApply(
|
||||
context: ActionHandlerContext<InstlSncnApplySaveRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
@@ -516,16 +505,7 @@ async function handleSplmntCmptn(context: ActionHandlerContext): Promise<void> {
|
||||
context.onSuccess?.();
|
||||
}
|
||||
|
||||
async function handleInstlSncnAncmnt(context: ActionHandlerContext): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.changePrgrsSttsComCd(context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEnvoSbmsn(
|
||||
async function handleChangePrgrsSttsComCd(
|
||||
context: ActionHandlerContext<DocPrgrsUpdateRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
@@ -536,25 +516,7 @@ async function handleEnvoSbmsn(
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRjct(context: ActionHandlerContext<DocPrgrsUpdateRequestDto>): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.changePrgrsSttsComCd(context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSncnAprv(context: ActionHandlerContext): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.changePrgrsSttsComCd(context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRvwRply(
|
||||
async function handleTechReview(
|
||||
context: ActionHandlerContext<InstlSncnApplySaveRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
@@ -565,15 +527,6 @@ async function handleRvwRply(
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRqstTechRvw(context: ActionHandlerContext): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.changePrgrsSttsComCd(context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDsgntRvwr(
|
||||
context: ActionHandlerContext<ElaprDmndSaveRequestDto>,
|
||||
): Promise<void> {
|
||||
@@ -585,28 +538,6 @@ async function handleDsgntRvwr(
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRvwStrg(
|
||||
context: ActionHandlerContext<InstlSncnApplySaveRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.techReview(context.data.detDto.instlSncnDocNo, context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRvwCmptn(
|
||||
context: ActionHandlerContext<InstlSncnApplySaveRequestDto>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await instlSncnService.techReview(context.data.detDto.instlSncnDocNo, context.request);
|
||||
context.onSuccess?.();
|
||||
} catch (error) {
|
||||
context.onError?.(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDmndSplmnt(context: ActionHandlerContext): Promise<void> {
|
||||
// TODO: 보완요청 API 호출
|
||||
context.onSuccess?.();
|
||||
@@ -628,19 +559,19 @@ async function handleGrndsChck(context: ActionHandlerContext): Promise<void> {
|
||||
}
|
||||
|
||||
const buttonActionHandlers: Record<InstlSncnViewButtonAction, ActionHandler> = {
|
||||
strg: handleStrg,
|
||||
aply: handleAply,
|
||||
strg: handleSaveApply,
|
||||
aply: handleSaveApply,
|
||||
del: handleDel,
|
||||
splmntCmptn: handleSplmntCmptn,
|
||||
instlSncnAncmnt: handleInstlSncnAncmnt,
|
||||
envoSbmsn: handleEnvoSbmsn,
|
||||
rjct: handleRjct,
|
||||
sncnAprv: handleSncnAprv,
|
||||
rvwRply: handleRvwRply,
|
||||
rqstTechRvw: handleRqstTechRvw,
|
||||
instlSncnAncmnt: handleChangePrgrsSttsComCd,
|
||||
envoSbmsn: handleChangePrgrsSttsComCd,
|
||||
rjct: handleChangePrgrsSttsComCd,
|
||||
sncnAprv: handleChangePrgrsSttsComCd,
|
||||
rvwRply: handleTechReview,
|
||||
rqstTechRvw: handleChangePrgrsSttsComCd,
|
||||
dsgntRvwr: handleDsgntRvwr,
|
||||
rvwStrg: handleRvwStrg,
|
||||
rvwCmptn: handleRvwCmptn,
|
||||
rvwStrg: handleTechReview,
|
||||
rvwCmptn: handleTechReview,
|
||||
dmndSplmnt: handleDmndSplmnt,
|
||||
atrzAprv: handleAtrzAprv,
|
||||
atrzRply: handleAtrzRply,
|
||||
|
||||
Reference in New Issue
Block a user