diff --git a/.env.development b/.env.development index 82c4f5a..8f818ca 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,9 @@ NEXT_PUBLIC_ENV=dev NEXT_PUBLIC_API_BASE=https://test-contact.kric.com/api +NEXT_PUBLIC_KART_URL=https://test-kart.kric.com ENV=dev CONTACT_SERVER=http://127.0.0.1:4001 API_CONTACT_SERVER=http://127.0.0.1:4001/api/v1 API_INTRANET_SERVER=https://intranet-ext.kric.com/api/v1 +AUTH_COOKIE_DOMAIN=kric.com diff --git a/.env.local b/.env.local index 8cacaa8..e1d2d30 100644 --- a/.env.local +++ b/.env.local @@ -1,7 +1,9 @@ NEXT_PUBLIC_ENV=local NEXT_PUBLIC_API_BASE=http://localhost:4000/api +NEXT_PUBLIC_KART_URL=https://test-kart.kric.com ENV=local CONTACT_SERVER=http://localhost:4001 API_CONTACT_SERVER=http://localhost:4001/api/v1 API_INTRANET_SERVER=https://intranet-ext.kric.com/api/v1 +AUTH_COOKIE_DOMAIN= \ No newline at end of file diff --git a/.env.production b/.env.production index d58e69e..b98909b 100644 --- a/.env.production +++ b/.env.production @@ -1,7 +1,9 @@ NEXT_PUBLIC_ENV=prod NEXT_PUBLIC_API_BASE=https://contact.kric.com/api +NEXT_PUBLIC_KART_URL=https://kart.kric.com ENV=prod CONTACT_SERVER=http://127.0.0.1:4001 API_CONTACT_SERVER=http://127.0.0.1:4001/api/v1 API_INTRANET_SERVER=https://intranet-ext.kric.com/api/v1 +AUTH_COOKIE_DOMAIN=kric.com diff --git a/AGENTS.md b/AGENTS.md index 294aaa2..667b1ed 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -229,6 +229,7 @@ When implementation is complete, report in Korean: - Treat the current React version, component style, state management, routing, styling, and test approach as authoritative. - Do not perform unrelated class-to-hook, JavaScript-to-TypeScript, state-library, styling-system, or React-to-Next.js migrations. - Keep components focused and follow the repository's established split between presentation, state, data access, and side effects. +- Do not use nested ternary expressions. Use clear `if`/`else` branches, early returns, or well-named intermediate variables instead; a single, non-nested ternary is acceptable only when it remains immediately readable. - Keep effects dependency-correct and clean up subscriptions, timers, listeners, and in-flight work where applicable. - Use stable semantic keys and preserve accessibility, loading, empty, error, disabled, and success states. - Preserve public component props and shared UI contracts unless a coordinated breaking change is explicitly approved. @@ -265,6 +266,35 @@ Before each related task, read the current contents of every matching reference, If a task spans multiple scopes, read every matching reference. Generated files under `.agent-harness/references/` are read-only copies; edit KriFrontCommon's `.agent/consumer.md` or `.agent/consumer-references/` and recompose instead. +## Noti-hub SMS Types + +- `MessageType.SMS = 21`, `LMS = 22`, `MMS = 23`; `ChannelType.SMS = 2` is unchanged. `SMS_TYPE_ARRAY` and `SmsType` include all three. +- `LMS_MMS = 22` remains a deprecated source-compatibility alias for LMS only. It does not represent MMS. Enum reverse lookup for 22 returns LMS. Use numeric bulk-list paths; the server no longer accepts LMS_MMS in paths. Numeric 21/22/23 bulk-list requests all return the entire SMS channel, not type-filtered lists. +- Requests retain their existing URLs/body shapes. The server chooses the actual type per recipient after substitution: attachment -> MMS; otherwise title or UTF-8 body >= 90 bytes -> LMS; otherwise SMS. +- Refresh templates from the save response (`tmplatTy`); display actual delivery types from `sendTy`, not the template or result code. A bulk can contain multiple SMS types. LMS/MMS share result codes; use existing server result labels. +- SMS, LMS, MMS and KKO use cancellation code 9998. Verify with `npm run typecheck`, `npm run build`, and `node --test tests/noti-hub-sms.test.mjs`. + +## Noti-hub Reservation Cancellation + +- Import cancellation types, constants, and helpers from `@kri/common/noti-hub` only. They are runtime-neutral and require no optional peers. +- Individual current cancellation state is determined by resultCode via isReserveCanceledResult; bulk current state is cancellationStatus (NONE/PARTIAL/ALL). These describe current cancellation state, not cancellation eligibility. cancelDt and cancelUser are request history, not current state. +- SendResultInfo, SendInfo, and BulkSendInfo expose optional cancelable. Use isSendCancelable(item), which returns true only for cancelable === true, for cancellation eligibility; missing values from older responses are treated as false. Never infer eligibility from cancelDt, result labels, or result codes. +- cancelable reflects query-time state and may change before cancellation. Determine the final outcome from SendCancelResponse counts. +- sendIdx is the single-cancel identifier, not cmid. It is absent from the latest abbreviated report (/api/v1/report/last/send/...). Request sendIdx must be a positive integer; bulkSendKey is required and at most 32 characters. +- EMAIL_RESERVE_CANCELED_RESULT_CODE is 108 for EMAIL. SMS_KKO_RESERVE_CANCELED_RESULT_CODE is 9998 for SMS, LMS, MMS, and KKO. Unknown message types are not recognized as canceled. +- Display the server's resultViewLabel/resultLabel ("예약 취소"). There is no separate result-code list API. +- HTTP 200 can contain notCancelableCount. parseSendCancelResponse validates nonnegative integer counts and targetCount = canceledCount + alreadyCanceledCount + notCancelableCount, throwing TypeError on invalid data. Bulk targetCount counts currently registered detail rows; response canceledCount counts only cancellations made by that request. +- Existing response fields are unchanged; all added fields on existing types are optional. Verify with npm run typecheck and npm run build. + +## HTTP Streaming + +- `@kri/common/http` HTTP clients expose streamGet/streamPost/streamPut/streamPatch/streamDel, returning HttpStreamResponse (status, statusText, headers, url, nullable body). +- Streaming shares ordinary authentication, URL, body and HTTP-error policy. Read body incrementally; no automatic JSON/NDJSON/SSE parsing or reconnect is performed. +- Streaming options accept an external AbortSignal. Caller cancellation raises AbortError without an HTTP error notification. Cancel the body when it will not be consumed. +- timeoutMs covers connection/headers (and an HTTP error body); idleTimeoutMs covers inactivity after successful headers and resets on consumed chunks. Both default to the client's defaultTimeoutMs (60 seconds by default), and 0 disables that timer for streaming only. +- Mid-stream transport/time-out errors reach the body reader. HTTP error statuses use existing HttpError handlers before a stream is returned. A 204 response has body=null. +- See HTTP_STREAMING.md for examples and node --test tests/http-stream.test.mjs for focused validation after npm run build. + ## KriUiRegistry Consumer Contract When implementing or changing frontend UI, use this order: @@ -274,6 +304,28 @@ When implementing or changing frontend UI, use this order: 3. Otherwise, prefer a suitable shadcn/ui component. 4. Create a custom component only when the preceding options cannot meet the requirement safely. +### KriAutoComplete Search Scroll + +- `kri-auto-complete` exposes `resetScrollOnSearch?: boolean` on `KriSingleSelect`, `KriMultiSelect`, and `MultiSelect`. It defaults to `false`, preserving existing behavior. +- When enabled, a search value change (including clearing it) resets the option list scroll to the top on the next animation frame in both `filter` and `inputOnly` modes. Async result updates alone do not trigger another reset. + +### KriAutoComplete Option Tooltip + +- `kri-auto-complete` exposes `optionTooltip?: 'singleLine' | 'wrap'` and `optionTooltipClassName?: string` on `KriSingleSelect`, `KriMultiSelect`, and `MultiSelect`. It is off by default, preserving existing behavior. +- When enabled, hovering an option shows its full `label` in a right-side tooltip. `singleLine` stays on one line until the available viewport width; `wrap` wraps at 28rem. The item depends on the shadcn `tooltip` component and provides its own `TooltipProvider`. + +### KriAutoComplete Search Match + +- `kri-auto-complete` exposes `searchMatch?: 'fuzzy' | 'contains'` on `KriSingleSelect`, `KriMultiSelect`, and `MultiSelect`. It defaults to `fuzzy` (cmdk's default subsequence scoring), preserving existing behavior. +- `contains` keeps only options whose label or value contains the search text as a case-insensitive substring, in the original option order. It applies only when `searchMode` is `filter`. + +### KriEditor SMS Preview + +- `changeSmsType` reports `SMS | LMS | MMS`. Update consumer callbacks to handle `MMS`; this widens the previous callback contract. +- Attachment presence (`smsHasAttachment`) takes priority and reports MMS. Otherwise a title or UTF-8 preview size >= `smsMaxBytes` (default 90) reports LMS; the remainder reports SMS. LMS/MMS share `lmsMaxBytes` (default 2000). +- UTF-8 byte counting includes `smsPreviewSuffix` and its separating newline, without storing the suffix in the body. +- This is a preview. Use the template-save response for saved `tmplatTy` and delivery-result `sendTy` for actual per-recipient type after server substitution. Registry updates require updating installed consumer copies. + ### Required Shared References Before each related task, read the current contents of every matching reference, even if it was read earlier in the session. diff --git a/src/app/(pages)/(main)/list/contact/page.tsx b/src/app/(pages)/(main)/list/contact/page.tsx index b62ba82..c33fd72 100644 --- a/src/app/(pages)/(main)/list/contact/page.tsx +++ b/src/app/(pages)/(main)/list/contact/page.tsx @@ -1,6 +1,6 @@ 'use client' -import { Suspense, useEffect, useMemo, useState } from "react"; +import { Suspense, useEffect, useMemo, useRef, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { ArrowLeft, RefreshCw } from "lucide-react"; import { useMounted } from "@kri/common/hooks"; @@ -37,6 +37,7 @@ const ListContactPageContent = () => { const userRole = auth?.user?.userRole ?? 0; const ctiCallPhase = useCtiCallPhase(); const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase); + const hasObservedCall = useRef(false); const queriesEnabled = mounted && prjctIdx > 0; const enabled = queriesEnabled && !!sid; @@ -74,10 +75,12 @@ const ListContactPageContent = () => { const hasGuardEntry = window.history.state?.[CALL_NAVIGATION_GUARD_KEY] === true; if (!shouldBlockNavigation) { - if (hasGuardEntry) window.history.back(); + if (hasGuardEntry && hasObservedCall.current) window.history.back(); + hasObservedCall.current = false; return; } + hasObservedCall.current = true; let isRestoringHistory = false; if (!hasGuardEntry) { diff --git a/src/app/(pages)/(main)/progress/survey/page.tsx b/src/app/(pages)/(main)/progress/survey/page.tsx index e7d4063..aaf1167 100644 --- a/src/app/(pages)/(main)/progress/survey/page.tsx +++ b/src/app/(pages)/(main)/progress/survey/page.tsx @@ -1,19 +1,18 @@ 'use client' -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 { useProjectInfoQuery } from "@/query/project"; +import { clientEnv } from "@/lib/env.client"; import { SurveyType } from "@/types/project"; import { SURVEY_TYPE_LABEL } from "@/const/projectConst"; const SurveyProgressPage = () => { const mounted = useMounted(); const { selectedProject } = useSelectedProject(); - const openedForRef = useRef(null); const prjctIdx = selectedProject?.prjctIdx ?? 0; const enabled = mounted && prjctIdx > 0; @@ -21,35 +20,7 @@ const SurveyProgressPage = () => { const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled); const surveys = projectInfoQuery.data?.surveys ?? []; - const [activeSurveyIdx, setActiveSurveyIdx] = useState(null); - const [openedUrl, setOpenedUrl] = useState(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 = selectedSurvey?.surveyPrjctCd ?? ""; - - const redirectUrlEnabled = enabled && !!selectedSurvey && isKonKiwi && !!pkey; - const redirectUrlQuery = useSurveyRedirectUrlQuery(isKiwi, pkey, redirectUrlEnabled); - - const targetUrl = !selectedSurvey - ? null - : isKonKiwi - ? (redirectUrlQuery.data ?? null) - : surveyTy === SurveyType.EXTERNAL - ? (selectedSurvey.surveyDashboardUrl || null) - : null; - - useEffect(() => { - if (!targetUrl || openedForRef.current === targetUrl) return; - openedForRef.current = targetUrl; - window.open(targetUrl, "_blank"); - setOpenedUrl(targetUrl); - }, [targetUrl]); - - const isLoading = !mounted || projectInfoQuery.isLoading || (redirectUrlEnabled && redirectUrlQuery.isLoading); + const isLoading = !mounted || projectInfoQuery.isLoading; if (isLoading) return ; @@ -62,7 +33,14 @@ const SurveyProgressPage = () => { ) : (
{surveys.map((survey) => { - const hasReport = survey.surveyTy !== SurveyType.NONE; + const isKonKiwi = survey.surveyTy === SurveyType.KON || survey.surveyTy === SurveyType.KIWI; + let targetUrl: string | null = null; + if (isKonKiwi && survey.surveyPrjctCd) { + const projectType = survey.surveyTy === SurveyType.KIWI ? 1 : 0; + targetUrl = `${clientEnv.KART_URL}/Report/Current?projectType=${projectType}&pkey=${encodeURIComponent(survey.surveyPrjctCd)}`; + } else if (survey.surveyTy === SurveyType.EXTERNAL) { + targetUrl = survey.surveyDashboardUrl || null; + } return (
{

{survey.surveyName}

{SURVEY_TYPE_LABEL[survey.surveyTy]}

- + {targetUrl ? ( + + ) : ( + + )}
); })} )} - {redirectUrlEnabled && redirectUrlQuery.isError ? ( -
- 설문 현황 링크를 불러오지 못했습니다. - -
- ) : null} - - {openedUrl ? ( -

- 새 창에서 열립니다. 열리지 않았다면{" "} - - 여기 - - 를 클릭해 주세요. -

- ) : null} ); }; diff --git a/src/app/api/kart/[[...slug]]/route.ts b/src/app/api/kart/[[...slug]]/route.ts index 5cb7db0..0360160 100644 --- a/src/app/api/kart/[[...slug]]/route.ts +++ b/src/app/api/kart/[[...slug]]/route.ts @@ -24,28 +24,6 @@ export const GET = async (req: NextRequest, context: RouteContext) => { return NextResponse.json(result, { status: 200 }); } - if(action === "survey-redirect-url" && slug.length === 3){ - const [, isKiwi, pkey] = slug; - if (!["0", "1"].includes(isKiwi)) { - return NextResponse.json({ message: "프로젝트 정보를 확인해 주세요." }, { status: 400 }); - } - - // Contact backend를 거쳐 KON/KIWI 현황 공유 링크를 발급한다. - const result = await contactApi.post( - `/kart/project/${isKiwi}/${encodeURIComponent(pkey)}/share`, - {}, - { expectText: true }, - ); - const shortUrl = typeof result === "string" && /^https?:\/\//.test(result) - ? result - : null; - if (!shortUrl) { - return NextResponse.json({ message: "KART 공유 링크 응답을 확인해 주세요." }, { status: 502 }); - } - - return NextResponse.json(shortUrl, { status: 200 }); - } - return NextResponse.json({ message: "Not found" }, { status: 404 }); } catch (error: unknown) { return errorToResponse(error); diff --git a/src/app/api/login/route.ts b/src/app/api/login/route.ts index 9ae3703..a90d4df 100644 --- a/src/app/api/login/route.ts +++ b/src/app/api/login/route.ts @@ -1,9 +1,8 @@ import { NextRequest, NextResponse } from "next/server"; import type { LoginRequest, LoginUser } from "@kri/common"; -import {serverEnv} from "@/lib/env.server"; +import {setAuthCookie} from "@/lib/auth-cookie"; import {createContactApi} from "@/lib/http-server"; import {errorToResponse} from "@kri/common/http"; -import {CookieKeys} from "@/store/cookie/cookie-keys"; //?ㅼ젣 Backend type LoginResponse = { @@ -19,13 +18,7 @@ export const POST = async (req: NextRequest) => { const result = await contactApi.post("/auth/login", body); const res = NextResponse.json(result.user, { status: 200 }); - res.cookies.set(CookieKeys.AuthToken, result.accessToken, { - httpOnly: true, - secure: serverEnv.ENV === "prod", - sameSite: "lax", - path: "/", - maxAge: 24 * 60 * 60, // 24?쒓컙 - }); + setAuthCookie(res, result.accessToken); return res; } catch (error : unknown) { diff --git a/src/app/api/logout/[[...slug]]/route.ts b/src/app/api/logout/[[...slug]]/route.ts index 43a8067..dc1b58c 100644 --- a/src/app/api/logout/[[...slug]]/route.ts +++ b/src/app/api/logout/[[...slug]]/route.ts @@ -1,9 +1,8 @@ import { NextRequest, NextResponse } from "next/server"; -import {serverEnv} from "@/lib/env.server"; +import {setAuthCookie} from "@/lib/auth-cookie"; import {createContactApi} from "@/lib/http-server"; import {errorToResponse} from "@kri/common/http"; import {RouteContext} from "@/types/common"; -import {CookieKeys} from "@/store/cookie/cookie-keys"; export async function POST( _req: NextRequest, @@ -22,13 +21,7 @@ export async function POST( await contactApi.post(url); const res = NextResponse.json({ ok: true }); - res.cookies.set(CookieKeys.AuthToken, "", { - httpOnly: true, - secure: serverEnv.ENV === "prod", - sameSite: "lax", - path: "/", - maxAge: 0, - }); + setAuthCookie(res, ""); return res; } catch (error: unknown) { diff --git a/src/components/list-contact/ListContactInfoPanel.tsx b/src/components/list-contact/ListContactInfoPanel.tsx index 1144b6c..edebfd5 100644 --- a/src/components/list-contact/ListContactInfoPanel.tsx +++ b/src/components/list-contact/ListContactInfoPanel.tsx @@ -63,15 +63,17 @@ const disabledContrastClass = 'bg-white disabled:opacity-100 disabled:text-foreg // disabled는 공용 Input 컴포넌트의 disabled:pointer-events-none 때문에 마우스 이벤트 자체를 못 받는다. const readOnlyContrastClass = 'bg-white read-only:text-foreground read-only:bg-muted/60' -const getCallButtonLabel = (isDialing: boolean, isOnCall: boolean) => { +const getCallButtonLabel = (isDialing: boolean, isOnCall: boolean, isEnding: boolean) => { + if (isEnding) return '종료 요청 중' if (isDialing) return '거는 중' if (isOnCall) return '전화 끊기' return '전화' } -const getCallButtonTitle = (isCtiReady: boolean, isDialing: boolean) => { +const getCallButtonTitle = (isCtiReady: boolean, isDialing: boolean, isEnding: boolean) => { if (!isCtiReady) return '전화 시스템에 연결되어 있지 않습니다.' if (isDialing) return '전화를 거는 중입니다.' + if (isEnding) return '통화 종료를 확인하고 있습니다.' return undefined } @@ -115,7 +117,8 @@ const ListContactInfoPanel = ({ const isCtiReady = ctiConnectionStatus === 'open' const ctiCallPhase = useCtiCallPhase() const isDialing = ctiCallPhase === 'dialing' - const isOnCall = ctiCallPhase === 'active' + const isEnding = ctiCallPhase === 'ending' + const isOnCall = ctiCallPhase === 'active' || isEnding const visibleHeaders = listHeaders .filter((header) => isListFieldVisibleForContact(header)) @@ -148,8 +151,7 @@ const ListContactInfoPanel = ({ } const handleCall = (telNum: string, listHderId: number) => { - if (!isCtiReady || isDialing) return - // CTI_HANGUP_PENDING_VENDOR: 외주사 Hangup 명령 동작 확인 후 통화 중 버튼을 활성화하면 즉시 사용할 수 있다. + if (!isCtiReady || isDialing || isEnding) return if (isOnCall) { ctiClient.hangup() return @@ -229,12 +231,12 @@ const ListContactInfoPanel = ({ type="button" variant="outline" className={cn('shrink-0 gap-2', isOnCall && 'bg-accent text-accent-foreground')} - disabled={isEditing || !isCtiReady || isDialing} - title={getCallButtonTitle(isCtiReady, isDialing)} + disabled={isEditing || !isCtiReady || isDialing || isEnding} + title={getCallButtonTitle(isCtiReady, isDialing, isEnding)} onClick={() => handleCall(value, header.listHderId)} > - {getCallButtonLabel(isDialing, isOnCall)} + {getCallButtonLabel(isDialing, isOnCall, isEnding)}