diff --git a/next.config.ts b/next.config.ts index fdef1bb..2dc0727 100644 --- a/next.config.ts +++ b/next.config.ts @@ -29,6 +29,17 @@ const nextConfig = createKriNextConfig({ }, ], }, + { + source: "/api/list-external/:path*", + headers: [ + { key: "Access-Control-Allow-Origin", value: "*" }, + { key: "Access-Control-Allow-Methods", value: "GET,POST,PATCH" }, + { + key: "Access-Control-Allow-Headers", + value: "Content-Type, X-API-Key", + }, + ], + }, ]; }, }) satisfies NextConfig; diff --git a/src/app/api/list-external/[[...slug]]/route.ts b/src/app/api/list-external/[[...slug]]/route.ts new file mode 100644 index 0000000..3418668 --- /dev/null +++ b/src/app/api/list-external/[[...slug]]/route.ts @@ -0,0 +1,115 @@ +import { NextRequest, NextResponse } from "next/server"; +import { RouteContext } from "@/types/common"; +import { createContactApiWithApiKey } from "@/lib/http-server"; +import { errorToResponse } from "@kri/common/http"; +import { ListSearchExternal } from "@/types/list"; + +const getApiKey = (req: NextRequest) => req.headers.get("x-api-key"); + +// backend가 제공하는 메소드/경로 그대로 사용 (path variable) +export const GET = async (req: NextRequest, context: RouteContext) => { + try { + const apiKey = getApiKey(req); + if (!apiKey) { + return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 }); + } + + const { slug = [] } = await context.params; + const [action, prjctIdx, sid] = slug; + const contactApi = await createContactApiWithApiKey(apiKey); + + if (action === "header" && prjctIdx) { + const result = await contactApi.get(`/list-external/header/${prjctIdx}`); + return NextResponse.json(result, { status: 200 }); + } + + if (action === "search" && prjctIdx && sid) { + const result = await contactApi.get( + `/list-external/search/${prjctIdx}/${encodeURIComponent(sid)}`, + ); + return NextResponse.json(result, { status: 200 }); + } + + return NextResponse.json({ message: "Not found" }, { status: 404 }); + } catch (error: unknown) { + return errorToResponse(error); + } +}; + +// backend가 제공하는 메소드/경로 그대로 사용 (path variable) +export const PATCH = async (req: NextRequest, context: RouteContext) => { + try { + const apiKey = getApiKey(req); + if (!apiKey) { + return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 }); + } + + const { slug = [] } = await context.params; + const [action, prjctIdx, sid] = slug; + + if (action === "update" && prjctIdx && sid) { + const body = await req.json().catch(() => null); + const contactApi = await createContactApiWithApiKey(apiKey); + const result = await contactApi.patch( + `/list-external/update/${prjctIdx}/${encodeURIComponent(sid)}`, + body, + ); + return NextResponse.json(result, { status: 200 }); + } + + return NextResponse.json({ message: "Not found" }, { status: 404 }); + } catch (error: unknown) { + return errorToResponse(error); + } +}; + +// 외부 연동 호환용: 항상 POST, path variable을 모두 url 쿼리 파람으로 받아 backend path variable로 전달 +export const POST = async (req: NextRequest, context: RouteContext) => { + try { + const apiKey = getApiKey(req); + if (!apiKey) { + return NextResponse.json({ message: "X-API-Key는 필수입니다." }, { status: 401 }); + } + + const { slug = [] } = await context.params; + const [action] = slug; + const { searchParams } = req.nextUrl; + const prjctIdx = searchParams.get("prjctIdx"); + const sid = searchParams.get("sid"); + const contactApi = await createContactApiWithApiKey(apiKey); + + if (action === "header") { + if (!prjctIdx) { + return NextResponse.json({ message: "prjctIdx는 필수입니다." }, { status: 400 }); + } + const result = await contactApi.get(`/list-external/header/${prjctIdx}`); + return NextResponse.json(result, { status: 200 }); + } + + if (action === "search") { + if (!prjctIdx || !sid) { + return NextResponse.json({ message: "prjctIdx, sid는 필수입니다." }, { status: 400 }); + } + const result = await contactApi.get( + `/list-external/search/${prjctIdx}/${encodeURIComponent(sid)}`, + ); + return NextResponse.json(result, { status: 200 }); + } + + if (action === "update") { + if (!prjctIdx || !sid) { + return NextResponse.json({ message: "prjctIdx, sid는 필수입니다." }, { status: 400 }); + } + const body = await req.json().catch(() => null); + const result = await contactApi.patch( + `/list-external/update/${prjctIdx}/${encodeURIComponent(sid)}`, + body, + ); + return NextResponse.json(result, { status: 200 }); + } + + return NextResponse.json({ message: "Not found" }, { status: 404 }); + } catch (error: unknown) { + return errorToResponse(error); + } +}; diff --git a/src/app/globals.css b/src/app/globals.css index 2fd8a27..b313134 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -172,6 +172,24 @@ vertical-align: baseline; } +/* 에디터 편집 화면은 [&_p]:my-2 유틸리티로 문단 사이 margin을 주지만, + 미리보기는 Tailwind preflight가 p의 기본 margin을 0으로 리셋해 내용 없는 빈

