260812_02_ENH:IP 기반 자리번호 조회 및 헤더 표시, 컨택에서 리스트 관리로 뒤로 가기 했을 경우 캐싱 제거
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import type { PaginationState } from '@tanstack/react-table'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { LoadingOverlayAdapter } from '@/components/app-shell/LoadingOverlayAdapter'
|
||||
import { useMounted } from "@kri/common/hooks";
|
||||
@@ -77,6 +78,7 @@ const createEmptySearchUiState = (): ListSearchUiState => ({
|
||||
|
||||
const ListManagePage = () => {
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const mounted = useMounted()
|
||||
const { auth } = useAuth()
|
||||
const { showDialog } = useDialog()
|
||||
@@ -139,6 +141,17 @@ const ListManagePage = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mounted, isSelectedProjectHydrated, restoreResolved])
|
||||
|
||||
// 브라우저 뒤로가기(popstate)는 Next.js가 이 페이지를 재마운트하지 않고 재사용할 수 있어
|
||||
// refetchOnMount만으로는 최신 데이터를 보장 못한다. popstate는 브라우저 네이티브 이벤트라
|
||||
// 재마운트 여부와 무관하게 항상 발생하므로, 여기서 명시적으로 무효화한다.
|
||||
useEffect(() => {
|
||||
const handlePopState = () => {
|
||||
void queryClient.invalidateQueries({ queryKey: ['list', 'search-filter'] })
|
||||
}
|
||||
window.addEventListener('popstate', handlePopState)
|
||||
return () => window.removeEventListener('popstate', handlePopState)
|
||||
}, [queryClient])
|
||||
|
||||
const restoredForThisProject = restoredVisit?.prjctIdx === prjctIdx ? restoredVisit : undefined
|
||||
|
||||
const selectedSidSet = useMemo(
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { KriHeader } from "@/components/layout/KriHeader";
|
||||
import type { TopMenuItem } from "@/config/menu.types";
|
||||
import type { LoginUser } from "@kri/common";
|
||||
import { useInternalInfoQuery } from "@/query/internal";
|
||||
|
||||
interface AppHeaderProps {
|
||||
isMain: boolean;
|
||||
@@ -40,6 +41,9 @@ export function AppHeader({
|
||||
increaseFontSize,
|
||||
onOpenReserveSearch,
|
||||
}: AppHeaderProps) {
|
||||
const internalInfoQuery = useInternalInfoQuery(!!userInfo);
|
||||
const seatNo = internalInfoQuery.data?.clientId ?? "";
|
||||
|
||||
return (
|
||||
<KriHeader
|
||||
logo={
|
||||
@@ -82,7 +86,10 @@ export function AppHeader({
|
||||
<Button variant="ghost" size="icon-lg" onClick={onOpenReserveSearch} title="예약 내역 조회">
|
||||
<CalendarClock className="size-6" />
|
||||
</Button>
|
||||
<span className="hidden text-sm text-gray-600 sm:inline">{userInfo?.userName || ""}</span>
|
||||
<span className="hidden text-sm text-gray-600 sm:inline">
|
||||
{userInfo?.userName || ""}
|
||||
{seatNo ? ` (${seatNo})` : ""}
|
||||
</span>
|
||||
<Button variant="ghost" size="sm" className="gap-2" onClick={() => onNavigate("/logout")}>
|
||||
<LogOut className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">로그아웃</span>
|
||||
|
||||
@@ -57,6 +57,9 @@ export const buildInitialValues = (listHeaders: listHeader[], detail?: ListSearc
|
||||
}
|
||||
|
||||
const disabledContrastClass = 'bg-white disabled:opacity-100 disabled:text-foreground disabled:bg-muted/60'
|
||||
// Input/textarea는 수정 불가 상태에서도 드래그 선택/복사가 가능해야 해서 disabled 대신 readOnly를 쓴다.
|
||||
// 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) => {
|
||||
if (isDialing) return '거는 중'
|
||||
@@ -189,9 +192,9 @@ const ListContactInfoPanel = ({
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
|
||||
<textarea
|
||||
className={`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed ${disabledContrastClass}`}
|
||||
className={`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${readOnlyContrastClass}`}
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
readOnly={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</FieldRow>
|
||||
@@ -204,9 +207,9 @@ const ListContactInfoPanel = ({
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={formatKoreanPhoneNumber(value)}
|
||||
disabled={!editable}
|
||||
readOnly={!editable}
|
||||
onChange={(e) => onChange(e.target.value.replace(/\D/g, ''))}
|
||||
className={disabledContrastClass}
|
||||
className={readOnlyContrastClass}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -245,9 +248,9 @@ const ListContactInfoPanel = ({
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
readOnly={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={disabledContrastClass}
|
||||
className={readOnlyContrastClass}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -327,9 +330,9 @@ const ListContactInfoPanel = ({
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
|
||||
<Input
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
readOnly={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={disabledContrastClass}
|
||||
className={readOnlyContrastClass}
|
||||
/>
|
||||
</FieldRow>
|
||||
)
|
||||
|
||||
@@ -1,24 +1,49 @@
|
||||
import {keepPreviousData, useQuery} from "@tanstack/react-query";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {internalApi} from "@/lib/http-client";
|
||||
import {InternalInfo} from "@/types/internal";
|
||||
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
||||
import { qk } from "@/query/key/keys";
|
||||
import { internalApi } from "@/lib/http-client";
|
||||
import { InternalInfo } from "@/types/internal";
|
||||
|
||||
const DEFAULT_INTERNAL_INFO: InternalInfo = {
|
||||
success: false,
|
||||
clientId: "",
|
||||
internalNo: "",
|
||||
externalNo: "",
|
||||
clientIp: "",
|
||||
};
|
||||
|
||||
function parseInternalInfo(value: unknown): InternalInfo {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new TypeError("Invalid internal API response.");
|
||||
}
|
||||
|
||||
const response = value as Record<string, unknown>;
|
||||
if (
|
||||
typeof response.success !== "boolean" ||
|
||||
typeof response.clientId !== "string" ||
|
||||
typeof response.internalNo !== "string" ||
|
||||
typeof response.externalNo !== "string" ||
|
||||
typeof response.clientIp !== "string"
|
||||
) {
|
||||
throw new TypeError("Invalid internal API response.");
|
||||
}
|
||||
|
||||
return {
|
||||
success: response.success,
|
||||
clientId: response.clientId,
|
||||
internalNo: response.internalNo,
|
||||
externalNo: response.externalNo,
|
||||
clientIp: response.clientIp,
|
||||
};
|
||||
}
|
||||
|
||||
export function useInternalInfoQuery(enabled?: boolean) {
|
||||
return useQuery({
|
||||
queryKey: qk.internalInfo(),
|
||||
queryFn: async (): Promise<InternalInfo> => {
|
||||
try {
|
||||
return await internalApi.get<InternalInfo>(
|
||||
`/new-contact-get-info.asp`,
|
||||
);
|
||||
} catch (error) {
|
||||
const response = await internalApi.get<unknown>(`/new-contact-api.asp`);
|
||||
return parseInternalInfo(response);
|
||||
} catch {
|
||||
//내부 정보 조회 실패
|
||||
return DEFAULT_INTERNAL_INFO;
|
||||
}
|
||||
@@ -28,4 +53,4 @@ export function useInternalInfoQuery(enabled?: boolean) {
|
||||
placeholderData: keepPreviousData, // 검색 중 빈 배열로 깜빡임 방지
|
||||
meta: { ignoreGlobalLoading: true }, // 원하면 전역 오버레이 제외(네가 이미 메타 방식 쓰고 있었지)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ export function useListSearchQuery(prjctIdx: number, request: ListSearchRequest,
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
// 다른 탭/창에 갔다가 이 탭으로 돌아왔을 때(컨택 진행 화면을 새 탭으로 열어 작업한 경우 등) 최신 결과를 보여주기 위함.
|
||||
refetchOnWindowFocus: true,
|
||||
placeholderData: keepPreviousData,
|
||||
meta: { ignoreGlobalLoading: false },
|
||||
});
|
||||
@@ -149,7 +151,10 @@ export function useUploadListItemFileMutation(prjctIdx: number, sid: string) {
|
||||
return nextApi.postForm<void>(`/list/item-file-upload/${prjctIdx}/${encodeURIComponent(sid)}`, formData);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: qk.listDetail(prjctIdx, sid) });
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: qk.listDetail(prjctIdx, sid) }),
|
||||
queryClient.invalidateQueries({ queryKey: ["list", "search-filter"] }),
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -247,6 +252,7 @@ export function useAddListEventMutation(prjctIdx: number, sid: string) {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: qk.listDetail(prjctIdx, sid) }),
|
||||
queryClient.invalidateQueries({ queryKey: qk.listEventHistory(prjctIdx, sid) }),
|
||||
queryClient.invalidateQueries({ queryKey: ["list", "search-filter"] }),
|
||||
]);
|
||||
},
|
||||
});
|
||||
@@ -261,6 +267,7 @@ export function useDeleteListEventMutation(prjctIdx: number, sid: string) {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: qk.listDetail(prjctIdx, sid) }),
|
||||
queryClient.invalidateQueries({ queryKey: qk.listEventHistory(prjctIdx, sid) }),
|
||||
queryClient.invalidateQueries({ queryKey: ["list", "search-filter"] }),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type InternalInfo = {
|
||||
success: boolean;
|
||||
clientId: string;
|
||||
internalNo: string;
|
||||
externalNo: string;
|
||||
|
||||
Reference in New Issue
Block a user