260812_02_ENH:IP 기반 자리번호 조회 및 헤더 표시, 컨택에서 리스트 관리로 뒤로 가기 했을 경우 캐싱 제거
This commit is contained in:
@@ -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"] }),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user