BIG-117: fix dashboard redirect all routes to homepage once refresh the page.

This commit is contained in:
a.bouhuolia
2021-09-23 09:44:30 +02:00
parent 8864e89674
commit 364859a793
13 changed files with 205 additions and 103 deletions

View File

@@ -1,3 +1,4 @@
import { isEqual } from 'lodash';
import React, { useRef, useEffect, useMemo } from 'react';
import useAsync from './async';
import useAutofocus from './useAutofocus';
@@ -97,7 +98,6 @@ export function useLocalStorage(key, initialValue) {
return [storedValue, setValue];
}
export function useMemorizedColumnsWidths(tableName) {
const [get, save] = useLocalStorage(`${tableName}.columns_widths`, {});
@@ -105,4 +105,43 @@ export function useMemorizedColumnsWidths(tableName) {
save(columnsResizing.columnWidths);
};
return [get, save, handleColumnResizing];
}
}
// Hook
function usePrevious(value) {
// The ref object is a generic container whose current property is mutable ...
// ... and can hold any value, similar to an instance property on a class
const ref = useRef();
// Store current value in ref
useEffect(() => {
ref.current = value;
}, [value]); // Only re-run if value changes
// Return previous value (happens before update in useEffect above)
return ref.current;
}
export function useWhen(condition, callback) {
React.useEffect(() => {
if (condition) {
callback();
}
}, [condition, callback]);
}
export function useWhenNot(condition, callback) {
return useWhen(!condition, callback);
}
export function useWatch(state, callback, props) {
const config = { immediate: false, ...props };
const previosuState = usePrevious(state);
const flag = React.useRef(false);
React.useEffect(() => {
if (!isEqual(previosuState, state) || (config.immediate && !flag.current)) {
flag.current = true;
callback(state);
}
}, [previosuState, state, config.immediate, callback]);
}

View File

@@ -3,11 +3,13 @@ import { useCallback } from 'react';
import { isAuthenticated } from 'store/authentication/authentication.reducer';
import {
setLogin,
setStoreReset,
} from 'store/authentication/authentication.actions';
import { useQueryClient } from 'react-query';
import { removeCookie } from '../../utils';
/**
* Removes the authentication cookies.
*/
function removeAuthenticationCookies() {
removeCookie('token');
removeCookie('organization_id');

View File

@@ -1,6 +1,10 @@
import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { dashboardPageTitle } from 'store/dashboard/dashboard.actions';
import {
splashStopLoading,
splashStartLoading,
dashboardPageTitle,
} from '../../store/dashboard/dashboard.actions';
export const useDispatchAction = (action) => {
const dispatch = useDispatch();
@@ -17,11 +21,12 @@ export const useDashboardPageTitle = () => {
return useDispatchAction(dashboardPageTitle);
};
export const useSetAccountsTableQuery = () => {
/**
* Splash loading screen actions.
*/
export const useSplashLoading = () => {
return [
useDispatchAction(splashStartLoading),
useDispatchAction(splashStopLoading),
];
};
export const useAccountsTableQuery = () => {
}