@campxdev/react-blueprint 1.5.7 → 1.5.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/export.ts CHANGED
@@ -2,3 +2,4 @@ export * from './src/components/export';
2
2
  export * from './src/hooks/export';
3
3
  export * from './src/redux/export';
4
4
  export * from './src/themes/export';
5
+ export * from './src/utils/export';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/react-blueprint",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "main": "./export.ts",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -6,26 +6,14 @@ import {
6
6
  } from '@mui/material';
7
7
  import _ from 'lodash';
8
8
  import { Link } from 'react-router-dom';
9
+
10
+ import { getBreadcrumbsCharacter } from '../../../utils/export';
9
11
  import { Typography } from '../../export';
10
12
 
11
13
  export type BreadcrumbsProps = {
12
14
  pathTrimCount: number;
13
15
  } & MuiBreadcrumbsProps;
14
16
 
15
- const getBreadcrumbsCharacter = () => {
16
- const unicodeChar = String.fromCharCode(0x21e5);
17
- const testElement = document.createElement('span');
18
- testElement.innerHTML = unicodeChar;
19
- document.body.appendChild(testElement);
20
- const isRendered = testElement.offsetWidth > 0;
21
- document.body.removeChild(testElement);
22
-
23
- const fallbackChar = '~~';
24
- const s = isRendered ? unicodeChar : fallbackChar;
25
-
26
- return s;
27
- };
28
-
29
17
  export const Breadcrumbs = ({ pathTrimCount, ...rest }: BreadcrumbsProps) => {
30
18
  const specialCharacter = getBreadcrumbsCharacter();
31
19
  const currentPathArray = window.location.pathname.split('/');
@@ -1 +1,3 @@
1
1
  export * from './usePageHeader';
2
+ export * from './useParams';
3
+ export * from './useUrlParams';
@@ -0,0 +1,20 @@
1
+ import { useParams as useReactRouterParams } from 'react-router-dom';
2
+ import { getBreadcrumbsCharacter } from '../utils/breadcrumbs';
3
+
4
+ export const useParams = (): {
5
+ [x: string]: { id: string | number; slug: string };
6
+ } => {
7
+ const params = useReactRouterParams();
8
+
9
+ const processedParams = Object.fromEntries(
10
+ Object.entries(params).map(([key, value]) => {
11
+ if (value) {
12
+ const [slug, id] = value.split(getBreadcrumbsCharacter());
13
+ return [key, { slug, id }];
14
+ }
15
+ return [];
16
+ }),
17
+ );
18
+
19
+ return processedParams;
20
+ };
@@ -0,0 +1,3 @@
1
+ export const useUrlParams = (): { [x: string]: string } => {
2
+ return Object.fromEntries(new URLSearchParams(window.location.search));
3
+ };
@@ -0,0 +1,23 @@
1
+ import _ from 'lodash';
2
+
3
+ export const getBreadcrumbsCharacter = () => {
4
+ const unicodeChar = String.fromCharCode(0x21e5);
5
+ const testElement = document.createElement('span');
6
+ testElement.innerHTML = unicodeChar;
7
+ document.body.appendChild(testElement);
8
+ const isRendered = testElement.offsetWidth > 0;
9
+ document.body.removeChild(testElement);
10
+
11
+ const fallbackChar = '~~';
12
+ const s = isRendered ? unicodeChar : fallbackChar;
13
+
14
+ return s;
15
+ };
16
+
17
+ type CreateUrlSlug = {
18
+ name: string;
19
+ id: string | number;
20
+ };
21
+ export const createBreadcrumbIdSlug = ({ name, id }: CreateUrlSlug): string => {
22
+ return `${_.kebabCase(name)}${getBreadcrumbsCharacter()}${id}`;
23
+ };
@@ -1,6 +1,2 @@
1
- import Cookies from 'js-cookie';
2
-
3
1
  export const isDevelopment: boolean = process.env.NODE_ENV === 'development';
4
- export const urlTenantKey = window.location.pathname.split('/')[1];
5
- export const institutionKey = window.location.pathname.split('/')[2];
6
- export const sessionKey = Cookies.get('campx_session_key');
2
+ export const isLocal = window.location.hostname === 'localhost';
@@ -0,0 +1,2 @@
1
+ export * from './breadcrumbs';
2
+ export * from './constants';
@@ -1,19 +0,0 @@
1
- import axios from 'axios';
2
- import Cookies from 'js-cookie';
3
-
4
- export default function logout() {
5
- axios({
6
- method: 'POST',
7
- baseURL: process.env.REACT_APP_API_HOST,
8
- url: '/auth-server/auth/logout',
9
- })
10
- .then((res) => {
11
- Cookies.remove('campx_tenant');
12
- Cookies.remove('campx_session_key');
13
- Cookies.remove('campx_institution');
14
- window.location.href = '/';
15
- })
16
- .catch((err) => {
17
- // toast("Unable To Logout.");
18
- });
19
- }