-
+ return (
+
+
+
+ {surveys.length === 0 ? (
+
연결된 설문이 없습니다.
+ ) : (
+
+ {surveys.map((survey) => {
+ const hasReport = survey.surveyTy !== SurveyType.NONE;
+ return (
+
+
+
{survey.surveyName}
+
{SURVEY_TYPE_LABEL[survey.surveyTy]}
+
+
+
+ );
+ })}
+
+ )}
+
+ {openedUrl ? (
새 창에서 열립니다. 열리지 않았다면{" "}
-
+
여기
를 클릭해 주세요.
-
- );
- }
-
- return (
-
);
};
diff --git a/src/app/(pages)/(main)/project/info/page.tsx b/src/app/(pages)/(main)/project/info/page.tsx
index 0d74fac..58e86f4 100644
--- a/src/app/(pages)/(main)/project/info/page.tsx
+++ b/src/app/(pages)/(main)/project/info/page.tsx
@@ -13,8 +13,9 @@ import {useDialog} from '@/hooks/useDialog'
import ResultCodeDialog from '@/components/dialog/ResultCodeDialog'
import { useDebouncedValue, useMounted } from "@kri/common/hooks";
import { LoadingOverlayAdapter } from '@/components/app-shell/LoadingOverlayAdapter'
+import { X } from 'lucide-react'
import {
- ProjectInfo, ProjectUpdateRequest, ResultCode,
+ ProjectInfo, ProjectSurvey, ProjectUpdateRequest, ResultCode,
ProjectStatus, ResultCodeType, SurveyType
} from "@/types/project";
import {
@@ -25,10 +26,12 @@ import {
} from "@/const/projectConst";
import type { MultiSelectOption } from "@/components/common/KriAutoComplete";
import {FW_TEAM} from "@/const/userConst";
+import {COMMON_TEXT_REGEX} from "@/const/validationConst";
+import {validateValue} from "@/utils/validation";
import {useItrntUserList} from "@/hooks/useItrntUserList";
import {useSelectedProject} from "@/hooks/useSelectedProject";
import {useAuth} from "@/hooks/useAuth";
-import {KriEditor} from "@/components/kri-editor";
+import {KriEditor, type KriEditorCommand} from "@/components/kri-editor";
import {useRouter} from "next/navigation";
import {
useProjectInfoQuery,
@@ -39,8 +42,10 @@ import {
useUploadScenarioImageMutation, useKartProjectListQuery,
} from "@/query/project";
import { useCmpnListQuery } from "@/query/cmpn";
-import { useCallerTelNumListQuery } from "@/query/intranet";
+import { useCallerTelNumListQuery, useGroupCodeListQuery } from "@/query/intranet";
import { formatKoreanPhoneNumber } from "@/utils/phone";
+import { useListHeaderQuery } from "@/query/list";
+import { MessageVariableList } from "@/components/message-template/MessageVariableList";
const defaultProjectInfo: ProjectInfo = {
prjctIdx: 0,
@@ -51,10 +56,7 @@ const defaultProjectInfo: ProjectInfo = {
ownerDept: '',
ownerFw: '',
callerTelNum: '',
- surveyTy: SurveyType.NONE,
- surveyPrjctCd: '',
- surveyUrl: '',
- surveyDashboardUrl: '',
+ surveys: [],
ff: false,
useContactSenario: false,
contactSenario: '',
@@ -63,27 +65,270 @@ const defaultProjectInfo: ProjectInfo = {
}
type ExternalTab = 'redirect' | 'api'
+type SurveyDraft = ProjectSurvey & { uiKey: string }
const baseUrl = 'https://contact.kric.com'
const sidParam = 'sid=[$SID]'
-const externalPidParamBase = 'contact-pid=[$prjctIdx]'
-const internalPidParamBase = 'pid=[$prjctIdx]'
+const surveyIdxParam = 'psidx=[$prjctSurveyIdx]'
const externalUrls = {
redirect: {
- complete: `${baseUrl}/redirect/complete?${internalPidParamBase}&${sidParam}`,
- screen: `${baseUrl}/redirect/screen?${internalPidParamBase}&${sidParam}`,
- quota: `${baseUrl}/redirect/quota?${internalPidParamBase}&${sidParam}`,
+ complete: `${baseUrl}/redirect/complete?${surveyIdxParam}&${sidParam}`,
+ screen: `${baseUrl}/redirect/screen?${surveyIdxParam}&${sidParam}`,
+ quota: `${baseUrl}/redirect/quota?${surveyIdxParam}&${sidParam}`,
},
api: {
- start: `${baseUrl}/api/external/start?${internalPidParamBase}&${sidParam}`,
- complete: `${baseUrl}/api/external/complete?${internalPidParamBase}&${sidParam}`,
- screen: `${baseUrl}/api/external/screen?${internalPidParamBase}&${sidParam}`,
- quota: `${baseUrl}/api/external/quota?${internalPidParamBase}&${sidParam}`,
+ start: `${baseUrl}/api/external/start?${surveyIdxParam}&${sidParam}`,
+ complete: `${baseUrl}/api/external/complete?${surveyIdxParam}&${sidParam}`,
+ screen: `${baseUrl}/api/external/screen?${surveyIdxParam}&${sidParam}`,
+ quota: `${baseUrl}/api/external/quota?${surveyIdxParam}&${sidParam}`,
},
} as const
-const internalSurvey = new Set([SurveyType.KON, SurveyType.KIWI]);
+const buildKonKiwiSurveyUrl = (surveyTy: SurveyType) =>
+ surveyTy === SurveyType.KON ? 'https://[$KON-URL]?sid=[$SID]' : 'https://[$KIWI-URL]?sid=[$SID]'
+
+const isValidHttpUrl = (value: string) => {
+ try {
+ const url = new URL(value)
+ return url.protocol === 'http:' || url.protocol === 'https:'
+ } catch {
+ return false
+ }
+}
+
+const isValidSurveyUrl = (value: string) => {
+ const konToken = '[$KON-URL]'
+ const kiwiToken = '[$KIWI-URL]'
+ const hasKonToken = value.includes(konToken)
+ const hasKiwiToken = value.includes(kiwiToken)
+ if (hasKonToken && hasKiwiToken) return false
+
+ const placeholderHost = hasKonToken ? 'kon-url.invalid' : hasKiwiToken ? 'kiwi-url.invalid' : null
+ const normalized = placeholderHost
+ ? value.replace(hasKonToken ? konToken : kiwiToken, placeholderHost)
+ : value
+ if (normalized.includes(konToken) || normalized.includes(kiwiToken)) return false
+
+ if (!isValidHttpUrl(normalized)) return false
+ return placeholderHost === null || new URL(normalized).hostname === placeholderHost
+}
+
+const createSurveyDraft = (surveyOrder: number): SurveyDraft => ({
+ uiKey: crypto.randomUUID(),
+ prjctSurveyIdx: null,
+ surveyOrder,
+ surveyName: '',
+ surveyTy: SurveyType.KON,
+ surveyPrjctCd: '',
+ surveyUrl: '',
+ surveyFullUrl: null,
+ surveyShortUrl: null,
+ surveyDashboardUrl: '',
+})
+
+type SurveyInvalidField = 'surveyName' | 'surveyUrl' | 'surveyDashboardUrl'
+
+type SurveyCardProps = {
+ survey: SurveyDraft
+ index: number
+ itrntPrjctCd: string
+ userTeam: string
+ invalidField: SurveyInvalidField | null
+ onRegisterFieldRef: (uiKey: string, field: SurveyInvalidField) => (el: HTMLInputElement | null) => void
+ onChange: (uiKey: string, patch: Partial
) => void
+ onRemove: (uiKey: string) => void
+}
+
+const SurveyCard = ({ survey, index, itrntPrjctCd, userTeam, invalidField, onRegisterFieldRef, onChange, onRemove }: SurveyCardProps) => {
+ const [externalTab, setExternalTab] = useState('redirect')
+ const [surveyKeyword, setSurveyKeyword] = useState('')
+ const debouncedKeyword = useDebouncedValue(surveyKeyword, 500)
+
+ const isKonKiwi = survey.surveyTy === SurveyType.KON || survey.surveyTy === SurveyType.KIWI
+ const isKiwi = survey.surveyTy === SurveyType.KIWI ? 1 : 0
+ const kartEnabled = !!itrntPrjctCd && !!userTeam && isKonKiwi
+
+ const kartProjectListQuery = useKartProjectListQuery({
+ itrntPrjctCd,
+ userTeam,
+ isKiwi,
+ keyword: debouncedKeyword,
+ enabled: kartEnabled,
+ })
+ const surveyProjectArray = kartProjectListQuery.data ?? []
+
+ const replaceParams = (url: string) =>
+ survey.prjctSurveyIdx != null ? url.replace('[$prjctSurveyIdx]', String(survey.prjctSurveyIdx)) : url
+
+ const handleTypeChange = (value: string) => {
+ const nextTy = Number(value) as SurveyType
+ onChange(survey.uiKey, {
+ surveyTy: nextTy,
+ surveyPrjctCd: '',
+ surveyUrl: '',
+ surveyFullUrl: null,
+ surveyShortUrl: null,
+ surveyDashboardUrl: '',
+ })
+ }
+
+ const handleKartSelect = (value: string) => {
+ onChange(survey.uiKey, {
+ surveyPrjctCd: value,
+ surveyUrl: buildKonKiwiSurveyUrl(survey.surveyTy),
+ surveyFullUrl: null,
+ surveyShortUrl: null,
+ })
+ }
+
+ return (
+
+
+
설문 {index + 1}
+
+
+
+
+
+
+ onChange(survey.uiKey, { surveyName: e.target.value })}
+ placeholder="설문명을 입력하세요"
+ className="h-9"
+ aria-invalid={invalidField === 'surveyName'}
+ />
+
+
+
+
+ {SURVEY_TYPE_ORDER.map((t) => {
+ const id = `survey-${survey.uiKey}-${t}`
+ return (
+
+
+
+
+ )
+ })}
+
+
+
+
+ {isKonKiwi && (
+
+
+ item.pkey}
+ getLabel={(item) => `[${item.pkey}] ${item.title}`}
+ searchMode={"inputOnly"}
+ onSearchValueChange={setSurveyKeyword}
+ placeholder="프로젝트를 선택하세요"
+ heightClassName="h-9"
+ widthClassName="w-full"
+ />
+
+ )}
+
+
+
+ onChange(survey.uiKey, {
+ surveyUrl: e.target.value,
+ surveyFullUrl: null,
+ surveyShortUrl: null,
+ })}
+ placeholder="https://"
+ className="h-9"
+ aria-invalid={invalidField === 'surveyUrl'}
+ />
+
+
+ {survey.surveyTy === SurveyType.EXTERNAL && (
+
+
+ onChange(survey.uiKey, { surveyDashboardUrl: e.target.value })}
+ placeholder="https://"
+ className="h-9"
+ aria-invalid={invalidField === 'surveyDashboardUrl'}
+ />
+
+ )}
+
+ {survey.surveyTy === SurveyType.EXTERNAL && (
+
+
setExternalTab(v as ExternalTab)} className="w-full">
+
+ 리다이렉트
+ API
+
+
+
+
+
+
+
+
+
API URL
+
+
API Method는 Post를 사용하시면 됩니다.
+
+
+
+
+ )}
+
+ )
+}
const ProjectInfoPage = () => {
const router = useRouter();
@@ -94,42 +339,38 @@ const ProjectInfoPage = () => {
const {auth} = useAuth();
const [projectInfo, setProjectInfo] = useState(defaultProjectInfo);
- const [surveyKeyword, setSurveyKeyword] = useState('');
- const debouncedKeyword = useDebouncedValue(surveyKeyword, 500);
+ const [surveys, setSurveys] = useState([]);
- const [externalTab, setExternalTab] = useState('redirect')
const sessionTempUrlsRef = useRef>(new Set());
const initialProjectInfoRef = useRef(null);
+ const scenarioEditorCmdRef = useRef(null);
+
+ const [invalidField, setInvalidField] = useState<'prjctName' | null>(null);
+ const [invalidSurveyField, setInvalidSurveyField] = useState<{ uiKey: string; field: SurveyInvalidField } | null>(null);
+ const prjctNameRef = useRef(null);
+ const surveyFieldRefs = useRef
@@ -347,6 +644,8 @@ const ProjectInfoPage = () => {
items={deptArray}
value={projectInfo.ownerDept || ''}
onChange={(value) => handleChange('ownerDept', value)}
+ getValue={(item) => item.value}
+ getLabel={(item) => item.label}
placeholder="담당 그룹을 선택하세요"
heightClassName="h-9"
widthClassName="w-full"
@@ -400,124 +699,31 @@ const ProjectInfoPage = () => {