chrone: sperate client and server to different repos.

This commit is contained in:
a.bouhuolia
2021-09-21 17:13:53 +02:00
parent e011b2a82b
commit 18df5530c7
10015 changed files with 17686 additions and 97524 deletions

View 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);
};

View 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 = () => {
}

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 };
}

6
src/hooks/state/index.js Normal file
View File

@@ -0,0 +1,6 @@
export * from './dashboard';
export * from './authentication';
export * from './globalErrors';
export * from './subscriptions';
export * from './organizations';
export * from './settings';

View 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]);
};

View 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);
};

View 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]);
}