mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
65
src/hooks/state/authentication.js
Normal file
65
src/hooks/state/authentication.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
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';
|
||||
|
||||
function removeAuthenticationCookies() {
|
||||
removeCookie('token');
|
||||
removeCookie('organization_id');
|
||||
removeCookie('tenant_id');
|
||||
removeCookie('authenticated_user_id');
|
||||
removeCookie('locale');
|
||||
}
|
||||
|
||||
export const useAuthActions = () => {
|
||||
const dispatch = useDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
setLogin: useCallback((login) => dispatch(setLogin(login)), [dispatch]),
|
||||
setLogout: useCallback(() => {
|
||||
// Resets store state.
|
||||
// dispatch(setStoreReset());
|
||||
|
||||
// Remove all cached queries.
|
||||
queryClient.removeQueries();
|
||||
|
||||
removeAuthenticationCookies();
|
||||
|
||||
window.location.reload();
|
||||
}, [queryClient]),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 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) => ({}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the authenticated organization id.
|
||||
*/
|
||||
export const useAuthOrganizationId = () => {
|
||||
return useSelector((state) => state.authentication.organizationId);
|
||||
};
|
||||
27
src/hooks/state/dashboard.js
Normal file
27
src/hooks/state/dashboard.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { dashboardPageTitle } from 'store/dashboard/dashboard.actions';
|
||||
|
||||
export const useDispatchAction = (action) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return useCallback(
|
||||
(payload) => {
|
||||
dispatch(action(payload));
|
||||
},
|
||||
[dispatch, action],
|
||||
);
|
||||
};
|
||||
|
||||
export const useDashboardPageTitle = () => {
|
||||
return useDispatchAction(dashboardPageTitle);
|
||||
};
|
||||
|
||||
export const useSetAccountsTableQuery = () => {
|
||||
|
||||
};
|
||||
|
||||
export const useAccountsTableQuery = () => {
|
||||
|
||||
}
|
||||
|
||||
17
src/hooks/state/globalErrors.js
Normal file
17
src/hooks/state/globalErrors.js
Normal 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 };
|
||||
}
|
||||
6
src/hooks/state/index.js
Normal file
6
src/hooks/state/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from './dashboard';
|
||||
export * from './authentication';
|
||||
export * from './globalErrors';
|
||||
export * from './subscriptions';
|
||||
export * from './organizations';
|
||||
export * from './settings';
|
||||
11
src/hooks/state/organizations.js
Normal file
11
src/hooks/state/organizations.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useCallback } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setOrganizations } from 'store/organizations/organizations.actions';
|
||||
|
||||
export const useSetOrganizations = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return useCallback((organizations) => {
|
||||
dispatch(setOrganizations(organizations))
|
||||
}, [dispatch]);
|
||||
};
|
||||
21
src/hooks/state/settings.js
Normal file
21
src/hooks/state/settings.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { setSettings } from 'store/settings/settings.actions';
|
||||
|
||||
export const useSetSettings = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return useCallback(
|
||||
(settings) => {
|
||||
dispatch(setSettings(settings));
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the authentication token.
|
||||
*/
|
||||
export const useSettingsSelector = () => {
|
||||
return useSelector((state) => state.settings.data);
|
||||
};
|
||||
14
src/hooks/state/subscriptions.js
Normal file
14
src/hooks/state/subscriptions.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useCallback } from "react"
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setSubscriptions } from 'store/subscription/subscription.actions';
|
||||
|
||||
/**
|
||||
* Sets subscriptions.
|
||||
*/
|
||||
export const useSetSubscriptions = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return useCallback((subscriptions) => {
|
||||
dispatch(setSubscriptions(subscriptions));
|
||||
}, [dispatch]);
|
||||
}
|
||||
Reference in New Issue
Block a user