fix: 공통코드 조회시 로케일 참조 기능 추가

This commit is contained in:
yoosangwook 2024-10-22 09:50:51 +09:00
parent 1903834314
commit f372c9ae61
2 changed files with 20 additions and 5 deletions

View File

@ -1,5 +1,6 @@
'use client' 'use client'
// import { useEffect } from 'react'
import { ErrorBoundary } from 'next/dist/client/components/error-boundary' import { ErrorBoundary } from 'next/dist/client/components/error-boundary'
import { useCommonCode } from '@/hooks/common/useCommonCode' import { useCommonCode } from '@/hooks/common/useCommonCode'
import ServerError from './error' import ServerError from './error'
@ -11,9 +12,8 @@ export const QcastProvider = ({ children }) => {
// useEffect(() => { // useEffect(() => {
// console.log('commonCode', commonCode) // console.log('commonCode', commonCode)
// console.log(findCommonCode(100200)) // console.log(findCommonCode(113600))
// console.log(findCommonCode(115800)) // }, [commonCode, findCommonCode])
// }, [commonCode])
return ( return (
<> <>

View File

@ -1,18 +1,33 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { useRecoilState } from 'recoil' import { useRecoilState, useRecoilValue } from 'recoil'
import { commonCodeState } from '@/store/commonCodeAtom' import { commonCodeState } from '@/store/commonCodeAtom'
import { globalLocaleStore } from '@/store/localeAtom'
import { isObjectNotEmpty } from '@/util/common-utils' import { isObjectNotEmpty } from '@/util/common-utils'
import { useAxios } from '../useAxios' import { useAxios } from '../useAxios'
export const useCommonCode = () => { export const useCommonCode = () => {
const [commonCode, setCommonCode] = useRecoilState(commonCodeState) const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
const globalLocale = useRecoilValue(globalLocaleStore)
const { promiseGet } = useAxios() const { promiseGet } = useAxios()
const findCommonCode = (key) => { const findCommonCode = (key) => {
// const arr = commonCode[key] // const arr = commonCode[key]
// return arr.sort((a, b) => a.clPriority - b.clPriority) // return arr.sort((a, b) => a.clPriority - b.clPriority)
return commonCode[key] const resultCodes = commonCode[key]?.map((code) => {
const result = {
clHeadCd: code.clHeadCd,
clCode: code.clCode,
clCodeNm: globalLocale === 'ko' ? code.clCodeNm : code.clCodeJp,
clPriority: code.clPriority,
} }
return result
})
return resultCodes
}
useEffect(() => {
findCommonCode()
}, [globalLocale])
useEffect(() => { useEffect(() => {
const getCommonCode = async () => { const getCommonCode = async () => {