wr: 시도,시군구 전체"0" 2건 조회현상 수정

This commit is contained in:
2026-09-21 17:51:09 +09:00
parent aafb326662
commit d7f101ee30
10 changed files with 255 additions and 93 deletions
@@ -48,9 +48,10 @@ export default function CoSttn() {
coSttnTxtSearch,
demandCompList,
coSttnPwInit,
coSttnDelete,
getMyUUID
} = useWrStore((state) => state);
const { regAuthrtYn, mdfcnAuthrtYn } = auth;
const { regAuthrtYn, mdfcnAuthrtYn, delAuthrtYn } = auth;
const alert = useAlertStore((state) => state.setMessage);
const { confirm } = useConfirm();
const [bdstTable, setBdstTable] = useState<DemandCompType[]>();
@@ -69,6 +70,7 @@ export default function CoSttn() {
const [seartchTxt, setSearchTxt] = useState<string>();
const [updateData, setUpdateData] = useState<DemandCompType>();
const [isResetSelection, setIsResetSelection] = useState<boolean>(false);
const [isDeleting, setIsDeleting] = useState(false);
const sanitizeDemandForPopup = useCallback((data?: DemandCompType) => {
if (!data) {
@@ -242,6 +244,52 @@ export default function CoSttn() {
});
};
/**
* 선택한 수요처를 논리삭제하고 현재 검색조건으로 목록을 다시 조회한다.
* @param data 삭제 대상 수요처
*/
const handleDeleteDemand = async (data: DemandCompType) => {
if (!data.dmdCoSn) {
alert("수요처 식별값이 없어 삭제할 수 없습니다.");
return;
}
const confirmed = await confirm(
`${data.dmdCoNm || "선택한 수요처"}를 삭제하시겠습니까? 삭제 후 목록과 로그인, 지도에서 조회되지 않습니다.`,
);
if (!confirmed) return;
const modifier = data.mdfr || await getMyUUID();
if (typeof modifier !== "string" || !modifier) {
alert("수정자 정보를 확인할 수 없어 삭제할 수 없습니다.");
return;
}
setIsDeleting(true);
try {
const deleted = await coSttnDelete(Number(data.dmdCoSn), modifier);
if (!deleted) {
alert("수요처 삭제에 실패하였습니다.");
return;
}
alert("수요처가 삭제되었습니다.");
setIsDmdModal({ isMoal: false, data: {} as DemandCompType });
setUpdateData(undefined);
setIsResetSelection(true);
const con =
objSearch.sgg && objSearch.sgg !== "0" ? objSearch.sgg : objSearch.city;
if (seartchTxt && seartchTxt.trim().length > 0) {
await coSttnTxtSearch(String(pageNation), "13", String(con), seartchTxt);
} else {
await coSttnSearch(String(pageNation), "13", String(con));
}
} finally {
setIsDeleting(false);
}
};
return (
<>
<ContentsDiv>
@@ -388,6 +436,8 @@ export default function CoSttn() {
getDemandCompList(searchText, pageCnt);
}}
rtnInputData={handleRtnInputData}
onDelete={handleDeleteDemand}
deleteDisabled={delAuthrtYn === "N" || isDeleting}
bodyClassNm={"w-full mx-auto bg-background rounded-lg shadow-md p-6"}
updateList={updateData}
openNetwork={true}
+5 -5
View File
@@ -1,5 +1,6 @@
export const dynamic = "force-dynamic";
import { SITE_ID } from "@/src/shared/config";
import { normalizeSelectData } from "@/app/store/common/code/normalizeSelectData";
import { NextResponse } from "next/server";
export const revalidate = 86400; //60 * 60 * 24;
@@ -143,13 +144,12 @@ export async function GET(request: Request) {
val: String(item.adstDstrCd) || "",
})) as SelectDataType[]),
],
cityCd: [
{ val: "0", text: "전체" },
...((city ?? []).map((item: any) => ({
cityCd: normalizeSelectData(
(city ?? []).map((item: any) => ({
val: item.adstDstrCd,
text: item.sido,
})) as SelectDataType[]),
],
})),
),
rvbsnCd: [
{ val: "0", text: "전체" },
...((rvbsn ?? []).map((item: any) => ({
+7 -5
View File
@@ -11,6 +11,7 @@ import {
ruseSeCd,
yn,
} from "./basicCode";
import { normalizeSelectData } from "./normalizeSelectData";
export const btnClass = "p-4 m-2 rounded-sm text-lg font-medium text-primary-foreground ";
const laeSecd = "41";
@@ -133,11 +134,12 @@ export const getSggCd = async (set: any) => {
};
export const getCityCd = async (set: any) => {
const city = await getFetch("common", "/addr/city");
const cityCd = city.map((item: any) => ({
val: item.adstDstrCd,
text: item.sido,
}));
cityCd.unshift({ val: "0", text: "전체" });
const cityCd = normalizeSelectData(
city.map((item: any) => ({
val: item.adstDstrCd,
text: item.sido,
})),
);
set((state: comCodeState) => ({
code: {
...state.code,
@@ -0,0 +1,28 @@
type SelectDataInput = {
text?: string | null;
val?: string | number | null;
};
export type NormalizedSelectData = {
text: string;
val: string;
};
/** 선택 목록을 값 기준으로 중복 제거하고 프런트 표준 전체 항목을 한 번만 추가한다. */
export const normalizeSelectData = (
items: readonly SelectDataInput[],
): NormalizedSelectData[] => {
const uniqueItems = new Map<string, NormalizedSelectData>();
items.forEach((item) => {
const val = String(item.val ?? "").trim();
if (!val || val === "0" || uniqueItems.has(val)) return;
uniqueItems.set(val, {
text: String(item.text ?? ""),
val,
});
});
return [{ text: "전체", val: "0" }, ...uniqueItems.values()];
};
+20 -2
View File
@@ -1,5 +1,5 @@
import type { CommonTableProps } from "@/app/store/common/type/header";
import { fetchType, getFetchWithCount, putFectch } from "@/components/lib/api";
import { deleteFectch, fetchType, getFetchWithCount, putFectch } from "@/components/lib/api";
import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form";
import { sha512 } from "js-sha512";
import { coSttHeadListExport, coSttNodeListExport } from "./headList";
@@ -26,6 +26,7 @@ type coSttnActions = {
coSttnSearch: (pageNo: string, pageCnt: string, con: string) => void;
coSttnTxtSearch: (pageNo: string, pageCnt: string, con: string, txt: string) => void;
coSttnPwInit: (dmdCoSn: number, dmdInfoId: string) => Promise<string>;
coSttnDelete: (dmdCoSn: number, mdfr: string) => Promise<boolean>;
};
export type coSttnType = coSttnState & coSttnActions;
@@ -148,6 +149,23 @@ export const coSttnActionsExport: (set: any) => coSttnActions = (
}
});
}
}
},
// 수요처를 물리삭제하지 않고 미사용 상태로 변경한다.
coSttnDelete: async (dmdCoSn: number, mdfr: string) => {
try {
const responseText = await deleteFectch(
`/reuseFc/request/${dmdCoSn}`,
{ mdfr },
);
const response = JSON.parse(responseText) as {
status?: number;
data?: number;
};
return response.status === 200 && Number(response.data) > 0;
} catch (error) {
console.error("수요처 삭제 중 오류가 발생했습니다.", error);
return false;
}
},
}
}