260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -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<ProjectSurvey>) => void
|
||||
onRemove: (uiKey: string) => void
|
||||
}
|
||||
|
||||
const SurveyCard = ({ survey, index, itrntPrjctCd, userTeam, invalidField, onRegisterFieldRef, onChange, onRemove }: SurveyCardProps) => {
|
||||
const [externalTab, setExternalTab] = useState<ExternalTab>('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 (
|
||||
<div className="space-y-3 rounded-lg border p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-base font-semibold">설문 {index + 1}</p>
|
||||
<Button type="button" variant="ghost" size="icon-sm" onClick={() => onRemove(survey.uiKey)} aria-label="설문 삭제">
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">
|
||||
설문명<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
ref={onRegisterFieldRef(survey.uiKey, 'surveyName')}
|
||||
value={survey.surveyName}
|
||||
onChange={(e) => onChange(survey.uiKey, { surveyName: e.target.value })}
|
||||
placeholder="설문명을 입력하세요"
|
||||
className="h-9"
|
||||
aria-invalid={invalidField === 'surveyName'}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">설문 타입</Label>
|
||||
<RadioGroup value={String(survey.surveyTy)} onValueChange={handleTypeChange} className="flex h-9 items-center gap-4">
|
||||
{SURVEY_TYPE_ORDER.map((t) => {
|
||||
const id = `survey-${survey.uiKey}-${t}`
|
||||
return (
|
||||
<div key={t} className="flex items-center space-x-2">
|
||||
<RadioGroupItem value={String(t)} id={id} />
|
||||
<Label htmlFor={id} className="font-normal cursor-pointer text-base">
|
||||
{SURVEY_TYPE_LABEL[t]}
|
||||
</Label>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isKonKiwi && (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">{SURVEY_TYPE_LABEL[survey.surveyTy]} 프로젝트</Label>
|
||||
<KriSingleSelect
|
||||
items={surveyProjectArray}
|
||||
value={survey.surveyPrjctCd || ''}
|
||||
onChange={handleKartSelect}
|
||||
getValue={(item) => item.pkey}
|
||||
getLabel={(item) => `[${item.pkey}] ${item.title}`}
|
||||
searchMode={"inputOnly"}
|
||||
onSearchValueChange={setSurveyKeyword}
|
||||
placeholder="프로젝트를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">설문 URL</Label>
|
||||
<Input
|
||||
ref={onRegisterFieldRef(survey.uiKey, 'surveyUrl')}
|
||||
value={survey.surveyUrl || ''}
|
||||
onChange={(e) => onChange(survey.uiKey, {
|
||||
surveyUrl: e.target.value,
|
||||
surveyFullUrl: null,
|
||||
surveyShortUrl: null,
|
||||
})}
|
||||
placeholder="https://"
|
||||
className="h-9"
|
||||
aria-invalid={invalidField === 'surveyUrl'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{survey.surveyTy === SurveyType.EXTERNAL && (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">설문 대시보드 URL</Label>
|
||||
<Input
|
||||
ref={onRegisterFieldRef(survey.uiKey, 'surveyDashboardUrl')}
|
||||
value={survey.surveyDashboardUrl || ''}
|
||||
onChange={(e) => onChange(survey.uiKey, { surveyDashboardUrl: e.target.value })}
|
||||
placeholder="https://"
|
||||
className="h-9"
|
||||
aria-invalid={invalidField === 'surveyDashboardUrl'}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{survey.surveyTy === SurveyType.EXTERNAL && (
|
||||
<div className="space-y-2">
|
||||
<Tabs value={externalTab} onValueChange={(v) => setExternalTab(v as ExternalTab)} className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value="redirect">리다이렉트</TabsTrigger>
|
||||
<TabsTrigger value="api">API</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="redirect" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">리다이렉트 URL</div>
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">완료:</Label>
|
||||
<Input value={replaceParams(externalUrls.redirect.complete)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">스크린 아웃:</Label>
|
||||
<Input value={replaceParams(externalUrls.redirect.screen)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">쿼터 풀:</Label>
|
||||
<Input value={replaceParams(externalUrls.redirect.quota)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="api" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">API URL</div>
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">시작 API:</Label>
|
||||
<Input value={replaceParams(externalUrls.api.start)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">완료 API:</Label>
|
||||
<Input value={replaceParams(externalUrls.api.complete)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">스크린 API:</Label>
|
||||
<Input value={replaceParams(externalUrls.api.screen)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">쿼터 API:</Label>
|
||||
<Input value={replaceParams(externalUrls.api.quota)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">API Method는 Post를 사용하시면 됩니다.</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const ProjectInfoPage = () => {
|
||||
const router = useRouter();
|
||||
@@ -94,42 +339,38 @@ const ProjectInfoPage = () => {
|
||||
const {auth} = useAuth();
|
||||
|
||||
const [projectInfo, setProjectInfo] = useState<ProjectInfo>(defaultProjectInfo);
|
||||
const [surveyKeyword, setSurveyKeyword] = useState('');
|
||||
const debouncedKeyword = useDebouncedValue(surveyKeyword, 500);
|
||||
const [surveys, setSurveys] = useState<SurveyDraft[]>([]);
|
||||
|
||||
const [externalTab, setExternalTab] = useState<ExternalTab>('redirect')
|
||||
const sessionTempUrlsRef = useRef<Set<string>>(new Set());
|
||||
const initialProjectInfoRef = useRef<ProjectInfo | null>(null);
|
||||
const scenarioEditorCmdRef = useRef<KriEditorCommand | null>(null);
|
||||
|
||||
const [invalidField, setInvalidField] = useState<'prjctName' | null>(null);
|
||||
const [invalidSurveyField, setInvalidSurveyField] = useState<{ uiKey: string; field: SurveyInvalidField } | null>(null);
|
||||
const prjctNameRef = useRef<HTMLInputElement>(null);
|
||||
const surveyFieldRefs = useRef<Map<string, HTMLInputElement>>(new Map());
|
||||
|
||||
const registerSurveyFieldRef = useCallback(
|
||||
(uiKey: string, field: SurveyInvalidField) => (el: HTMLInputElement | null) => {
|
||||
const key = `${uiKey}:${field}`;
|
||||
if (el) surveyFieldRefs.current.set(key, el);
|
||||
else surveyFieldRefs.current.delete(key);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const userTeam = auth.user?.userTeam ?? "";
|
||||
const prjctIdx = selectedProject?.prjctIdx ?? 0;
|
||||
const enabled = mounted && prjctIdx > 0;
|
||||
|
||||
|
||||
const surveyTy = projectInfo.surveyTy ?? SurveyType.NONE;
|
||||
const isInternalSurvey = internalSurvey.has(surveyTy);
|
||||
const isKiwi = surveyTy === SurveyType.KON ? 0 : surveyTy === SurveyType.KIWI ? 1 : 0;
|
||||
|
||||
// 조회 쿼리들
|
||||
// 조회 쿼리들
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled);
|
||||
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled);
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled);
|
||||
const cmpnListQuery = useCmpnListQuery();
|
||||
const assignedCmpnQuery = useAssignedCmpnIdsQuery(prjctIdx, enabled);
|
||||
const callerTelNumListQuery = useCallerTelNumListQuery(mounted);
|
||||
|
||||
const kartEnabled =
|
||||
mounted &&
|
||||
!!projectInfo.itrntPrjctCd &&
|
||||
!!userTeam &&
|
||||
isInternalSurvey;
|
||||
|
||||
const kartProjectListQuery = useKartProjectListQuery({
|
||||
itrntPrjctCd: projectInfo.itrntPrjctCd,
|
||||
userTeam,
|
||||
isKiwi,
|
||||
keyword: debouncedKeyword,
|
||||
enabled: kartEnabled,
|
||||
});
|
||||
const groupCodeListQuery = useGroupCodeListQuery(mounted);
|
||||
|
||||
const updateMutation = useUpdateProjectMutation(prjctIdx);
|
||||
const deleteMutation = useDeleteProjectMutation(prjctIdx);
|
||||
@@ -147,17 +388,22 @@ const ProjectInfoPage = () => {
|
||||
}));
|
||||
}, [cmpnListQuery.data]);
|
||||
|
||||
|
||||
const surveyProjectArray = kartProjectListQuery.data ?? [];
|
||||
const callerTelNumArray = callerTelNumListQuery.data ?? [];
|
||||
|
||||
const deptArray = useMemo(() => {
|
||||
const groupCodeLabelMap = useMemo(
|
||||
() => new Map((groupCodeListQuery.data ?? []).map((g) => [g.groupCode, g.groupCodeLabel])),
|
||||
[groupCodeListQuery.data]
|
||||
);
|
||||
|
||||
const deptArray: MultiSelectOption[] = useMemo(() => {
|
||||
const teams = Array.from(new Set((users ?? []).map((u) => u.userTeam).filter(Boolean)));
|
||||
|
||||
if (!teams.includes("T900")) teams.push("T900"); // TFT
|
||||
|
||||
return teams.sort((a, b) => a.localeCompare(b, "ko"));
|
||||
}, [users]);
|
||||
return teams
|
||||
.sort((a, b) => a.localeCompare(b, "ko"))
|
||||
.map((code) => ({ value: code, label: groupCodeLabelMap.get(code) ?? code }));
|
||||
}, [users, groupCodeLabelMap]);
|
||||
|
||||
const fwArray: MultiSelectOption[] = useMemo(() => {
|
||||
return (users ?? [])
|
||||
@@ -169,6 +415,19 @@ const ProjectInfoPage = () => {
|
||||
setProjectInfo((prev) => ({...prev, [field]: value}))
|
||||
}
|
||||
|
||||
const handleAddSurvey = () => {
|
||||
setSurveys((prev) => [...prev, createSurveyDraft(prev.length + 1)])
|
||||
}
|
||||
|
||||
const handleRemoveSurvey = (uiKey: string) => {
|
||||
if (!confirm('삭제 후 저장하면 이 설문은 영구적으로 삭제됩니다. 삭제하시겠습니까?')) return
|
||||
setSurveys((prev) => prev.filter((s) => s.uiKey !== uiKey))
|
||||
}
|
||||
|
||||
const handleSurveyChange = (uiKey: string, patch: Partial<ProjectSurvey>) => {
|
||||
setSurveys((prev) => prev.map((s) => (s.uiKey === uiKey ? { ...s, ...patch } : s)))
|
||||
}
|
||||
|
||||
const handleImageUpload = useCallback(
|
||||
async (file: File): Promise<string> => {
|
||||
if (!projectInfo.prjctCd) {
|
||||
@@ -188,17 +447,98 @@ const ProjectInfoPage = () => {
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!projectInfo.prjctName) {
|
||||
alert('프로젝트명을 입력해주세요.')
|
||||
setInvalidField(null);
|
||||
setInvalidSurveyField(null);
|
||||
|
||||
const prjctNameCheck = validateValue(projectInfo.prjctName, {
|
||||
required: true,
|
||||
requiredMessage: '프로젝트명을 입력해주세요.',
|
||||
maxLength: 128,
|
||||
pattern: COMMON_TEXT_REGEX,
|
||||
patternMessage: '프로젝트명에 허용되지 않는 문자가 포함되어 있습니다.',
|
||||
});
|
||||
if (!prjctNameCheck.valid) {
|
||||
alert(prjctNameCheck.message)
|
||||
setInvalidField('prjctName')
|
||||
prjctNameRef.current?.focus()
|
||||
return
|
||||
}
|
||||
|
||||
for (const survey of surveys) {
|
||||
const label = survey.surveyName || `설문 ${survey.surveyOrder}`
|
||||
|
||||
const nameCheck = validateValue(survey.surveyName, {
|
||||
required: true,
|
||||
requiredMessage: `${label}: 설문명을 입력해주세요.`,
|
||||
maxLength: 32,
|
||||
pattern: COMMON_TEXT_REGEX,
|
||||
patternMessage: `${label}: 설문명에 허용되지 않는 문자가 포함되어 있습니다.`,
|
||||
})
|
||||
if (!nameCheck.valid) {
|
||||
alert(nameCheck.message)
|
||||
setInvalidSurveyField({ uiKey: survey.uiKey, field: 'surveyName' })
|
||||
surveyFieldRefs.current.get(`${survey.uiKey}:surveyName`)?.focus()
|
||||
return
|
||||
}
|
||||
|
||||
if (survey.surveyTy === SurveyType.KON || survey.surveyTy === SurveyType.KIWI) {
|
||||
if (!survey.surveyPrjctCd?.trim()) {
|
||||
alert(`${label}: 연동할 프로젝트를 선택해주세요.`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const urlCheck = validateValue(survey.surveyUrl ?? '', {
|
||||
required: true,
|
||||
requiredMessage: `${label}: 설문 URL을 입력해주세요.`,
|
||||
maxLength: 1024,
|
||||
pattern: COMMON_TEXT_REGEX,
|
||||
patternMessage: `${label}: 설문 URL에 허용되지 않는 문자가 포함되어 있습니다.`,
|
||||
})
|
||||
if (!urlCheck.valid) {
|
||||
alert(urlCheck.message)
|
||||
setInvalidSurveyField({ uiKey: survey.uiKey, field: 'surveyUrl' })
|
||||
surveyFieldRefs.current.get(`${survey.uiKey}:surveyUrl`)?.focus()
|
||||
return
|
||||
}
|
||||
|
||||
if (!isValidSurveyUrl(survey.surveyUrl ?? '')) {
|
||||
alert(`${label}: 올바른 HTTP(S) 설문 URL을 입력해 주세요.`)
|
||||
setInvalidSurveyField({ uiKey: survey.uiKey, field: 'surveyUrl' })
|
||||
surveyFieldRefs.current.get(`${survey.uiKey}:surveyUrl`)?.focus()
|
||||
return
|
||||
}
|
||||
|
||||
const dashCheck = validateValue(survey.surveyDashboardUrl ?? '', {
|
||||
maxLength: 1024,
|
||||
pattern: COMMON_TEXT_REGEX,
|
||||
patternMessage: `${label}: 설문 대시보드 URL에 허용되지 않는 문자가 포함되어 있습니다.`,
|
||||
})
|
||||
if (!dashCheck.valid) {
|
||||
alert(dashCheck.message)
|
||||
setInvalidSurveyField({ uiKey: survey.uiKey, field: 'surveyDashboardUrl' })
|
||||
surveyFieldRefs.current.get(`${survey.uiKey}:surveyDashboardUrl`)?.focus()
|
||||
return
|
||||
}
|
||||
|
||||
const dashboardUrl = survey.surveyDashboardUrl?.trim() ?? ''
|
||||
if (survey.surveyTy === SurveyType.EXTERNAL && dashboardUrl && !isValidHttpUrl(dashboardUrl)) {
|
||||
alert(`${label}: 올바른 HTTP(S) 설문 대시보드 URL을 입력해 주세요.`)
|
||||
setInvalidSurveyField({ uiKey: survey.uiKey, field: 'surveyDashboardUrl' })
|
||||
surveyFieldRefs.current.get(`${survey.uiKey}:surveyDashboardUrl`)?.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const updateCodeArray = structuredClone(
|
||||
resultCodeArray.filter((rc) => changeResultCodeType.includes(rc.resultCdTy))
|
||||
);
|
||||
|
||||
const requestUpdateProject: ProjectUpdateRequest = {
|
||||
projectInfo: projectInfo,
|
||||
projectInfo: {
|
||||
...projectInfo,
|
||||
surveys: surveys.map(({ uiKey, ...rest }) => rest),
|
||||
},
|
||||
resultCodeList: updateCodeArray,
|
||||
assignCmpnIdList: assignCmpnIdArray,
|
||||
}
|
||||
@@ -222,6 +562,7 @@ const ProjectInfoPage = () => {
|
||||
useEffect(() => {
|
||||
if (projectInfoQuery.data) {
|
||||
setProjectInfo(projectInfoQuery.data);
|
||||
setSurveys(projectInfoQuery.data.surveys.map((s) => ({ ...s, uiKey: crypto.randomUUID() })));
|
||||
initialProjectInfoRef.current = projectInfoQuery.data;
|
||||
}
|
||||
}, [projectInfoQuery.data]);
|
||||
@@ -238,52 +579,6 @@ const ProjectInfoPage = () => {
|
||||
}
|
||||
}, [assignedCmpnQuery.data]);
|
||||
|
||||
useEffect(() => {
|
||||
if (projectInfo.surveyTy !== SurveyType.EXTERNAL) {
|
||||
setExternalTab('redirect')
|
||||
}
|
||||
}, [projectInfo.surveyTy]);
|
||||
|
||||
// KON/KIWI 프로젝트 "선택"을 사용자가 직접 바꿨을 때만 surveyUrl을 자동 생성한다.
|
||||
// 저장된 프로젝트를 불러오는 경우(조회) 등에는 저장돼 있는 surveyUrl을 그대로 보여줘야 한다.
|
||||
const handleSurveyPrjctCdChange = (value: string) => {
|
||||
setProjectInfo((prev) => {
|
||||
const next = {...prev, surveyPrjctCd: value};
|
||||
|
||||
if (value && internalSurvey.has(prev.surveyTy || SurveyType.NONE)) {
|
||||
const pidParam = externalPidParamBase.replace('[$prjctIdx]', String(prev.prjctIdx));
|
||||
let surveyUrl = `/project/${value}/INDEX.asp?${pidParam}&${sidParam}`;
|
||||
if (prev.surveyTy === SurveyType.KON) {
|
||||
surveyUrl = `https://kon.kric.com` + surveyUrl
|
||||
} else if (prev.surveyTy === SurveyType.KIWI) {
|
||||
surveyUrl = `https://kon.kiwisurvey.kr` + surveyUrl
|
||||
}
|
||||
|
||||
next.surveyUrl = surveyUrl;
|
||||
}
|
||||
|
||||
return next;
|
||||
})
|
||||
}
|
||||
|
||||
// 설문 연동(surveyTy)을 바꾸면 선택된 KON/KIWI 프로젝트, 설문 URL, 설문 대시보드 URL을 초기화한다.
|
||||
// 단, 최초 조회 시점의 surveyTy로 다시 돌아오면 그때 저장돼 있던 값을 복원한다.
|
||||
const handleSurveyTyChange = (value: string) => {
|
||||
const nextSurveyTy = Number(value) as SurveyType;
|
||||
const initial = initialProjectInfoRef.current;
|
||||
const backToInitial = !!initial && initial.surveyTy === nextSurveyTy;
|
||||
|
||||
setProjectInfo((prev) => ({
|
||||
...prev,
|
||||
surveyTy: nextSurveyTy,
|
||||
surveyPrjctCd: backToInitial ? (initial!.surveyPrjctCd ?? '') : '',
|
||||
surveyUrl: backToInitial ? (initial!.surveyUrl ?? '') : '',
|
||||
surveyDashboardUrl: backToInitial ? (initial!.surveyDashboardUrl ?? '') : '',
|
||||
}))
|
||||
}
|
||||
|
||||
const replacePrjctIdx = (url: string) => url.replace('[$prjctIdx]', String(projectInfo.prjctIdx));
|
||||
|
||||
if (!mounted) return <LoadingOverlayAdapter force />
|
||||
|
||||
return (
|
||||
@@ -333,10 +628,12 @@ const ProjectInfoPage = () => {
|
||||
프로젝트 명<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
ref={prjctNameRef}
|
||||
value={projectInfo.prjctName || ''}
|
||||
onChange={(e) => handleChange('prjctName', e.target.value)}
|
||||
placeholder="프로젝트명을 입력하세요"
|
||||
className="h-9"
|
||||
aria-invalid={invalidField === 'prjctName'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -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 = () => {
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg p-6 space-y-4 bg-white mt-3">
|
||||
<h3 className="text-xl font-semibold">설문 연동</h3>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-xl font-semibold">설문 연동</h3>
|
||||
<Button type="button" variant="outline" onClick={handleAddSurvey}>
|
||||
설문 추가
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<RadioGroup
|
||||
value={String(projectInfo.surveyTy ?? SurveyType.NONE)}
|
||||
onValueChange={handleSurveyTyChange}
|
||||
className="flex gap-4"
|
||||
>
|
||||
{SURVEY_TYPE_ORDER.map((t) => {
|
||||
const id = `survey-${t}`; // 유니크 보장
|
||||
return (
|
||||
<div key={t} className="flex items-center space-x-2">
|
||||
<RadioGroupItem value={String(t)} id={id} />
|
||||
<Label htmlFor={id} className="font-normal cursor-pointer text-base">
|
||||
{SURVEY_TYPE_LABEL[t]}
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
|
||||
{(projectInfo.surveyTy === SurveyType.KON || projectInfo.surveyTy === SurveyType.KIWI) && (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">{SURVEY_TYPE_LABEL[projectInfo.surveyTy]} 프로젝트</Label>
|
||||
<KriSingleSelect
|
||||
items={surveyProjectArray}
|
||||
value={projectInfo.surveyPrjctCd || ''}
|
||||
onChange={handleSurveyPrjctCdChange}
|
||||
getValue={(item) => item.pkey}
|
||||
getLabel={(item) => `[${item.pkey}] ${item.title}`}
|
||||
searchMode={"inputOnly"}
|
||||
onSearchValueChange={setSurveyKeyword}
|
||||
placeholder="프로젝트를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{projectInfo.surveyTy !== SurveyType.NONE && (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">설문 URL</Label>
|
||||
<Input
|
||||
value={projectInfo.surveyUrl || ''}
|
||||
onChange={(e) => handleChange('surveyUrl', e.target.value)}
|
||||
placeholder="https://"
|
||||
className="h-9"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{projectInfo.surveyTy === SurveyType.EXTERNAL && (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-base">설문 대시보드 URL</Label>
|
||||
<Input
|
||||
value={projectInfo.surveyDashboardUrl || ''}
|
||||
onChange={(e) => handleChange('surveyDashboardUrl', e.target.value)}
|
||||
placeholder="https://"
|
||||
className="h-9"
|
||||
{surveys.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">연결된 설문이 없습니다. "설문 추가"로 등록해주세요.</p>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{surveys.map((survey, index) => (
|
||||
<SurveyCard
|
||||
key={survey.uiKey}
|
||||
survey={survey}
|
||||
index={index}
|
||||
itrntPrjctCd={projectInfo.itrntPrjctCd}
|
||||
userTeam={userTeam}
|
||||
invalidField={invalidSurveyField?.uiKey === survey.uiKey ? invalidSurveyField.field : null}
|
||||
onRegisterFieldRef={registerSurveyFieldRef}
|
||||
onChange={handleSurveyChange}
|
||||
onRemove={handleRemoveSurvey}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{projectInfo.surveyTy === SurveyType.EXTERNAL && (
|
||||
<div className="space-y-2">
|
||||
<Tabs value={externalTab} onValueChange={(v) => setExternalTab(v as ExternalTab)} className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value="redirect">리다이렉트</TabsTrigger>
|
||||
<TabsTrigger value="api">API</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="redirect" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">리다이렉트 URL</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">완료:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.redirect.complete)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">스크린 아웃:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.redirect.screen)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">쿼터 풀:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.redirect.quota)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="api" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">API URL</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">시작 API:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.api.start)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">완료 API:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.api.complete)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">스크린 API:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.api.screen)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 text-base">쿼터 API:</Label>
|
||||
<Input value={replacePrjctIdx(externalUrls.api.quota)} readOnly className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-muted-foreground">API Method는 Post를 사용하시면 됩니다.</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -549,11 +755,17 @@ const ProjectInfoPage = () => {
|
||||
|
||||
{projectInfo.useContactSenario && (
|
||||
<div className="ml-6 border rounded p-4 bg-gray-50 text-sm text-gray-600">
|
||||
<MessageVariableList
|
||||
listHeaders={listHeaderQuery.data ?? []}
|
||||
surveys={surveys}
|
||||
onInsert={(value) => scenarioEditorCmdRef.current?.insertText(value)}
|
||||
/>
|
||||
<KriEditor
|
||||
value={projectInfo.contactSenario ?? "<p></p>"}
|
||||
onChange={(html: string) => handleChange("contactSenario", html)}
|
||||
onCommandReady={(command) => { scenarioEditorCmdRef.current = command }}
|
||||
placeholder="컨택 시나리오를 작성해 주세요"
|
||||
className="w-full"
|
||||
className="mt-4 w-full"
|
||||
debounceMs={600} // 기본 400ms, 원하면 늘리세요(예: 600~1000)
|
||||
onImageUpload={async (file) => await handleImageUpload(file)} // 사용 시만
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user