feat: Store SN Root 경로에서 사용하도록 수정중 (추가 작업 필요)
This commit is contained in:
+20
-22
@@ -1,4 +1,4 @@
|
||||
import { getGeoData, getCmsData } from "@/components/lib/api";
|
||||
import { getCmsData } from "@/components/lib/api";
|
||||
|
||||
|
||||
export interface Option { id: number, name: string }
|
||||
@@ -11,35 +11,33 @@ export type BIZ_CD_TYPE = {
|
||||
prntLwpoCd: null
|
||||
};
|
||||
|
||||
export const fetchCtpvData = async (set: (state: any) => void) => {
|
||||
export const fetchCtpvSggData = async (set: (state: any) => void) => {
|
||||
try {
|
||||
const ctpvData = await getGeoData('/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo%3Atb_ms_ctpv&outputFormat=application%2Fjson');
|
||||
const ctpvList: Option[] = ctpvData.features
|
||||
const ctpvData = await getCmsData('/api/v1/code/cache/ADSTDSTRCD');
|
||||
console.log("CTPV Data:", ctpvData);
|
||||
const ctpvList: Option[] = ctpvData
|
||||
.filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length === 2)
|
||||
.map((feature: any) => ({
|
||||
id: feature.properties.mctpv_cd.trim(),
|
||||
name: feature.properties.mctpv_korn_nm
|
||||
id: feature.lwpoCd,
|
||||
name: feature.lwpoCdNm
|
||||
}))
|
||||
.sort((a: Option, b: Option) => a.name.localeCompare(b.name, 'ko'));
|
||||
set({ ctpv: ctpvList });
|
||||
} catch (e: any) {
|
||||
// alert("시도 데이터 로드 실패: " + e.message);
|
||||
console.error("CTPV 데이터 로드 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchSggData = async (set: (state: any) => void) => {
|
||||
try {
|
||||
const sggData = await getGeoData('/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo%3Atb_ms_sgg&outputFormat=application%2Fjson');
|
||||
const sggList: Option[] = sggData.features
|
||||
.map((feature: any) => ({
|
||||
id: feature.properties.sgg_cd,
|
||||
name: feature.properties.sgg_korn_nm
|
||||
const sggList: Option[] = ctpvData
|
||||
.filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length !== 2)
|
||||
.map((item: any) => ({
|
||||
id: item.lwpoCd,
|
||||
name: item.lwpoCdNm
|
||||
}))
|
||||
.sort((a: Option, b: Option) => a.name.localeCompare(b.name, 'ko'));
|
||||
set({ sgg: sggList });
|
||||
|
||||
console.log("CTPV List:", ctpvList);
|
||||
console.log("SGG List:", sggList);
|
||||
|
||||
set({ ctpv: ctpvList, sgg: sggList });
|
||||
} catch (e: any) {
|
||||
// alert("시군구 데이터 로드 실패: " + e.message);
|
||||
console.error("SGG 데이터 로드 실패:", e);
|
||||
// alert("시도, 시군구 데이터 로드 실패: " + e.message);
|
||||
console.error("CTPV 데이터 로드 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { create } from "zustand";
|
||||
import { getGeoData, getCmsData } from "@/components/lib/api";
|
||||
import { fetchCtpvData, fetchSggData, fetchBIZ_SE_CD, fetchBIZ_TY_CD } from "./index";
|
||||
import { fetchCtpvSggData, fetchBIZ_SE_CD, fetchBIZ_TY_CD } from "./index";
|
||||
|
||||
interface Option { id: number, name: string }
|
||||
|
||||
@@ -17,8 +17,7 @@ interface SnStoreState {
|
||||
sgg: Option[];
|
||||
BIZ_SE_CD: BIZ_CD_TYPE[];
|
||||
BIZ_TY_CD: BIZ_CD_TYPE[];
|
||||
fetchCtpvData: () => Promise<void>;
|
||||
fetchSggData: () => Promise<void>;
|
||||
fetchCtpvSggData: () => Promise<void>;
|
||||
fetchBIZ_SE_CD: () => Promise<void>;
|
||||
fetchBIZ_TY_CD: () => Promise<void>;
|
||||
}
|
||||
@@ -28,8 +27,7 @@ const useStore = create<SnStoreState>((set) => ({
|
||||
sgg: [],
|
||||
BIZ_SE_CD: [],
|
||||
BIZ_TY_CD: [],
|
||||
fetchCtpvData: () => fetchCtpvData(set),
|
||||
fetchSggData: () => fetchSggData(set),
|
||||
fetchCtpvSggData: () => fetchCtpvSggData(set),
|
||||
fetchBIZ_SE_CD: () => fetchBIZ_SE_CD(set),
|
||||
fetchBIZ_TY_CD: () => fetchBIZ_TY_CD(set),
|
||||
}));
|
||||
|
||||
@@ -2,5 +2,6 @@ export { useMutationWrapper } from "./use-mutation-wrapper";
|
||||
export { useAlertStore } from "./use-alert-store";
|
||||
export { useMenuStore } from "./use-menu-store";
|
||||
export { useUserStore } from "./use-user-store";
|
||||
export { useDataStore } from "./use-data-store";
|
||||
export { usePrompt } from "./use-prompt";
|
||||
export { getCookie, setCookie, removeCookie } from "./cookie";
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useStore } from "zustand";
|
||||
import { useContext } from "react";
|
||||
import type { DataStore } from "../store/data-store";
|
||||
import { StoreContext } from "../providers/store-provider";
|
||||
|
||||
export const useDataStore = <T>(selector: (store: DataStore) => T): T => {
|
||||
const storeContext = useContext(StoreContext);
|
||||
|
||||
if (!storeContext) {
|
||||
throw new Error("useDataStore must be used within StoreProvider");
|
||||
}
|
||||
|
||||
return useStore(storeContext.dataStore, selector);
|
||||
};
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
createAttachmentStore,
|
||||
createMenuStore,
|
||||
createUserStore,
|
||||
createDataStore,
|
||||
} from "../store";
|
||||
|
||||
type StoreContextType = {
|
||||
@@ -13,6 +14,7 @@ type StoreContextType = {
|
||||
attachmentStore: ReturnType<typeof createAttachmentStore>;
|
||||
menuStore: ReturnType<typeof createMenuStore>;
|
||||
userStore: ReturnType<typeof createUserStore>;
|
||||
dataStore: ReturnType<typeof createDataStore>;
|
||||
};
|
||||
|
||||
export const StoreContext = createContext<StoreContextType | undefined>(
|
||||
@@ -27,6 +29,7 @@ export const StoreProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
attachmentStore: createAttachmentStore(),
|
||||
menuStore: createMenuStore(),
|
||||
userStore: createUserStore(),
|
||||
dataStore: createDataStore(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { create } from "zustand";
|
||||
import { getCmsData } from "@/components/lib/api";
|
||||
|
||||
export interface Option { id: number, name: string }
|
||||
|
||||
export type BIZ_CD_TYPE = {
|
||||
lwpoCd: string,
|
||||
upCd: string,
|
||||
lwpoCdNm: string,
|
||||
unit: string,
|
||||
prntLwpoCd: null
|
||||
};
|
||||
|
||||
export type DataState = {
|
||||
ctpv: Option[];
|
||||
sgg: Option[];
|
||||
BIZ_SE_CD: BIZ_CD_TYPE[];
|
||||
BIZ_TY_CD: BIZ_CD_TYPE[];
|
||||
}
|
||||
|
||||
export type FetchData = {
|
||||
fetchCtpvSggData: () => Promise<void>;
|
||||
fetchBIZ_SE_CD: () => Promise<void>;
|
||||
fetchBIZ_TY_CD: () => Promise<void>;
|
||||
};
|
||||
|
||||
export type DataStore = DataState & FetchData;
|
||||
|
||||
export const defaultInitState: DataState = {
|
||||
ctpv: [],
|
||||
sgg: [],
|
||||
BIZ_SE_CD: [],
|
||||
BIZ_TY_CD: [],
|
||||
};
|
||||
|
||||
const fetchCtpvSggData = async (set: (state: any) => void) => {
|
||||
try {
|
||||
const ctpvData = await getCmsData('/api/v1/code/cache/ADSTDSTRCD');
|
||||
console.log("CTPV Data:", ctpvData);
|
||||
const ctpvList: Option[] = ctpvData
|
||||
.filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length === 2)
|
||||
.map((feature: any) => ({
|
||||
id: feature.lwpoCd,
|
||||
name: feature.lwpoCdNm
|
||||
}))
|
||||
.sort((a: Option, b: Option) => a.name.localeCompare(b.name, 'ko'));
|
||||
|
||||
const sggList: Option[] = ctpvData
|
||||
.filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length !== 2)
|
||||
.map((item: any) => ({
|
||||
id: item.lwpoCd,
|
||||
name: item.lwpoCdNm
|
||||
}))
|
||||
.sort((a: Option, b: Option) => a.name.localeCompare(b.name, 'ko'));
|
||||
|
||||
set({ ctpv: ctpvList, sgg: sggList });
|
||||
} catch (e: any) {
|
||||
// alert("시도, 시군구 데이터 로드 실패: " + e.message);
|
||||
console.error("CTPV 데이터 로드 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchBIZ_SE_CD = async (set: (state: any) => void) => {
|
||||
try {
|
||||
const res = await getCmsData(`/api/v1/code/cache/BIZSECD`);
|
||||
set({ BIZ_SE_CD: res });
|
||||
} catch (e: any) {
|
||||
// alert("BIZ_SE_CD 데이터 로드 실패: " + e.message);
|
||||
console.error("BIZ_SE_CD 데이터 로드 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchBIZ_TY_CD = async (set: (state: any) => void) => {
|
||||
try {
|
||||
const res = await getCmsData(`/api/v1/code/cache/BIZTYCD`);
|
||||
set({ BIZ_TY_CD: res });
|
||||
} catch (e: any) {
|
||||
// alert("BIZ_TY_CD 데이터 로드 실패: " + e.message);
|
||||
console.error("BIZ_TY_CD 데이터 로드 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
export const createDataStore = (initState: DataState = defaultInitState) => {
|
||||
return create<DataStore>((set) => ({
|
||||
...initState,
|
||||
fetchCtpvSggData: () => fetchCtpvSggData(set),
|
||||
fetchBIZ_SE_CD: () => fetchBIZ_SE_CD(set),
|
||||
fetchBIZ_TY_CD: () => fetchBIZ_TY_CD(set),
|
||||
}));
|
||||
};
|
||||
@@ -2,3 +2,4 @@ export { createAlertStore } from "./alert-store";
|
||||
export { createAttachmentStore } from "./attachment-store";
|
||||
export { createMenuStore, type BbsType } from "./menu-store";
|
||||
export { createUserStore, type IUserInfo } from "./user-store";
|
||||
export { createDataStore, type DataStore } from "./data-store";
|
||||
Reference in New Issue
Block a user