[as fr] 기본계획 보완완료 직후 버튼 체크 로직 실시간 반영으로 변경함

This commit is contained in:
2026-10-27 17:03:22 +09:00
parent cbbf5c8832
commit 20280f0244
4 changed files with 54 additions and 24 deletions
@@ -94,8 +94,12 @@ export function useSaveApplySewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (body: SewerBscPlanApplySaveRequestDto) => sewerBscPlanService.saveApply(body),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
onSuccess: (data) => {
if (data?.sewerBscPlanDocNo) {
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.detail(data.sewerBscPlanDocNo) });
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.details(data.sewerBscPlanDocNo) });
}
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all, refetchType: "all" });
},
});
}
@@ -106,10 +110,9 @@ export function useSubmitSupplementSewerBscPlan() {
mutationFn: ({ id, body }: { id: string; body: SewerBscPlanApplySaveRequestDto }) =>
sewerBscPlanService.submitSupplement(id, body),
onSuccess: (_data, { id }) => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.invalidateQueries({
queryKey: sewerBscPlanKeys.detail(id),
});
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.detail(id) });
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.details(id) });
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all, refetchType: "all" });
},
});
}
@@ -13,7 +13,7 @@ interface SewerBscPlanDetailGateProps {
function SewerBscPlanDetailGate({ id, propChgCycl }: SewerBscPlanDetailGateProps) {
const userInfo = useUserStore((state) => state.userInfo);
const { data, isLoading, isError } = useSewerBscPlan(id);
const { data, isLoading, isFetching, isError } = useSewerBscPlan(id);
const shouldRedirectToEdit = canEditPbadmsDoc({
docSeComCd: "SEWER",
prgrsSttsComCd: data?.detDto?.prgrsSttsComCd,
@@ -24,7 +24,7 @@ function SewerBscPlanDetailGate({ id, propChgCycl }: SewerBscPlanDetailGateProps
return (
<PbadmsDetailGate
isPending={!userInfo || isLoading}
isPending={!userInfo || isLoading || isFetching}
isError={isError}
shouldRedirectToEdit={Boolean(userInfo) && shouldRedirectToEdit}
editHref={`/sewer-bsc-plan/${id}/edit?chgCycl=${chgCycl}`}
@@ -1,6 +1,11 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useUserStore, withListQs } from "@/shared/lib";
import { useSewerBscPlanDetails } from "@/entities/sewer-bsc-plan";
import { canEditPbadmsDoc } from "@/widgets/pbadms-sprt";
import { Skeleton } from "@common/components";
import { SewerBscPlanFormPage } from "./sewer-bsc-plan-form-page";
@@ -11,10 +16,26 @@ interface SewerBscPlanEditPageProps {
}
function SewerBscPlanEditPage({ id, propChgCycl }: SewerBscPlanEditPageProps) {
const router = useRouter();
const userInfo = useUserStore((state) => state.userInfo);
const chgCycl = propChgCycl ?? 1;
const { data, isLoading: isDetailsLoading } = useSewerBscPlanDetails(id, chgCycl);
if (isDetailsLoading) {
const canEdit = canEditPbadmsDoc({
docSeComCd: "SEWER",
prgrsSttsComCd: data?.detDto?.prgrsSttsComCd,
rgtr: data?.detDto?.rgtr,
loggedInUserUnqId: userInfo?.userUnqId,
});
useEffect(() => {
if (isDetailsLoading || !data?.detDto || !userInfo) return;
if (!canEdit) {
router.replace(withListQs(`/sewer-bsc-plan/${id}?chgCycl=${chgCycl}`));
}
}, [canEdit, chgCycl, data?.detDto, id, isDetailsLoading, router, userInfo]);
if (isDetailsLoading || (Boolean(data?.detDto) && !canEdit && Boolean(userInfo))) {
return (
<div className="mt-6 space-y-6 px-4">
<div className="space-y-2">
@@ -77,7 +77,9 @@ function SewerBscPlanFormPage({
const alert = useAlertStore((state) => state.setMessage);
const [isSubmitting, setIsSubmitting] = useState(false);
const isEditMode = mode === "edit";
const isSplmntPrgrsStts = initialData?.detDto?.prgrsSttsComCd === "SL";
const prgrsSttsComCd = initialData?.detDto?.prgrsSttsComCd ?? "";
const isDraftStatus = !isEditMode || prgrsSttsComCd === "SV" || prgrsSttsComCd === "";
const isSplmntPrgrsStts = isEditMode && prgrsSttsComCd === "SL";
const { data: acntgTree = [] } = useAcntgSeMngTree();
const { data: essentialFiles = [] } = useEsntlAtchFileMngTree({ docSeComCd: "SEWER" });
@@ -164,10 +166,12 @@ function SewerBscPlanFormPage({
if (!result?.sewerBscPlanDocNo) return;
alert("신청 완료되었습니다.");
router.push(
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.detail(result.sewerBscPlanDocNo) });
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.details(result.sewerBscPlanDocNo) });
await queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all, refetchType: "all" });
router.replace(
withListQs(`/sewer-bsc-plan/${result.sewerBscPlanDocNo}?chgCycl=${result.chgCycl ?? 1}`),
);
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
} catch (error) {
console.error("신청 실패:", error);
alert("신청 중 오류가 발생했습니다.");
@@ -202,9 +206,11 @@ function SewerBscPlanFormPage({
if (!result) return;
alert("보완 완료 처리되었습니다.");
await queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.detail(docNo) });
queryClient.removeQueries({ queryKey: sewerBscPlanKeys.details(docNo) });
await queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all, refetchType: "all" });
const chgCycl = data.sewerBscPlanDtl.chgCycl ?? initialData?.detDto?.chgCycl ?? 1;
router.push(withListQs(`/sewer-bsc-plan/${docNo}?chgCycl=${chgCycl}`));
router.replace(withListQs(`/sewer-bsc-plan/${docNo}?chgCycl=${chgCycl}`));
} catch (error) {
console.error("보완 완료 실패:", error);
alert("보완 완료 처리 중 오류가 발생했습니다.");
@@ -286,7 +292,15 @@ function SewerBscPlanFormPage({
>
목록
</Button>
{!isSplmntPrgrsStts ? (
{isSplmntPrgrsStts ? (
<Button
type="button"
onClick={form.handleSubmit(onSplmntCmptn)}
disabled={isSubmitting}
>
보완 완료
</Button>
) : isDraftStatus ? (
<>
<Button type="submit" disabled={isSubmitting}>
저장
@@ -312,15 +326,7 @@ function SewerBscPlanFormPage({
</>
)}
</>
) : (
<Button
type="button"
onClick={form.handleSubmit(onSplmntCmptn)}
disabled={isSubmitting}
>
보완 완료
</Button>
)}
) : null}
</div>
</div>
</div>