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 { useSessionStore } from '@/store/session'
import { InquiryRequest } from '@/types/Inquiry'
import { InquiryCommCode, InquiryRequest } from '@/types/Inquiry'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import { CONFIRM_MESSAGE, SUCCESS_MESSAGE, useAlertMsg, WARNING_MESSAGE } from '@/hooks/useAlertMsg'
@ -152,15 +152,15 @@ export default function RegistForm() {
</option>
{commonCodeList
.filter((code) => code.headId === 'QNA_CLS_LRG_CD')
.filter((code) => code.headCd === InquiryCommCode.QNA_CLS_LRG_CD.headCd)
.map((code) => (
<option key={code.code} value={code.code}>
{code.name}
{code.codeJp}
</option>
))}
</select>
</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">
<select
className="select-form"
@ -173,16 +173,16 @@ export default function RegistForm() {
</option>
{commonCodeList
.filter((code) => code.refChar1 === inquiryRequest.qnaClsLrgCd)
.filter((code) => code.refChr1 === inquiryRequest.qnaClsLrgCd)
.map((code) => (
<option key={code.code} value={code.code}>
{code.name}
{code.codeJp}
</option>
))}
</select>
</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">
<select
className="select-form"
@ -195,10 +195,10 @@ export default function RegistForm() {
</option>
{commonCodeList
.filter((code) => code.refChar1 === inquiryRequest.qnaClsMidCd)
.filter((code) => code.refChr1 === inquiryRequest.qnaClsMidCd)
.map((code) => (
<option key={code.code} value={code.code}>
{code.name}
{code.codeJp}
</option>
))}
</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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useInquiryFilterStore } from '@/store/inquiryFilterStore'
import { useMemo } from 'react'
import { useRouter } from 'next/navigation'
import { useAlertMsg } from '@/hooks/useAlertMsg'
import { useCommCode } from './useCommCode'
import { CommCode } from '@/types/CommCode'
/**
* @description
@ -20,7 +21,7 @@ import { useAlertMsg } from '@/hooks/useAlertMsg'
* @returns {boolean} isSavingInquiry -
* @returns {Function} saveInquiry -
* @returns {Function} downloadFile -
* @returns {CommonCode[]} commonCodeList -
* @returns {CommCode[]} commonCodeList -
*/
export function useInquiry(
qnoNo?: number,
@ -33,7 +34,7 @@ export function useInquiry(
isSavingInquiry: boolean
saveInquiry: (formData: FormData) => Promise<InquirySaveResponse>
downloadFile: (encodeFileNo: number, srcFileNm: string) => Promise<Blob | null>
commonCodeList: CommonCode[]
commonCodeList: CommCode[]
} {
const queryClient = useQueryClient()
const { inquiryListRequest, offset, isMyInquiry } = useInquiryFilterStore()
@ -216,7 +217,8 @@ export function useInquiry(
}
/**
* @description
* @description
* - , ,
*
* @returns {Object}
* @returns {CommonCode[]} data -
@ -225,15 +227,13 @@ export function useInquiry(
const { data: commonCodeList, isLoading: isLoadingCommonCodeList } = useQuery({
queryKey: ['commonCodeList'],
queryFn: async () => {
const isListQuery = false
const shouldThrowError = false
const resp = await tryFunction(
() => axiosInstance(null).get<CommonCode[]>('/api/comm-code', { params: { headId: 'QNA_CD' } }),
isListQuery,
shouldThrowError,
)
return resp?.data ?? []
const { getCommCode } = useCommCode()
const resp = await Promise.all([
getCommCode(InquiryCommCode.QNA_CLS_LRG_CD.headId),
getCommCode(InquiryCommCode.QNA_CLS_MID_CD.headId),
getCommCode(InquiryCommCode.QNA_CLS_SML_CD.headId),
])
return resp.flat()
},
staleTime: Infinity,
gcTime: Infinity,

View File

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