fix: 문의 유형 공통코드 조회 로직 수정

- 기존 구현 되어 있던 공통코드 조회 api 사용
This commit is contained in:
Dayoung 2025-08-07 14:03:34 +09:00
parent 5a08c9067f
commit 5a49b86205
3 changed files with 36 additions and 32 deletions

View File

@ -2,7 +2,7 @@
import { useInquiry } from '@/hooks/useInquiry' import { useInquiry } from '@/hooks/useInquiry'
import { useSessionStore } from '@/store/session' import { useSessionStore } from '@/store/session'
import { InquiryRequest } from '@/types/Inquiry' import { InquiryCommCode, InquiryRequest } from '@/types/Inquiry'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
import { CONFIRM_MESSAGE, SUCCESS_MESSAGE, useAlertMsg, WARNING_MESSAGE } from '@/hooks/useAlertMsg' import { CONFIRM_MESSAGE, SUCCESS_MESSAGE, useAlertMsg, WARNING_MESSAGE } from '@/hooks/useAlertMsg'
@ -152,15 +152,15 @@ export default function RegistForm() {
</option> </option>
{commonCodeList {commonCodeList
.filter((code) => code.headId === 'QNA_CLS_LRG_CD') .filter((code) => code.headCd === InquiryCommCode.QNA_CLS_LRG_CD.headCd)
.map((code) => ( .map((code) => (
<option key={code.code} value={code.code}> <option key={code.code} value={code.code}>
{code.name} {code.codeJp}
</option> </option>
))} ))}
</select> </select>
</div> </div>
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsLrgCd).length > 0 && inquiryRequest.qnaClsLrgCd && ( {commonCodeList.filter((code) => code.refChr1 === inquiryRequest.qnaClsLrgCd).length > 0 && inquiryRequest.qnaClsLrgCd && (
<div className="data-input mt5"> <div className="data-input mt5">
<select <select
className="select-form" className="select-form"
@ -173,16 +173,16 @@ export default function RegistForm() {
</option> </option>
{commonCodeList {commonCodeList
.filter((code) => code.refChar1 === inquiryRequest.qnaClsLrgCd) .filter((code) => code.refChr1 === inquiryRequest.qnaClsLrgCd)
.map((code) => ( .map((code) => (
<option key={code.code} value={code.code}> <option key={code.code} value={code.code}>
{code.name} {code.codeJp}
</option> </option>
))} ))}
</select> </select>
</div> </div>
)} )}
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsMidCd).length > 0 && inquiryRequest.qnaClsMidCd && ( {commonCodeList.filter((code) => code.refChr1 === inquiryRequest.qnaClsMidCd).length > 0 && inquiryRequest.qnaClsMidCd && (
<div className="data-input mt5"> <div className="data-input mt5">
<select <select
className="select-form" className="select-form"
@ -195,10 +195,10 @@ export default function RegistForm() {
</option> </option>
{commonCodeList {commonCodeList
.filter((code) => code.refChar1 === inquiryRequest.qnaClsMidCd) .filter((code) => code.refChr1 === inquiryRequest.qnaClsMidCd)
.map((code) => ( .map((code) => (
<option key={code.code} value={code.code}> <option key={code.code} value={code.code}>
{code.name} {code.codeJp}
</option> </option>
))} ))}
</select> </select>

View File

@ -1,11 +1,12 @@
import { InquiryList, Inquiry, InquirySaveResponse, CommonCode } from '@/types/Inquiry' import { InquiryList, Inquiry, InquirySaveResponse, InquiryCommCode } from '@/types/Inquiry'
import { useAxios } from '@/hooks/useAxios' import { useAxios } from '@/hooks/useAxios'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useInquiryFilterStore } from '@/store/inquiryFilterStore' import { useInquiryFilterStore } from '@/store/inquiryFilterStore'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
import { useAlertMsg } from '@/hooks/useAlertMsg' import { useAlertMsg } from '@/hooks/useAlertMsg'
import { useCommCode } from './useCommCode'
import { CommCode } from '@/types/CommCode'
/** /**
* @description * @description
@ -20,7 +21,7 @@ import { useAlertMsg } from '@/hooks/useAlertMsg'
* @returns {boolean} isSavingInquiry - * @returns {boolean} isSavingInquiry -
* @returns {Function} saveInquiry - * @returns {Function} saveInquiry -
* @returns {Function} downloadFile - * @returns {Function} downloadFile -
* @returns {CommonCode[]} commonCodeList - * @returns {CommCode[]} commonCodeList -
*/ */
export function useInquiry( export function useInquiry(
qnoNo?: number, qnoNo?: number,
@ -33,7 +34,7 @@ export function useInquiry(
isSavingInquiry: boolean isSavingInquiry: boolean
saveInquiry: (formData: FormData) => Promise<InquirySaveResponse> saveInquiry: (formData: FormData) => Promise<InquirySaveResponse>
downloadFile: (encodeFileNo: number, srcFileNm: string) => Promise<Blob | null> downloadFile: (encodeFileNo: number, srcFileNm: string) => Promise<Blob | null>
commonCodeList: CommonCode[] commonCodeList: CommCode[]
} { } {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const { inquiryListRequest, offset, isMyInquiry } = useInquiryFilterStore() const { inquiryListRequest, offset, isMyInquiry } = useInquiryFilterStore()
@ -216,7 +217,8 @@ export function useInquiry(
} }
/** /**
* @description * @description
* - , ,
* *
* @returns {Object} * @returns {Object}
* @returns {CommonCode[]} data - * @returns {CommonCode[]} data -
@ -225,15 +227,13 @@ export function useInquiry(
const { data: commonCodeList, isLoading: isLoadingCommonCodeList } = useQuery({ const { data: commonCodeList, isLoading: isLoadingCommonCodeList } = useQuery({
queryKey: ['commonCodeList'], queryKey: ['commonCodeList'],
queryFn: async () => { queryFn: async () => {
const isListQuery = false const { getCommCode } = useCommCode()
const shouldThrowError = false const resp = await Promise.all([
getCommCode(InquiryCommCode.QNA_CLS_LRG_CD.headId),
const resp = await tryFunction( getCommCode(InquiryCommCode.QNA_CLS_MID_CD.headId),
() => axiosInstance(null).get<CommonCode[]>('/api/comm-code', { params: { headId: 'QNA_CD' } }), getCommCode(InquiryCommCode.QNA_CLS_SML_CD.headId),
isListQuery, ])
shouldThrowError, return resp.flat()
)
return resp?.data ?? []
}, },
staleTime: Infinity, staleTime: Infinity,
gcTime: Infinity, gcTime: Infinity,

View File

@ -180,13 +180,17 @@ export type InquirySaveResponse = {
mailYn: string mailYn: string
} }
/** export const InquiryCommCode = {
* @description QNA_CLS_LRG_CD: {
*/ headCd: '204200',
export type CommonCode = { headId: 'QNA_CLS_LRG_CD',
headCd: string },
headId: string QNA_CLS_MID_CD: {
code: string headCd: '204300',
name: string headId: 'QNA_CLS_MID_CD',
refChar1: string },
QNA_CLS_SML_CD: {
headCd: '204400',
headId: 'QNA_CLS_SML_CD',
},
} }