wcz-layout 5.2.2 → 5.3.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "wcz-layout",
3
3
  "license": "MIT",
4
4
  "author": "Dalibor Homola",
5
- "version": "5.2.2",
5
+ "version": "5.3.1",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "exports": {
@@ -6,8 +6,8 @@ import I18NextHttpBackend from 'i18next-http-backend';
6
6
  import moment from 'moment';
7
7
  import { createContext, ReactNode, SyntheticEvent, useCallback, useEffect, useMemo, useState } from 'react';
8
8
  import { initReactI18next, useTranslation } from 'react-i18next';
9
- import Layout from '../components/Layout';
10
9
  import CenteredBox from '../components/common/CenteredBox';
10
+ import Layout from '../components/Layout';
11
11
  import KeycloakExtendedConfig from '../models/KeycloakExtendedConfig';
12
12
  import { LeftDrawerItem } from '../models/LeftDrawerItem';
13
13
  import SnackbarModel from '../models/SnackbarModel';
@@ -39,7 +39,6 @@ i18next
39
39
  .use(I18NextHttpBackend)
40
40
  .init({ fallbackLng: 'en' });
41
41
 
42
- //Moment
43
42
  moment.defaultFormat = 'YYYY-MM-DD';
44
43
 
45
44
  declare module "moment" {
@@ -103,10 +102,11 @@ export function LayoutProvider(props: LayoutProviderProps) {
103
102
  queries: {
104
103
  enabled: enabled,
105
104
  refetchOnWindowFocus: false,
106
- onError: message => setSnackbar({ message: String(message), severity: "error" })
105
+ onError: message => setSnackbar({ message: String(message), severity: "error" }),
106
+ retry: false
107
107
  },
108
108
  mutations: {
109
- onError: message => setSnackbar({ message: String(message), severity: "error" })
109
+ onError: message => setSnackbar({ message: String(message), severity: "error" }),
110
110
  }
111
111
  });
112
112
  };
