This commit is contained in:
2026-04-28 09:27:54 +07:00
commit 68d05da584
320 changed files with 26229 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
'use client';
import { useRef } from 'react';
import { Provider } from 'react-redux';
import { store } from './store';
export default function StoreProvider({
children,
}: {
children: React.ReactNode;
}) {
const storeRef = useRef(store);
return <Provider store={storeRef.current}>{children}</Provider>;
}
+48
View File
@@ -0,0 +1,48 @@
import { UserData } from '@/interface/user';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
const getStoredApplication = () => {
if (typeof window !== "undefined") {
const saved = sessionStorage.getItem('selected_application');
return saved ? JSON.parse(saved) : null;
}
return null;
};
interface UserState {
data: UserData | null;
isAuthenticated: boolean;
selectedApplication: any | null;
}
const initialState: UserState = {
data: null,
isAuthenticated: false,
selectedApplication: getStoredApplication(),
};
const userSlice = createSlice({
name: 'user',
initialState,
reducers: {
setUserData: (state, action: PayloadAction<UserData>) => {
state.data = action.payload;
state.isAuthenticated = true;
},
setSelectedApplication: (state, action: PayloadAction<any>) => {
state.selectedApplication = action.payload;
if (typeof window !== "undefined") {
sessionStorage.setItem('selected_application', JSON.stringify(action.payload));
}
},
clearSelectedApplication: (state) => {
state.selectedApplication = null;
if (typeof window !== "undefined") {
sessionStorage.removeItem('selected_application');
}
},
},
});
export const { setUserData, setSelectedApplication, clearSelectedApplication } = userSlice.actions;
export default userSlice.reducer;
+11
View File
@@ -0,0 +1,11 @@
import { configureStore } from '@reduxjs/toolkit';
import userReducer from './features/userSlice';
export const store = configureStore({
reducer: {
user: userReducer,
},
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;