260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -11,7 +11,7 @@ import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
||||
import { AssignTargetList, useAssignTargetRows } from '@/components/assign/AssignTargetList'
|
||||
import { ListSearchTable } from '@/components/list/ListSearchTable'
|
||||
import { useResultCodesQuery } from '@/query/project'
|
||||
import { useProjectInfoQuery, useResultCodesQuery } from '@/query/project'
|
||||
import { useListHeaderQuery } from '@/query/list'
|
||||
import { useResetListAssignMutation, useUpsertListAssignMutation } from '@/query/assign'
|
||||
import { ListHeaderAssignConst, LIST_HEADER_TYPE_LABEL } from '@/const/listConst'
|
||||
@@ -42,14 +42,17 @@ const ListAssignPage = () => {
|
||||
const [assignFilterIds, setAssignFilterIds] = useState<string[]>([])
|
||||
const [transferResve, setTransferResve] = useState(false)
|
||||
const [currentListFilter, setCurrentListFilter] = useState<ListFilter>(() => createEmptyListFilter())
|
||||
const [filterSummary, setFilterSummary] = useState<string[]>([])
|
||||
|
||||
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled)
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
|
||||
const upsertListAssignMutation = useUpsertListAssignMutation(prjctIdx)
|
||||
const resetListAssignMutation = useResetListAssignMutation(prjctIdx)
|
||||
const assignTargetRows = useAssignTargetRows({ prjctIdx, enabled, assignType })
|
||||
|
||||
const resultCodeArray = useMemo<ResultCode[]>(() => resultCodesQuery.data ?? [], [resultCodesQuery.data])
|
||||
const surveyArray = useMemo(() => projectInfoQuery.data?.surveys ?? [], [projectInfoQuery.data])
|
||||
const listHeaders = useMemo<listHeader[]>(() => listHeaderQuery.data ?? [], [listHeaderQuery.data])
|
||||
|
||||
const handleTabChange = (value: string) => {
|
||||
@@ -91,12 +94,16 @@ const ListAssignPage = () => {
|
||||
return { type: assignType, values: assignFilterIds }
|
||||
}, [assignType, assignFilterIds])
|
||||
|
||||
const hasNoAppliedFilter = () => filterSummary.length === 0 && assignFilterIds.length === 0
|
||||
|
||||
const handleAssign = async () => {
|
||||
if (!selectedAssignId) {
|
||||
alert('배정할 대상을 선택해주세요.')
|
||||
return
|
||||
}
|
||||
|
||||
if (hasNoAppliedFilter() && !confirm('적용된 필터가 없습니다. 전체 리스트를 대상으로 진행 하시겠습니까?')) {
|
||||
return
|
||||
}
|
||||
|
||||
await upsertListAssignMutation.mutateAsync({
|
||||
assignId: selectedAssignId,
|
||||
@@ -110,6 +117,9 @@ const ListAssignPage = () => {
|
||||
}
|
||||
|
||||
const handleResetAssign = async () => {
|
||||
if (hasNoAppliedFilter() && !confirm('적용된 필터가 없습니다. 전체 리스트를 대상으로 진행 하시겠습니까?')) {
|
||||
return
|
||||
}
|
||||
if (!confirm('정말 배정을 초기화 하시겠습니까?')) return
|
||||
|
||||
await resetListAssignMutation.mutateAsync({
|
||||
@@ -151,9 +161,11 @@ const ListAssignPage = () => {
|
||||
userId={auth?.user?.userId ?? ''}
|
||||
userCmpn={auth?.user?.userCmpn ?? ''}
|
||||
resultCodes={resultCodeArray}
|
||||
surveys={surveyArray}
|
||||
listHeaders={listHeaders}
|
||||
selectMode="none"
|
||||
onCurrentFilterChange={setCurrentListFilter}
|
||||
onFilterSummaryChange={setFilterSummary}
|
||||
excludeFilterHeaderTypes={[assignType]}
|
||||
externalAssignFilter={externalAssignFilter}
|
||||
filterActions={
|
||||
|
||||
@@ -141,9 +141,7 @@ const ProjectAssignPage = () => {
|
||||
};
|
||||
|
||||
const {
|
||||
assignBase,
|
||||
assignView,
|
||||
ableBase,
|
||||
ableView,
|
||||
} = useMemo(() => {
|
||||
const roleVal = roleFilter?.value;
|
||||
@@ -168,9 +166,7 @@ const ProjectAssignPage = () => {
|
||||
const _ableView = kAble ? _ableBase0.filter((u) => kwFilter(u, kAble)) : _ableBase0;
|
||||
|
||||
return {
|
||||
assignBase: _assignBase,
|
||||
assignView: _assignView,
|
||||
ableBase: _ableBase0,
|
||||
ableView: _ableView,
|
||||
};
|
||||
}, [
|
||||
@@ -218,18 +214,21 @@ const ProjectAssignPage = () => {
|
||||
alert("저장되었습니다.");
|
||||
};
|
||||
|
||||
// 로그인 계정의 소속 회사를 기본 선택하되, 매치되는 게 없으면 자사(ownCmpn) 중 가장 상단 1개로 대체한다.
|
||||
useEffect(() => {
|
||||
const cmpn = auth.user?.userCmpn ?? "";
|
||||
const hasAuthCmpn = companyArray.some((company) => company.cmpnId === cmpn);
|
||||
|
||||
if (cmpn && hasAuthCmpn) {
|
||||
if (cmpn && companyArray.some((company) => company.cmpnId === cmpn)) {
|
||||
setCompanyFilter(cmpn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (companyFilter && !companyArray.some((company) => company.cmpnId === companyFilter)) {
|
||||
setCompanyFilter("");
|
||||
// 이미 유효한 값이 선택돼 있으면(사용자가 직접 고른 값 포함) 그대로 둔다.
|
||||
if (companyFilter && companyArray.some((company) => company.cmpnId === companyFilter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ownCmpn = companyArray.find((company) => company.ownCmpn);
|
||||
setCompanyFilter(ownCmpn?.cmpnId ?? "");
|
||||
}, [auth.user?.userCmpn, companyArray, companyFilter]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -331,7 +330,7 @@ const ProjectAssignPage = () => {
|
||||
/>
|
||||
</th>
|
||||
<th className="p-2 text-left text-base font-medium">
|
||||
배정된 {roleFilter?.label} ( {assignBase.length}명 )
|
||||
배정된 {roleFilter?.label} ( {assignView.length}명 )
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -424,7 +423,7 @@ const ProjectAssignPage = () => {
|
||||
/>
|
||||
</th>
|
||||
<th className="p-2 text-left text-base font-medium">
|
||||
배정 가능 {roleFilter?.label} ({ableBase.length}명 )
|
||||
배정 가능 {roleFilter?.label} ({ableView.length}명 )
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Suspense, useEffect, useMemo, useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { ArrowLeft, CalendarClock } from "lucide-react";
|
||||
import { ArrowLeft, CalendarClock, RefreshCw } from "lucide-react";
|
||||
import { useMounted } from "@kri/common/hooks";
|
||||
import { LoadingOverlayAdapter } from "@/components/app-shell/LoadingOverlayAdapter";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -93,7 +93,6 @@ const ListContactPageContent = () => {
|
||||
listDetailQuery.refetch();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert("저장 중 오류가 발생했습니다.");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,6 +107,17 @@ const ListContactPageContent = () => {
|
||||
</Button>
|
||||
<h1 className="text-2xl font-bold tracking-tight">컨택 진행</h1>
|
||||
<span className="text-2xl font-bold tracking-tight">SID: {sid}</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={listDetailQuery.isFetching}
|
||||
aria-label="리스트 정보 새로고침"
|
||||
title="리스트 정보 새로고침"
|
||||
onClick={() => listDetailQuery.refetch()}
|
||||
>
|
||||
<RefreshCw className={`h-4 w-4 ${listDetailQuery.isFetching ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('reservationListDialog')}>
|
||||
<CalendarClock className="h-4 w-4" />
|
||||
@@ -129,7 +139,7 @@ const ListContactPageContent = () => {
|
||||
isEditing={isEditing}
|
||||
listHeaders={listHeaders}
|
||||
detail={listDetailQuery.data}
|
||||
surveyUrl={projectInfoQuery.data?.surveyUrl}
|
||||
surveys={projectInfoQuery.data?.surveys ?? []}
|
||||
callerTelNum={projectInfoQuery.data?.callerTelNum}
|
||||
resultCodes={resultCodeArray}
|
||||
formValues={formValues}
|
||||
@@ -149,6 +159,7 @@ const ListContactPageContent = () => {
|
||||
userId={userId}
|
||||
userRole={userRole}
|
||||
resultCodes={resultCodeArray}
|
||||
useFF={projectInfoQuery.data?.ff ?? false}
|
||||
useContactSenario={projectInfoQuery.data?.useContactSenario ?? false}
|
||||
contactSenario={projectInfoQuery.data?.contactSenario}
|
||||
/>
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
useUpdateListHeaderMutation,
|
||||
useUploadListExcelMutation,
|
||||
} from '@/query/list'
|
||||
import { useResultCodesQuery } from '@/query/project'
|
||||
import { useProjectInfoQuery, useResultCodesQuery } from '@/query/project'
|
||||
import type { ListTableRow } from '@/components/table-column/ListTableColumn'
|
||||
import {
|
||||
createEmptyListFilter,
|
||||
@@ -69,7 +69,7 @@ const createEmptySearchUiState = (): ListSearchUiState => ({
|
||||
searchText: '',
|
||||
searchContactResult: [],
|
||||
searchInterviewResult: [],
|
||||
searchSurveyResult: [],
|
||||
surveyResultSelections: {},
|
||||
filterRows: [],
|
||||
sorting: [],
|
||||
})
|
||||
@@ -107,6 +107,7 @@ const ListManagePage = () => {
|
||||
const isInternal = isInternalManager(userRole);
|
||||
|
||||
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled)
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
|
||||
const uploadHistoryQuery = useListUploadHistoryQuery(prjctIdx, enabled)
|
||||
const downloadListExcelTemplateMutation = useDownloadListExcelTemplateMutation()
|
||||
@@ -120,6 +121,7 @@ const ListManagePage = () => {
|
||||
const downloadUploadHistoryFileMutation = useDownloadUploadHistoryFileMutation(prjctIdx)
|
||||
|
||||
const resultCodeArray = useMemo<ResultCode[]>(() => resultCodesQuery.data ?? [], [resultCodesQuery.data])
|
||||
const surveyArray = useMemo(() => projectInfoQuery.data?.surveys ?? [], [projectInfoQuery.data])
|
||||
const headerManageRows = useMemo<listHeader[]>(() => listHeaderQuery.data ?? [], [listHeaderQuery.data])
|
||||
|
||||
// 컨택 진행 화면에서 돌아왔을 때 1회만 복원하고, 재방문 시 다시 나타나지 않도록 즉시 지운다.
|
||||
@@ -280,6 +282,7 @@ const ListManagePage = () => {
|
||||
userId={userId}
|
||||
userCmpn={userCmpn}
|
||||
resultCodes={resultCodeArray}
|
||||
surveys={surveyArray}
|
||||
listHeaders={headerManageRows}
|
||||
enableBatchEdit={canManageList}
|
||||
refreshKey={listRefreshKey}
|
||||
|
||||
@@ -16,7 +16,6 @@ import {useAuth} from "@/hooks/useAuth";
|
||||
import type { MultiSelectOption } from "@/components/common/KriAutoComplete";
|
||||
import { useMounted } from "@kri/common/hooks";
|
||||
import { LoadingOverlayAdapter } from "@/components/app-shell/LoadingOverlayAdapter";
|
||||
import {DEFAULT_COMPANY_NAME} from "@/const/userConst";
|
||||
import {Upload} from "lucide-react";
|
||||
import {
|
||||
useRoleListQuery,
|
||||
@@ -160,7 +159,15 @@ const UserManagePage = () => {
|
||||
mounted &&
|
||||
isInternalManager(auth.user?.userRole)
|
||||
|
||||
const userCmpn = auth.user?.userCmpn ?? DEFAULT_COMPANY_NAME;
|
||||
// 로그인 계정의 소속 회사를 기본 선택하되, 회사 목록에 매치되는 게 없으면 자사(ownCmpn) 중 가장 상단 1개로 대체한다.
|
||||
const userCmpn = useMemo(() => {
|
||||
const currentCmpnId = auth.user?.userCmpn;
|
||||
const matched = userCmpnArray.find((c) => c.cmpnId === currentCmpnId);
|
||||
if (matched) return matched.cmpnId;
|
||||
|
||||
const fallback = userCmpnArray.find((c) => c.ownCmpn);
|
||||
return fallback?.cmpnId ?? currentCmpnId ?? '';
|
||||
}, [auth.user?.userCmpn, userCmpnArray]);
|
||||
|
||||
if (!mounted) return <LoadingOverlayAdapter force />;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import { LoadingOverlayAdapter } from "@/components/app-shell/LoadingOverlayAdap
|
||||
import {useItrntUserList} from "@/hooks/useItrntUserList";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {useCreateProjectMutation, useProjectListQuery, useProjectOwnerListQuery} from "@/query/project";
|
||||
import {useGroupCodeListQuery} from "@/query/intranet";
|
||||
import {PROJECT_STATUS_LABEL} from "@/const/projectConst";
|
||||
import {isManager} from "@/utils/userRole";
|
||||
|
||||
@@ -52,8 +53,21 @@ const MainPage = () => {
|
||||
|
||||
const enabled = mounted && !isLoading; // intranet user list 준비된 뒤에만 호출
|
||||
const ownerQuery = useProjectOwnerListQuery(enabled);
|
||||
const groupCodeListQuery = useGroupCodeListQuery(enabled);
|
||||
|
||||
const groupCodeLabelMap = useMemo(() => {
|
||||
return new Map((groupCodeListQuery.data ?? []).map((g) => [g.groupCode, g.groupCodeLabel]));
|
||||
}, [groupCodeListQuery.data]);
|
||||
|
||||
const deptArray = useMemo(() => {
|
||||
const ownerDeptList = ownerQuery.data?.ownerDeptList ?? [];
|
||||
|
||||
return ownerDeptList.map((code) => ({
|
||||
value: code,
|
||||
label: groupCodeLabelMap.get(code) ?? code,
|
||||
}));
|
||||
}, [ownerQuery.data?.ownerDeptList, groupCodeLabelMap]);
|
||||
|
||||
const deptArray = ownerQuery.data?.ownerDeptList ?? [];
|
||||
const fwArray = useMemo(() => {
|
||||
const ownerFwIDList = ownerQuery.data?.ownerFwList ?? [];
|
||||
|
||||
@@ -86,7 +100,7 @@ const MainPage = () => {
|
||||
const [searchDept, setSearchDept] = useState<string[]>([]);
|
||||
const [searchFw, setSearchFw] = useState<string[]>([]);
|
||||
|
||||
const columns = getProjectColumns(users);
|
||||
const columns = getProjectColumns(users, groupCodeLabelMap);
|
||||
const userId = auth.user?.userId ?? "";
|
||||
const userRole = auth.user?.userRole;
|
||||
|
||||
@@ -119,7 +133,6 @@ const MainPage = () => {
|
||||
itrntPrjctCd: projectInfo.itrntPrjctCd,
|
||||
ownerDept: projectInfo.ownerDept,
|
||||
ownerFw: projectInfo.ownerFw,
|
||||
surveyTy: projectInfo.surveyTy,
|
||||
ff: projectInfo.ff
|
||||
} as SelectedProject);
|
||||
|
||||
@@ -134,7 +147,6 @@ const MainPage = () => {
|
||||
itrntPrjctCd: projectInfo.itrntPrjctCd,
|
||||
ownerDept: projectInfo.ownerDept,
|
||||
ownerFw: projectInfo.ownerFw,
|
||||
surveyTy: projectInfo.surveyTy,
|
||||
ff: projectInfo.ff
|
||||
} as SelectedProject);
|
||||
|
||||
@@ -177,6 +189,8 @@ const MainPage = () => {
|
||||
items={deptArray}
|
||||
value={searchDept}
|
||||
onChange={setSearchDept}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="담당 그룹"
|
||||
widthClassName="w-60"
|
||||
heightClassName="h-9"
|
||||
|
||||
@@ -1,66 +1,99 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
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 { SurveyType } from "@/types/project";
|
||||
import { SURVEY_TYPE_LABEL } from "@/const/projectConst";
|
||||
|
||||
const SurveyProgressPage = () => {
|
||||
const mounted = useMounted();
|
||||
const { selectedProject } = useSelectedProject();
|
||||
const openedRef = useRef(false);
|
||||
const openedForRef = useRef<string | null>(null);
|
||||
|
||||
const prjctIdx = selectedProject?.prjctIdx ?? 0;
|
||||
const enabled = mounted && prjctIdx > 0;
|
||||
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled);
|
||||
const projectInfo = projectInfoQuery.data;
|
||||
const surveyTy = projectInfo?.surveyTy ?? SurveyType.NONE;
|
||||
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 = projectInfo?.surveyPrjctCd ?? "";
|
||||
const pkey = selectedSurvey?.surveyPrjctCd ?? "";
|
||||
|
||||
const redirectUrlEnabled = enabled && !!projectInfo && isKonKiwi && !!pkey;
|
||||
const redirectUrlEnabled = enabled && !!selectedSurvey && isKonKiwi && !!pkey;
|
||||
const redirectUrlQuery = useSurveyRedirectUrlQuery(isKiwi, pkey, redirectUrlEnabled);
|
||||
|
||||
const targetUrl = isKonKiwi
|
||||
? (redirectUrlQuery.data ?? null)
|
||||
: surveyTy === SurveyType.EXTERNAL
|
||||
? (projectInfo?.surveyDashboardUrl || null)
|
||||
: null;
|
||||
const targetUrl = !selectedSurvey
|
||||
? null
|
||||
: isKonKiwi
|
||||
? (redirectUrlQuery.data ?? null)
|
||||
: surveyTy === SurveyType.EXTERNAL
|
||||
? (selectedSurvey.surveyDashboardUrl || null)
|
||||
: null;
|
||||
|
||||
useEffect(() => {
|
||||
if (openedRef.current || !targetUrl) return;
|
||||
openedRef.current = true;
|
||||
if (!targetUrl || openedForRef.current === targetUrl) return;
|
||||
openedForRef.current = targetUrl;
|
||||
window.open(targetUrl, "_blank");
|
||||
setOpenedUrl(targetUrl);
|
||||
}, [targetUrl]);
|
||||
|
||||
const isLoading = !mounted || projectInfoQuery.isLoading || (redirectUrlEnabled && redirectUrlQuery.isLoading);
|
||||
|
||||
if (isLoading) return <LoadingOverlayAdapter force />;
|
||||
|
||||
if (targetUrl) {
|
||||
return (
|
||||
<div className="space-y-6 text-sm">
|
||||
<AppPageTitle titleText="설문 현황" />
|
||||
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 hasReport = survey.surveyTy !== SurveyType.NONE;
|
||||
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>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={!hasReport}
|
||||
onClick={() => setActiveSurveyIdx(survey.prjctSurveyIdx ?? null)}
|
||||
>
|
||||
바로가기
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{openedUrl ? (
|
||||
<p>
|
||||
새 창에서 열립니다. 열리지 않았다면{" "}
|
||||
<a href={targetUrl} target="_blank" rel="noreferrer" className="text-blue-600 underline">
|
||||
<a href={openedUrl} target="_blank" rel="noreferrer" className="text-blue-600 underline">
|
||||
여기
|
||||
</a>
|
||||
를 클릭해 주세요.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6 text-sm">
|
||||
<AppPageTitle titleText="연결 가능한 현황이 없습니다." />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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)} // 사용 시만
|
||||
/>
|
||||
|
||||
@@ -23,15 +23,15 @@ const LoginPage = () => {
|
||||
const passwordInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const tryLogin = async () => {
|
||||
if (!userId) return alert("Please enter ID.");
|
||||
if (!userPw) return alert("Please enter password.");
|
||||
if (!userId) return alert("아이디를 입력해주세요.");
|
||||
if (!userPw) return alert("비밀번호를 입력해주세요.");
|
||||
|
||||
setError(null);
|
||||
try {
|
||||
await loginMutation.mutateAsync({ userId, userPw });
|
||||
} catch (e) {
|
||||
const err = apiError(e, {
|
||||
fallbackMessage: "Login failed.",
|
||||
fallbackMessage: "로그인에 실패했습니다.",
|
||||
});
|
||||
if (err.status === 401 || err.status === 403) setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
else if (err.code === NONE_HTTP_ERROR) setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
@@ -100,7 +100,7 @@ const LoginPage = () => {
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
placeholder="password"
|
||||
placeholder="Password"
|
||||
value={userPw}
|
||||
onChange={(e) => setUserPw(e.currentTarget.value)}
|
||||
onKeyDown={handlePwKeyDown}
|
||||
|
||||
14
src/app/api/external/[[...slug]]/route.ts
vendored
14
src/app/api/external/[[...slug]]/route.ts
vendored
@@ -36,7 +36,7 @@ const toRequiredNumber = (value: string): number | null => {
|
||||
const buildExternalEventBody = (
|
||||
req: NextRequest,
|
||||
action: ExternalAction,
|
||||
prjctIdx: number,
|
||||
prjctSurveyIdx: number,
|
||||
sid: number,
|
||||
): ExternalEventBody => {
|
||||
const pathname = req.nextUrl.pathname;
|
||||
@@ -45,12 +45,12 @@ const buildExternalEventBody = (
|
||||
|
||||
return {
|
||||
action: actionCode,
|
||||
prjctIdx,
|
||||
prjctSurveyIdx,
|
||||
sid,
|
||||
meta: {
|
||||
entryType: getEntryTypeCode(h),
|
||||
action: actionCode,
|
||||
pid: String(prjctIdx),
|
||||
psidx: String(prjctSurveyIdx),
|
||||
sid: String(sid),
|
||||
remoteAddr: getHeader(h, "x-orig-ip") || getClientIp(req),
|
||||
uri: getHeader(h, "x-orig-uri") || pathname,
|
||||
@@ -74,14 +74,14 @@ const handleExternalEvent = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const prjctIdx = toRequiredNumber((searchParams.get("pid") ?? "").trim());
|
||||
const prjctSurveyIdx = toRequiredNumber((searchParams.get("psidx") ?? "").trim());
|
||||
const sid = toRequiredNumber((searchParams.get("sid") ?? "").trim());
|
||||
|
||||
if (!prjctIdx || !sid) {
|
||||
return NextResponse.json({ message: "pid와 sid는 필수입니다." }, { status: 400 });
|
||||
if (!prjctSurveyIdx || !sid) {
|
||||
return NextResponse.json({ message: "psidx, sid는 필수입니다." }, { status: 400 });
|
||||
}
|
||||
|
||||
const body = buildExternalEventBody(req, action, prjctIdx, sid);
|
||||
const body = buildExternalEventBody(req, action, prjctSurveyIdx, sid);
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
await contactApi.post(`/list-hist/survey`, body);
|
||||
|
||||
@@ -3,7 +3,7 @@ import {RouteContext} from "@/types/common";
|
||||
import {createIntranetApi} from "@/lib/http-server";
|
||||
import {CallerTelNumInfo, IntranetProjectSearchResponse} from "@/types/project";
|
||||
import {errorToResponse} from "@kri/common/http";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
import {GroupCodeInfo, ItrntUserInfo} from "@/types/user";
|
||||
|
||||
export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
@@ -34,6 +34,12 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "group-code-list"){
|
||||
const result = await itrntApi.get<GroupCodeInfo[]>(`/user/group-code-list`);
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
|
||||
@@ -2,6 +2,25 @@ import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createContactApi} from "@/lib/http-server";
|
||||
import {errorToResponse} from "@kri/common/http";
|
||||
import type {ListCallHistSession} from "@/types/list";
|
||||
|
||||
export const GET = async (_req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { slug = [] } = await context.params;
|
||||
const [action, agentSessionId] = slug;
|
||||
if (action !== "session" || !agentSessionId) {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const contactApi = await createContactApi();
|
||||
const result = await contactApi.get<ListCallHistSession>(
|
||||
`/list-call-hist/session/${encodeURIComponent(agentSessionId)}`,
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
|
||||
@@ -32,6 +32,17 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "item-file-download" && slug.length === 4) {
|
||||
const result = await contactApi.get<ArrayBuffer>(
|
||||
`/list/item-file/download/${slug[1]}/${slug[2]}/${slug[3]}`,
|
||||
{ expectBinary: true },
|
||||
);
|
||||
return new NextResponse(result, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/octet-stream" },
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
|
||||
Reference in New Issue
Block a user