mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: BIG-171 alerts global and lazy loading.
This commit is contained in:
@@ -12,6 +12,7 @@ import DashboardSplitPane from 'components/Dashboard/DashboardSplitePane';
|
|||||||
import GlobalHotkeys from './GlobalHotkeys';
|
import GlobalHotkeys from './GlobalHotkeys';
|
||||||
import DashboardProvider from './DashboardProvider';
|
import DashboardProvider from './DashboardProvider';
|
||||||
import DrawersContainer from 'components/DrawersContainer';
|
import DrawersContainer from 'components/DrawersContainer';
|
||||||
|
import AlertsContainer from 'containers/AlertsContainer';
|
||||||
import EnsureSubscriptionIsActive from '../Guards/EnsureSubscriptionIsActive';
|
import EnsureSubscriptionIsActive from '../Guards/EnsureSubscriptionIsActive';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +56,7 @@ export default function Dashboard() {
|
|||||||
<DialogsContainer />
|
<DialogsContainer />
|
||||||
<GlobalHotkeys />
|
<GlobalHotkeys />
|
||||||
<DrawersContainer />
|
<DrawersContainer />
|
||||||
|
<AlertsContainer />
|
||||||
</DashboardProvider>
|
</DashboardProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import AccountDeleteAlert from 'containers/Alerts/AccountDeleteAlert';
|
|
||||||
import AccountInactivateAlert from 'containers/Alerts/AccountInactivateAlert';
|
const AccountDeleteAlert = React.lazy(() =>
|
||||||
import AccountActivateAlert from 'containers/Alerts/AccountActivateAlert';
|
import('containers/Alerts/AccountDeleteAlert'),
|
||||||
|
);
|
||||||
|
const AccountInactivateAlert = React.lazy(() =>
|
||||||
|
import('containers/Alerts/AccountInactivateAlert'),
|
||||||
|
);
|
||||||
|
const AccountActivateAlert = React.lazy(() =>
|
||||||
|
import('containers/Alerts/AccountActivateAlert'),
|
||||||
|
);
|
||||||
// import AccountBulkDeleteAlert from 'containers/Alerts/AccountBulkDeleteAlert';
|
// import AccountBulkDeleteAlert from 'containers/Alerts/AccountBulkDeleteAlert';
|
||||||
// import AccountBulkInactivateAlert from 'containers/Alerts/AccountBulkInactivateAlert';
|
// import AccountBulkInactivateAlert from 'containers/Alerts/AccountBulkInactivateAlert';
|
||||||
// import AccountBulkActivateAlert from 'containers/Alerts/AccountBulkActivateAlert';
|
// import AccountBulkActivateAlert from 'containers/Alerts/AccountBulkActivateAlert';
|
||||||
|
|
||||||
/**
|
export default [
|
||||||
* Accounts alert.
|
{ name: 'account-delete', component: AccountDeleteAlert },
|
||||||
*/
|
{ name: 'account-inactivate', component: AccountInactivateAlert },
|
||||||
export default function AccountsAlerts({
|
{ name: 'account-activate', component: AccountActivateAlert },
|
||||||
|
];
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div class="accounts-alerts">
|
|
||||||
<AccountDeleteAlert name={'account-delete'} />
|
|
||||||
<AccountInactivateAlert name={'account-inactivate'} />
|
|
||||||
<AccountActivateAlert name={'account-activate'} />
|
|
||||||
|
|
||||||
{/* <AccountBulkDeleteAlert name={'accounts-bulk-delete'} />
|
|
||||||
<AccountBulkInactivateAlert name={'accounts-bulk-inactivate'} />
|
|
||||||
<AccountBulkActivateAlert name={'accounts-bulk-activate'} /> */}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { AccountsChartProvider } from './AccountsChartProvider';
|
|||||||
|
|
||||||
import AccountsViewsTabs from 'containers/Accounts/AccountsViewsTabs';
|
import AccountsViewsTabs from 'containers/Accounts/AccountsViewsTabs';
|
||||||
import AccountsActionsBar from 'containers/Accounts/AccountsActionsBar';
|
import AccountsActionsBar from 'containers/Accounts/AccountsActionsBar';
|
||||||
import AccountsAlerts from './AccountsAlerts';
|
|
||||||
import AccountsDataTable from './AccountsDataTable';
|
import AccountsDataTable from './AccountsDataTable';
|
||||||
|
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
@@ -49,8 +48,6 @@ function AccountsChart({
|
|||||||
<AccountsDataTable />
|
<AccountsDataTable />
|
||||||
</DashboardContentTable>
|
</DashboardContentTable>
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
|
|
||||||
<AccountsAlerts />
|
|
||||||
</AccountsChartProvider>
|
</AccountsChartProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/containers/AlertsContainer/components.js
Normal file
100
src/containers/AlertsContainer/components.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import React, { Suspense } from 'react';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
import { Intent, Classes, ProgressBar } from '@blueprintjs/core';
|
||||||
|
import { debounce } from 'lodash';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import clsx from 'classnames';
|
||||||
|
|
||||||
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
|
function AlertLazyFallbackMessage({ amount }) {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<ToastText>Alert content is loading, just a second.</ToastText>
|
||||||
|
<ProgressBar
|
||||||
|
className={clsx({
|
||||||
|
[Classes.PROGRESS_NO_STRIPES]: amount >= 100,
|
||||||
|
})}
|
||||||
|
intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS}
|
||||||
|
value={amount / 100}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertLazyFallback({}) {
|
||||||
|
const progressToastInterval = React.useRef(null);
|
||||||
|
const toastKey = React.useRef(null);
|
||||||
|
|
||||||
|
const toastProgressLoading = (amount) => {
|
||||||
|
return {
|
||||||
|
message: <AlertLazyFallbackMessage amount={amount} />,
|
||||||
|
onDismiss: (didTimeoutExpire) => {
|
||||||
|
if (!didTimeoutExpire) {
|
||||||
|
window.clearInterval(progressToastInterval.current);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
timeout: amount < 100 ? 0 : 2000,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerProgressToast = () => {
|
||||||
|
let progress = 0;
|
||||||
|
toastKey.current = AppToaster.show(toastProgressLoading(0));
|
||||||
|
|
||||||
|
progressToastInterval.current = window.setInterval(() => {
|
||||||
|
if (toastKey.current == null || progress > 100) {
|
||||||
|
window.clearInterval(progressToastInterval.current);
|
||||||
|
} else {
|
||||||
|
progress += 10 + Math.random() * 20;
|
||||||
|
AppToaster.show(toastProgressLoading(progress), toastKey.current);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
const hideProgressToast = () => {
|
||||||
|
window.clearInterval(progressToastInterval.current);
|
||||||
|
AppToaster.dismiss(toastKey.current);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Debounce the trigger.
|
||||||
|
const dobounceTrigger = React.useRef(
|
||||||
|
debounce(() => {
|
||||||
|
triggerProgressToast();
|
||||||
|
}, 500),
|
||||||
|
);
|
||||||
|
React.useEffect(() => {
|
||||||
|
dobounceTrigger.current();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
hideProgressToast();
|
||||||
|
dobounceTrigger.current.cancel();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertLazyInside({ isOpen, name, Component }) {
|
||||||
|
if (!isOpen) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<AlertLazyFallback />}>
|
||||||
|
<Component name={name} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AlertLazy = R.compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
)(AlertLazyInside);
|
||||||
|
|
||||||
|
const ToastText = styled.div`
|
||||||
|
margin-bottom: 10px;
|
||||||
|
`;
|
||||||
13
src/containers/AlertsContainer/index.js
Normal file
13
src/containers/AlertsContainer/index.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { AlertLazy } from './components'
|
||||||
|
import registered from './registered';
|
||||||
|
|
||||||
|
export default function AlertsContainer() {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
{registered.map((alert) => (
|
||||||
|
<AlertLazy name={alert.name} Component={alert.component} />
|
||||||
|
))}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
3
src/containers/AlertsContainer/registered.js
Normal file
3
src/containers/AlertsContainer/registered.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import AccountsAlerts from '../Accounts/AccountsAlerts';
|
||||||
|
|
||||||
|
export default [...AccountsAlerts];
|
||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
T,
|
T,
|
||||||
} from '../../../components';
|
} from '../../../components';
|
||||||
import AccountsAlerts from './../../Accounts/AccountsAlerts';
|
|
||||||
|
|
||||||
import { useCashFlowAccountsContext } from './CashFlowAccountsProvider';
|
import { useCashFlowAccountsContext } from './CashFlowAccountsProvider';
|
||||||
|
|
||||||
@@ -173,8 +172,6 @@ export default function CashflowAccountsGrid() {
|
|||||||
<CashflowAccountsGridItems accounts={cashflowAccounts} />
|
<CashflowAccountsGridItems accounts={cashflowAccounts} />
|
||||||
)}
|
)}
|
||||||
</BankAccountsList>
|
</BankAccountsList>
|
||||||
|
|
||||||
<AccountsAlerts />
|
|
||||||
</CashflowAccountsGridWrap>
|
</CashflowAccountsGridWrap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user