260723_01_ENH: 설문 URL 치환시 모든 헤더 정보에 대해서 치환 가능하게 수정

This commit is contained in:
2026-07-23 16:03:33 +09:00
parent 2dd5b88c6f
commit a7af497542
16 changed files with 36 additions and 200 deletions

View File

@@ -9,11 +9,12 @@ import { KriSingleSelect } from '@/components/common/KriAutoComplete'
import { useDialog } from '@/hooks/useDialog'
import { useDownloadListItemFileByHeaderMutation, useUploadListItemFileMutation } from '@/query/list'
import { ListHeaderConst } from '@/const/listConst'
import { LIST_IS_USE_LABEL } from '@/components/table-column/ListTableColumn'
import type { listHeader, ListSearchWithFullResult } from '@/types/list'
import type { MessageSendChannel } from '@/types/message'
import { type ProjectSurvey, type ResultCode, ResultCodeType } from '@/types/project'
import { formatKst } from '@kri/common'
import { isListFieldEditableForContact, isListFieldVisibleForContact } from '@/utils/listAccess'
import { isAssignHeaderType, isListFieldEditableForContact, isListFieldVisibleForContact } from '@/utils/listAccess'
import { substituteSurveyUrl } from '@/lib/surveyUrl'
import { formatKoreanPhoneNumber } from '@/utils/phone'
import SurveyQrDialog from '@/components/dialog/SurveyQrDialog'
@@ -41,17 +42,24 @@ export type ListContactInfoPanelProps = {
onSaved?: () => void
}
const resolveHeaderValue = (header: listHeader, detail?: ListSearchWithFullResult): string => {
if (header.listHderTy === ListHeaderConst.MEMO) return detail?.memo ?? ''
if (header.listHderTy === ListHeaderConst.IS_USE) {
return detail?.use != null ? (LIST_IS_USE_LABEL[detail.use] ?? '') : ''
}
if (isAssignHeaderType(header.listHderTy)) {
return detail?.assignList?.[header.listHderTy] ?? ''
}
return detail?.itemList?.[header.listHderId] ?? ''
}
export const buildInitialValues = (listHeaders: listHeader[], detail?: ListSearchWithFullResult) => {
const values: Record<number, string> = {}
for (const header of listHeaders) {
if (header.listHderTy === ListHeaderConst.SID) continue
if (!isListFieldVisibleForContact(header)) continue
if (header.listHderTy === ListHeaderConst.MEMO) {
values[header.listHderId] = detail?.memo ?? ''
continue
}
values[header.listHderId] = detail?.itemList?.[header.listHderId] ?? ''
values[header.listHderId] = resolveHeaderValue(header, detail)
}
return values
@@ -115,14 +123,22 @@ const ListContactInfoPanel = ({
const surveyResultByIdx = new Map((detail?.surveyResults ?? []).map((result) => [result.prjctSurveyIdx, result]))
// 설문 URL 치환은 화면 노출(면접원 노출) 여부와 무관하게 전체 헤더 값을 대상으로 한다.
const surveyUrlValues: Record<string, string> = {}
for (const header of listHeaders) {
if (header.listHderTy === ListHeaderConst.SID) continue
surveyUrlValues[header.listHderNm] = resolveHeaderValue(header, detail)
}
surveyUrlValues.SID = sid // 예약 토큰: 헤더명이 'SID'인 커스텀 헤더가 있어도 항상 실제 sid로 치환한다.
const handleStartSurvey = (survey: ProjectSurvey) => {
if (!survey.surveyUrl) return
window.open(substituteSurveyUrl(survey.surveyUrl, sid), '_blank', 'noopener,noreferrer')
window.open(substituteSurveyUrl(survey.surveyUrl, surveyUrlValues), '_blank', 'noopener,noreferrer')
}
const handleShowQr = (survey: ProjectSurvey) => {
if (!survey.surveyUrl) return
setQrTargetUrl(substituteSurveyUrl(survey.surveyUrl, sid))
setQrTargetUrl(substituteSurveyUrl(survey.surveyUrl, surveyUrlValues))
showDialog('surveyQrDialog')
}

View File

@@ -36,6 +36,7 @@ import { type ProjectSurvey, type ResultCode, ResultCodeType } from '@/types/pro
import {
applyListAccessFilter,
getLockedListFilterHeaderTypes,
isAssignHeaderType,
isListFilterVisibleByAccess,
isListHeaderVisibleByAccess,
} from '@/utils/listAccess'
@@ -127,11 +128,6 @@ const toFilterCondition = (row: FilterRow, usesListValue: boolean): Omit<ListOth
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.CONTAINS, values }
}
const isAssignHeaderType = (value: number): value is ListHeaderAssignType =>
value === ListHeaderAssignConst.OUTSOURCE ||
value === ListHeaderAssignConst.CONTACT_INTERVIEWER ||
value === ListHeaderAssignConst.FIELD_INTERVIEWER
const TEXT_LIKE_OPERATORS: FilterOperator[] = ['eq', 'neq', 'contains', 'notContains', 'empty', 'notEmpty']
const ASSIGN_LIKE_OPERATORS: FilterOperator[] = ['eq', 'neq', 'empty', 'notEmpty']
const IS_USE_OPERATORS: FilterOperator[] = ['eq', 'neq']

View File

@@ -1,3 +1,5 @@
// project.surveyUrl에 들어있는 [$SID] 치환 토큰을 실제 sid로 바꾼다.
// project.surveyUrl에 들어있는 [$SID], [$헤더명] 치환 토큰을 values에 있는 값으로 바꾼다.
// 값이 없는 토큰은 빈 문자열로 치환한다(URL에 인코딩되지 않은 대괄호가 남지 않도록).
// 참고: src/app/(pages)/(main)/project/info/page.tsx의 sidParam = 'sid=[$SID]'와 동일한 토큰.
export const substituteSurveyUrl = (surveyUrl: string, sid: string) => surveyUrl.replaceAll("[$SID]", sid);
export const substituteSurveyUrl = (surveyUrl: string, values: Record<string, string>) =>
surveyUrl.replace(/\[\$([^\]]+)\]/g, (_, key: string) => values[key] ?? "");

View File

@@ -1,8 +1,13 @@
import { ListHeaderAssignConst, ListHeaderConst } from "@/const/listConst";
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from "@/const/userConst";
import { ListIsUse, type ListFilter, type listHeader } from "@/types/list";
import { ListIsUse, type ListFilter, type listHeader, type ListHeaderAssignType } from "@/types/list";
import {isExternalManager, isFieldWorkUser, isInternalManager, isManager} from "@/utils/userRole";
export const isAssignHeaderType = (value: number): value is ListHeaderAssignType =>
value === ListHeaderAssignConst.OUTSOURCE ||
value === ListHeaderAssignConst.CONTACT_INTERVIEWER ||
value === ListHeaderAssignConst.FIELD_INTERVIEWER;
type ListAccessUser = {
userRole?: number | null;
userId?: string | null;