fix: 공통코드 조회시 로케일 참조 기능 추가
This commit is contained in:
parent
1903834314
commit
f372c9ae61
@ -1,5 +1,6 @@
|
||||
'use client'
|
||||
|
||||
// import { useEffect } from 'react'
|
||||
import { ErrorBoundary } from 'next/dist/client/components/error-boundary'
|
||||
import { useCommonCode } from '@/hooks/common/useCommonCode'
|
||||
import ServerError from './error'
|
||||
@ -11,9 +12,8 @@ export const QcastProvider = ({ children }) => {
|
||||
|
||||
// useEffect(() => {
|
||||
// console.log('commonCode', commonCode)
|
||||
// console.log(findCommonCode(100200))
|
||||
// console.log(findCommonCode(115800))
|
||||
// }, [commonCode])
|
||||
// console.log(findCommonCode(113600))
|
||||
// }, [commonCode, findCommonCode])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@ -1,19 +1,34 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||
import { commonCodeState } from '@/store/commonCodeAtom'
|
||||
import { globalLocaleStore } from '@/store/localeAtom'
|
||||
import { isObjectNotEmpty } from '@/util/common-utils'
|
||||
import { useAxios } from '../useAxios'
|
||||
|
||||
export const useCommonCode = () => {
|
||||
const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
|
||||
const globalLocale = useRecoilValue(globalLocaleStore)
|
||||
const { promiseGet } = useAxios()
|
||||
|
||||
const findCommonCode = (key) => {
|
||||
// const arr = commonCode[key]
|
||||
// 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(() => {
|
||||
const getCommonCode = async () => {
|
||||
await promiseGet({ url: '/api/commcode/qc-comm-code' }).then((res) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user