@@ -1,12 +1,12 @@
1
- export default interface KeycloakExtendedConfig {
2
- autoLogin?: boolean,
3
- confidential?: Confidential,
4
- realm: string,
5
- "auth-server-url": string,
6
- idpHint?: string
7
- }
8
-
9
- export interface Confidential {
10
- client: string,
11
- secret: string
1
+ export default interface KeycloakExtendedConfig {
2
+ autoLogin?: boolean,
3
+ confidential?: Confidential,
4
+ realm: string,
5
+ "auth-server-url": string,
6
+ idpHint?: string
7
+ }
8
+
9
+ export interface Confidential {
10
+ client: string,
11
+ secret: string
12
12
  }
@@ -1,6 +1,6 @@
1
- export interface LeftDrawerItem {
2
- title: string,
3
- path: string,
4
- icon: React.ReactNode,
5
- hidden?: boolean
6
- }
1
+ export interface LeftDrawerItem {
2
+ title: string,
3
+ path: string,
4
+ icon: React.ReactNode,
5
+ hidden?: boolean
6
+ }
@@ -1,6 +1,6 @@
1
- import { AlertColor } from "@mui/material";
2
-
3
- export default interface SnackbarModel {
4
- message: string,
5
- severity?: AlertColor
1
+ import { AlertColor } from "@mui/material";
2
+
3
+ export default interface SnackbarModel {
4
+ message: string,
5
+ severity?: AlertColor
6
6
  }
@@ -1,13 +1,13 @@
1
- import { KeycloakPromise } from "keycloak-js";
2
-
3
- export interface User {
4
- id: string,
5
- name: string,
6
- department: string
7
- }
8
-
9
- export interface ExtendedUser extends User {
10
- loggedIn: boolean,
11
- login: () => KeycloakPromise<void, void>,
12
- logout: () => KeycloakPromise<void, void>
1
+ import { KeycloakPromise } from "keycloak-js";
2
+
3
+ export interface User {
4
+ id: string,
5
+ name: string,
6
+ department: string
7
+ }
8
+
9
+ export interface ExtendedUser extends User {
10
+ loggedIn: boolean,
11
+ login: () => KeycloakPromise<void, void>,
12
+ logout: () => KeycloakPromise<void, void>
13
13
  }
@@ -1,92 +1,92 @@
1
- import { getToken } from "./UserService";
2
-
3
- export const fetchGet = async (url: string, signal: AbortSignal | undefined): Promise<any> => {
4
- const initReq: RequestInit = await getRequestInit("GET", null, signal);
5
-
6
- const response: Response = await fetch(url, initReq);
7
- if (!response.ok)
8
- throw await getQueryErrorMessage(response);
9
-
10
- return response.json();
11
- };
12
-
13
- export const fetchFileGet = async (url: string, signal: AbortSignal | undefined): Promise<Blob> => {
14
- const initReq: RequestInit = await getRequestInit("GET", null, signal);
15
-
16
- const response: Response = await fetch(url, initReq);
17
- if (!response.ok)
18
- throw await getQueryErrorMessage(response);
19
-
20
- return response.blob();
21
- };
22
-
23
- export const fetchPost = async (url: string, data: unknown): Promise<any> => {
24
- const initReq: RequestInit = await getRequestInit("POST", data);
25
-
26
- const response: Response = await fetch(url, initReq);
27
- if (!response.ok)
28
- throw await getQueryErrorMessage(response);
29
-
30
- return response.json();
31
- };
32
-
33
- export const fetchPut = async (url: string, data: unknown): Promise<Response> => {
34
- const initReq: RequestInit = await getRequestInit("PUT", data);
35
-
36
- const response: Response = await fetch(url, initReq);
37
- if (!response.ok)
38
- throw await getQueryErrorMessage(response);
39
-
40
- return response;
41
- };
42
-
43
- export const fetchDelete = async (url: string): Promise<Response> => {
44
- const initReq: RequestInit = await getRequestInit("DELETE");
45
-
46
- const response: Response = await fetch(url, initReq);
47
- if (!response.ok)
48
- throw await getQueryErrorMessage(response);
49
-
50
- return response;
51
- };
52
-
53
- const getRequestInit = async (method: string, data?: unknown, signal?: AbortSignal): Promise<RequestInit> => {
54
- const request: RequestInit = {
55
- method: method,
56
- signal: signal,
57
- credentials: 'include'
58
- };
59
-
60
- if (data) {
61
- if (data instanceof FormData)
62
- request.body = data;
63
- else
64
- request.body = JSON.stringify(data);
65
- }
66
-
67
- if (data instanceof FormData)
68
- request.headers = {
69
- 'Authorization': `Bearer ${await getToken()}`
70
- };
71
- else {
72
- request.headers = {
73
- 'Content-Type': 'application/json',
74
- 'Authorization': `Bearer ${await getToken()}`
75
- };
76
- }
77
-
78
- return request;
79
- };
80
-
81
- const getQueryErrorMessage = async (response: Response): Promise<string> => {
82
- let message: string = `Error connecting to server`;
83
-
84
- const detailMessage: string | undefined = await response.json()
85
- .then(data => data.message ?? data.title)
86
- .catch(() => (message));
87
-
88
- if (detailMessage)
89
- message = detailMessage;
90
-
91
- return message;
1
+ import { getToken } from "./UserService";
2
+
3
+ export const fetchGet = async (url: string, signal: AbortSignal | undefined): Promise<any> => {
4
+ const initReq: RequestInit = await getRequestInit("GET", null, signal);
5
+
6
+ const response: Response = await fetch(url, initReq);
7
+ if (!response.ok)
8
+ throw await getQueryErrorMessage(response);
9
+
10
+ return response.json();
11
+ };
12
+
13
+ export const fetchFileGet = async (url: string, signal: AbortSignal | undefined): Promise<Blob> => {
14
+ const initReq: RequestInit = await getRequestInit("GET", null, signal);
15
+
16
+ const response: Response = await fetch(url, initReq);
17
+ if (!response.ok)
18
+ throw await getQueryErrorMessage(response);
19
+
20
+ return response.blob();
21
+ };
22
+
23
+ export const fetchPost = async (url: string, data: unknown): Promise<any> => {
24
+ const initReq: RequestInit = await getRequestInit("POST", data);
25
+
26
+ const response: Response = await fetch(url, initReq);
27
+ if (!response.ok)
28
+ throw await getQueryErrorMessage(response);
29
+
30
+ return response.json();
31
+ };
32
+
33
+ export const fetchPut = async (url: string, data: unknown): Promise<Response> => {
34
+ const initReq: RequestInit = await getRequestInit("PUT", data);
35
+
36
+ const response: Response = await fetch(url, initReq);
37
+ if (!response.ok)
38
+ throw await getQueryErrorMessage(response);
39
+
40
+ return response;
41
+ };
42
+
43
+ export const fetchDelete = async (url: string): Promise<Response> => {
44
+ const initReq: RequestInit = await getRequestInit("DELETE");
45
+
46
+ const response: Response = await fetch(url, initReq);
47
+ if (!response.ok)
48
+ throw await getQueryErrorMessage(response);
49
+
50
+ return response;
51
+ };
52
+
53
+ const getRequestInit = async (method: string, data?: unknown, signal?: AbortSignal): Promise<RequestInit> => {
54
+ const request: RequestInit = {
55
+ method: method,
56
+ signal: signal,
57
+ credentials: 'include'
58
+ };
59
+
60
+ if (data) {
61
+ if (data instanceof FormData)
62
+ request.body = data;
63
+ else
64
+ request.body = JSON.stringify(data);
65
+ }
66
+
67
+ if (data instanceof FormData)
68
+ request.headers = {
69
+ 'Authorization': `Bearer ${await getToken()}`
70
+ };
71
+ else {
72
+ request.headers = {
73
+ 'Content-Type': 'application/json',
74
+ 'Authorization': `Bearer ${await getToken()}`
75
+ };
76
+ }
77
+
78
+ return request;
79
+ };
80
+
81
+ const getQueryErrorMessage = async (response: Response): Promise<string> => {
82
+ let message: string = `[${response.status}] ${response.statusText}`;
83
+
84
+ const detailMessage: string | undefined = await response.json()
85
+ .then(data => `[${response.status}] ${data.message}`)
86
+ .catch(() => (message));
87
+
88
+ if (detailMessage)
89
+ message = detailMessage;
90
+
91
+ return message;
92
92
  };
@@ -1,8 +1,8 @@
1
- import { Guid } from "guid-ts";
2
-
3
- export const isAndroid: boolean = /(android)/i.test(navigator.userAgent);
4
- export const isMobile: boolean = /(android|iphone)/i.test(navigator.userAgent);
5
-
6
- export const isDevelopment: boolean = window.location.href.includes(".dev") || window.location.href.includes("localhost");
7
-
8
- export const newGuid = (): string => Guid.newGuid().toString();
1
+ import { Guid } from "guid-ts";
2
+
3
+ export const isAndroid: boolean = /(android)/i.test(navigator.userAgent);
4
+ export const isMobile: boolean = /(android|iphone)/i.test(navigator.userAgent);
5
+
6
+ export const isDevelopment: boolean = window.location.href.includes(".dev") || window.location.href.includes("localhost");
7
+
8
+ export const newGuid = (): string => Guid.newGuid().toString();