diff --git a/src/entities/common/api/use-codes-select-mutation.ts b/src/entities/common/api/use-codes-select-mutation.ts index 8285717..4fd14d4 100644 --- a/src/entities/common/api/use-codes-select-mutation.ts +++ b/src/entities/common/api/use-codes-select-mutation.ts @@ -22,12 +22,12 @@ export const codesSelect = ({ }: CodesSelectParams) => { if(method === 'get'){ return resultify( - axios.get(API_URL.codesSelect()), + axios.get(API_URL.codesSelect()), ); } else{ return resultify( - axios.post(API_URL.codesSelect(), { + axios.post(API_URL.codesSelect(), { codeCl, colNm, code1, @@ -38,8 +38,8 @@ export const codesSelect = ({ } }; -export const useCodesSelectMutation = (options?: UseMutationOptions) => { - const mutation = useMutation({ +export const useCodesSelectMutation = (options?: UseMutationOptions) => { + const mutation = useMutation({ ...options, mutationFn: ({ codeCl, diff --git a/src/entities/common/model/store.ts b/src/entities/common/model/store.ts index 14bc0ad..0bb9f88 100644 --- a/src/entities/common/model/store.ts +++ b/src/entities/common/model/store.ts @@ -10,6 +10,12 @@ export interface BannerInfoState { export interface CommonState { serviceCodes: Array; setServiceCodes: (update: SetStateAction>) => void; + creditCardList: Array; + setCreditCardList: (update: SetStateAction>) => void; + bankList: Array; + setBankList: (update: SetStateAction>) => void; + virtualBankList: Array; + setVirtualBankList: (update: SetStateAction>) => void; }; const initialBannerInfoState = { @@ -51,5 +57,41 @@ export const createCommonStore = lens((set, get) => ({ ] }; }); - } + }, + setCreditCardList: (update) => { + set((state: CommonState) => { + const newCreditCardList = (typeof update === 'function') + ? update(state.creditCardList): update; + return { + ...state, + creditCardList: [ + ...newCreditCardList + ] + }; + }); + }, + setBankList: (update) => { + set((state: CommonState) => { + const newBankList = (typeof update === 'function') + ? update(state.bankList): update; + return { + ...state, + bankList: [ + ...newBankList + ] + }; + }); + }, + setVirtualBankList: (update) => { + set((state: CommonState) => { + const newVirtualBankList = (typeof update === 'function') + ? update(state.virtualBankList): update; + return { + ...state, + virtualBankList: [ + ...newVirtualBankList + ] + }; + }); + }, })); diff --git a/src/entities/common/model/types.ts b/src/entities/common/model/types.ts index d394b56..7e116d6 100644 --- a/src/entities/common/model/types.ts +++ b/src/entities/common/model/types.ts @@ -98,7 +98,7 @@ export interface CodesSelectParams { colNm?: string; code1?: string; code2?: string; - useCl?: string; + useCl?: number; method: 'get' | 'post'; }; export interface CodeListItem { diff --git a/src/widgets/sub-layout/index.tsx b/src/widgets/sub-layout/index.tsx index 2f3b16a..83242d9 100644 --- a/src/widgets/sub-layout/index.tsx +++ b/src/widgets/sub-layout/index.tsx @@ -10,7 +10,12 @@ import { FooterNavigation } from '@/widgets/navigation/footer'; import { PullToRefresh } from '@/widgets/pull-to-refresh/pull-to-refresh'; import { useNavigate } from '@/shared/lib/hooks'; import { useScrollToTop } from '@/shared/lib/hooks/use-scroll-to-top'; -import { HeaderType } from '@/entities/common/model/types'; +import { + CodeListItem, + CodesSelectParams, + CodesSelectPostResponse, + HeaderType +} from '@/entities/common/model/types'; import { useHomeGroupsMutation } from '@/entities/home/api/use-home-groups-mutation'; import { useUserInfo } from '@/entities/user/lib/use-user-info'; import { useAppBridge } from '@/hooks'; @@ -19,11 +24,11 @@ import { getLocalStorage, setLocalStorage } from '@/shared/lib'; import { StorageKeys } from '@/shared/constants/local-storage'; import { HomeGroupsParams, HomeGroupsResponse } from '@/entities/home/model/types'; import { BusinessPropertyByMidParams, BusinessPropertyByMidResponse, LoginResponse, ShortcutUserParams, ShortcutUserResponse, UserFindAuthMethodParams, UserFindAuthMethodResponse } from '@/entities/user/model/types'; -import { useCodesListByCodeClMutation } from '@/entities/common/api/use-codes-list-by-codeCl-mutaion'; import { useShortcutUserMutation } from '@/entities/user/api/use-shortcut-user-mutation'; import { useShortcutDefaultMutation } from '@/entities/user/api/use-shortcut-detault-mutation'; import { useBusinessPropertyByMidMutation } from '@/entities/user/api/use-business-property-by-mid-mutation'; import { useUserFindAuthMethodMutation } from '@/entities/user/api/use-user-find-authmethod-mutation'; +import { useCodesSelectMutation } from '@/entities/common/api/use-codes-select-mutation'; export interface ContextType { setOnBack: (onBack: () => void) => void; @@ -36,7 +41,12 @@ export interface ContextType { setFavoriteEdit: (favoriteEdit?: boolean) => void; }; -export interface CallServiceCodeProps { +export interface CallCodesSelectProps { + codeCl: string; + code1Filter?: Array; +}; +export interface OnSetCommonCodesProps { + data: Array; codeCl: string; code1Filter?: Array; }; @@ -62,7 +72,7 @@ export const SubLayout = () => { const { isNativeEnvironment } = useAppBridge(); const { mutateAsync: homeGroups } = useHomeGroupsMutation(); - const { mutateAsync: codesListByCodeCl} = useCodesListByCodeClMutation(); + const { mutateAsync: codesSelect} = useCodesSelectMutation(); const { mutateAsync: shortcutUser } = useShortcutUserMutation(); const { mutateAsync: shortcutDefault } = useShortcutDefaultMutation(); const { mutateAsync: businessPropertyByMid } = useBusinessPropertyByMidMutation(); @@ -92,11 +102,7 @@ export const SubLayout = () => { setLoginSuccess(true); setHeaderNavigationKey(headerNavigationKey + 1); - let filter0022: Array = ['01', '02', '03', '05', '14', '21', '24', '26', '31']; - callServiceCode({ - codeCl: '0022', - code1Filter: filter0022 - }); + }); }; @@ -206,21 +212,59 @@ export const SubLayout = () => { callLogin(userParmas).then(() => { callHomeGroups(); callShortcutUser(); + + callCodesSelect({ codeCl: '0001' }); + callCodesSelect({ codeCl: '0002' }); + + let filter0022: Array = ['01', '02', '03', '05', '14', '21', '24', '26', '31']; + callCodesSelect({ + codeCl: '0022', + code1Filter: filter0022 + }); + + callCodesSelect({ codeCl: '0074' }); + }).catch((error: any) => { setLoginSuccess(false); }); }, []); - const callServiceCode = ({ + const callCodesSelect = ({ codeCl, code1Filter - }: CallServiceCodeProps) => { - let params = { - codeCl: codeCl + }: CallCodesSelectProps) => { + let params: CodesSelectParams = { + codeCl: codeCl, + useCl: 0, + method: 'post' }; - let options = []; - codesListByCodeCl(params).then((rs) => { - options = rs.map((value, index) => { + + codesSelect(params).then((rs: CodesSelectPostResponse) => { + if(rs){ + onSetCommonCodes({ + data: rs.codeList, + codeCl: codeCl, + code1Filter: code1Filter + }); + } + }); + }; + + const onSetCommonCodes = ({ + data, + codeCl, + code1Filter + }: OnSetCommonCodesProps) => { + if(codeCl === '0001'){ + + useStore.getState().CommonStore.setCreditCardList(data); + } + else if(codeCl === '0002'){ + useStore.getState().CommonStore.setBankList(data); + } + else if(codeCl === '0022'){ + let options = []; + options = data.map((value, index) => { return { name: value.desc1, value: value.code1 @@ -231,12 +275,19 @@ export const SubLayout = () => { return code1Filter.includes(value.value); }); } - options = options.sort((a, b) => a.value - b.value); + options = options.sort((a, b) => { + if(a > b) return 1; + else if(a < b) return -1; + else return 0; + }); options.unshift({ name: '전체', value: '' }); useStore.getState().CommonStore.setServiceCodes(options); - }); + } + else if(codeCl === '0074'){ + useStore.getState().CommonStore.setVirtualBankList(data); + } }; const saveToken = (token: LoginResponse) => {