diff --git a/apps/wr/app/page.tsx b/apps/wr/app/page.tsx index a3c2e4c7a..d9c5d3f0e 100644 --- a/apps/wr/app/page.tsx +++ b/apps/wr/app/page.tsx @@ -1,12 +1,12 @@ import PublicReuseFaciltyInsert from './publicReuseFaciltyInsert/page'; +import { StoreProvider } from './store'; export default function Home() { - - - return ( + + ); } diff --git a/apps/wr/app/publicReuseFaciltyInsert/page.tsx b/apps/wr/app/publicReuseFaciltyInsert/page.tsx index f5e565fd3..18434ac92 100644 --- a/apps/wr/app/publicReuseFaciltyInsert/page.tsx +++ b/apps/wr/app/publicReuseFaciltyInsert/page.tsx @@ -1,115 +1,20 @@ -import {UiTable} from '@common/business_components'; -import { TableRow } from '@common/components'; -import { TableHead } from '@common/components'; +"use client"; +import { UiTable } from '@common/business_components'; +import { Button, TableHead, TableRow } from '@common/components'; +import { useEffect } from 'react'; +import { useWrStore } from '../store'; +import type { TableUpperProps } from '../store/publicReuseFaciltyInsert'; -interface TableUpperProps { - id: string; - title: string; - upName : string; - upSequnce: number; -} - -const publicReuseFacility = [ - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - reuse: "Y", - register: "Y" - }, - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - reuse: "Y", - register: "Y" - }, - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - reuse: "Y", - register: "Y" - }, - -] - -const publicReuseFacilityUper = [ - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - reuse: "Y", - register: "Y" - }, - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - reuse: "Y", - register: "Y" - }, - { - sido: "서울", - sigungo: "강남구", - facilityName: "난지", - location: "경기도 고양시 덕양구 대차로 4가", - locationgubun: "500", - facilityCapacity: "800,000", - yn: "Y", - authoDay: "2012", - area:"123" - }, - ] - - - -const headList = [ - { id: "sido", title: "시도" }, - { id: "sigungo", title: "시군구" }, - { id: "facilityName", title: "시설명" }, - { id: "location", title: "위치" }, - { id: "locationgubun", title: "지역구분" }, - { id: "facilityCapacity", title: "시설용량" }, - { id: "reuse", title: '재이용여부' }, - { id: "register", title: '등록여부' }]; - - - - const upHeadList = [ - { id: "sido", title: "시도" }, - { id: "sigungo", title: "시군구" }, - { id: "facilityName", title: "시설명" }, - { id: "location", title: "위치" }, - { id: "locationgubun", title: "지역구분" }, - { id: "facilityCapacity", title: "시설용량" }, - { id: "yn", title: '여부', upName:'upChangeRe' , upSequnce:1 }, - { id: "authoDay", title: '허가일',upName:'upChangeRe', upSequnce:2 }, - { id: "area", title: '면적' ,upName:'upChangeRe',upSequnce:3 }]; const headMakeColSpan = (upHeadList: any) => { return ( <> { upHeadList.map((head: TableUpperProps) => - (head.upName === 'upChangeRe'&& head.upSequnce=== 1?{'중축 개축 증축 '}: - head.upSequnce> 1?null:{head.title}))} + (!head.upSequnce?null: + head.upName === 'upChangeRe'&& head.upSequnce=== 1?{'중축 개축 증축 '}: + head.upSequnce > 1?null:{head.title}))} {upHeadList.map((head: TableUpperProps) => @@ -118,15 +23,26 @@ const headList = [ ) } - - - export default function PublicReuseFaciltyInsert() { - +export default function PublicReuseFaciltyInsert() { + const { isInit, upHeadList, publicReuseFacilityUper, decrementList} = useWrStore((state) => state); const nodeList= headMakeColSpan(upHeadList); const total = 100; - return (
- -
+ //sample + useEffect(() => { + if(!isInit) + decrementList(); + }, [isInit]); + + return ( + <> + +
+ {/* sample store */} + +
+ ); } diff --git a/apps/wr/app/store/index.tsx b/apps/wr/app/store/index.tsx new file mode 100644 index 000000000..6578fa47d --- /dev/null +++ b/apps/wr/app/store/index.tsx @@ -0,0 +1,46 @@ +'use client' + +import { type ReactNode, createContext, useContext, useRef } from 'react' +import { useStore } from 'zustand' +import { type WrStore, StoreZus } from './store' + + +export type StoreApi = ReturnType + +export const StoreContext = createContext( + undefined, +) + +export interface StoreProviderProps { + children: ReactNode +} + +export const StoreProvider = ({ + children, +}: StoreProviderProps) => { + const storeRef = useRef(null) + console.log("StoreProvider"); + + if (!storeRef.current) { + storeRef.current = StoreZus() + } + + return ( + + {children} + + ) +} + +export const useWrStore = ( + selector: (store: WrStore) => T, +): T => { + const storeContext = useContext(StoreContext) + console.log("useStore", storeContext); + + if (!storeContext) { + throw new Error(`useStore must be used within StoreProvider`) + } + + return useStore(storeContext, selector) +} \ No newline at end of file diff --git a/apps/wr/app/store/publicReuseFaciltyInsert/index.tsx b/apps/wr/app/store/publicReuseFaciltyInsert/index.tsx new file mode 100644 index 000000000..15b252b24 --- /dev/null +++ b/apps/wr/app/store/publicReuseFaciltyInsert/index.tsx @@ -0,0 +1,97 @@ +export type TableUpperProps = { + id: string; + title: string; + upName?: string; + upSequnce?: number; +} +type PublicReuseFacility = { + sido: string, + sigungo: string, + facilityName: string, + location: string, + locationgubun: string, + facilityCapacity: string, + yn?: string, + authoDay?: string, + area?: string, + reuse?: string, + register?: string +} +const upHeadList:TableUpperProps[] = [ + { id: "sido", title: "시도"}, + { id: "sigungo", title: "시군구"}, + { id: "facilityName", title: "시설명"}, + { id: "location", title: "위치"}, + { id: "locationgubun", title: "지역구분"}, + { id: "facilityCapacity", title: "시설용량"}, + { id: "yn", title: '여부', upName:'upChangeRe' , upSequnce:1 }, + { id: "authoDay", title: '허가일',upName:'upChangeRe', upSequnce:2 }, + { id: "area", title: '면적' ,upName:'upChangeRe',upSequnce:3 }]; + +const publicReuseFacilityUper:PublicReuseFacility[] = [ + { + sido: "서울", + sigungo: "강남구", + facilityName: "난지", + location: "경기도 고양시 덕양구 대차로 4가", + locationgubun: "500", + facilityCapacity: "800,000", + reuse: "Y", + register: "Y" + }, + { + sido: "서울", + sigungo: "강남구", + facilityName: "난지", + location: "경기도 고양시 덕양구 대차로 4가", + locationgubun: "500", + facilityCapacity: "800,000", + reuse: "Y", + register: "Y" + }, + { + sido: "서울", + sigungo: "강남구", + facilityName: "난지", + location: "경기도 고양시 덕양구 대차로 4가", + locationgubun: "500", + facilityCapacity: "800,000", + yn: "Y", + authoDay: "2012", + area:"123" + }, +] + +export type tableState = { + isInit: boolean; + upHeadList: TableUpperProps[]; + publicReuseFacilityUper: PublicReuseFacility[]; +} +type tableActions = { + decrementList: () => void +} + +export type tableType = tableState & tableActions; + +export const tableStateExport:tableState= { + isInit:false, + upHeadList: upHeadList, + publicReuseFacilityUper: publicReuseFacilityUper, +} +export const tableActionsExport:(set:any)=>tableActions=(set: any) => { + + console.log("tableActionsExport"); + return { + decrementList:()=>set( + (state:tableState) => { + + console.log("tableActionsExport", state); + return ( + { + upHeadList: state.upHeadList, + publicReuseFacilityUper: + state.publicReuseFacilityUper.slice(0, state.publicReuseFacilityUper.length - 1) + })} + ) + } +} diff --git a/apps/wr/app/store/store.tsx b/apps/wr/app/store/store.tsx new file mode 100644 index 000000000..8ba4ea81b --- /dev/null +++ b/apps/wr/app/store/store.tsx @@ -0,0 +1,12 @@ +import { createStore } from 'zustand/vanilla'; +import { tableActionsExport, tableStateExport, type tableState, type tableType } from './publicReuseFaciltyInsert/index'; +export type WrStore = tableType; +export const StoreZus = (initState: tableState = tableStateExport) => { + return createStore()((set) => { + return { + ...initState, + ...tableActionsExport(set) + } + }) +} +//store 등록하는 부분 \ No newline at end of file