mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: register pages routes guards.
feat: retrieve all organizations details to authenticated user. feat: redux organization reducers and actions.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { Switch, Route } from 'react-router';
|
||||
import classNames from 'classnames';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import DashboardLoadingIndicator from './DashboardLoadingIndicator';
|
||||
|
||||
import Sidebar from 'components/Sidebar/Sidebar';
|
||||
import DashboardContent from 'components/Dashboard/DashboardContent';
|
||||
@@ -9,29 +11,56 @@ import PreferencesContent from 'components/Preferences/PreferencesContent';
|
||||
import PreferencesSidebar from 'components/Preferences/PreferencesSidebar';
|
||||
import Search from 'containers/GeneralSearch/Search';
|
||||
import DashboardSplitPane from 'components/Dashboard/DashboardSplitePane';
|
||||
import EnsureOrganizationIsReady from './EnsureOrganizationIsReady';
|
||||
|
||||
export default function Dashboard() {
|
||||
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
||||
import withOrganizationsActions from 'containers/Organization/withOrganizationActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
|
||||
function Dashboard({
|
||||
// #withSettings
|
||||
requestFetchOptions,
|
||||
|
||||
// #withOrganizations
|
||||
requestOrganizationsList,
|
||||
}) {
|
||||
const fetchOrganizations = useQuery(
|
||||
['organizations'],
|
||||
(key) => requestOrganizationsList(),
|
||||
);
|
||||
return (
|
||||
<div className={classNames('dashboard')}>
|
||||
<Switch>
|
||||
<Route path="/preferences">
|
||||
<DashboardSplitPane>
|
||||
<Sidebar />
|
||||
<PreferencesSidebar />
|
||||
</DashboardSplitPane>
|
||||
<PreferencesContent />
|
||||
</Route>
|
||||
<EnsureOrganizationIsReady>
|
||||
<DashboardLoadingIndicator
|
||||
isLoading={
|
||||
fetchOrganizations.isLoading
|
||||
}>
|
||||
<Switch>
|
||||
<Route path="/preferences">
|
||||
<DashboardSplitPane>
|
||||
<Sidebar />
|
||||
<PreferencesSidebar />
|
||||
</DashboardSplitPane>
|
||||
<PreferencesContent />
|
||||
</Route>
|
||||
|
||||
<Route path="/">
|
||||
<DashboardSplitPane>
|
||||
<Sidebar />
|
||||
<DashboardContent />
|
||||
</DashboardSplitPane>
|
||||
</Route>
|
||||
</Switch>
|
||||
<Route path="/">
|
||||
<DashboardSplitPane>
|
||||
<Sidebar />
|
||||
<DashboardContent />
|
||||
</DashboardSplitPane>
|
||||
</Route>
|
||||
</Switch>
|
||||
|
||||
<Search />
|
||||
<DialogsContainer />
|
||||
</div>
|
||||
<Search />
|
||||
<DialogsContainer />
|
||||
</DashboardLoadingIndicator>
|
||||
</EnsureOrganizationIsReady>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettingsActions,
|
||||
withOrganizationsActions,
|
||||
)(Dashboard);
|
||||
25
client/src/components/Dashboard/DashboardLoadingIndicator.js
Normal file
25
client/src/components/Dashboard/DashboardLoadingIndicator.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Choose, Icon } from 'components';
|
||||
|
||||
export default function Dashboard({
|
||||
isLoading = false,
|
||||
children,
|
||||
}) {
|
||||
return (
|
||||
<div className={classNames('dashboard')}>
|
||||
<Choose>
|
||||
<Choose.When condition={isLoading}>
|
||||
<div class="center">
|
||||
<Icon icon="bigcapital" height={37} width={214} />
|
||||
<span>Please wait while resources loading...</span>
|
||||
</div>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.Otherwise>
|
||||
{ children }
|
||||
</Choose.Otherwise>
|
||||
</Choose>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
16
client/src/components/Dashboard/EnsureOrganizationIsReady.js
Normal file
16
client/src/components/Dashboard/EnsureOrganizationIsReady.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
|
||||
export default function EnsureOrganizationIsReady({
|
||||
children,
|
||||
}) {
|
||||
const isOrganizationReady = false;
|
||||
|
||||
return (isOrganizationReady) ? children : (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: '/register'
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user