mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
Merge branch 'featrue/roles-permission' of https://github.com/bigcapitalhq/client into featrue/roles-permission
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
import {
|
||||
useAuthenticatedAccount,
|
||||
useCurrentOrganization,
|
||||
@@ -10,9 +9,9 @@ import { useWatch, useWatchImmediate, useWhen } from '../../hooks';
|
||||
import { setCookie, getCookie } from '../../utils';
|
||||
|
||||
/**
|
||||
* Boots dashboard meta.
|
||||
* Dashboard meta async booting.
|
||||
*/
|
||||
function useDashboardMetaBoot() {
|
||||
export function useDashboardMetaBoot() {
|
||||
const {
|
||||
data: dashboardMeta,
|
||||
isLoading: isDashboardMetaLoading,
|
||||
@@ -20,7 +19,7 @@ function useDashboardMetaBoot() {
|
||||
} = useDashboardMeta();
|
||||
|
||||
const [startLoading, stopLoading] = useSplashLoading();
|
||||
|
||||
|
||||
useWatchImmediate((value) => {
|
||||
value && startLoading();
|
||||
}, isDashboardMetaLoading);
|
||||
@@ -28,12 +27,26 @@ function useDashboardMetaBoot() {
|
||||
useWatchImmediate(() => {
|
||||
isDashboardMetaSuccess && stopLoading();
|
||||
}, isDashboardMetaSuccess);
|
||||
|
||||
return {
|
||||
isLoading: isDashboardMetaLoading,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard async booting.
|
||||
* @returns {{ isLoading: boolean }}
|
||||
*/
|
||||
export function DashboardBoot({ authenticatedUserId }) {
|
||||
export function useDashboardBoot() {
|
||||
const { isLoading } = useDashboardMetaBoot();
|
||||
|
||||
return { isLoading };
|
||||
}
|
||||
|
||||
/**
|
||||
* Application async booting.
|
||||
*/
|
||||
export function useApplicationBoot() {
|
||||
// Fetches the current user's organization.
|
||||
const {
|
||||
isSuccess: isCurrentOrganizationSuccess,
|
||||
@@ -45,8 +58,6 @@ export function DashboardBoot({ authenticatedUserId }) {
|
||||
const { isSuccess: isAuthUserSuccess, isLoading: isAuthUserLoading } =
|
||||
useAuthenticatedAccount();
|
||||
|
||||
useDashboardMetaBoot();
|
||||
|
||||
// Initial locale cookie value.
|
||||
const localeCookie = getCookie('locale');
|
||||
|
||||
@@ -109,5 +120,8 @@ export function DashboardBoot({ authenticatedUserId }) {
|
||||
isBooted.current = true;
|
||||
},
|
||||
);
|
||||
return null;
|
||||
|
||||
return {
|
||||
isLoading: isOrgLoading || isAuthUserLoading,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import React from 'react';
|
||||
import { DashboardAbilityProvider } from '../../components';
|
||||
import { useDashboardBoot } from './DashboardBoot';
|
||||
|
||||
/**
|
||||
* Dashboard provider.
|
||||
*/
|
||||
export default function DashboardProvider({ children }) {
|
||||
return <DashboardAbilityProvider>{children}</DashboardAbilityProvider>;
|
||||
const { isLoading } = useDashboardBoot();
|
||||
|
||||
return (
|
||||
<DashboardAbilityProvider>
|
||||
{isLoading ? null : children}
|
||||
</DashboardAbilityProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,15 @@
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
|
||||
import { DashboardBoot } from '../../components';
|
||||
|
||||
import withDashboard from '../../containers/Dashboard/withDashboard';
|
||||
import { useApplicationBoot } from '../../components';
|
||||
|
||||
/**
|
||||
* Private pages provider.
|
||||
*/
|
||||
function PrivatePagesProviderComponent({
|
||||
splashScreenCompleted,
|
||||
|
||||
export function PrivatePagesProvider({
|
||||
// #ownProps
|
||||
children,
|
||||
}) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<DashboardBoot />
|
||||
{splashScreenCompleted ? children : null}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
const { isLoading } = useApplicationBoot();
|
||||
|
||||
export const PrivatePagesProvider = R.compose(
|
||||
withDashboard(({ splashScreenCompleted }) => ({
|
||||
splashScreenCompleted,
|
||||
})),
|
||||
)(PrivatePagesProviderComponent);
|
||||
return <React.Fragment>{!isLoading ? children : null}</React.Fragment>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user