feat: dashboard back link in expand mode.

This commit is contained in:
Ahmed Bouhuolia
2020-11-30 10:59:10 +02:00
parent 0acc998283
commit fe55c84941
19 changed files with 131 additions and 25 deletions

View File

@@ -0,0 +1,38 @@
import React from 'react';
import withBreadcrumbs from 'react-router-breadcrumbs-hoc';
import { useHistory } from 'react-router-dom';
import routes from 'routes/dashboard';
import { If, Icon } from 'components';
import withDashboard from 'containers/Dashboard/withDashboard';
import { compose } from 'utils';
function DashboardBackLink({ dashboardBackLink, breadcrumbs }) {
const history = useHistory();
const crumb = breadcrumbs[breadcrumbs.length - 2];
const handleClick = (event) => {
const url =
typeof dashboardBackLink === 'string'
? dashboardBackLink
: crumb.match.url;
history.push(url);
event.preventDefault();
};
return (
<If condition={dashboardBackLink && crumb}>
<div class="dashboard__back-link">
<a href="#no-link" onClick={handleClick}>
<Icon icon={'arrow-left'} iconSize={18} /> Back to list.
</a>
</div>
</If>
);
}
export default compose(
withBreadcrumbs(routes),
withDashboard(({ dashboardBackLink }) => ({
dashboardBackLink,
})),
)(DashboardBackLink);

View File

