FIX;Toaster error for API middleware
This commit is contained in:
parent
35fae22fc3
commit
26b6acdf26
5 changed files with 24 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@romanjaros/treejs-constants": "^0.0.38",
|
||||
"@romanjaros/treejs-components": "^0.0.38",
|
||||
"@romanjaros/treejs-types": "^0.0.38",
|
||||
"@romanjaros/treejs-utils": "^0.0.38"
|
||||
},
|
||||
|
|
3
modules/treejs-api/src/components/errors.tsx
Normal file
3
modules/treejs-api/src/components/errors.tsx
Normal file
|
@ -0,0 +1,3 @@
|
|||
import * as React from 'react';
|
||||
|
||||
export const UnexpectedError = (): React.ReactElement => <div>Nastala neočekávaná chyba při volání serveru</div>
|
|
@ -1,19 +1,26 @@
|
|||
import * as React from 'react';
|
||||
import { Middleware } from 'redux';
|
||||
import { is } from 'ramda';
|
||||
|
||||
import { addToasterComponent } from '@romanjaros/treejs-components/Toaster/utils/registerToaster';
|
||||
import { addToaster } from '@romanjaros/treejs-components/Toaster/actions';
|
||||
import { IAction } from '@romanjaros/treejs-types/redux/actions';
|
||||
import { isNilOrEmpty, isJSON } from '@romanjaros/treejs-utils';
|
||||
import { STATUS } from '@romanjaros/treejs-types/common';
|
||||
|
||||
import { IFetchConfig } from './types';
|
||||
import { fetchStatusActions } from './actions';
|
||||
import { FetchActions } from './constants';
|
||||
import { resolveParams } from './utils';
|
||||
import { UnexpectedError } from './components/errors';
|
||||
|
||||
|
||||
interface ISettings {
|
||||
BASE_ENDPOINT_URL: string;
|
||||
}
|
||||
|
||||
addToasterComponent('fetchUnexpectedError', <UnexpectedError />);
|
||||
|
||||
export const FetchEndpoint = (setting: ISettings): Middleware => (store) => (next) => async (action: IAction<IFetchConfig>) => {
|
||||
if (action.type === FetchActions.FETCH) {
|
||||
if (isNilOrEmpty(action.payload.url)) {
|
||||
|
@ -45,6 +52,8 @@ export const FetchEndpoint = (setting: ISettings): Middleware => (store) => (nex
|
|||
store.dispatch(fetchStatusActions.onError(action.payload));
|
||||
if (is(Function, action.payload.onError)) {
|
||||
action.payload.onError(error);
|
||||
} else {
|
||||
store.dispatch(addToaster({ name: 'fetchUnexpectedError', status: STATUS.error }));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,15 @@ class PageLayout extends React.PureComponent<IProps, IState> {
|
|||
});
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: IProps) {
|
||||
if (this.props.topMenuItems !== prevProps.topMenuItems) {
|
||||
this.setState({
|
||||
maxLeftMenuItemCount: this.props.topMenuItems.length,
|
||||
})
|
||||
this.updateDimensions();
|
||||
}
|
||||
}
|
||||
|
||||
public componentWillUnmount() {
|
||||
window.removeEventListener("resize", this.updateDimensions);
|
||||
}
|
||||
|
@ -65,10 +74,10 @@ class PageLayout extends React.PureComponent<IProps, IState> {
|
|||
const fullWidth = getComputedStyleInt(this.topMenuRef.current, 'width');
|
||||
const leftSideWidth = getComputedStyleInt(this.leftSideMenuRef.current, 'width');
|
||||
const leftSideMarginRight = getComputedStyleInt(this.leftSideMenuRef.current, 'marginLeft');
|
||||
const leftMenuItems = this.getTopLeftMenuItemsWidth(this.topMenuRef.current.children);
|
||||
|
||||
if (leftSideMarginRight === 0) {
|
||||
const requiredWidth = fullWidth - leftSideMarginRight - leftSideWidth;
|
||||
const leftMenuItems = this.getTopLeftMenuItemsWidth(this.topMenuRef.current.children);
|
||||
|
||||
let newWidth = this.topMenuRef.current.scrollWidth;
|
||||
let index = 0;
|
||||
|
|
|
@ -19,7 +19,7 @@ export const closeToaster = (name: IToasterId) => (dispatch: Dispatch) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const addToaster = (options: IToasterOption) => (dispatch: Dispatch<any>) => {
|
||||
export const addToaster = (options: IToasterOption): any => (dispatch: Dispatch<any>) => {
|
||||
if (!isNilOrEmpty(timeouts[options.name])) {
|
||||
clearTimeout(timeouts[options.name]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue