commonCode get in hook => page 한번만 호출하도록

This commit is contained in:
hyojun.choi 2025-05-13 15:11:12 +09:00
parent a652d09b8d
commit bca3100a12
2 changed files with 18 additions and 14 deletions

View File

@ -20,6 +20,8 @@ import { stuffSearchState } from '@/store/stuffAtom'
import { QcastContext } from '@/app/QcastProvider'
import { usePopup } from '@/hooks/usePopup'
import { commonCodeState } from '@/store/commonCodeAtom'
import { isObjectNotEmpty } from '@/util/common-utils'
export const ToggleonMouse = (e, act, target) => {
const listWrap = e.target.closest(target)
@ -67,6 +69,21 @@ export default function Header(props) {
const [SelectOptions, setSelectOptions] = useState([])
const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
const { promiseGet } = useAxios()
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()
}
}, [])
const getAutoLoginParam = async () => {
await promisePost({ url: '/api/login/v1.0/user/login/autoLoginEncryptData', data: { loginId: userSession.userId } })
.then((res) => {

View File

@ -22,9 +22,8 @@ import { useAxios } from '../useAxios'
* const honorificCodes = findCommonCode(200800);
*/
export const useCommonCode = () => {
const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
const globalLocale = useRecoilValue(globalLocaleStore)
const { promiseGet } = useAxios()
const [commonCode, setCommonCode] = useRecoilState(commonCodeState)
const findCommonCode = (key) => {
const resultCodes = commonCode[key]?.map((code) => {
@ -41,18 +40,6 @@ export const useCommonCode = () => {
return resultCodes
}
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,