@asaleh37/ui-base 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaleh37/ui-base",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Ahmed Saleh Mohamed",
@@ -10,7 +10,6 @@ import { AppInfo, AppInfoActions } from "../redux/features/common/AppInfoSlice";
10
10
 
11
11
  const App: React.FC<AppInfo> = (props: AppInfo) => {
12
12
  const dispatch = useDispatch();
13
- console.log("App Info", props);
14
13
  const AppLayoutState = useSelector((state: RootState) => state.AppLayout);
15
14
  let themeOptions = { ...LightThemeOptions };
16
15
  if (AppLayoutState.themeMode === "dark") {
@@ -26,7 +25,7 @@ const App: React.FC<AppInfo> = (props: AppInfo) => {
26
25
  }, []);
27
26
  return (
28
27
  <ThemeProvider theme={theme}>
29
- {props?.apiBaseUrl ? <Layout /> : <>No Info Yet</>}
28
+ <Layout />
30
29
  </ThemeProvider>
31
30
  );
32
31
  };
@@ -1,5 +1,5 @@
1
1
  import { Provider } from "react-redux";
2
- import { store } from "../redux/store";
2
+ import { addReducer, store } from "../redux/store";
3
3
  import { library } from "@fortawesome/fontawesome-svg-core";
4
4
  import { fab } from "@fortawesome/free-brands-svg-icons";
5
5
  import { far } from "@fortawesome/free-regular-svg-icons";
