Files
contact-front/src/app/(pages)/(main)/progress/survey/page.tsx

73 lines
2.7 KiB
TypeScript

'use client'
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 } 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 prjctIdx = selectedProject?.prjctIdx ?? 0;
const enabled = mounted && prjctIdx > 0;
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled);
const surveys = projectInfoQuery.data?.surveys ?? [];
const isLoading = !mounted || projectInfoQuery.isLoading;
if (isLoading) return <LoadingOverlayAdapter force />;
return (
<div className="space-y-6 text-sm">
<AppPageTitle titleText="설문 현황" />
{surveys.length === 0 ? (
<p className="text-muted-foreground">연결된 설문이 없습니다.</p>
) : (
<div className="max-w-[600px] space-y-2">
{surveys.map((survey) => {
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}
className="flex items-center justify-between rounded-lg border bg-white p-4"
>
<div>
<p className="font-semibold">{survey.surveyName}</p>
<p className="text-xs text-muted-foreground">{SURVEY_TYPE_LABEL[survey.surveyTy]}</p>
</div>
{targetUrl ? (
<Button asChild>
<a href={targetUrl} target="_blank" rel="noopener noreferrer">
바로가기
</a>
</Button>
) : (
<Button type="button" disabled>바로가기</Button>
)}
</div>
);
})}
</div>
)}
</div>
);
};
export default SurveyProgressPage;