로그인 처리
iipbs_sn / build (push) Waiting to run

This commit is contained in:
yschoi
2025-05-26 10:32:26 +09:00
parent 6156cf6419
commit d975e8fed0
14 changed files with 494 additions and 262 deletions
+1 -45
View File
@@ -1,45 +1 @@
'use client'
import { type ReactNode, createContext, useContext, useRef } from 'react'
import { useStore } from 'zustand'
import { type SnStore, StoreZus } from './store'
export type StoreApi = ReturnType<typeof StoreZus>
export const StoreContext = createContext<StoreApi | undefined>(
undefined,
)
export interface StoreProviderProps {
children: ReactNode
}
export const StoreProvider = ({
children,
}: StoreProviderProps) => {
const storeRef = useRef<StoreApi | null>(null)
if (!storeRef.current) {
storeRef.current = StoreZus()
}
return (
<StoreContext.Provider value={storeRef.current}>
{children}
</StoreContext.Provider>
)
}
export const useSnStore = <T,>(
//selector: (store: ReturnType<typeof StoreZus>) => T,
selector: (store: SnStore) => T,
): T => {
const storeContext = useContext(StoreContext)
if (!storeContext) {
throw new Error(`useStore must be used within StoreProvider`)
}
return useStore(storeContext, selector)
}
export { useUserStore, type IUserInfo } from "./user-store";
-76
View File
@@ -1,76 +0,0 @@
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
}
const upHeadList:TableUpperProps[] = [
{ id: "sido", title: "자산ID"},
{ id: "sigungo", title: "설비시설"},
{ id: "facilityName", title: "주소"},
{ id: "location", title: "자산코드"},
{ id: "locationgubun", title: "자산명"},
{ id: "facilityCapacity", title: "용도"},
{ id: "yn", title: '신설/교체'},
{ id: "authoDay", title: '처리구역'},
{ id: "area", title: '내용연수' },
{ id: "reuse", title: '취득금액' },
];
const publicReuseFacilityUper:PublicReuseFacility[] = [
{
sido: "1048967",
sigungo: "관로",
facilityName: "양평군 양평읍 백안리 25-5전",
location: "S-T-S-2018000675",
locationgubun: "2018000675",
facilityCapacity: "오수관",
yn: "신설",
authoDay: "양평하수처리구역",
area: "30",
reuse: "28,313,220"
}
]
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) => {
return {
decrementList:()=>set(
(state:tableState) => {
return (
{
upHeadList: state.upHeadList,
publicReuseFacilityUper: state.publicReuseFacilityUper.slice(0, state.publicReuseFacilityUper.length - 1)
})}
)
}
}
+27
View File
@@ -0,0 +1,27 @@
"use client";
import { createContext, useRef } from "react";
import { createUserStore } from "../store/user-store";
type StoreContextType = {
userStore: ReturnType<typeof createUserStore>;
};
export const StoreContext = createContext<StoreContextType | undefined>(
undefined,
);
export const StoreProvider = ({ children }: { children: React.ReactNode }) => {
const storeRef = useRef<StoreContextType | null>(null);
if (storeRef.current === null) {
storeRef.current = {
userStore: createUserStore(),
};
}
return (
<StoreContext.Provider value={storeRef.current}>
{children}
</StoreContext.Provider>
);
};
-14
View File
@@ -1,14 +0,0 @@
import { createStore } from 'zustand/vanilla';
import { tableActionsExport, tableStateExport, type tableState, type tableType } from './table';
export type SnStore = tableType;
//export type SnStore = ReturnType<typeof StoreZus>["getState"];
export const StoreZus = (initState: tableState = tableStateExport) => {
return createStore<SnStore>()((set) => {
return {
...initState,
...tableActionsExport(set)
}
})
}
//store 등록하는 부분
-116
View File
@@ -1,116 +0,0 @@
export type TableUpperProps = {
id: string,
title: string,
upSequnce?: number,
upName?: string
}
type PublicReuseFacility = {
sido: string,
sigungo: string,
facilityName: string,
location: string,
locationgubun: string,
facilityCapacity: string,
yn?: string,
authoDay?: string,
area?: string,
reuse?: string
}
const upHeadList:TableUpperProps[] = [
{ id: "sido", title: "자산ID"},
{ id: "sigungo", title: "설비시설"},
{ id: "facilityName", title: "주소"},
{ id: "location", title: "자산코드"},
{ id: "locationgubun", title: "자산명"},
{ id: "facilityCapacity", title: "용도"},
{ id: "yn", title: '신설/교체'},
{ id: "authoDay", title: '처리구역'},
{ id: "area", title: '내용연수' },
{ id: "reuse", title: '취득금액' },
];
const publicReuseFacilityUper:PublicReuseFacility[] = [
{
sido: "1048967",
sigungo: "관로",
facilityName: "양평군 양평읍 백안리 25-5전",
location: "S-T-S-2018000675",
locationgubun: "2018000675",
facilityCapacity: "오수관",
yn: "신설",
authoDay: "양평하수처리구역",
area: "30",
reuse: "28,313,220"
}
]
export type tableState = {
isInit: boolean;
upHeadList: TableUpperProps[];
publicReuseFacilityUper: PublicReuseFacility[];
}
type tableActions = {
setHeadList: (newHeadList: TableUpperProps[]) => void
setTableData: (newTableDataList: PublicReuseFacility[]) => void
decrementList: () => void
addRow: (newTableData: PublicReuseFacility) => void
}
export type tableType = tableState & tableActions;
export const tableStateExport:tableState= {
isInit:false,
upHeadList: [
{ id: "sido", title: "자산ID"},
{ id: "sigungo", title: "설비시설"},
{ id: "facilityName", title: "주소"},
{ id: "location", title: "자산코드"},
{ id: "locationgubun", title: "자산명"},
{ id: "facilityCapacity", title: "용도"},
{ id: "yn", title: '신설/교체'},
{ id: "authoDay", title: '처리구역'},
{ id: "area", title: '내용연수' },
{ id: "reuse", title: '취득금액' },
],
publicReuseFacilityUper: publicReuseFacilityUper,
}
export const tableActionsExport:(set:any)=>tableActions=(set: any) => {
return {
// 마지막 데이터 삭제
decrementList: ()=>set(
(state: tableState) => {
return (
{
...state,
upHeadList: state.upHeadList,
publicReuseFacilityUper: state.publicReuseFacilityUper.slice(0, state.publicReuseFacilityUper.length - 1)
})}
),
// 데이터 추가
addRow: (newTableData: PublicReuseFacility)=>set(
(state: tableState) => {
console.log('asdfasdfadsf')
return (
{
...state,
upHeadList: state.upHeadList,
publicReuseFacilityUper: [...state.publicReuseFacilityUper, newTableData]
})}
),
// 테이블 헤더 변경
setHeadList: (newHeadList: TableUpperProps[]) => set(
(state: tableState) => ({
...state,
upHeadList: newHeadList
})
),
// 시설 목록 데이터 변경
setTableData: (newTableData: PublicReuseFacility[]) => set(
(state: tableState) => ({
...state,
publicReuseFacilityUper: newTableData
})
),
}
}
+74
View File
@@ -0,0 +1,74 @@
"use client";
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { createStore } from "zustand/vanilla";
export interface IUserInfo {
regDt: string;
mdfcnDt: string;
rgtr: string;
mdfr: string;
adminRoleYn: string;
userUnqId: string;
userId: string;
userName: string;
email: string;
encryptedPassword: string;
refreshToken: string;
userStateCode: string;
lastLoginDate: string;
loginFailCount: number;
pswdHnt: string;
pswdAns: string;
mphn: string;
telno: string;
zip: string;
addr: string;
daddr: string;
laeSeCd: string;
ogdpSeCd: string;
aprvYn: string;
autzrId: string;
expryYmd: string;
lastPswdChgDt: string;
googleId: string;
kakaoId: string;
naverId: string;
isSocialUser: boolean;
hasPassword: boolean;
}
export type UserState = {
userInfo: IUserInfo | null;
};
type UserStore = {
userInfo: IUserInfo | null;
setUserInfo: (userInfo: IUserInfo | null) => void;
};
// ✅ zustand 기본 create + persist 적용
export const useUserStore = create<UserStore>()(
persist(
(set) => ({
userInfo: null,
setUserInfo: (userInfo) => set({ userInfo }),
}),
{
name: "user-store", // localStorage 키
partialize: (state) => ({ userInfo: state.userInfo }), // 선택적 저장
},
),
);
export const defaultInitState: UserState = {
userInfo: null,
};
export const createUserStore = (initState: UserState = defaultInitState) => {
return createStore<UserStore>()((set) => ({
...initState,
setUserInfo: (userInfo: IUserInfo | null) => set(() => ({ userInfo })),
}));
};