@@ -9,7 +9,7 @@ import withBreadcrumbs from 'react-router-breadcrumbs-hoc';
import routes from 'routes/dashboard'; import routes from 'routes/dashboard';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
function DashboardBreadcrumbs( {breadcrumbs }){ function DashboardBreadcrumbs({ breadcrumbs }){
const history = useHistory(); const history = useHistory();
return( return(

View File

@@ -13,6 +13,7 @@ import { FormattedMessage as T } from 'react-intl';
import DashboardTopbarUser from 'components/Dashboard/TopbarUser'; import DashboardTopbarUser from 'components/Dashboard/TopbarUser';
import DashboardBreadcrumbs from 'components/Dashboard/DashboardBreadcrumbs'; import DashboardBreadcrumbs from 'components/Dashboard/DashboardBreadcrumbs';
import DashboardBackLink from 'components/Dashboard/DashboardBackLink';
import { Icon, Hint, If } from 'components'; import { Icon, Hint, If } from 'components';
import withSearch from 'containers/GeneralSearch/withSearch'; import withSearch from 'containers/GeneralSearch/withSearch';
@@ -114,6 +115,8 @@ function DashboardTopbar({
<div class="dashboard__breadcrumbs"> <div class="dashboard__breadcrumbs">
<DashboardBreadcrumbs /> <DashboardBreadcrumbs />
</div> </div>
<DashboardBackLink />
</div> </div>
<div class="dashboard__topbar-right"> <div class="dashboard__topbar-right">

View File

@@ -130,7 +130,7 @@ export default [
children: [ children: [
{ {
text: <T id={'expenses'} />, text: <T id={'expenses'} />,
href: '/expenses-list', href: '/expenses',
}, },
{ {
text: <T id={'new_expense'} />, text: <T id={'new_expense'} />,

View File

@@ -32,7 +32,8 @@ function MakeJournalEntriesPage({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand resetSidebarPreviousExpand,
setDashboardBackLink
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -40,10 +41,14 @@ function MakeJournalEntriesPage({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink('/manual-journals');
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink]);

View File

@@ -10,6 +10,7 @@ export default (mapState) => {
editViewId: state.dashboard.topbarEditViewId, editViewId: state.dashboard.topbarEditViewId,
sidebarExpended: state.dashboard.sidebarExpended, sidebarExpended: state.dashboard.sidebarExpended,
preferencesPageTitle: state.dashboard.preferencesPageTitle, preferencesPageTitle: state.dashboard.preferencesPageTitle,
dashboardBackLink: state.dashboard.backLink,
}; };
return mapState ? mapState(mapped, state, props) : mapped; return mapState ? mapState(mapped, state, props) : mapped;
}; };

View File

@@ -57,6 +57,11 @@ const mapActionsToProps = (dispatch) => ({
recordSidebarPreviousExpand: () => dispatch({ recordSidebarPreviousExpand: () => dispatch({
type: t.RECORD_SIDEBAR_PREVIOUS_EXPAND, type: t.RECORD_SIDEBAR_PREVIOUS_EXPAND,
}), }),
setDashboardBackLink: (backLink) => dispatch({
type: t.SET_DASHBOARD_BACK_LINK,
payload: { backLink }
})
}); });
export default connect(null, mapActionsToProps); export default connect(null, mapActionsToProps);

View File

@@ -30,6 +30,7 @@ function Expenses({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink,
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -37,12 +38,16 @@ function Expenses({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
const fetchAccounts = useQuery('accounts-list', (key) => const fetchAccounts = useQuery('accounts-list', (key) =>
requestFetchAccounts(), requestFetchAccounts(),

View File

@@ -33,6 +33,7 @@ function Bills({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -40,12 +41,16 @@ function Bills({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
// Handle fetch accounts // Handle fetch accounts
const fetchAccounts = useQuery('accounts-list', (key) => const fetchAccounts = useQuery('accounts-list', (key) =>

View File

@@ -36,6 +36,7 @@ function PaymentMade({
changePageTitle, changePageTitle,
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink
}) { }) {
const { id: paymentMadeId } = useParams(); const { id: paymentMadeId } = useParams();
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
@@ -43,12 +44,16 @@ function PaymentMade({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
// Handle page title change in new and edit mode. // Handle page title change in new and edit mode.
useEffect(() => { useEffect(() => {

View File

@@ -28,7 +28,8 @@ function Estimates({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand resetSidebarPreviousExpand,
setDashboardBackLink,
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -36,12 +37,16 @@ function Estimates({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
const fetchEstimate = useQuery( const fetchEstimate = useQuery(
['estimate', id], ['estimate', id],

View File

@@ -29,6 +29,7 @@ function Invoices({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink,
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -36,18 +37,22 @@ function Invoices({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
const fetchInvoice = useQuery( const fetchInvoice = useQuery(
['invoice', id], ['invoice', id],
(key, _id) => requsetFetchInvoice(_id), (key, _id) => requsetFetchInvoice(_id),
{ enabled: !!id }, { enabled: !!id },
); );
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({})); const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));

View File

@@ -6,7 +6,7 @@ import { useQuery } from 'react-query';
import DashboardInsider from 'components/Dashboard/DashboardInsider'; import DashboardInsider from 'components/Dashboard/DashboardInsider';
import PaymentReceiveForm from './PaymentReceiveForm'; import PaymentReceiveForm from './PaymentReceiveForm';
import withDashboardActions from "containers/Dashboard/withDashboardActions"; import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import withAccountsActions from 'containers/Accounts/withAccountsActions'; import withAccountsActions from 'containers/Accounts/withAccountsActions';
import withSettingsActions from 'containers/Settings/withSettingsActions'; import withSettingsActions from 'containers/Settings/withSettingsActions';
import withPaymentReceivesActions from './withPaymentReceivesActions'; import withPaymentReceivesActions from './withPaymentReceivesActions';
@@ -18,7 +18,6 @@ import { compose } from 'utils';
* Payment receive form page. * Payment receive form page.
*/ */
function PaymentReceiveFormPage({ function PaymentReceiveFormPage({
// #withDashboardAction // #withDashboardAction
changePageTitle, changePageTitle,
@@ -37,25 +36,30 @@ function PaymentReceiveFormPage({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink,
}) { }) {
const { id: paymentReceiveId } = useParams(); const { id: paymentReceiveId } = useParams();
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
// Fetches payment recevie details. // Fetches payment recevie details.
const fetchPaymentReceive = useQuery( const fetchPaymentReceive = useQuery(
['payment-receive', paymentReceiveId], ['payment-receive', paymentReceiveId],
(key, _id) => requestFetchPaymentReceive(_id), (key, _id) => requestFetchPaymentReceive(_id),
{ enabled: paymentReceiveId }, { enabled: paymentReceiveId },
) );
// Handle fetch accounts data. // Handle fetch accounts data.
const fetchAccounts = useQuery('accounts-list', (key) => const fetchAccounts = useQuery('accounts-list', (key) =>
@@ -66,8 +70,8 @@ function PaymentReceiveFormPage({
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({})); const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));
// Fetches customers list. // Fetches customers list.
const fetchCustomers = useQuery( const fetchCustomers = useQuery(['customers-list'], () =>
['customers-list'], () => requestFetchCustomers(), requestFetchCustomers(),
); );
return ( return (
@@ -80,11 +84,9 @@ function PaymentReceiveFormPage({
} }
name={'payment-receive-form'} name={'payment-receive-form'}
> >
<PaymentReceiveForm <PaymentReceiveForm paymentReceiveId={paymentReceiveId} />
paymentReceiveId={paymentReceiveId}
/>
</DashboardInsider> </DashboardInsider>
) );
} }
export default compose( export default compose(

View File

@@ -33,6 +33,7 @@ function Receipts({
// #withDashboardActions // #withDashboardActions
setSidebarShrink, setSidebarShrink,
resetSidebarPreviousExpand, resetSidebarPreviousExpand,
setDashboardBackLink,
}) { }) {
const history = useHistory(); const history = useHistory();
const { id } = useParams(); const { id } = useParams();
@@ -40,12 +41,16 @@ function Receipts({
useEffect(() => { useEffect(() => {
// Shrink the sidebar by foce. // Shrink the sidebar by foce.
setSidebarShrink(); setSidebarShrink();
// Show the back link on dashboard topbar.
setDashboardBackLink(true);
return () => { return () => {
// Reset the sidebar to the previous status. // Reset the sidebar to the previous status.
resetSidebarPreviousExpand(); resetSidebarPreviousExpand();
// Hide the back link on dashboard topbar.
setDashboardBackLink(false);
}; };
}, [resetSidebarPreviousExpand, setSidebarShrink]); }, [resetSidebarPreviousExpand, setSidebarShrink, setDashboardBackLink]);
const fetchReceipt = useQuery( const fetchReceipt = useQuery(
['receipt', id], ['receipt', id],
@@ -101,5 +106,5 @@ export default compose(
withItemsActions, withItemsActions,
withAccountsActions, withAccountsActions,
withSettingsActions, withSettingsActions,
withDashboardActions withDashboardActions,
)(Receipts); )(Receipts);

View File

@@ -174,7 +174,7 @@ export default [
breadcrumb: 'Edit', breadcrumb: 'Edit',
}, },
{ {
path: `/expenses-list`, path: `/expenses`,
component: LazyLoader({ component: LazyLoader({
loader: () => import('containers/Expenses/ExpensesList'), loader: () => import('containers/Expenses/ExpensesList'),
}), }),

View File

@@ -349,5 +349,11 @@ export default {
'M19 14V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zm-9-1c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm13-6v11c0 1.1-.9 2-2 2H4v-2h17V7h2z', 'M19 14V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zm-9-1c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm13-6v11c0 1.1-.9 2-2 2H4v-2h17V7h2z',
], ],
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
},
"arrow-left": {
path: [
'M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z',
],
viewBox: '0 0 24 24',
} }
}; };

View File

@@ -13,6 +13,7 @@ const initialState = {
dialogs: {}, dialogs: {},
topbarEditViewId: null, topbarEditViewId: null,
requestsLoading: 0, requestsLoading: 0,
backLink: false,
}; };
const reducerInstance = createReducer(initialState, { const reducerInstance = createReducer(initialState, {
@@ -82,6 +83,11 @@ const reducerInstance = createReducer(initialState, {
[t.RESET_SIDEBAR_PREVIOUS_EXPAND]: (state) => { [t.RESET_SIDEBAR_PREVIOUS_EXPAND]: (state) => {
state.sidebarExpended = state.previousSidebarExpended; state.sidebarExpended = state.previousSidebarExpended;
}, },
[t.SET_DASHBOARD_BACK_LINK]: (state, action) => {
const { backLink } = action.payload;
state.backLink = backLink;
}
}); });
export default persistReducer({ export default persistReducer({

View File

@@ -17,4 +17,5 @@ export default {
SIDEBAR_SHRINK: 'SIDEBAR_SHRINK', SIDEBAR_SHRINK: 'SIDEBAR_SHRINK',
RESET_SIDEBAR_PREVIOUS_EXPAND: 'RESET_SIDEBAR_PREVIOUS_EXPAND', RESET_SIDEBAR_PREVIOUS_EXPAND: 'RESET_SIDEBAR_PREVIOUS_EXPAND',
RECORD_SIDEBAR_PREVIOUS_EXPAND: 'RECORD_SIDEBAR_PREVIOUS_EXPAND', RECORD_SIDEBAR_PREVIOUS_EXPAND: 'RECORD_SIDEBAR_PREVIOUS_EXPAND',
SET_DASHBOARD_BACK_LINK: 'SET_DASHBOARD_BACK_LINK'
}; };

View File

@@ -111,6 +111,15 @@
} }
} }
&__back-link{
margin-left: 24px;
display: flex;
a{
margin: auto 0;
}
}
&__actions-bar{ &__actions-bar{
border-bottom: 2px solid #EAEAEA; border-bottom: 2px solid #EAEAEA;