@@ -13,12 +13,29 @@ LicenseInfo.setLicenseKey(
13
13
  import "react-toastify/dist/ReactToastify.css";
14
14
  import App from "./App";
15
15
  import { AppInfo } from "../redux/features/common/AppInfoSlice";
16
+ import { commonStoresInitialState } from "../redux/features/common/CommonStoreSlice";
16
17
 
17
18
  library.add(fab);
18
19
  library.add(far);
19
20
  library.add(fas);
20
21
 
21
22
  export const BaseApp: React.FC<AppInfo> = (props) => {
23
+ if (props?.businessCommonStoresMetaData) {
24
+ for (let businessStoreKey of Object.keys(
25
+ props.businessCommonStoresMetaData
26
+ )) {
27
+ commonStoresInitialState[businessStoreKey] =
28
+ props.businessCommonStoresMetaData[businessStoreKey];
29
+ }
30
+ }
31
+ if (props?.businessReduxReducers) {
32
+ for (let businessReducerKey of Object.keys(props.businessReduxReducers)) {
33
+ addReducer(
34
+ businessReducerKey,
35
+ props.businessReduxReducers[businessReducerKey]
36
+ );
37
+ }
38
+ }
22
39
  return (
23
40
  <Provider store={store}>
24
41
  <App {...props} />
@@ -36,8 +36,6 @@ const Login: React.FC = () => {
36
36
  }
37
37
  setIsLoginInProcess(true);
38
38
  let response: any = null;
39
- console.log("login appinfo", appInfo);
40
- debugger;
41
39
  try {
42
40
  response = await axios.post(
43
41
  `${appInfo.apiBaseUrl}/api/auth/login`,
@@ -71,32 +69,34 @@ const Login: React.FC = () => {
71
69
  );
72
70
  const loginTheme = createTheme(DarkThemeOptions);
73
71
  const checkUserSession = async () => {
74
- if (userSession.isAuthenticated == null) {
75
- try {
76
- let response = await axios.get(
77
- `${appInfo.apiBaseUrl}/api/auth/userInfo`,
78
- {
79
- withCredentials: true,
72
+ if (appInfo?.apiBaseUrl) {
73
+ if (userSession.isAuthenticated == null) {
74
+ try {
75
+ let response = await axios.get(
76
+ `${appInfo.apiBaseUrl}/api/auth/userInfo`,
77
+ {
78
+ withCredentials: true,
79
+ }
80
+ );
81
+ if (response != null && response.data != null) {
82
+ const UserSession = {
83
+ isAuthenticated: true,
84
+ authorities: response.data.authorities,
85
+ userProfile: response.data,
86
+ };
87
+ dispatch(UserSessionActions.setAuthenticated(UserSession));
88
+ } else {
89
+ dispatch(UserSessionActions.setUnAuthenticated());
80
90
  }
81
- );
82
- if (response != null && response.data != null) {
83
- const UserSession = {
84
- isAuthenticated: true,
85
- authorities: response.data.authorities,
86
- userProfile: response.data,
87
- };
88
- dispatch(UserSessionActions.setAuthenticated(UserSession));
89
- } else {
91
+ } catch (error) {
90
92
  dispatch(UserSessionActions.setUnAuthenticated());
91
93
  }
92
- } catch (error) {
93
- dispatch(UserSessionActions.setUnAuthenticated());
94
94
  }
95
95
  }
96
96
  };
97
97
  useEffect(() => {
98
98
  checkUserSession();
99
- }, []);
99
+ }, [appInfo]);
100
100
  return (
101
101
  <ThemeProvider theme={loginTheme}>
102
102
  <Paper
@@ -4,3 +4,4 @@ export * from "zod";
4
4
  export { toast } from "react-toastify";
5
5
  export { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
6
6
  export type { FontAwesomeIconProps } from "@fortawesome/react-fontawesome";
7
+ export * from "./templates";
@@ -1,8 +1,8 @@
1
1
  import { useDispatch, useSelector } from "react-redux";
2
2
  import { RootState } from "../../../redux/store";
3
- import { setStoreData } from "../../../redux/features/business/CommonStoreSlice";
4
3
  import useSession from "../../../hooks/UseSession";
5
4
  import useAxios from "../../../hooks/useAxios";
5
+ import { setStoreData } from "../../../redux/features/common/CommonStoreSlice";
6
6
 
7
7
  export type ApiActionsProps = {
8
8
  findAll?: string;
@@ -23,7 +23,7 @@ function union(a, b) {
23
23
  return [...a, ...not(b, a)];
24
24
  }
25
25
 
26
- type TransferListProps = {
26
+ export type TransferListProps = {
27
27
  valueField: string;
28
28
  displayField: string;
29
29
  options: Array<any>;
@@ -0,0 +1,19 @@
1
+ export { default as TransferList } from "./TransferList";
2
+ export { default as TemplateDashboard } from "./visuals/TemplateDashboard";
3
+ export { default as TemplateBarChart } from "./visuals/charts/TemplateBarChart";
4
+ export { default as TemplateDataCard } from "./visuals/charts/TemplateDataCard";
5
+ export { default as TemplateGauge } from "./visuals/charts/TemplateGauge";
6
+ export { default as TemplateLineChart } from "./visuals/charts/TemplateLineChart";
7
+ export { default as TemplateLineProgress } from "./visuals/charts/TemplateLineProgress";
8
+ export { default as TemplatePieChart } from "./visuals/charts/TemplatePieChart";
9
+ export { default as CheckBox } from "./DataEntryTemplates/TemplateDataForm/FormFields/CheckBox";
10
+ export { default as ComboBox } from "./DataEntryTemplates/TemplateDataForm/FormFields/ComboBox";
11
+ export { default as Datefield } from "./DataEntryTemplates/TemplateDataForm/FormFields/Datefield";
12
+ export { default as DatetimeField } from "./DataEntryTemplates/TemplateDataForm/FormFields/DatetimeField";
13
+ export { default as TemplateTextField } from "./DataEntryTemplates/TemplateDataForm/FormFields/TemplateTextField";
14
+ export { default as TemplateForm } from "./DataEntryTemplates/TemplateDataForm/TemplateForm";
15
+ export { default as TemplateGrid } from "./DataEntryTemplates/TemplateDataGrid/TemplateGrid";
16
+
17
+ export type * from "./DataEntryTemplates/DataEntryTypes";
18
+ export type { DashboardProps } from "./visuals/TemplateDashboard";
19
+ export type { TransferListProps } from "./TransferList";
@@ -27,7 +27,7 @@ export interface SingleRecordWidgetProps {
27
27
  labelField: string;
28
28
  }
29
29
 
30
- interface DashboardProps {
30
+ export interface DashboardProps {
31
31
  dashboardTitle: string;
32
32
  dashboardWidgets: Array<WidgetProps>;
33
33
  }
@@ -0,0 +1,6 @@
1
+ export { default as useAxios } from "./useAxios";
2
+ export { useConfirmationWindow } from "./UseConfirmationWindow";
3
+ export { default as useLoadingMask } from "./useLoadingMask";
4
+ export { useIsMobile } from "./UseMobile";
5
+ export { default as useSession } from "./UseSession";
6
+ export { useWindow } from "./UseWindow";
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- // export { default as MyComponent1 } from "./MyComponent1";
2
- // export type { MyComponent1Props } from "./MyComponent1";
3
1
  export * from "./components";
2
+ export * from "./hooks";
3
+ export * from "./util";
@@ -14,12 +14,11 @@ import useLoadingMask from "../hooks/useLoadingMask";
14
14
  import { useIsMobile } from "../hooks/UseMobile";
15
15
  import useSession from "../hooks/UseSession";
16
16
  import useAxios from "../hooks/useAxios";
17
- import { setStoreData } from "../redux/features/business/CommonStoreSlice";
18
17
  import { DRAWER_WIDTH } from "../redux/features/common/AppLayoutSlice";
19
18
  import { UserSessionProps } from "../redux/features/common/UserSessionSlice";
20
19
  import LoadingMask from "../components/common/LoadingMask";
21
20
  import Login from "../components/common/Login";
22
-
21
+ import { setStoreData } from "../redux/features/common/CommonStoreSlice";
23
22
 
24
23
  const Main = styled("main", {
25
24
  shouldForwardProp: (prop) => prop !== "open",
@@ -104,7 +103,7 @@ export default function Layout() {
104
103
  return (
105
104
  <BrowserRouter>
106
105
  <ToastContainer draggable={true} position="bottom-center" />
107
- <LoadingMask />
106
+ <LoadingMask />
108
107
  {UserSession.value.isAuthenticated === true ? (
109
108
  <Main open={AppLayoutState.sideBarOpened}>
110
109
  <CssBaseline />
@@ -9,6 +9,9 @@ import { SystemRoute } from "../routes/types";
9
9
 
10
10
  const MainContent: React.FC = () => {
11
11
  const AppLayoutState = useSelector((state: RootState) => state.AppLayout);
12
+ const businessRoutes = useSelector(
13
+ (state: RootState) => state.AppInfo.value.businessRoutes
14
+ );
12
15
  return (
13
16
  <CacheProvider
14
17
  value={AppLayoutState.appDirection === "ltr" ? cacheLtr : cacheRtl}
@@ -19,7 +22,7 @@ const MainContent: React.FC = () => {
19
22
  flexDirection: "column",
20
23
  // alignItems: "center",
21
24
  justifyContent: "flex-start",
22
- flex: 1,
25
+ flex: 1,
23
26
  overflow: "hidden",
24
27
  padding: 3,
25
28
  }}
@@ -28,7 +31,16 @@ const MainContent: React.FC = () => {
28
31
  {SYSTEM_ROUTES.map((route: SystemRoute, index) => {
29
32
  return (
30
33
  <Route
31
- key={index}
34
+ key={"adm" + index}
35
+ path={route.path}
36
+ Component={route.component}
37
+ />
38
+ );
39
+ })}
40
+ {businessRoutes.map((route: SystemRoute, index) => {
41
+ return (
42
+ <Route
43
+ key={"bs" + index}
32
44
  path={route.path}
33
45
  Component={route.component}
34
46
  />
@@ -232,6 +232,9 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(
232
232
  export default function NavigationTree() {
233
233
  const navigate = useNavigate();
234
234
  const appLayoutState = useSelector((state: RootState) => state.AppLayout);
235
+ const businessNavigationItems = useSelector(
236
+ (state: RootState) => state.AppInfo.value.businessNavigationItems
237
+ );
235
238
  const dispatch = useDispatch();
236
239
  const isMobile = useIsMobile();
237
240
  const { isUserAuthorized } = useSession();
@@ -251,7 +254,12 @@ export default function NavigationTree() {
251
254
  });
252
255
  };
253
256
 
254
- const authoriedNavigationItems = filterData(NavigationItems);
257
+ const mergedNavigationItems = [
258
+ ...NavigationItems,
259
+ ...businessNavigationItems,
260
+ ];
261
+
262
+ const authoriedNavigationItems = filterData(mergedNavigationItems);
255
263
 
256
264
  return (
257
265
  <RichTreeView
@@ -1,4 +1,4 @@
1
- import { CommonStoresInterface } from "../business/CommonStoreSlice";
1
+ import { CommonStoresInterface } from "../common/CommonStoreSlice";
2
2
 
3
3
  export const ADMINISTRATION_STORES: CommonStoresInterface = {
4
4
  SystemDataSourceType: {
@@ -1,4 +1,7 @@
1
- import { createSlice } from "@reduxjs/toolkit";
1
+ import { createSlice, Reducer } from "@reduxjs/toolkit";
2
+ import { SystemRoute } from "../../../routes/types";
3
+ import { ExtendedTreeItemProps } from "../../../navigationItems";
4
+ import { StoreMetaData } from "./CommonStoreSlice";
2
5
 
3
6
  export type AppInfo = {
4
7
  documentTitle: string | null;
@@ -6,6 +9,10 @@ export type AppInfo = {
6
9
  appName: string | null;
7
10
  appVersion: string | null;
8
11
  appLogo: any | null;
12
+ businessRoutes: Array<SystemRoute>;
13
+ businessNavigationItems: Array<ExtendedTreeItemProps>;
14
+ businessReduxReducers: { [key: string]: Reducer<any> };
15
+ businessCommonStoresMetaData: { [key: string]: StoreMetaData };
9
16
  };
10
17
 
11
18
  export type AppInfoProp = {
@@ -19,6 +26,10 @@ const initialState: AppInfoProp = {
19
26
  appName: null,
20
27
  appVersion: null,
21
28
  appLogo: null,
29
+ businessRoutes: [],
30
+ businessNavigationItems: [],
31
+ businessReduxReducers: {},
32
+ businessCommonStoresMetaData: {},
22
33
  },
23
34
  };
24
35
 
@@ -1,5 +1,4 @@
1
1
  import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2
- import { BUSINESS_STORES } from "./BusinessStoresMetaData";
3
2
  import { ADMINISTRATION_STORES } from "../administration/AdministrationStoresMetaData";
4
3
 
5
4
  export interface CommonStoresInterface {
@@ -18,14 +17,13 @@ export interface StoreMetaData {
18
17
  authority?: string;
19
18
  }
20
19
 
21
- const initialState: CommonStoresInterface = {
22
- ...BUSINESS_STORES,
20
+ export const commonStoresInitialState: CommonStoresInterface = {
23
21
  ...ADMINISTRATION_STORES,
24
22
  };
25
23
 
26
24
  const commonStoreSlice = createSlice({
27
25
  name: "loadingMask",
28
- initialState,
26
+ initialState: commonStoresInitialState,
29
27
  reducers: {
30
28
  setStoreData(state, action: PayloadAction<setStoreDataProps>) {
31
29
  state[action.payload.storeKey].data = action.payload.data;
@@ -1,18 +1,26 @@
1
- import { configureStore } from "@reduxjs/toolkit";
1
+ import { configureStore, Reducer } from "@reduxjs/toolkit";
2
2
  import AppLayoutReducer from "./features/common/AppLayoutSlice";
3
3
  import UserSessionReducer from "./features/common/UserSessionSlice";
4
4
  import LoadingMaskReducer from "./features/common/LoadingMaskSlice";
5
- import CommonStoreReducer from "./features/business/CommonStoreSlice";
5
+ import CommonStoreReducer from "./features/common/CommonStoreSlice";
6
6
  import AppInfoReducer from "./features/common/AppInfoSlice";
7
7
 
8
+ const reducers = {
9
+ AppLayout: AppLayoutReducer,
10
+ UserSession: UserSessionReducer,
11
+ loadingMask: LoadingMaskReducer,
12
+ commonStores: CommonStoreReducer,
13
+ AppInfo: AppInfoReducer,
14
+ };
15
+
16
+ export function addReducer(key: string, reducer: Reducer<any>) {
17
+ if (!reducers[key]) {
18
+ reducers[key] = reducer;
19
+ }
20
+ }
21
+
8
22
  export const store = configureStore({
9
- reducer: {
10
- AppLayout: AppLayoutReducer,
11
- UserSession: UserSessionReducer,
12
- loadingMask: LoadingMaskReducer,
13
- commonStores: CommonStoreReducer,
14
- AppInfo: AppInfoReducer,
15
- },
23
+ reducer: reducers,
16
24
  });
17
25
 
18
26
  // Infer the `RootState` and `AppDispatch` types from the store itself
@@ -0,0 +1,2 @@
1
+ export * from "./AppUtils";
2
+ export * from "./constants";
@@ -1,3 +0,0 @@
1
- import { CommonStoresInterface } from "./CommonStoreSlice";
2
-
3
- export const BUSINESS_STORES: CommonStoresInterface = {};