가 + 높이 0으로 사라진다. 편집 화면과 동일하게 margin을 줘서 빈 줄이 보이도록 한다. */ +.kri-editor-preview p { + margin: 0.5em 0; +} +.kri-editor-preview p:first-child { + margin-top: 0; +} +.kri-editor-preview p:last-child { + margin-bottom: 0; +} +/* 내용이 전혀 없는

는 높이가 0이라 위/아래 margin이 서로 collapse되어 사라진다. + min-height로 실제 높이를 줘서 collapse를 막아야 빈 줄이 화면에 보인다. */ +.kri-editor-preview p:empty { + min-height: 1em; +} + .ProseMirror .ProseMirror-selectednode img { outline: 5px solid #0ea5e9; outline-offset: -5px; diff --git a/src/components/dialog/ListHeaderManageDialog.tsx b/src/components/dialog/ListHeaderManageDialog.tsx index af60237..f66c4f8 100644 --- a/src/components/dialog/ListHeaderManageDialog.tsx +++ b/src/components/dialog/ListHeaderManageDialog.tsx @@ -1,6 +1,6 @@ 'use client' -import { CSSProperties, useEffect, useState } from 'react' +import { CSSProperties, useEffect, useRef, useState } from 'react' import { closestCenter, DndContext, @@ -182,6 +182,7 @@ const ListHeaderManageDialog = ({ const [localRows, setLocalRows] = useState([]) const [activeId, setActiveId] = useState(null) const [submitting, setSubmitting] = useState(false) + const originalRowsRef = useRef([]) const resolvedOpen = open ?? isDialogOpen(dialogId) const sensors = useSensors( @@ -191,7 +192,9 @@ const ListHeaderManageDialog = ({ useEffect(() => { if (!resolvedOpen) return - setLocalRows([...rows].sort((a, b) => a.listHderOrder - b.listHderOrder).map((row) => ({ ...row }))) + const sorted = [...rows].sort((a, b) => a.listHderOrder - b.listHderOrder).map((row) => ({ ...row })) + setLocalRows(sorted) + originalRowsRef.current = sorted.map((row) => ({ ...row })) }, [resolvedOpen, rows]) const handleOpenChange = (nextOpen: boolean) => { @@ -294,6 +297,35 @@ const ListHeaderManageDialog = ({ } const handleConfirm = async () => { + const names = localRows.map((row) => row.listHderNm.trim()) + const duplicateNames = [...new Set(names.filter((name, index) => names.indexOf(name) !== index))] + if (duplicateNames.length > 0) { + alert(`중복된 헤더명이 있습니다: ${duplicateNames.join(', ')}`) + return + } + + const localById = new Map(localRows.map((row) => [row.listHderId, row])) + const renamedNames = originalRowsRef.current + .filter((row) => { + const current = localById.get(row.listHderId) + return current && current.listHderNm.trim() !== row.listHderNm.trim() + }) + .map((row) => row.listHderNm) + const deletedNames = originalRowsRef.current + .filter((row) => !localById.has(row.listHderId)) + .map((row) => row.listHderNm) + + if (renamedNames.length > 0 || deletedNames.length > 0) { + const messageLines = [ + '헤더명이 수정 되거나 헤더가 삭제되면 KON또는 KON-KIWI의 리스트 관련 하드코딩이 있다면 해당 문항에 문제가 생길 수 있습니다. 진행 하시겠습니까?\n', + ] + + if (renamedNames.length > 0) messageLines.push(`수정예정: ${renamedNames.join(', ')}`) + if (deletedNames.length > 0) messageLines.push(`삭제예정: ${deletedNames.join(', ')}`) + + if (!window.confirm(messageLines.join('\n'))) return + } + setSubmitting(true) try { const orderedRows = localRows.map((row, index) => ({ @@ -326,7 +358,8 @@ const ListHeaderManageDialog = ({ } > -
+
+ ⚠️ 헤더명이 수정 되거나 헤더가 삭제되면 KON또는 KON-KIWI의 리스트 관련 하드코딩에 영향이 있을 수 있습니다. - diff --git a/src/lib/http-server.ts b/src/lib/http-server.ts index 2bba369..7700daf 100644 --- a/src/lib/http-server.ts +++ b/src/lib/http-server.ts @@ -20,6 +20,14 @@ export const createContactApi = () => { return createServerApi(serverEnv.API_CONTACT_SERVER); }; +// KON/KON-KIWI 등 쿠키 세션이 없는 외부 시스템이 X-API-Key로 호출하는 경우 사용. +// 받은 X-API-Key를 backend로 그대로 전달한다. +export const createContactApiWithApiKey = (apiKey: string) => { + return createServerApi(serverEnv.API_CONTACT_SERVER, { + "X-API-Key": apiKey, + }); +}; + //Todo: Front에서 바로 붙지 말고 Backend를 통해서 처리 하도록 수정 필요 export const createNotihubApi = () => { return createServerApi(serverEnv.API_NOTIHUB_SERVER); diff --git a/src/types/list.ts b/src/types/list.ts index 2b1c189..bd21367 100644 --- a/src/types/list.ts +++ b/src/types/list.ts @@ -367,3 +367,9 @@ export type ListSearchWithFullResult = ListSearchWithResult & { mailSendResult: ListSendResult; smsSendResult?: ListSendResult; }; + +export type ListSearchExternal = { + prjctIdx: number; + sid: string; + itemList: Record; +};