@campxdev/campx-web-utils 0.1.12 → 0.1.14

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@campxdev/campx-web-utils",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "main": "./exports.ts",
5
5
  "private": false,
6
6
  "dependencies": {
7
- "@campxdev/react-blueprint": "^1.1.2",
7
+ "@campxdev/react-blueprint": "^1.1.3",
8
8
  "@hookform/resolvers": "^3.9.0",
9
9
  "@mui/x-date-pickers": "^7.11.0",
10
10
  "@testing-library/jest-dom": "^5.14.1",
package/src/App.tsx CHANGED
@@ -1,15 +1,13 @@
1
- import { BrowserRouter, useRoutes } from "react-router-dom";
2
- import Providers from "./context/Providers";
1
+ import { useRoutes } from "react-router-dom";
2
+
3
3
  import { mainRoutes } from "./Pages/main";
4
+ import { Providers } from "./context/export";
4
5
 
5
6
  export default function App() {
6
- var baseName = "/";
7
7
  return (
8
- <BrowserRouter basename={baseName}>
9
- <Providers>
10
- <AppRouter />
11
- </Providers>
12
- </BrowserRouter>
8
+ <Providers>
9
+ <AppRouter />
10
+ </Providers>
13
11
  );
14
12
  }
15
13
  const AppRouter = () => {
@@ -4,9 +4,10 @@ import { SnackbarStore } from "../context/SnackbarProvider";
4
4
 
5
5
  const isDevelopment = process.env.NODE_ENV == "development";
6
6
 
7
- const tenantCode = isDevelopment
8
- ? Cookies.get("campx_tenant")
9
- : window.location.hostname.split(".")[0];
7
+ const tenantCode =
8
+ window.location.hostname === "localhost"
9
+ ? Cookies.get("campx_tenant")
10
+ : window.location.hostname.split(".")[0];
10
11
  const institutionCode = window.location.pathname.split("/")[1];
11
12
 
12
13
  export const formatParams = (params: any) => {
@@ -12,12 +12,10 @@ import { ReactNode, useState } from "react";
12
12
  import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary";
13
13
  import { QueryErrorResetBoundary } from "react-query";
14
14
  import { useLocation, useNavigate } from "react-router-dom";
15
- import { axios } from "../../config/axios";
16
15
  import { Login } from "./Login";
17
16
 
18
17
  export type ErrorBoundaryProps = {
19
18
  children: ReactNode;
20
- resetKey?: string;
21
19
  };
22
20
 
23
21
  const StyledAlert = styled(Alert)(({ theme }) => ({
@@ -57,7 +55,7 @@ export const ErrorBoundary = (props: ErrorBoundaryProps) => {
57
55
  );
58
56
  };
59
57
 
60
- export const ErrorFallback = ({ error, resetErrorBoundary }: any) => {
58
+ const ErrorFallback = ({ error, resetErrorBoundary }: any) => {
61
59
  if (error?.response?.status) {
62
60
  switch (error?.response?.status) {
63
61
  case 401:
@@ -98,20 +96,12 @@ const UnAuth = () => {
98
96
 
99
97
  const sessionCookie = Cookies.get("campx_session_key");
100
98
 
101
- const appinit = async () => {
102
- await axios.get("/auth/my-permissions").catch((e: any) => {
103
- navigate("/auth/login");
104
- });
105
- };
106
-
107
99
  const handleLoginClick = () => {
108
100
  if (window.location.hostname == "localhost") {
109
101
  setModalOpen(true);
110
102
  } else {
111
103
  if (!sessionCookie) {
112
104
  navigate("/auth/login");
113
- } else {
114
- appinit();
115
105
  }
116
106
  }
117
107
  };
@@ -1,10 +1,20 @@
1
- import { MuiThemeProvider } from "@campxdev/react-blueprint";
2
- import { ReactNode } from "react";
1
+ import { lightTheme, MuiThemeProvider } from "@campxdev/react-blueprint";
2
+ import Cookies from "js-cookie";
3
+ import { ReactNode, useEffect } from "react";
3
4
  import { QueryClient, QueryClientProvider } from "react-query";
4
- import { SnackbarProvider } from "./SnackbarProvider";
5
+ import { BrowserRouter } from "react-router-dom";
5
6
  import { ErrorBoundary } from "./export";
7
+ import { SnackbarProvider } from "./SnackbarProvider";
6
8
 
7
- export default function Providers({ children }: { children: ReactNode }) {
9
+ export const Providers = ({
10
+ children,
11
+ basename,
12
+ theme = lightTheme,
13
+ }: {
14
+ children: ReactNode;
15
+ basename?: string;
16
+ theme?: any;
17
+ }) => {
8
18
  const queryClient = new QueryClient({
9
19
  defaultOptions: {
10
20
  queries: {
@@ -15,13 +25,30 @@ export default function Providers({ children }: { children: ReactNode }) {
15
25
  },
16
26
  });
17
27
 
28
+ var tenantCode =
29
+ window.location.hostname === "localhost"
30
+ ? Cookies.get("campx_tenant")
31
+ : window.location.hostname.split(".")[0];
32
+ var institutionCode =
33
+ window.location.pathname.split("/")[1] !== ""
34
+ ? window.location.pathname.split("/")[1]
35
+ : Cookies.get("campx_institution");
36
+ var baseName = tenantCode && institutionCode ? `/${institutionCode}` : "/";
37
+ useEffect(() => {
38
+ if (window.location.pathname === "/" && institutionCode && tenantCode) {
39
+ window.location.replace(window.location.origin + `/${institutionCode}`);
40
+ }
41
+ }, []);
42
+
18
43
  return (
19
- <QueryClientProvider client={queryClient}>
20
- <MuiThemeProvider>
21
- <SnackbarProvider>
22
- <ErrorBoundary>{children}</ErrorBoundary>
23
- </SnackbarProvider>
24
- </MuiThemeProvider>
25
- </QueryClientProvider>
44
+ <BrowserRouter basename={basename ?? baseName}>
45
+ <QueryClientProvider client={queryClient}>
46
+ <MuiThemeProvider theme={theme}>
47
+ <SnackbarProvider>
48
+ <ErrorBoundary>{children}</ErrorBoundary>
49
+ </SnackbarProvider>
50
+ </MuiThemeProvider>
51
+ </QueryClientProvider>
52
+ </BrowserRouter>
26
53
  );
27
- }
54
+ };
package/types/theme.d.ts CHANGED
@@ -54,5 +54,6 @@ declare module "@mui/material/Typography" {
54
54
  label1: true;
55
55
  label2: true;
56
56
  subtitle3: true;
57
+ button1: true;
57
58
  }
58
59
  }