공통코드

This commit is contained in:
focp212@naver.com
2025-10-23 15:27:52 +09:00
parent 86b72b10fa
commit 673d838541
4 changed files with 117 additions and 24 deletions

View File

@@ -22,12 +22,12 @@ export const codesSelect = ({
}: CodesSelectParams) => {
if(method === 'get'){
return resultify(
axios.get<CodesSelectGetResponse>(API_URL.codesSelect()),
axios.get<CodesSelectGetResponse & CodesSelectPostResponse>(API_URL.codesSelect()),
);
}
else{
return resultify(
axios.post<CodesSelectPostResponse>(API_URL.codesSelect(), {
axios.post<CodesSelectGetResponse & CodesSelectPostResponse>(API_URL.codesSelect(), {
codeCl,
colNm,
code1,
@@ -38,8 +38,8 @@ export const codesSelect = ({
}
};
export const useCodesSelectMutation = (options?: UseMutationOptions<CodesSelectGetResponse | CodesSelectPostResponse, CBDCAxiosError, CodesSelectParams>) => {
const mutation = useMutation<CodesSelectGetResponse | CodesSelectPostResponse, CBDCAxiosError, CodesSelectParams>({
export const useCodesSelectMutation = (options?: UseMutationOptions<CodesSelectGetResponse & CodesSelectPostResponse, CBDCAxiosError, CodesSelectParams>) => {
const mutation = useMutation<CodesSelectGetResponse & CodesSelectPostResponse, CBDCAxiosError, CodesSelectParams>({
...options,
mutationFn: ({
codeCl,

View File

@@ -10,6 +10,12 @@ export interface BannerInfoState {
export interface CommonState {
serviceCodes: Array<any>;
setServiceCodes: (update: SetStateAction<Array<any>>) => void;
creditCardList: Array<any>;
setCreditCardList: (update: SetStateAction<Array<any>>) => void;
bankList: Array<any>;
setBankList: (update: SetStateAction<Array<any>>) => void;
virtualBankList: Array<any>;
setVirtualBankList: (update: SetStateAction<Array<any>>) => void;
};
const initialBannerInfoState = {
@@ -51,5 +57,41 @@ export const createCommonStore = lens<CommonState>((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
]
};
});
},
}));

View File

@@ -98,7 +98,7 @@ export interface CodesSelectParams {
colNm?: string;
code1?: string;
code2?: string;
useCl?: string;
useCl?: number;
method: 'get' | 'post';
};
export interface CodeListItem {

View File

@@ -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<any>;
};
export interface OnSetCommonCodesProps {
data: Array<CodeListItem>;
codeCl: string;
code1Filter?: Array<any>;
};
@@ -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<string> = ['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<string> = ['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) => {