261008_01_ENH: 알림톡 템플릿 관련내용 구현 및 발송 구현
This commit is contained in:
@@ -11,7 +11,7 @@ import { useSendResultBySidQuery } from '@/query/message'
|
||||
import { useInternalInfoQuery } from '@/query/internal'
|
||||
import { clientEnv } from '@/lib/env.client'
|
||||
import { ChannelType } from '@kri/common/noti-hub'
|
||||
import type { SendResultInfo } from '@/types/message'
|
||||
import type { SendResultInfo } from '@kri/common/noti-hub'
|
||||
import { formatKst } from '@kri/common'
|
||||
import { type ResultCode, ResultCodeType } from '@/types/project'
|
||||
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from '@/const/userConst'
|
||||
@@ -272,13 +272,14 @@ const SendResultTable = ({ isLoading, results }: { isLoading: boolean; results:
|
||||
}
|
||||
|
||||
const SendResultHistory = ({ sid, prjctCd }: { sid: string; prjctCd: string }) => {
|
||||
const [tab, setTab] = useState<'email' | 'sms'>('email')
|
||||
const [tab, setTab] = useState<'email' | 'sms' | 'kko'>('email')
|
||||
|
||||
const emailQuery = useSendResultBySidQuery(sid, prjctCd, clientEnv.REQUEST_SVC, ChannelType.EMAIL, tab === 'email')
|
||||
const smsQuery = useSendResultBySidQuery(sid, prjctCd, clientEnv.REQUEST_SVC, ChannelType.SMS, tab === 'sms')
|
||||
const activeQuery = tab === 'email' ? emailQuery : smsQuery
|
||||
const kkoQuery = useSendResultBySidQuery(sid, prjctCd, clientEnv.REQUEST_SVC, ChannelType.KKO, tab === 'kko')
|
||||
const activeQuery = tab === 'email' ? emailQuery : tab === 'sms' ? smsQuery : kkoQuery
|
||||
|
||||
const handleTabClick = (e: React.MouseEvent, next: 'email' | 'sms') => {
|
||||
const handleTabClick = (e: React.MouseEvent, next: 'email' | 'sms' | 'kko') => {
|
||||
e.stopPropagation()
|
||||
setTab(next)
|
||||
}
|
||||
@@ -307,6 +308,14 @@ const SendResultHistory = ({ sid, prjctCd }: { sid: string; prjctCd: string }) =
|
||||
>
|
||||
문자
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={tab === 'kko' ? 'default' : 'outline'}
|
||||
onClick={(e) => handleTabClick(e, 'kko')}
|
||||
>
|
||||
알림톡
|
||||
</Button>
|
||||
<RefreshIconButton onRefresh={() => activeQuery.refetch()} isFetching={activeQuery.isFetching} />
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import { Mail, MessageSquare, Paperclip, Phone, QrCode } from 'lucide-react'
|
||||
import { Mail, MessageCircle, MessageSquare, Paperclip, Phone, QrCode } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -24,6 +24,7 @@ import { useCtiCallPhase } from '@/hooks/useCtiCallPhase'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { downloadFile } from '@kri/common/browser'
|
||||
import {
|
||||
buildKkoVariableValues,
|
||||
buildListContactVariableValues,
|
||||
resolveListHeaderValue,
|
||||
} from '@/components/list-contact/listContactVariables'
|
||||
@@ -126,6 +127,8 @@ const ListContactInfoPanel = ({
|
||||
const surveyResultByIdx = new Map((detail?.surveyResults ?? []).map((result) => [result.prjctSurveyIdx, result]))
|
||||
|
||||
const surveyUrlValues = buildListContactVariableValues(listHeaders, detail, sid)
|
||||
// 알림톡은 #{설문명}도 설문 URL로 치환한다. 문자·메일은 기존처럼 헤더 값만 쓴다.
|
||||
const kkoVariableValues = buildKkoVariableValues(surveyUrlValues, surveys)
|
||||
|
||||
const handleStartSurvey = (survey: ProjectSurvey) => {
|
||||
if (!survey.surveyUrl) return
|
||||
@@ -240,6 +243,16 @@ const ListContactInfoPanel = ({
|
||||
<MessageSquare className="h-4 w-4" />
|
||||
발송
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="shrink-0 gap-2"
|
||||
disabled={isEditing}
|
||||
onClick={() => handleSend('kko', header.listHderId)}
|
||||
>
|
||||
<MessageCircle className="h-4 w-4" />
|
||||
알림톡
|
||||
</Button>
|
||||
</div>
|
||||
{(isDialing || isOnCall) &&
|
||||
<p className="text-sm text-red-600 font-medium mt-1">
|
||||
@@ -383,7 +396,7 @@ const ListContactInfoPanel = ({
|
||||
itrntPrjctCd={itrntPrjctCd}
|
||||
sid={sid}
|
||||
destHeaderId={sendTarget?.headerId ?? 0}
|
||||
variableValues={surveyUrlValues}
|
||||
variableValues={sendTarget?.channel === 'kko' ? kkoVariableValues : surveyUrlValues}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { LIST_IS_USE_LABEL } from '@/components/table-column/ListTableColumn'
|
||||
import { ListHeaderConst } from '@/const/listConst'
|
||||
import type { listHeader, ListSearchWithFullResult } from '@/types/list'
|
||||
import type { ProjectSurvey } from '@/types/project'
|
||||
import { isAssignHeaderType } from '@/utils/listAccess'
|
||||
import { substituteVariables } from '@/lib/variableSubstitution'
|
||||
|
||||
export const resolveListHeaderValue = (
|
||||
header: listHeader,
|
||||
@@ -34,3 +36,21 @@ export const buildListContactVariableValues = (
|
||||
values.SID = sid
|
||||
return values
|
||||
}
|
||||
|
||||
// 알림톡 변수 값: 헤더 값에 더해 설문명(#{설문명})을 대상자 값으로 채운 설문 URL로 치환한다.
|
||||
// 같은 이름의 헤더가 있으면 헤더 값을 우선한다.
|
||||
export const buildKkoVariableValues = (
|
||||
headerValues: Record<string, string>,
|
||||
surveys: ProjectSurvey[],
|
||||
): Record<string, string> => {
|
||||
const values: Record<string, string> = { ...headerValues }
|
||||
|
||||
for (const survey of surveys) {
|
||||
const surveyName = survey.surveyName?.trim()
|
||||
const surveyUrl = survey.surveyUrl?.trim()
|
||||
if (!surveyName || !surveyUrl || surveyName in values) continue
|
||||
values[surveyName] = substituteVariables(surveyUrl, headerValues)
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user