feat: Add getCommonCode hook
This commit is contained in:
parent
e3ad0fc9cb
commit
f8bdce6177
@ -1,24 +1,19 @@
|
||||
'use client'
|
||||
|
||||
import { ErrorBoundary } from 'next/dist/client/components/error-boundary'
|
||||
import { useCommonCode } from '@/hooks/common/useCommonCode'
|
||||
import ServerError from './error'
|
||||
|
||||
import '@/styles/common.scss'
|
||||
|
||||
// import KO from '@/locales/ko.json'
|
||||
// import JA from '@/locales/ja.json'
|
||||
|
||||
export const QcastProvider = ({ children }) => {
|
||||
// const globalLocale = useRecoilValue(globalLocaleStore)
|
||||
// const [appMessageState, setAppMessageState] = useRecoilState(appMessageStore)
|
||||
const { commonCode, findCommonCode } = useCommonCode()
|
||||
|
||||
// useEffect(() => {
|
||||
// if (globalLocale === 'ko') {
|
||||
// setAppMessageState(KO)
|
||||
// } else {
|
||||
// setAppMessageState(JA)
|
||||
// }
|
||||
// }, [globalLocale])
|
||||
// console.log('commonCode', commonCode)
|
||||
// console.log(findCommonCode(100200))
|
||||
// console.log(findCommonCode(115800))
|
||||
// }, [commonCode])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
33
src/hooks/common/useCommonCode.js
Normal file
33
src/hooks/common/useCommonCode.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { commonCodeState } from '@/store/commonCodeAtom'
|
||||
import { isObjectNotEmpty } from '@/util/common-utils'
|
||||
import { useAxios } from '../useAxios'
|
||||
|
||||
export const useCommonCode = () => {
|
||||
const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
|
||||
const { get, promiseGet } = useAxios()
|
||||
|
||||
const findCommonCode = (key) => {
|
||||
// const arr = commonCode[key]
|
||||
// return arr.sort((a, b) => a.clPriority - b.clPriority)
|
||||
return commonCode[key]
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const getCommonCode = async () => {
|
||||
await promiseGet({ url: '/api/commcode/qc-comm-code' }).then((res) => {
|
||||
setCommonCode(Object.groupBy(res.data, ({ clHeadCd }) => clHeadCd))
|
||||
})
|
||||
}
|
||||
|
||||
if (!isObjectNotEmpty(commonCode)) {
|
||||
getCommonCode()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return {
|
||||
commonCode,
|
||||
findCommonCode,
|
||||
}
|
||||
}
|
||||
6
src/store/commonCodeAtom.js
Normal file
6
src/store/commonCodeAtom.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { atom } from 'recoil'
|
||||
|
||||
export const commonCodeState = atom({
|
||||
key: 'commonCode',
|
||||
default: {},
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user