diff --git a/apps/_template/client-ip.ts b/apps/_template/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/_template/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/_template/middleware.ts b/apps/_template/middleware.ts index e6bbba40a..54d2aeeef 100644 --- a/apps/_template/middleware.ts +++ b/apps/_template/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { PORT, PROXY_HOST, SERVER_API_URL, SITE_ID } from "@/shared/config"; const serverApiUrl = process.env.SERVER_API_URL ?? "http://localhost:3000"; @@ -9,7 +10,7 @@ function addSecurityHeaders(response: NextResponse): NextResponse { return response; } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -45,6 +46,11 @@ export function middleware(req: NextRequest) { return addSecurityHeaders(response); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: ["/server/:path*", "/"], }; diff --git a/apps/as/client-ip.ts b/apps/as/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/as/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/as/middleware.ts b/apps/as/middleware.ts index dbd2a53f7..73dfa37ab 100644 --- a/apps/as/middleware.ts +++ b/apps/as/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { AUTH_USER_ID, @@ -18,7 +19,7 @@ function addSecurityHeaders(response: NextResponse): NextResponse { return response; } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -83,6 +84,11 @@ export function middleware(req: NextRequest) { return addSecurityHeaders(response); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: ["/server/:path*", "/attach-service/:path*", "/"], }; diff --git a/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts b/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts index 244dcdc9a..f1e7e7499 100644 --- a/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts +++ b/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts @@ -99,6 +99,7 @@ const ROLE_USER01_ATRZ_STATUS_ACTIONS: Record< FNRS_CNSLTN_VIEW_BUTTON_ACTION.fileVrfc, FNRS_CNSLTN_VIEW_BUTTON_ACTION.dsgntRvwr, ], + ATRZ02: [FNRS_CNSLTN_VIEW_BUTTON_ACTION.pwrkCnsltnDocMng], }, SL: { ATRZ01: [FNRS_CNSLTN_VIEW_BUTTON_ACTION.pwrkCnsltnDocMng], diff --git a/apps/cm/client-ip.ts b/apps/cm/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/cm/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/cm/middleware.ts b/apps/cm/middleware.ts index bae4e6579..56a839dae 100644 --- a/apps/cm/middleware.ts +++ b/apps/cm/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { CLAIM_NAME, AUTH_USER_ID, @@ -19,7 +20,7 @@ const serverApiUrl3 = process.env.NEXT_PUBLIC_SERVER_API_URL3 ?? serverApiUrl; const serverApiUrl5 = process.env.NEXT_PUBLIC_SERVER_API_URL5 ?? serverApiUrl; -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -177,6 +178,11 @@ export function middleware(req: NextRequest) { return NextResponse.next(); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/server/:path*", diff --git a/apps/cs/client-ip.ts b/apps/cs/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/cs/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/cs/middleware.ts b/apps/cs/middleware.ts index adc6077b9..404938806 100644 --- a/apps/cs/middleware.ts +++ b/apps/cs/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { AUTH_USER_ID, @@ -23,7 +24,7 @@ function addSecurityHeaders(response: NextResponse): NextResponse { return response; } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -103,6 +104,11 @@ export function middleware(req: NextRequest) { return addSecurityHeaders(response); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/server/:path*", diff --git a/apps/dc/client-ip.ts b/apps/dc/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/dc/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/dc/middleware.ts b/apps/dc/middleware.ts index 9a27b0b78..23380f1c0 100644 --- a/apps/dc/middleware.ts +++ b/apps/dc/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { CLAIM_NAME, AUTH_USER_ID, @@ -26,7 +27,7 @@ function addSecurityHeaders(response: NextResponse): NextResponse { return response; } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -170,6 +171,11 @@ export function middleware(req: NextRequest) { return addSecurityHeaders(response); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: ["/server/:path*", "/attach-service/:path*", "/api/link/:path*", "/"], }; diff --git a/apps/dm/.env.dmz b/apps/dm/.env.dmz new file mode 100644 index 000000000..4be29ca57 --- /dev/null +++ b/apps/dm/.env.dmz @@ -0,0 +1,26 @@ +# 공단 운영 +NEXT_PUBLIC_SITE_ID = DM +NEXT_PUBLIC_PORT = 3000 +NEXT_PUBLIC_CLAIM_NAME = Authorization +NEXT_PUBLIC_AUTH_USER_ID = token-id +NEXT_PUBLIC_ACCESS_TOKEN = access-token +NEXT_PUBLIC_REFRESH_TOKEN = refresh-token +#NEXT_PUBLIC_PROXY_HOST = https://devreuse.hasuon.or.kr +#NEXT_PUBLIC_CM_LOGIN_PAGE_URL = https://devqueen.hasuon.or.kr/auth/login +SERVER_API_URL = https://apigateway.hasuon.or.kr +CS_SERVER_API_URL = https://apigateway.hasuon.or.kr +FO_SERVER_API_URL = https://apigateway.hasuon.or.kr/operation-service +WR_SERVER_API_URL = https://apigateway.hasuon.or.kr/reuse-service +NEXT_PUBLIC_GEOSERVER_URL = http://apigateway.hasuon.or.kr/reuse-service/api/v1/geoserver-proxy/geoserver +NEXT_PUBLIC_LX_GEOSERVER_URL = http://apigateway.hasuon.or.kr/reuse-service/api/v1/geoserver-proxy/geoserver_swl +NEXT_PUBLIC_CS_TUS_UPLOAD = /attach-service/api/v1/tus/upload +NEXT_PUBLIC_NGII_URL = https://map.ngii.go.kr +NEXT_PUBLIC_NGII_PARAM = 04trYP9_xwLAfALjwZ-B8g&service=WMTS&request=GetTile&version=1.0.0&format=image/png&layer=korean_map&style=korean&tilematrixset=korean&tilematrix={z}&tilecol={x}&tilerow={y} +SEWERAGE_API_URL = http://apigateway.hasuon.or.kr/sewerage-service +GATEWAY_URL = http://apigateway.hasuon.or.kr +CONTENTS_INTRO = 24 +CONTENTS_EXAMPLE = 25 + +NEXT_PUBLIC_FINDADRESS_URL=https://business.juso.go.kr/addrlink/addrLinkApi.do +NEXT_PRIVATE_WR_ADDRESS_KEY = U01TXOFVVEgyMDI1MDgyODE0MTAxNzExNjEyMjA= +NEXT_PUBLIC_NGII_CLIENT_URL = https://map.ngii.go.kr diff --git a/apps/dm/app/store/sdmMng/index.tsx b/apps/dm/app/store/sdmMng/index.tsx index 45c8a2dca..f4c3e137a 100644 --- a/apps/dm/app/store/sdmMng/index.tsx +++ b/apps/dm/app/store/sdmMng/index.tsx @@ -504,8 +504,9 @@ const postSdmData = async (data: DemandCompType) => { // 수요정보 등록 const postSdmInfoData = async (data: SdmInfoFormData): Promise => { try { + // 첫 수요정보 등록도 가능하도록 수요정보 유무와 상관없이 수요처 사용 여부만 확인 const activeDemand = data.dmdInfoId - ? await getSdmInfoStatusList(data.dmdInfoId) + ? await getSdmInfoStatusList(data.dmdInfoId, false) : null; if (!activeDemand?.dmdInfoId) { sessionStorage.removeItem("user"); @@ -525,8 +526,9 @@ const postSdmInfoData = async (data: SdmInfoFormData): Promise => { // 수요정보 수정 const fetchUpdateSdmInfoData = async (data: SdmInfoFormData): Promise => { try { + // 수요처 사용 여부만 확인 const activeDemand = data.dmdInfoId - ? await getSdmInfoStatusList(data.dmdInfoId) + ? await getSdmInfoStatusList(data.dmdInfoId, false) : null; if (!activeDemand?.dmdInfoId) { sessionStorage.removeItem("user"); @@ -606,9 +608,11 @@ type DemandStatusResponse = DemandCompType & { demandMatchings?: DemandMatchings[]; }; -const getSdmInfoStatusList = async (dmdInfoId: string): Promise => { +// withInfoList=true : 수요정보가 1건 이상 있는 수요처만 조회됨(백엔드 INNER JOIN) +// withInfoList=false: 수요정보가 없어도 사용 중(use_yn='Y')인 수요처면 조회됨(백엔드 LEFT JOIN) +const getSdmInfoStatusList = async (dmdInfoId: string, withInfoList = true): Promise => { try { - const url = '/reuseFc/request/' + dmdInfoId + '?infoListYn=Y'; + const url = '/reuseFc/request/' + dmdInfoId + (withInfoList ? '?infoListYn=Y' : ''); const res = await getFetch(fetchType.WR, url); return res?.data ?? null; } catch (error) { @@ -708,7 +712,8 @@ export const SdmReducer = (set: any): SdmActions => { }, insertSdmData: async (data: DemandCompType) => { - const preRes = await getSdmInfoStatusList(data.dmdInfoId); + // 수요정보가 없는 기존 수요처도 중복으로 판단하도록 수요처만 조회 + const preRes = await getSdmInfoStatusList(data.dmdInfoId, false); if (preRes?.dmdInfoId) { toast.error('이미 등록된 수요처입니다.'); return; @@ -759,6 +764,18 @@ export const SdmReducer = (set: any): SdmActions => { const res = await getSdmInfoStatusList(dmdInfoId); if (!res?.dmdInfoId) { + // 수요정보가 0건이면 위 조회는 비어 있으므로, 수요처 사용 여부를 다시 확인해 빈 목록으로 처리 + const activeDemand = await getSdmInfoStatusList(dmdInfoId, false); + if (activeDemand?.dmdInfoId) { + set((state: SdmType) => ({ + Sdm: { + ...state.Sdm, + sdmInfoStatusList: [], + } + })) + return true; + } + sessionStorage.removeItem("user"); set((state: SdmType) => ({ Sdm: { diff --git a/apps/dm/client-ip.ts b/apps/dm/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/dm/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/dm/middleware.ts b/apps/dm/middleware.ts index af427a9a6..9391207c6 100644 --- a/apps/dm/middleware.ts +++ b/apps/dm/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { CLAIM_NAME, AUTH_USER_ID } from "./src/shared/config"; import { SERVER_API_FO_URL, SERVER_API_WR_URL } from "./src/shared/config/env"; @@ -24,7 +25,7 @@ function toDecodedQueryString(params: URLSearchParams): string { return new URLSearchParams(entries).toString(); } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; console.log(`[Middleware] Request URL: ${req.url}`); const searchParams = req.nextUrl.searchParams; @@ -158,6 +159,11 @@ export function middleware(req: NextRequest) { return NextResponse.next(); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/server/:path*", diff --git a/apps/fo/client-ip.ts b/apps/fo/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/fo/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/fo/middleware.ts b/apps/fo/middleware.ts index e3ee26b31..0b9c20616 100644 --- a/apps/fo/middleware.ts +++ b/apps/fo/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { SERVER_API_CS_URL, SERVER_API_FO_URL, SERVER_API_WR_URL } from "./src/shared/config/env"; const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id"; @@ -49,7 +50,7 @@ function rewriteWith(url: string, req: NextRequest, withAuth = false): NextRespo return NextResponse.rewrite(new URL(url), { headers }); } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { console.log("Middleware 진입:", req.nextUrl.pathname); const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -170,6 +171,11 @@ export function middleware(req: NextRequest) { return NextResponse.next(); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/", diff --git a/apps/sn/app/(map-layout)/map/components/gis-management/gis-upload-preview-map.tsx b/apps/sn/app/(map-layout)/map/components/gis-management/gis-upload-preview-map.tsx index 9166cc885..4c2fee280 100644 --- a/apps/sn/app/(map-layout)/map/components/gis-management/gis-upload-preview-map.tsx +++ b/apps/sn/app/(map-layout)/map/components/gis-management/gis-upload-preview-map.tsx @@ -56,7 +56,11 @@ const FALLBACK_PIPE_MIN_ZOOM = 13; const MIN_ZOOM_VISIBILITY_OFFSET = 0.01; const NETWORK_LAYER_GROUP = "SN_NETWORK"; const PIPE_LAYER_TYPE = "tb_ms_swage_ppl"; -const NGII_WMTS_URL = `/ngii-server/openapi/Gettile.do?apikey=${process.env.NEXT_PUBLIC_NGII_PARAM ?? ""}`; +// NGII 타일 호출 기준 주소. 값이 없으면 기존처럼 Next 서버(middleware)를 경유한다. +const NGII_WMTS_BASE = + process.env.NEXT_PUBLIC_NGII_CLIENT_URL || "/ngii-server"; +// NGII 배경지도 타일 URL 틀. {z}, {x}, {y}는 타일 요청 시 치환한다. +const NGII_WMTS_URL = `${NGII_WMTS_BASE}/openapi/Gettile.do?apikey=${process.env.NEXT_PUBLIC_NGII_PARAM ?? ""}`; const NGII_RESOLUTIONS = [ 1044.48, 522.24, 261.12, 130.56, 65.28, 32.64, 16.32, 8.16, 4.08, 2.04, 1.02, 0.51, 0.255, diff --git a/apps/sn/client-ip.ts b/apps/sn/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/sn/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/sn/middleware.ts b/apps/sn/middleware.ts index 6b2c5dfe0..76f202bbe 100644 --- a/apps/sn/middleware.ts +++ b/apps/sn/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id"; const CLAIM_NAME = process.env.NEXT_PUBLIC_CLAIM_NAME || "Authorization"; @@ -37,7 +38,7 @@ function rewriteWith(url: string, req: NextRequest, withAuth = false): NextRespo : NextResponse.rewrite(new URL(url)); } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { console.log("Middleware 진입:", req.nextUrl.pathname); const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -150,6 +151,11 @@ export function middleware(req: NextRequest) { } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/server/:path*", diff --git a/apps/st/client-ip.ts b/apps/st/client-ip.ts new file mode 100644 index 000000000..c58b0dd36 --- /dev/null +++ b/apps/st/client-ip.ts @@ -0,0 +1,68 @@ +import type { NextRequest, NextResponse } from "next/server"; + +/** + * 브라우저 실제 IP를 백엔드로 전달하기 위한 헤더 이름. + * + * 구조: [브라우저] → [앱 Ingress] → [Next middleware] → [API Ingress] → [apigateway] + * - 앱 Ingress(ingress-nginx 기본 설정)가 X-Forwarded-For를 실제 접속 IP(브라우저)로 채웁니다. + * - API Ingress는 X-Forwarded-For / X-Real-IP를 middleware IP로 덮어쓰므로, 별도 헤더로 브라우저 IP를 넘깁니다. + * - 백엔드 LogUtil.getUserIp()가 이 헤더를 가장 먼저 읽습니다. + * + * 브라우저가 같은 이름의 헤더를 보내도 middleware가 항상 덮어쓰거나 지웁니다(위조 방지). + */ +export const CLIENT_IP_HEADER = "x-client-ip"; + +const OVERRIDE_HEADERS = "x-middleware-override-headers"; +const REQUEST_HEADER_PREFIX = "x-middleware-request-"; +const REWRITE_HEADER = "x-middleware-rewrite"; + +/** 앱 Ingress가 채운 X-Forwarded-For 첫 번째 값(브라우저 IP)을 구합니다. */ +export function resolveClientIp(req: NextRequest): string { + const forwardedFor = req.headers.get("x-forwarded-for") ?? ""; + let ip = forwardedFor.split(",")[0]?.trim() ?? ""; + if (!ip) { + ip = req.headers.get("x-real-ip")?.trim() ?? ""; + } + if (ip.toLowerCase().startsWith("::ffff:") && ip.includes(".")) { + ip = ip.substring("::ffff:".length); + } + return ip; +} + +/** + * middleware가 만든 rewrite 응답에 X-Client-IP 요청 헤더를 붙입니다. + * (NextResponse.rewrite(url, { request: { headers } }) 와 같은 방식으로 요청 헤더를 덮어씀) + * rewrite가 아닌 응답(NextResponse.next 등)은 그대로 반환합니다. + */ +export function attachClientIp(req: NextRequest, res: NextResponse): NextResponse { + if (!res || !res.headers.has(REWRITE_HEADER)) { + return res; + } + + const ip = resolveClientIp(req); + const existing = res.headers.get(OVERRIDE_HEADERS); + + // 백엔드로 넘길 요청 헤더 이름 목록 + const names = new Set(); + if (existing) { + existing.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean).forEach((name) => names.add(name)); + } else { + req.headers.forEach((value, key) => { + const name = key.toLowerCase(); + names.add(name); + res.headers.set(REQUEST_HEADER_PREFIX + name, value); + }); + } + + if (ip) { + names.add(CLIENT_IP_HEADER); + res.headers.set(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER, ip); + } else { + // IP를 못 구하면 브라우저가 보낸 X-Client-IP가 그대로 넘어가지 않도록 제거 + names.delete(CLIENT_IP_HEADER); + res.headers.delete(REQUEST_HEADER_PREFIX + CLIENT_IP_HEADER); + } + + res.headers.set(OVERRIDE_HEADERS, Array.from(names).join(",")); + return res; +} diff --git a/apps/st/middleware.ts b/apps/st/middleware.ts index bd0020508..3772e2227 100644 --- a/apps/st/middleware.ts +++ b/apps/st/middleware.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; +import { attachClientIp } from "./client-ip"; import { AUTH_USER_ID, @@ -26,7 +27,7 @@ function addSecurityHeaders(response: NextResponse): NextResponse { return response; } -export function middleware(req: NextRequest) { +function baseMiddleware(req: NextRequest) { const pathname = req.nextUrl.pathname; const searchParams = req.nextUrl.searchParams; @@ -149,6 +150,11 @@ export function middleware(req: NextRequest) { return addSecurityHeaders(response); } +/** 백엔드로 브라우저 IP(X-Client-IP)를 전달하도록 rewrite 응답에 요청 헤더를 추가 */ +export function middleware(req: NextRequest) { + return attachClientIp(req, baseMiddleware(req)); +} + export const config = { matcher: [ "/server/:path*", diff --git a/apps/st/src/components/button/SumitButton.tsx b/apps/st/src/components/button/SumitButton.tsx index 0c0875ed2..5b0a5bc05 100644 --- a/apps/st/src/components/button/SumitButton.tsx +++ b/apps/st/src/components/button/SumitButton.tsx @@ -4,11 +4,16 @@ interface SubmitButtonProps { submitFunc: () => void; /** 버튼 문구 (기본: 제출) */ text?: string; + disabled?: boolean; } -const SubmitButton = ({ submitFunc, text = "제출" }: SubmitButtonProps) => { +const SubmitButton = ({ submitFunc, text = "제출", disabled = false }: SubmitButtonProps) => { return ( - diff --git a/apps/st/src/components/module/DataGrid.tsx b/apps/st/src/components/module/DataGrid.tsx index 7516fa3d5..b576c8cf6 100644 --- a/apps/st/src/components/module/DataGrid.tsx +++ b/apps/st/src/components/module/DataGrid.tsx @@ -253,7 +253,12 @@ declare module "realgrid" { setOptions(options: { footer?: { visible?: boolean }; summaryMode?: "aggregate" | "statistical" | "none"; - checkBar?: { visible?: boolean; exclusive?: boolean; syncHeadCheck?: boolean }; + checkBar?: { + visible?: boolean; + exclusive?: boolean; + syncHeadCheck?: boolean; + checkableOnly?: boolean; + }; }): void; } } @@ -432,6 +437,7 @@ type GridViewWithCheckApi = { checkEvent?: boolean, ) => void; setAllCheck?: (checked: boolean) => void; + setCheckable?: (itemIndex: number, checkable: boolean) => void; }; function isRowCheckedFlag(value: unknown): boolean { @@ -847,6 +853,7 @@ const DataGrid = ({ isExcelExport = true, fixedColumns, showHeaderCheckbox = false, + checkableCallback, rowData, setRowData, getGridDataRef, @@ -902,6 +909,7 @@ const DataGrid = ({ const onItemCheckedRef = useRef(onItemChecked); const onItemAllCheckedRef = useRef(onItemAllChecked); + const checkableCallbackRef = useRef(checkableCallback); const isSyncingChecksFromRowDataRef = useRef(false); const columnsFieldsSigRef = useRef(""); const emptyCellHoverKeyRef = useRef(""); @@ -923,6 +931,7 @@ const DataGrid = ({ onScrollToBottomRef.current = onScrollToBottom; onItemCheckedRef.current = onItemChecked; onItemAllCheckedRef.current = onItemAllChecked; + checkableCallbackRef.current = checkableCallback; onCellEditedRef.current = onCellEdited; onDataCellClickRef.current = onDataCellClick; @@ -1608,7 +1617,12 @@ useEffect(() => { // 헤더 체크박스 표시 여부 설정 gridView.setOptions({ - checkBar: { visible: showHeaderCheckbox, exclusive: false, syncHeadCheck: true }, + checkBar: { + visible: showHeaderCheckbox, + exclusive: false, + syncHeadCheck: true, + checkableOnly: true, + }, rowIndicator: { visible: false }, }); @@ -2272,6 +2286,17 @@ useEffect(() => { if (onItemChecked) { gridView.onItemChecked = (_grid, itemIndex, checked) => { if (isSyncingChecksFromRowDataRef.current) return; + const row = rowDataRef.current[itemIndex]; + if ( + row && + checkableCallbackRef.current && + !checkableCallbackRef.current(row, itemIndex) + ) { + if (checked) { + (_grid as GridViewWithCheckApi).checkItem?.(itemIndex, false, false); + } + return; + } onItemCheckedRef.current?.(itemIndex, checked); }; } else { @@ -2307,7 +2332,15 @@ useEffect(() => { gridView.checkAll?.(false, false, false, false); gridView.setAllCheck?.(false); rowData.forEach((row, itemIndex) => { - if (!isRowCheckedFlag((row as Record).__checked)) return; + const checkable = + checkableCallbackRef.current?.(row, itemIndex) ?? true; + gridView.setCheckable?.(itemIndex, checkable); + if ( + !checkable || + !isRowCheckedFlag((row as Record).__checked) + ) { + return; + } if (gridView.checkItem) { gridView.checkItem(itemIndex, true, false); return; diff --git a/apps/st/src/components/module/SearchForm.tsx b/apps/st/src/components/module/SearchForm.tsx index c1a1d2fd9..afed3d920 100644 --- a/apps/st/src/components/module/SearchForm.tsx +++ b/apps/st/src/components/module/SearchForm.tsx @@ -136,7 +136,7 @@ const SearchForm = (props: SearchFormProps = {}) => { const { setMessage: alert } = useAlertStore((state) => state); const userInfo = useUserStore((state) => state.userInfo); const mergedProps = { ...defaultSearchFormProps, ...props }; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd ?? ""; const sidoSelectText = props.sidoSelectText && props.sidoSelectText.trim() !== "" ? props.sidoSelectText diff --git a/apps/st/src/components/module/VerificationResultDialog.tsx b/apps/st/src/components/module/VerificationResultDialog.tsx index 60913eac0..dc99d8245 100644 --- a/apps/st/src/components/module/VerificationResultDialog.tsx +++ b/apps/st/src/components/module/VerificationResultDialog.tsx @@ -14,6 +14,10 @@ import { import type { RealGridReact } from "realgrid-react"; import { useAlertStore } from "@/shared/lib"; +import { + isJeonnamGwangjuHeadquartersOperableRow, + shouldRestrictFinanceVerificationToHeadquarters, +} from "@/entities/statistics"; import { statisticsApi } from "@/entities/statistics/api/statistics-service"; import type { VerificationResultListRequest, VerificationResultReportItem } from "@/entities/statistics/model/statistics-interface"; import { @@ -91,6 +95,14 @@ function verificationMthdCellStyle({ return undefined; } +function isResultRowOperable( + restrictHeadquarters: boolean, + row: { sewerBzmnCd?: string | number | null; admdstNm?: string | number | null }, +): boolean { + if (!restrictHeadquarters) return true; + return isJeonnamGwangjuHeadquartersOperableRow(row); +} + /** History와 동일 + 구분(검증유형) + 편집 가능한 처리의견(예외사유) */ const verificationSubmitResultColumnInfo: ColumnInfo = { columns: [ @@ -171,6 +183,12 @@ export function VerificationResultDialog({ const [loading, setLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(null); + const restrictHeadquarters = shouldRestrictFinanceVerificationToHeadquarters( + stableQueryContext?.statsCd, + stableQueryContext?.sewerBzmnCd, + stableQueryContext?.sggNm, + ); + const [rows, setRows] = useState([]); const [checkedIndices, setCheckedIndices] = useState>(() => new Set()); @@ -180,6 +198,11 @@ export function VerificationResultDialog({ const onPrcsOpnnExplnEdited = useCallback((params: CellEditedCallbackParams) => { if (params.fieldName !== "prcsOpnnExpln") return; + const row = rows[params.itemIndex]; + if (row && !isResultRowOperable(restrictHeadquarters, row)) { + setRowCheckByItemIndex(gridRef, params.itemIndex, false); + return; + } const text = String(params.newValue ?? ""); const hasValue = text.trim().length > 0; setRowCheckByItemIndex(gridRef, params.itemIndex, hasValue); @@ -189,7 +212,7 @@ export function VerificationResultDialog({ else next.delete(params.itemIndex); return next; }); - }, []); + }, [restrictHeadquarters, rows]); const resetState = useCallback(() => { setPageIndex(0); @@ -206,6 +229,7 @@ export function VerificationResultDialog({ vrfcSn: item.vrfcSn, vrfcMthdCd, vrfcMthdNm: VRFC_MTHD_NAME_MAP[vrfcMthdCd] ?? item.vrfcMthdNm, + sewerBzmnCd: item.sewerBzmnCd ?? "", ctpvNm: item.ctpvNm, admdstNm: item.admdstNm ?? item.sggNm ?? "-", fcltNm: item.fcltNm ?? "-", @@ -307,6 +331,11 @@ export function VerificationResultDialog({ setCheckedIndices((prev) => { const next = new Set(prev); rows.forEach((row, itemIndex) => { + if (!isResultRowOperable(restrictHeadquarters, row)) { + setRowCheckByItemIndex(gridRef, itemIndex, false); + next.delete(itemIndex); + return; + } const has = String(row.prcsOpnnExpln ?? "").trim().length > 0; setRowCheckByItemIndex(gridRef, itemIndex, has); if (has) next.add(itemIndex); @@ -315,7 +344,7 @@ export function VerificationResultDialog({ }); }); return () => cancelAnimationFrame(id); - }, [rows, loading]); + }, [rows, loading, restrictHeadquarters]); const handleExceptionSubmitClick = useCallback(async () => { if (checkedIndices.size === 0) { @@ -326,6 +355,11 @@ export function VerificationResultDialog({ const gridRows = getGridDataRef.current?.() ?? []; const payload: VerificationExceptionSubmitItem[] = []; for (const idx of checkedIndices) { + const row = rows[idx] ?? gridRows[idx]; + if (row && !isResultRowOperable(restrictHeadquarters, row)) { + alert("전남광주통합특별시는 본청 데이터만 조작할 수 있습니다."); + return; + } const prcsOpnnExpln = String(gridRows[idx]?.prcsOpnnExpln ?? "").trim(); if (!prcsOpnnExpln) { alert("예외 제출 사유를 작성해주세요."); @@ -373,6 +407,7 @@ export function VerificationResultDialog({ rows, onExceptionSubmitted, onOpenChange, + restrictHeadquarters, stableQueryContext, ]); @@ -419,9 +454,30 @@ export function VerificationResultDialog({ getGridRef={gridRef} getGridDataRef={getGridDataRef} onCellEdited={onPrcsOpnnExplnEdited} - cellStyleCallback={verificationMthdCellStyle} + cellStyleCallback={(params) => { + const mthdStyle = verificationMthdCellStyle(params); + if (!isResultRowOperable(restrictHeadquarters, params.row)) { + const mthdName = + typeof mthdStyle === "string" ? mthdStyle : undefined; + return { + styleName: ["rg-cell-readonly", mthdName] + .filter(Boolean) + .join(" "), + editable: false, + readOnly: true, + }; + } + return mthdStyle; + }} + checkableCallback={(row) => + isResultRowOperable(restrictHeadquarters, row) + } cellTooltipCallback={cellContentTooltip} onItemChecked={(itemIndex, checked) => { + const row = rows[itemIndex]; + if (checked && row && !isResultRowOperable(restrictHeadquarters, row)) { + return; + } setCheckedIndices((prev) => { const next = new Set(prev); if (checked) next.add(itemIndex); @@ -431,7 +487,15 @@ export function VerificationResultDialog({ }} onItemAllChecked={(checked) => { setCheckedIndices( - checked ? new Set(rows.map((_, i) => i)) : new Set(), + checked + ? new Set( + rows.flatMap((row, i) => + isResultRowOperable(restrictHeadquarters, row) + ? [i] + : [], + ), + ) + : new Set(), ); }} /> diff --git a/apps/st/src/components/module/VerificationResultHistoryDialog.tsx b/apps/st/src/components/module/VerificationResultHistoryDialog.tsx index cd0ea4490..84b89fccf 100644 --- a/apps/st/src/components/module/VerificationResultHistoryDialog.tsx +++ b/apps/st/src/components/module/VerificationResultHistoryDialog.tsx @@ -14,6 +14,10 @@ import { import type { RealGridReact } from "realgrid-react"; import { useAlertStore } from "@/shared/lib"; +import { + isJeonnamGwangjuHeadquartersOperableRow, + shouldRestrictFinanceVerificationToHeadquarters, +} from "@/entities/statistics"; import { statisticsApi } from "@/entities/statistics/api/statistics-service"; import type { VerificationResultListRequest, VerificationResultReportItem } from "@/entities/statistics/model/statistics-interface"; import { @@ -137,6 +141,14 @@ function verificationPrcsYnNmCellStyle({ fieldName, row }: CellStyleCallbackPara return "rg-cell-vrf-prcs-ok"; } +function isHistoryRowOperable( + restrictHeadquarters: boolean, + row: { sewerBzmnCd?: string | number | null; admdstNm?: string | number | null }, +): boolean { + if (!restrictHeadquarters) return true; + return isJeonnamGwangjuHeadquartersOperableRow(row); +} + const verificationResultColumnInfo: ColumnInfo = { columns: [ { name: "ctpvNm", fieldName: "ctpvNm", header: { text: "시도" }, editable: false }, @@ -227,6 +239,12 @@ export function VerificationResultHistoryDialog({ const [resetSubmitting, setResetSubmitting] = useState(false); const [checkedVrfcByTab, setCheckedVrfcByTab] = useState(createEmptyCheckedVrfcByTab); + const restrictHeadquarters = shouldRestrictFinanceVerificationToHeadquarters( + stableQueryContext?.statsCd, + stableQueryContext?.sewerBzmnCd, + stableQueryContext?.sggNm, + ); + const nvGridRef = useRef(null); const imrGridRef = useRef(null); const hbGridRef = useRef(null); @@ -375,10 +393,12 @@ export function VerificationResultHistoryDialog({ (entries: VerificationResultReportItem[], checkedMap: Map): VerificationResultGridRow[] => entries.map((item) => { const vrfcSn = Number(item.vrfcSn); - const isChecked = Number.isFinite(vrfcSn) && checkedMap.has(vrfcSn); + const operable = isHistoryRowOperable(restrictHeadquarters, item); + const isChecked = operable && Number.isFinite(vrfcSn) && checkedMap.has(vrfcSn); return { vrfcSn: item.vrfcSn, __checked: isChecked ? 1 : 0, + sewerBzmnCd: item.sewerBzmnCd ?? "", ctpvNm: item.ctpvNm ?? "-", admdstNm: item.admdstNm ?? item.sggNm ?? "-", fcltNm: item.fcltNm ?? "-", @@ -395,7 +415,7 @@ export function VerificationResultHistoryDialog({ mdfcnDt: (item.mdfcnDt ?? "").slice(0, 16), }; }), - [], + [restrictHeadquarters], ); /** 페이지(entries) 변경 시에만 __checked 반영 — 클릭마다 rowData를 바꾸지 않아 체크 UI가 안정적 */ @@ -432,6 +452,13 @@ export function VerificationResultHistoryDialog({ return; } setCheckedVrfcByTab((prev) => ({ ...prev, [tab]: syncedMap })); + for (const vrfcSn of syncedMap.keys()) { + const onPage = currentEntries.find((e) => Number(e.vrfcSn) === vrfcSn); + if (onPage && !isHistoryRowOperable(restrictHeadquarters, onPage)) { + alert("전남광주통합특별시는 본청 데이터만 조작할 수 있습니다."); + return; + } + } const vrfcSnList = Array.from(syncedMap.keys()); let mdfrUuid: string; try { @@ -477,6 +504,7 @@ export function VerificationResultHistoryDialog({ entriesByTab, loadTabPage, onExceptionResetSubmitted, + restrictHeadquarters, stableQueryContext, tabPages, ]); @@ -487,6 +515,18 @@ export function VerificationResultHistoryDialog({ const { pageIndex, pageCount } = tabPages[tab]; const loading = loadingByTab[tab]; const gridRef = gridRefByTab[tab]; + const historyCellStyle = (params: CellStyleCallbackParams) => { + const statusStyle = verificationPrcsYnNmCellStyle(params); + if (!isHistoryRowOperable(restrictHeadquarters, params.row)) { + const statusName = typeof statusStyle === "string" ? statusStyle : undefined; + return { + styleName: ["rg-cell-readonly", statusName].filter(Boolean).join(" "), + editable: false, + readOnly: true, + }; + } + return statusStyle; + }; if (!loading && rows.length === 0) { return

{emptyMessage}

; @@ -504,13 +544,18 @@ export function VerificationResultHistoryDialog({ showHeaderCheckbox enableSort={false} getGridRef={gridRef} - cellStyleCallback={verificationPrcsYnNmCellStyle} + cellStyleCallback={historyCellStyle} + checkableCallback={(row) => isHistoryRowOperable(restrictHeadquarters, row)} cellTooltipCallback={cellContentTooltip} onItemChecked={(itemIndex, checked) => { const entry = entries[itemIndex]; if (!entry) return; const vrfcSn = Number(entry.vrfcSn); if (!Number.isFinite(vrfcSn)) return; + if (checked && !isHistoryRowOperable(restrictHeadquarters, entry)) { + uncheckGridRow(gridRef, itemIndex); + return; + } if (checked && !canExceptionReset(entry.vrfcSttsCd)) { alert(EXCEPTION_RESET_ONLY_PRCS_YN_2_MESSAGE); uncheckGridRow(gridRef, itemIndex); @@ -530,6 +575,10 @@ export function VerificationResultHistoryDialog({ map.delete(vrfcSn); return; } + if (!isHistoryRowOperable(restrictHeadquarters, entry)) { + uncheckGridRow(gridRef, itemIndex); + return; + } if (canExceptionReset(entry.vrfcSttsCd)) { map.set(vrfcSn, String(entry.vrfcSttsCd ?? "")); } else { diff --git a/apps/st/src/components/statistics/input/PublicSewageFacilityInp.tsx b/apps/st/src/components/statistics/input/PublicSewageFacilityInp.tsx index a99d8a3f8..2b9bd34d6 100644 --- a/apps/st/src/components/statistics/input/PublicSewageFacilityInp.tsx +++ b/apps/st/src/components/statistics/input/PublicSewageFacilityInp.tsx @@ -310,7 +310,6 @@ const PublicSewageFacilityInp = () => { swtrmtFcltCd: nullableTrimmedString(d.swtrmtFcltCd), swtrmtFcltNm: nullableTrimmedString(d.swtrmtFcltNm), fcltSn: nullableTrimmedString(d.fcltSn), - fcltPstnCn: nullableTrimmedString(d.fcltPstnCn), inflwSwagePhysQnt: toNumber(d.inflwSwagePhysQnt), inflwSwageBoilQnt: toNumber(d.inflwSwageBoilQnt), inflwSwageAltdQnt: toNumber(d.inflwSwageAltdQnt), diff --git a/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx b/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx index dab2b251c..e3549dd99 100644 --- a/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx +++ b/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx @@ -42,9 +42,11 @@ import type { import { filterBySelectedAdmdstCd, isGugunOkForToolbar, + isJeonnamGwangjuSggNotApplicableSearch, isJeonnamGwangjuSidoAllSearch, isJeonnamGwangjuSidoAllToolbarException, isSubmitOkForToolbar, + JEONNAM_GWANGJU_HEADQUARTERS_ADMDST_NM, JEONNAM_GWANGJU_SIDO_ALL_SAVE_SUBMIT_MESSAGE, resolveNoApplicableForRequest, toInputSearchRegion, @@ -183,6 +185,47 @@ function isJeonnamGwangjuSidoAllToolbarTab(tabKey: string | null | undefined): b return Boolean(tabKey && ARTICLE_EDIT_TAB_KEYS.has(tabKey)); } +function isJeonnamGwangjuHeadquartersGridRow( + row: Record, +): boolean { + return ( + String(row.admdstNm ?? "").trim() === JEONNAM_GWANGJU_HEADQUARTERS_ADMDST_NM || + String(row.sggNm ?? "").trim() === JEONNAM_GWANGJU_HEADQUARTERS_ADMDST_NM + ); +} + +function hasJeonnamGwangjuHeadquartersGridRows( + rows: readonly Record[], +): boolean { + return rows.some(isJeonnamGwangjuHeadquartersGridRow); +} + +function isOnlyJeonnamGwangjuHeadquartersGridRows( + rows: readonly Record[], +): boolean { + return rows.length > 0 && rows.every(isJeonnamGwangjuHeadquartersGridRow); +} + +function isJeonnamGwangjuSggHeadquartersOnlyNotApplicable( + searchContext: SearchFormValues | null, + rows: readonly Record[], +): boolean { + return ( + isJeonnamGwangjuSggNotApplicableSearch(searchContext) && + isOnlyJeonnamGwangjuHeadquartersGridRows(rows) + ); +} + +function isEmptyForNotApplicable( + searchContext: SearchFormValues | null, + rows: readonly Record[], +): boolean { + return ( + rows.length === 0 || + isJeonnamGwangjuSggHeadquartersOnlyNotApplicable(searchContext, rows) + ); +} + function buildGugunOkForToolbar( values: SearchFormValues | null, tabKey?: string | null, @@ -221,7 +264,9 @@ function buildNoApplicableForRequest( values: SearchFormValues | null, checked: boolean, isSaveListEmpty: boolean, + tabKey?: string | null, ): boolean { + if (buildSubmitOkForToolbar(values, tabKey)) return checked; return resolveNoApplicableForRequest(sidoListRef.current, values, checked, isSaveListEmpty); } @@ -748,11 +793,29 @@ const SewageExcretaRelatedInp = () => { tabKey: string, hasRows: boolean, statusInfo: SewerageStatusInfo | null | undefined, - ): boolean => - NOT_APPLICABLE_TAB_KEYS.has(tabKey) && - hasSearched && - !hasRows && - computeTabEnterable(statusInfo, inputPeriodEnterable); + rows: readonly Record[] = [], + searchContext: SearchFormValues | null = null, + ): boolean => { + if ( + !NOT_APPLICABLE_TAB_KEYS.has(tabKey) || + !hasSearched || + !computeTabEnterable(statusInfo, inputPeriodEnterable) + ) { + return false; + } + if (!hasRows) return true; + if ( + ARTICLE_EDIT_TAB_KEYS.has(tabKey) && + isJeonnamGwangjuSggHeadquartersOnlyNotApplicable(searchContext, rows) + ) { + return true; + } + return ( + ARTICLE_EDIT_TAB_KEYS.has(tabKey) && + isJeonnamGwangjuSidoAllSearch(sidoListRef.current, searchContext) && + !hasJeonnamGwangjuHeadquartersGridRows(rows) + ); + }; const setIsNotApplicableForTab = useCallback((tabKey: string, nextValue: boolean) => { setIsNotApplicableByTab((prev) => { @@ -1330,10 +1393,17 @@ const SewageExcretaRelatedInp = () => { } commitActiveGrid(); - const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0); + const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0, tabKey); const currentData = getTabGridRows(tabKey); if (NOT_APPLICABLE_TAB_KEYS.has(tabKey)) { - if (!noApplicable && currentData.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { + if ( + !noApplicable && + isEmptyForNotApplicable( + searchContextByTab.get(tabKey) ?? lastSearchedValues, + currentData, + ) && + buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey) + ) { alert("해당사항 없음을 체크해주세요."); return; } @@ -1372,7 +1442,7 @@ const SewageExcretaRelatedInp = () => { const isDistrictRowTab = DISTRICT_ROW_TAB_KEYS.has(tabKey); const isPublicInstitutionTab = ARTICLE_EDIT_TAB_KEYS.has(tabKey); - const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0); + const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0, tabKey); const currentData = getTabGridRows(tabKey); const mapRows = rowDataMap.get(tabKey) ?? []; @@ -1443,7 +1513,15 @@ const SewageExcretaRelatedInp = () => { ) .map((row) => buildPublicInstitutionIndustrySaveItem(row, list)); - if (!noApplicable && submitList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { + if ( + !noApplicable && + (submitList.length === 0 || + isJeonnamGwangjuSggHeadquartersOnlyNotApplicable( + searchContextByTab.get(tabKey) ?? lastSearchedValues, + currentData, + )) && + buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey) + ) { alert("해당사항 없음을 체크해주세요."); return; } @@ -1640,7 +1718,8 @@ const SewageExcretaRelatedInp = () => { const isDistrictRowTab = DISTRICT_ROW_TAB_KEYS.has(tabKey); const isPublicInstitutionTab = ARTICLE_EDIT_TAB_KEYS.has(tabKey); - const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0); + const notApplicableChecked = isNotApplicableByTab.get(tabKey) ?? false; + const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, notApplicableChecked, getTabGridRows(tabKey).length === 0, tabKey); const currentData = getTabGridRows(tabKey); const mapRows = rowDataMap.get(tabKey) ?? []; @@ -1730,7 +1809,30 @@ const SewageExcretaRelatedInp = () => { ) .map((row) => buildPublicInstitutionIndustrySaveItem(row, list)); - if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { + if ( + isJeonnamGwangjuSidoAllSearch( + sidoListRef.current, + lastSearchedValues, + ) && + !notApplicableChecked && + !hasJeonnamGwangjuHeadquartersGridRows(currentData) + ) { + alert("본청 데이터 제거 시 해당사항 없음을 체크해주세요."); + return; + } + + if ( + !noApplicable && + (saveList.length === 0 || + isJeonnamGwangjuSggHeadquartersOnlyNotApplicable( + searchContextByTab.get(tabKey) ?? lastSearchedValues, + currentData, + )) && + buildSubmitOkForToolbar( + searchContextByTab.get(tabKey) ?? lastSearchedValues, + tabKey, + ) + ) { alert("해당사항 없음을 체크해주세요."); return; } @@ -2021,10 +2123,23 @@ const SewageExcretaRelatedInp = () => { ARTICLE_EDIT_TAB_KEYS.has(activeTab) && showEnterableToolbarButtons; const gugunOk = buildGugunOkForToolbar(searchContextForToolbar, activeTab); const submitOk = buildSubmitOkForToolbar(searchContextForToolbar, activeTab); + const disableSubmit = + isJeonnamGwangjuSidoAllToolbarTab(activeTab) && + isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + searchContextForToolbar, + relatedToolbarUserIdRef.current, + ); const showNotApplicableForActiveTab = NOT_APPLICABLE_TAB_KEYS.has(activeTab) && loadedTabKeys.has(activeTab) && - shouldShowNotApplicable(activeTab, activeTabHasRowData, activeTabStatus) && + shouldShowNotApplicable( + activeTab, + activeTabHasRowData, + activeTabStatus, + rowDataMap.get(activeTab) ?? [], + searchContextForToolbar, + ) && submitOk; const showSecondaryToolbarCard = hasSearched && @@ -2092,7 +2207,9 @@ const SewageExcretaRelatedInp = () => { void lastYearDataFunc()} /> - {submitOk && } + {submitOk && ( + + )} )} {activeTabStatus?.lclgvSbmsnSttsCd === "2" && submitOk && inputPeriodEnterable && ( diff --git a/apps/st/src/components/statistics/input/SewagePipeInp.tsx b/apps/st/src/components/statistics/input/SewagePipeInp.tsx index b7cf15409..8bb498347 100644 --- a/apps/st/src/components/statistics/input/SewagePipeInp.tsx +++ b/apps/st/src/components/statistics/input/SewagePipeInp.tsx @@ -71,7 +71,10 @@ import type { SearchFormValues } from "@/components/type/SearchForm.type"; import { FactInstallStatusInpColumn } from "@/components/util/column/input/sewagePipe/FactInstallStatusInpColumn"; import { ManholeStatusInpColumn } from "@/components/util/column/input/sewagePipe/ManholeStatusInpColumn"; import { PipeDiameterStatusInpColumn } from "@/components/util/column/input/sewagePipe/PipeDiameterStatusInpColumn"; -import { PipeTypeStatusInpColumn } from "@/components/util/column/input/sewagePipe/PipeTypeStatusInpColumn"; +import { + getPipeTypeStatusInpColumn, + resolvePipeTypeColumnEndYear, +} from "@/components/util/column/input/sewagePipe/PipeTypeStatusInpColumn"; import { RegionalFactStatusInpColumn } from "@/components/util/column/input/sewagePipe/RegionalFactStatusInpColumn"; import { SewagePipeInpColumnInfoList } from "@/components/util/column/input/sewagePipe/SewagePipeInpColumn"; import { fetchColumnGuidesRecord } from "@/components/util/grid/columnGuides"; @@ -119,11 +122,6 @@ function buildSewagePipeSearchParam( }; } -const getPipeTypeLastDataYear = () => { - const lastDataYear = new Date().getFullYear() - 1; - return Math.max(1995, lastDataYear); -}; - const PIPE_TYPE_STATUS_TAB_KEY = "ST00020003"; /** 조회 연도(statsYr)에 해당하는 연도 (y{year}* 필드용) */ @@ -131,7 +129,7 @@ const resolvePipeTypeEditableYear = (statsYr: string | null | undefined): number if (!statsYr) return null; const year = Number(statsYr); if (!Number.isFinite(year)) return null; - return Math.min(getPipeTypeLastDataYear(), Math.max(1995, year)); + return Math.min(resolvePipeTypeColumnEndYear(statsYr), Math.max(1995, year)); }; /** 조회 연도(statsYr)에 해당하는 연도별 매설연장 필드명 (y{year}LyngPrlg) */ @@ -257,8 +255,9 @@ function getSewagePipeRowVerificationErrors( function normalizePipeTypeStatusRow( row: SeweragePipeInputPipeTypeStatusItem, ctpvNm: string, + statsYr?: string | number | null, ): Record { - const lastDataYear = getPipeTypeLastDataYear(); + const lastDataYear = resolvePipeTypeColumnEndYear(statsYr); const { yearlyStatList, lyngPrlgWhol, @@ -276,8 +275,8 @@ function normalizePipeTypeStatusRow( for (const y of yearlyStatList ?? []) { const year = Number(y.lyngYr); - if (!Number.isFinite(year)) continue; - const targetYear = Math.min(lastDataYear, Math.max(1995, year)); + if (!Number.isFinite(year) || year > lastDataYear) continue; + const targetYear = Math.max(1995, year); yearFields[`y${targetYear}PrlgWhol`] = (yearFields[`y${targetYear}PrlgWhol`] ?? 0) + Number(y.pipeWholPrlg ?? 0); yearFields[`y${targetYear}LyngPrlg`] = @@ -614,10 +613,14 @@ const SewagePipeInp = () => { }; }); return SewagePipeInpColumnInfoList.map((tab: ColumnInfoList) => { - const canEdit = - (computeTabEnterable(tabStatusInfoMap.get(tab.tabKey) ?? null, inputPeriodEnterable) || isAdminInfo) && inputPeriodEnterable; - const applyEditable = (cols: ColumnConfig[] | undefined) => + const sourceTab = tab.tabKey === PIPE_TYPE_STATUS_TAB_KEY + ? getPipeTypeStatusInpColumn(lastSearchedYear) + : tab; + const canEdit = + (computeTabEnterable(tabStatusInfoMap.get(sourceTab.tabKey) ?? null, inputPeriodEnterable) || isAdminInfo) && inputPeriodEnterable; + const applyEditable = (cols: ColumnConfig[] | undefined) => + sourceTab.tabKey === PIPE_TYPE_STATUS_TAB_KEY ? applyPipeTypeStatusEditableColumns( cols, canEdit, @@ -635,20 +638,20 @@ const SewagePipeInp = () => { }, ); - if (tab.left && tab.right) { + if (sourceTab.left && sourceTab.right) { return { - ...tab, - left: { ...tab.left, columns: applyColumnGuides(applyEditable(tab.left.columns), tab.tabKey) }, - right: { ...tab.right, columns: applyColumnGuides(applyEditable(tab.right.columns), tab.tabKey) }, + ...sourceTab, + left: { ...sourceTab.left, columns: applyColumnGuides(applyEditable(sourceTab.left.columns), sourceTab.tabKey) }, + right: { ...sourceTab.right, columns: applyColumnGuides(applyEditable(sourceTab.right.columns), sourceTab.tabKey) }, }; } return { - ...tab, - columns: applyColumnGuides(applyEditable(tab.columns), tab.tabKey), - ...(tab.tabKey === PIPE_TYPE_STATUS_TAB_KEY && tab.columnLayout + ...sourceTab, + columns: applyColumnGuides(applyEditable(sourceTab.columns), sourceTab.tabKey), + ...(sourceTab.tabKey === PIPE_TYPE_STATUS_TAB_KEY && sourceTab.columnLayout ? { columnLayout: applyPipeTypeStatusColumnLayout( - tab.columnLayout, + sourceTab.columnLayout, shouldHidePipeTypeEditableYearDmltn( canEdit, inputPeriodEnterable, @@ -807,7 +810,11 @@ const SewagePipeInp = () => { if (response.status === 'success') { const commonInfo = response.data.commonInfo; const convertedData = filterFetched(response.data.pipeTypeStatusList).map((d) => - normalizePipeTypeStatusRow(d, commonInfo.ctpvNm), + normalizePipeTypeStatusRow( + d, + commonInfo.ctpvNm, + searchParam.statsYr ?? values.year, + ), ); applyRowMap((m) => m.set('ST00020003', toGridRows(convertedData))); setTabStatusInfoMap((prev) => new Map(prev).set(tabKey, response.data.statusInfo)); @@ -1320,7 +1327,7 @@ const SewagePipeInp = () => { return; } const columnFormatMap = new Map(); - PipeTypeStatusInpColumn.columns.forEach((col) => { + getPipeTypeStatusInpColumn(values.year).columns.forEach((col) => { if (col.fieldName && col.dataFormat) columnFormatMap.set(col.fieldName, col.dataFormat); }); const formatNumber = (value: string | number | null | undefined, fieldName: string): number => { @@ -1332,7 +1339,7 @@ const SewagePipeInp = () => { const decimalPlaces = format.match(/\.(\d+)/)?.[1]?.length ?? 0; return decimalPlaces > 0 ? parseFloat(num.toFixed(decimalPlaces)) : Math.round(num); }; - const lastDataYear = getPipeTypeLastDataYear(); + const lastDataYear = resolvePipeTypeColumnEndYear(values.year); const submitList = currentData.map((d) => { const yearlyStatList = []; for (let year = 1995; year <= lastDataYear; year++) { @@ -1803,7 +1810,7 @@ const SewagePipeInp = () => { } const columnFormatMap = new Map(); - PipeTypeStatusInpColumn.columns.forEach((col) => { + getPipeTypeStatusInpColumn(values.year).columns.forEach((col) => { if (col.fieldName && col.dataFormat) { columnFormatMap.set(col.fieldName, col.dataFormat); } @@ -1819,7 +1826,7 @@ const SewagePipeInp = () => { return decimalPlaces > 0 ? parseFloat(num.toFixed(decimalPlaces)) : Math.round(num); }; - const lastDataYear = getPipeTypeLastDataYear(); + const lastDataYear = resolvePipeTypeColumnEndYear(values.year); const saveList = currentData.map((d) => { const yearlyStatList = []; @@ -2193,7 +2200,11 @@ const SewagePipeInp = () => { return ( { const { showSaveInToolbar, showEnterableToolbarButtons, showActionToolbarCard } = activeTabToolbar; const submitOk = buildSubmitOkForToolbar(searchContextForToolbar); + const disableSubmit = isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + searchContextForToolbar, + financeToolbarUserIdRef.current, + ); const verificationCellStyle = ({ fieldName, @@ -1303,7 +1308,9 @@ const SewerageFinanceInp = () => { void lastYearDataFunc()} /> - {submitOk && } + {submitOk && ( + + )} )} {activeTabStatus?.lclgvSbmsnSttsCd === "2" && submitOk && inputPeriodEnterable && ( diff --git a/apps/st/src/components/statistics/review/ExcretaTreatmentFacilityRvw.tsx b/apps/st/src/components/statistics/review/ExcretaTreatmentFacilityRvw.tsx index 9f8bc2ad2..045559b67 100644 --- a/apps/st/src/components/statistics/review/ExcretaTreatmentFacilityRvw.tsx +++ b/apps/st/src/components/statistics/review/ExcretaTreatmentFacilityRvw.tsx @@ -97,7 +97,7 @@ const ExcretaTreatmentFacilityRvw = () => { return null; } - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!instSeCd) { return null; } @@ -108,7 +108,7 @@ const ExcretaTreatmentFacilityRvw = () => { statsCd: reviewOpinionContext.statsCd, instSeCd, }; - }, [reviewOpinionContext, userInfo?.instSeCd]); + }, [reviewOpinionContext, userInfo?.laeSeCd]); const handleReset = () => { setRowData([]); diff --git a/apps/st/src/components/statistics/review/PrivateSewageFacilityRvw.tsx b/apps/st/src/components/statistics/review/PrivateSewageFacilityRvw.tsx index 13a55c8b3..fef67b4d9 100644 --- a/apps/st/src/components/statistics/review/PrivateSewageFacilityRvw.tsx +++ b/apps/st/src/components/statistics/review/PrivateSewageFacilityRvw.tsx @@ -109,7 +109,7 @@ const PrivateSewageFacilityRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -121,7 +121,7 @@ const PrivateSewageFacilityRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/PublicSewageFacilityRvw.tsx b/apps/st/src/components/statistics/review/PublicSewageFacilityRvw.tsx index 5b749aa77..f75c276b1 100644 --- a/apps/st/src/components/statistics/review/PublicSewageFacilityRvw.tsx +++ b/apps/st/src/components/statistics/review/PublicSewageFacilityRvw.tsx @@ -81,7 +81,7 @@ const PublicSewageFacilityRvw = () => { return null; } - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!instSeCd) { return null; } @@ -92,7 +92,7 @@ const PublicSewageFacilityRvw = () => { statsCd: reviewOpinionContext.statsCd, instSeCd, }; - }, [reviewOpinionContext, userInfo?.instSeCd]); + }, [reviewOpinionContext, userInfo?.laeSeCd]); const handleReset = () => { setRowData([]); diff --git a/apps/st/src/components/statistics/review/PumpingStationRvw.tsx b/apps/st/src/components/statistics/review/PumpingStationRvw.tsx index 6aea889f2..cf4674da7 100644 --- a/apps/st/src/components/statistics/review/PumpingStationRvw.tsx +++ b/apps/st/src/components/statistics/review/PumpingStationRvw.tsx @@ -92,7 +92,7 @@ const PumpingStationRvw = () => { return null; } - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!instSeCd) { return null; } @@ -103,7 +103,7 @@ const PumpingStationRvw = () => { statsCd: reviewOpinionContext.statsCd, instSeCd, }; - }, [reviewOpinionContext, userInfo?.instSeCd]); + }, [reviewOpinionContext, userInfo?.laeSeCd]); const handleReset = () => { setRowData([]); diff --git a/apps/st/src/components/statistics/review/SewageExcretaRelatedRvw.tsx b/apps/st/src/components/statistics/review/SewageExcretaRelatedRvw.tsx index 5c2b803c9..deab7446e 100644 --- a/apps/st/src/components/statistics/review/SewageExcretaRelatedRvw.tsx +++ b/apps/st/src/components/statistics/review/SewageExcretaRelatedRvw.tsx @@ -112,7 +112,7 @@ const SewageExcretaRelatedRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -124,7 +124,7 @@ const SewageExcretaRelatedRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SewageExcretaSlurgeRvw.tsx b/apps/st/src/components/statistics/review/SewageExcretaSlurgeRvw.tsx index d19e36628..9fbdd0071 100644 --- a/apps/st/src/components/statistics/review/SewageExcretaSlurgeRvw.tsx +++ b/apps/st/src/components/statistics/review/SewageExcretaSlurgeRvw.tsx @@ -112,7 +112,7 @@ const SewageExcretaSlurgeRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -124,7 +124,7 @@ const SewageExcretaSlurgeRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SewagePipeMaintainRvw.tsx b/apps/st/src/components/statistics/review/SewagePipeMaintainRvw.tsx index b7d2e05be..041614c2a 100644 --- a/apps/st/src/components/statistics/review/SewagePipeMaintainRvw.tsx +++ b/apps/st/src/components/statistics/review/SewagePipeMaintainRvw.tsx @@ -127,7 +127,7 @@ const SewagePipeMaintainRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -139,7 +139,7 @@ const SewagePipeMaintainRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SewagePipeRvw.tsx b/apps/st/src/components/statistics/review/SewagePipeRvw.tsx index 1cb5c084f..71c800129 100644 --- a/apps/st/src/components/statistics/review/SewagePipeRvw.tsx +++ b/apps/st/src/components/statistics/review/SewagePipeRvw.tsx @@ -187,7 +187,7 @@ const SewagePipeRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -199,7 +199,7 @@ const SewagePipeRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SewageReservoirPumpRvw.tsx b/apps/st/src/components/statistics/review/SewageReservoirPumpRvw.tsx index 7a3101e6d..25b0da262 100644 --- a/apps/st/src/components/statistics/review/SewageReservoirPumpRvw.tsx +++ b/apps/st/src/components/statistics/review/SewageReservoirPumpRvw.tsx @@ -133,7 +133,7 @@ const SewageReservoirPumpRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsCd; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -145,7 +145,7 @@ const SewageReservoirPumpRvw = () => { statsCd, instSeCd, }; - }, [activeStatsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SewerageFinanceRvw.tsx b/apps/st/src/components/statistics/review/SewerageFinanceRvw.tsx index 2d0e52354..11dcf7dd7 100644 --- a/apps/st/src/components/statistics/review/SewerageFinanceRvw.tsx +++ b/apps/st/src/components/statistics/review/SewerageFinanceRvw.tsx @@ -112,7 +112,7 @@ const SewerageFinanceRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -124,7 +124,7 @@ const SewerageFinanceRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/SeweragePenetrationRateRvw.tsx b/apps/st/src/components/statistics/review/SeweragePenetrationRateRvw.tsx index 1872baabf..cf1275a28 100644 --- a/apps/st/src/components/statistics/review/SeweragePenetrationRateRvw.tsx +++ b/apps/st/src/components/statistics/review/SeweragePenetrationRateRvw.tsx @@ -81,7 +81,7 @@ const SeweragePenetrationRateRvw = () => { return null; } - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!instSeCd) { return null; } @@ -92,7 +92,7 @@ const SeweragePenetrationRateRvw = () => { statsCd: reviewOpinionContext.statsCd, instSeCd, }; - }, [reviewOpinionContext, userInfo?.instSeCd]); + }, [reviewOpinionContext, userInfo?.laeSeCd]); const handleReset = () => { setRowData([]); diff --git a/apps/st/src/components/statistics/review/SewerageServiceLevelRvw.tsx b/apps/st/src/components/statistics/review/SewerageServiceLevelRvw.tsx index 4176bbb8e..5e257e107 100644 --- a/apps/st/src/components/statistics/review/SewerageServiceLevelRvw.tsx +++ b/apps/st/src/components/statistics/review/SewerageServiceLevelRvw.tsx @@ -110,7 +110,7 @@ const SewerageServiceLevelRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -122,7 +122,7 @@ const SewerageServiceLevelRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/review/StatsInputStatusRvw.tsx b/apps/st/src/components/statistics/review/StatsInputStatusRvw.tsx index 360706821..e3e972a9d 100644 --- a/apps/st/src/components/statistics/review/StatsInputStatusRvw.tsx +++ b/apps/st/src/components/statistics/review/StatsInputStatusRvw.tsx @@ -271,7 +271,7 @@ const StatsInputStatusRvw = () => { const statsYr = lastSearchedValues.year ?? ""; const sewerBzmnCd = lastSearchedValues.bsnmCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !instSeCd) { return null; @@ -282,7 +282,7 @@ const StatsInputStatusRvw = () => { sewerBzmnCd, instSeCd, }; - }, [lastSearchedValues, userInfo?.instSeCd]); + }, [lastSearchedValues, userInfo?.laeSeCd]); const submitFunc = () => { if (submitDialogContext == null) { diff --git a/apps/st/src/components/statistics/review/WaterReuseRvw.tsx b/apps/st/src/components/statistics/review/WaterReuseRvw.tsx index 2b91e32ba..c12478edd 100644 --- a/apps/st/src/components/statistics/review/WaterReuseRvw.tsx +++ b/apps/st/src/components/statistics/review/WaterReuseRvw.tsx @@ -115,7 +115,7 @@ const WaterReuseRvw = () => { const statsYr = lastSearchValues.year ?? ""; const sewerBzmnCd = lastSearchValues.bsnmCd ?? ""; const statsCd = activeStatsStatusInfo.statsCd ?? ""; - const instSeCd = userInfo?.instSeCd ?? ""; + const instSeCd = userInfo?.laeSeCd?? ""; if (!statsYr || !sewerBzmnCd || !statsCd || !instSeCd) { return null; @@ -127,7 +127,7 @@ const WaterReuseRvw = () => { statsCd, instSeCd, }; - }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.instSeCd]); + }, [activeStatsStatusInfo.statsCd, lastSearchValues, userInfo?.laeSeCd]); const { showReviewOpinionButton, showReturnButton, showSubmitButton } = useMemo(() => { const statsStatusInfo = activeStatsStatusInfo; diff --git a/apps/st/src/components/statistics/verification/ImrVerificationHistory.tsx b/apps/st/src/components/statistics/verification/ImrVerificationHistory.tsx index a160cb203..81cacd686 100644 --- a/apps/st/src/components/statistics/verification/ImrVerificationHistory.tsx +++ b/apps/st/src/components/statistics/verification/ImrVerificationHistory.tsx @@ -158,7 +158,7 @@ const ImrVerificationHistory = () => { }); const userInfo = useUserStore((state) => state.userInfo); - const userInstSeCd = userInfo?.instSeCd; + const userInstSeCd = userInfo?.laeSeCd; const { data: sidoData } = useSidoList({ instSeCd: userInstSeCd }); const sidoOptions = sidoData?.sidoList ?? []; const selectedSidoBsnmCd = diff --git a/apps/st/src/components/statistics/verification/RejectReasonInputDialog.tsx b/apps/st/src/components/statistics/verification/RejectReasonInputDialog.tsx new file mode 100644 index 000000000..8d72df8aa --- /dev/null +++ b/apps/st/src/components/statistics/verification/RejectReasonInputDialog.tsx @@ -0,0 +1,113 @@ +"use client"; + +import { useEffect, useState } from "react"; + +import { + Button, + Dialog, + DialogClose, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, + Label, + Textarea, +} from "@common/components"; + +export interface RejectReasonInputDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + onConfirm?: (reason: string) => void | Promise; +} + +export function RejectReasonInputDialog({ + open, + onOpenChange, + onConfirm, +}: RejectReasonInputDialogProps) { + const [reason, setReason] = useState(""); + const [reasonError, setReasonError] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); + + const resetForm = () => { + setReason(""); + setReasonError(false); + }; + + const handleDialogOpenChange = (nextOpen: boolean) => { + if (!nextOpen) resetForm(); + onOpenChange(nextOpen); + }; + + useEffect(() => { + if (!open) resetForm(); + }, [open]); + + const handleConfirm = async () => { + const trimmed = reason.trim(); + if (!trimmed) { + setReasonError(true); + return; + } + try { + setIsSubmitting(true); + await onConfirm?.(trimmed); + } finally { + setIsSubmitting(false); + } + }; + + const canSubmit = reason.trim().length > 0 && !isSubmitting; + + return ( + + + + 반려 + +
+
+ +