refactoring: authentication with react-query.

This commit is contained in:
a.bouhuolia
2021-02-20 15:33:20 +02:00
parent 8f680e2068
commit a079f711d4
57 changed files with 1629 additions and 1290 deletions

View File

@@ -0,0 +1,41 @@
import { useDispatch, useSelector } from 'react-redux';
import { useCallback } from 'react';
import { isAuthenticated } from 'store/authentication/authentication.reducer';
import { setLogin, setLogout } from 'store/authentication/authentication.actions';
export const useAuthActions = () => {
const dispatch = useDispatch();
return {
setLogin: useCallback((login) => dispatch(setLogin(login)), [dispatch]),
setLogout: useCallback(() => dispatch(setLogout()), [dispatch]),
};
};
/**
* Retrieve whether the user is authenticated.
*/
export const useIsAuthenticated = () => {
return useSelector(isAuthenticated);
};
/**
* Retrieve the authentication token.
*/
export const useAuthToken = () => {
return useSelector((state) => state.authentication.token);
};
/**
* Retrieve the authentication user.
*/
export const useAuthUser = () => {
return useSelector((state) => state.authentication.user);
};
/**
* Retrieve the authenticated organization id.
*/
export const useAuthOrganizationId = () => {
return useSelector((state) => state.authentication.organization);
};

View File

@@ -0,0 +1,17 @@
import { useCallback } from 'react';
import { useSelector, useDispatch } from "react-redux";
import { setGlobalErrors } from 'store/globalErrors/globalErrors.actions';
export const useSetGlobalErrors = () => {
const dispatch = useDispatch();
return useCallback((errors) => {
dispatch(setGlobalErrors(errors));
}, [dispatch]);
};
export const useGlobalErrors = () => {
const globalErrors = useSelector(state => state.globalErrors.data);
return { globalErrors };
}

View File

@@ -1 +1,3 @@
export * from './dashboard';
export * from './dashboard';
export * from './authentication';
export * from './globalErrors';