@campxdev/campx-web-utils 0.1.0 → 0.1.1

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/export.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/config/axios";
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@campxdev/campx-web-utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "./exports.ts",
5
5
  "private": false,
6
6
  "dependencies": {
7
+ "@campxdev/react-blueprint": "^0.1.41",
7
8
  "@testing-library/jest-dom": "^5.14.1",
8
9
  "@testing-library/react": "^13.0.0",
9
10
  "@testing-library/user-event": "^13.2.1",
@@ -11,12 +12,18 @@
11
12
  "@types/node": "^16.7.13",
12
13
  "@types/react": "^18.0.0",
13
14
  "@types/react-dom": "^18.0.0",
15
+ "axios": "^1.7.2",
16
+ "cookie-js": "^0.0.1",
17
+ "pullstate": "^1.25.0",
14
18
  "react": "^18.3.1",
15
19
  "react-dom": "^18.3.1",
16
20
  "react-scripts": "5.0.1",
17
21
  "typescript": "^4.4.2",
18
22
  "web-vitals": "^2.1.0"
19
23
  },
24
+ "devDependencies": {
25
+ "@types/js-cookie": "^3.0.2"
26
+ },
20
27
  "scripts": {
21
28
  "start": "react-scripts start",
22
29
  "build": "react-scripts build",
File without changes
@@ -0,0 +1,22 @@
1
+ import Axios from "axios";
2
+ import Cookies from "js-cookie";
3
+
4
+ const isDevelopment = process.env.NODE_ENV == "development";
5
+
6
+ const sessionKey = Cookies.get("campx_session_key");
7
+ const tenantCode = isDevelopment
8
+ ? window.location.pathname.split("/")[1]
9
+ : window.location.hostname.split(".")[0];
10
+ const institutionCode = isDevelopment
11
+ ? window.location.pathname.split("/")[2]
12
+ : window.location.pathname.split("/")[1];
13
+
14
+ export const axios = Axios.create({
15
+ baseURL: process.env.REACT_APP_API_HOST,
16
+ withCredentials: true,
17
+ headers: {
18
+ "x-tenant-id": tenantCode,
19
+ "x-institution-code": institutionCode,
20
+ ...(isDevelopment && sessionKey ? { campx_session_key: sessionKey } : {}),
21
+ },
22
+ });
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+
3
+ const LoginContext = createContext<{ openLoginDialog: () => void }>({
4
+ openLoginDialog: () => {},
5
+ });
@@ -0,0 +1,12 @@
1
+ import { Store } from "pullstate";
2
+
3
+ export type ApplicationStoreType = {
4
+ isLoginDialogOpen: boolean;
5
+ };
6
+
7
+ export const initialApplicationState: ApplicationStoreType = {
8
+ isLoginDialogOpen: false,
9
+ };
10
+ export const ApplicationStore = new Store<ApplicationStoreType>(
11
+ initialApplicationState
12
+ );