261102_04_ENH: 설문현황 KON·KIWI 바로가기를 환경별 KART 프로젝트 URL로 변경

This commit is contained in:
2026-11-02 16:07:03 +09:00
parent 475204b12b
commit 5a82fe6396
8 changed files with 26 additions and 96 deletions

View File

@@ -1,19 +1,18 @@
'use client'
import { useEffect, useRef, useState } from "react";
import { useMounted } from "@kri/common/hooks";
import AppPageTitle from "@/components/app-shell/AppPageTitle";
import { LoadingOverlayAdapter } from "@/components/app-shell/LoadingOverlayAdapter";
import { Button } from "@/components/ui/button";
import { useSelectedProject } from "@/hooks/useSelectedProject";
import { useProjectInfoQuery, useSurveyRedirectUrlQuery } from "@/query/project";
import { useProjectInfoQuery } from "@/query/project";
import { clientEnv } from "@/lib/env.client";
import { SurveyType } from "@/types/project";
import { SURVEY_TYPE_LABEL } from "@/const/projectConst";
const SurveyProgressPage = () => {
const mounted = useMounted();
const { selectedProject } = useSelectedProject();
const openedForRef = useRef<string | null>(null);
const prjctIdx = selectedProject?.prjctIdx ?? 0;
const enabled = mounted && prjctIdx > 0;
@@ -21,35 +20,7 @@ const SurveyProgressPage = () => {
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled);
const surveys = projectInfoQuery.data?.surveys ?? [];
const [activeSurveyIdx, setActiveSurveyIdx] = useState<number | null>(null);
const [openedUrl, setOpenedUrl] = useState<string | null>(null);
const selectedSurvey = surveys.find((s) => s.prjctSurveyIdx === activeSurveyIdx) ?? null;
const surveyTy = selectedSurvey?.surveyTy ?? SurveyType.NONE;
const isKonKiwi = surveyTy === SurveyType.KON || surveyTy === SurveyType.KIWI;
const isKiwi = surveyTy === SurveyType.KIWI ? 1 : 0;
const pkey = selectedSurvey?.surveyPrjctCd ?? "";
const redirectUrlEnabled = enabled && !!selectedSurvey && isKonKiwi && !!pkey;
const redirectUrlQuery = useSurveyRedirectUrlQuery(isKiwi, pkey, redirectUrlEnabled);
const targetUrl = !selectedSurvey
? null
: isKonKiwi
? (redirectUrlQuery.data ?? null)
: surveyTy === SurveyType.EXTERNAL
? (selectedSurvey.surveyDashboardUrl || null)
: null;
useEffect(() => {
if (!targetUrl || openedForRef.current === targetUrl) return;
openedForRef.current = targetUrl;
window.open(targetUrl, "_blank");
setOpenedUrl(targetUrl);
}, [targetUrl]);
const isLoading = !mounted || projectInfoQuery.isLoading || (redirectUrlEnabled && redirectUrlQuery.isLoading);
const isLoading = !mounted || projectInfoQuery.isLoading;
if (isLoading) return <LoadingOverlayAdapter force />;
@@ -62,7 +33,14 @@ const SurveyProgressPage = () => {
) : (
<div className="max-w-[600px] space-y-2">
{surveys.map((survey) => {
const hasReport = survey.surveyTy !== SurveyType.NONE;
const isKonKiwi = survey.surveyTy === SurveyType.KON || survey.surveyTy === SurveyType.KIWI;
let targetUrl: string | null = null;
if (isKonKiwi && survey.surveyPrjctCd) {
const projectType = survey.surveyTy === SurveyType.KIWI ? 1 : 0;
targetUrl = `${clientEnv.KART_URL}/Report/Current?projectType=${projectType}&pkey=${encodeURIComponent(survey.surveyPrjctCd)}`;
} else if (survey.surveyTy === SurveyType.EXTERNAL) {
targetUrl = survey.surveyDashboardUrl || null;
}
return (
<div
key={survey.prjctSurveyIdx ?? survey.surveyOrder}
@@ -72,37 +50,21 @@ const SurveyProgressPage = () => {
<p className="font-semibold">{survey.surveyName}</p>
<p className="text-xs text-muted-foreground">{SURVEY_TYPE_LABEL[survey.surveyTy]}</p>
</div>
<Button
type="button"
disabled={!hasReport}
onClick={() => setActiveSurveyIdx(survey.prjctSurveyIdx ?? null)}
>
바로가기
</Button>
{targetUrl ? (
<Button asChild>
<a href={targetUrl} target="_blank" rel="noopener noreferrer">
바로가기
</a>
</Button>
) : (
<Button type="button" disabled>바로가기</Button>
)}
</div>
);
})}
</div>
)}
{redirectUrlEnabled && redirectUrlQuery.isError ? (
<div role="alert" className="flex items-center gap-2 text-destructive">
<span>설문 현황 링크를 불러오지 못했습니다.</span>
<Button type="button" variant="outline" onClick={() => void redirectUrlQuery.refetch()}>
다시 시도
</Button>
</div>
) : null}
{openedUrl ? (
<p>
새 창에서 열립니다. 열리지 않았다면{" "}
<a href={openedUrl} target="_blank" rel="noreferrer" className="text-blue-600 underline">
여기
</a>
를 클릭해 주세요.
</p>
) : null}
</div>
);
};

View File

@@ -24,28 +24,6 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
return NextResponse.json(result, { status: 200 });
}
if(action === "survey-redirect-url" && slug.length === 3){
const [, isKiwi, pkey] = slug;
if (!["0", "1"].includes(isKiwi)) {
return NextResponse.json({ message: "프로젝트 정보를 확인해 주세요." }, { status: 400 });
}
// Contact backend를 거쳐 KON/KIWI 현황 공유 링크를 발급한다.
const result = await contactApi.post<unknown>(
`/kart/project/${isKiwi}/${encodeURIComponent(pkey)}/share`,
{},
{ expectText: true },
);
const shortUrl = typeof result === "string" && /^https?:\/\//.test(result)
? result
: null;
if (!shortUrl) {
return NextResponse.json({ message: "KART 공유 링크 응답을 확인해 주세요." }, { status: 502 });
}
return NextResponse.json(shortUrl, { status: 200 });
}
return NextResponse.json({ message: "Not found" }, { status: 404 });
} catch (error: unknown) {
return errorToResponse(error);