mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
87
src/store/dashboard/dashboard.actions.js
Normal file
87
src/store/dashboard/dashboard.actions.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export function dashboardPageTitle(pageTitle) {
|
||||
return {
|
||||
type: t.CHANGE_DASHBOARD_PAGE_TITLE,
|
||||
pageTitle,
|
||||
};
|
||||
}
|
||||
|
||||
export function dashboardPageHint(pageHint) {
|
||||
return {
|
||||
type: t.CHANGE_DASHBOARD_PAGE_HINT,
|
||||
pageHint,
|
||||
};
|
||||
}
|
||||
|
||||
export function openDialog(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_DIALOG,
|
||||
name: name,
|
||||
payload: payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function closeDialog(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_DIALOG,
|
||||
name: name,
|
||||
payload: payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function openAlert(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_ALERT,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function closeAlert(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_ALERT,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function openDrawer(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_DRAWER,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
export function closeDrawer(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_DRAWER,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the sidebar expend.
|
||||
*/
|
||||
export function toggleExpendSidebar(toggle) {
|
||||
return {
|
||||
type: t.SIDEBAR_EXPEND_TOGGLE,
|
||||
payload: { toggle }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function appIsLoading(toggle) {
|
||||
return {
|
||||
type: t.APP_IS_LOADING,
|
||||
payload: { isLoading: toggle },
|
||||
};
|
||||
}
|
||||
|
||||
export function appIntlIsLoading(toggle) {
|
||||
return {
|
||||
type: t.APP_INTL_IS_LOADING,
|
||||
payload: { isLoading: toggle },
|
||||
};
|
||||
}
|
||||
130
src/store/dashboard/dashboard.reducer.js
Normal file
130
src/store/dashboard/dashboard.reducer.js
Normal file
@@ -0,0 +1,130 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { isUndefined } from 'lodash';
|
||||
import t from 'store/types';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
|
||||
const initialState = {
|
||||
pageTitle: '',
|
||||
pageSubtitle: '',
|
||||
pageHint: '',
|
||||
preferencesPageTitle: '',
|
||||
sidebarExpended: true,
|
||||
dialogs: {},
|
||||
alerts: {},
|
||||
drawers: {},
|
||||
topbarEditViewId: null,
|
||||
requestsLoading: 0,
|
||||
backLink: false,
|
||||
appIsLoading: true,
|
||||
appIntlIsLoading: true,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:dashboard';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
[t.CHANGE_DASHBOARD_PAGE_TITLE]: (state, action) => {
|
||||
state.pageTitle = action.pageTitle;
|
||||
},
|
||||
|
||||
[t.ALTER_DASHBOARD_PAGE_SUBTITLE]: (state, action) => {
|
||||
state.pageSubtitle = action.pageSubtitle;
|
||||
},
|
||||
|
||||
[t.CHANGE_DASHBOARD_PAGE_HINT]: (state, action) => {
|
||||
state.pageHint = action.payload.pageHint;
|
||||
},
|
||||
|
||||
[t.CHANGE_PREFERENCES_PAGE_TITLE]: (state, action) => {
|
||||
state.preferencesPageTitle = action.pageTitle;
|
||||
},
|
||||
|
||||
[t.OPEN_DIALOG]: (state, action) => {
|
||||
state.dialogs[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
|
||||
[t.CLOSE_DIALOG]: (state, action) => {
|
||||
state.dialogs[action.name] = {
|
||||
...state.dialogs[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
|
||||
[t.OPEN_ALERT]: (state, action) => {
|
||||
state.alerts[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
|
||||
[t.CLOSE_ALERT]: (state, action) => {
|
||||
state.alerts[action.name] = {
|
||||
...state.alerts[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
[t.OPEN_DRAWER]: (state, action) => {
|
||||
state.drawers[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
[t.CLOSE_DRAWER]: (state, action) => {
|
||||
state.drawers[action.name] = {
|
||||
...state.drawers[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
[t.CLOSE_ALL_DIALOGS]: (state, action) => {},
|
||||
|
||||
[t.SET_TOPBAR_EDIT_VIEW]: (state, action) => {
|
||||
state.topbarEditViewId = action.id;
|
||||
},
|
||||
|
||||
[t.SIDEBAR_EXPEND_TOGGLE]: (state, action) => {
|
||||
const { toggle } = action.payload;
|
||||
state.sidebarExpended = isUndefined(toggle)
|
||||
? !state.sidebarExpended
|
||||
: !!toggle;
|
||||
},
|
||||
|
||||
[t.SET_DASHBOARD_BACK_LINK]: (state, action) => {
|
||||
const { backLink } = action.payload;
|
||||
state.backLink = backLink;
|
||||
},
|
||||
|
||||
[t.APP_IS_LOADING]: (state, action) => {
|
||||
const { isLoading } = action.payload;
|
||||
state.appIsLoading = isLoading;
|
||||
},
|
||||
|
||||
[t.APP_INTL_IS_LOADING]: (state, action) => {
|
||||
const { isLoading } = action.payload;
|
||||
state.appIntlIsLoading = isLoading;
|
||||
},
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
|
||||
export const getDialogPayload = (state, dialogName) => {
|
||||
return typeof state.dashboard.dialogs[dialogName] !== 'undefined'
|
||||
? state.dashboard.dialogs[dialogName].payload
|
||||
: {};
|
||||
};
|
||||
|
||||
export const getDialogActiveStatus = (state, dialogName) => {
|
||||
return true;
|
||||
};
|
||||
40
src/store/dashboard/dashboard.selectors.js
Normal file
40
src/store/dashboard/dashboard.selectors.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const dialogByNameSelector = (state, props) =>
|
||||
state.dashboard.dialogs?.[props.dialogName];
|
||||
|
||||
export const isDialogOpenFactory = () =>
|
||||
createSelector(dialogByNameSelector, (dialog) => {
|
||||
return dialog && dialog.isOpen;
|
||||
});
|
||||
|
||||
export const getDialogPayloadFactory = () =>
|
||||
createSelector(dialogByNameSelector, (dialog) => {
|
||||
return { ...dialog?.payload };
|
||||
});
|
||||
|
||||
const alertByNameSelector = (state, props) =>
|
||||
state.dashboard.alerts?.[props.name];
|
||||
|
||||
export const isAlertOpenFactory = () =>
|
||||
createSelector(alertByNameSelector, (alert) => {
|
||||
return alert && alert.isOpen;
|
||||
});
|
||||
|
||||
export const getAlertPayloadFactory = () =>
|
||||
createSelector(alertByNameSelector, (alert) => {
|
||||
return { ...alert?.payload };
|
||||
});
|
||||
|
||||
const drawerByNameSelector = (state, props) =>
|
||||
state.dashboard.drawers?.[props.name];
|
||||
|
||||
export const isDrawerOpenFactory = () =>
|
||||
createSelector(drawerByNameSelector, (drawer) => {
|
||||
return drawer && drawer.isOpen;
|
||||
});
|
||||
|
||||
export const getDrawerPayloadFactory = () =>
|
||||
createSelector(drawerByNameSelector, (drawer) => {
|
||||
return { ...drawer?.payload };
|
||||
});
|
||||
19
src/store/dashboard/dashboard.types.js
Normal file
19
src/store/dashboard/dashboard.types.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export default {
|
||||
OPEN_DIALOG: 'OPEN_DIALOG',
|
||||
CLOSE_DIALOG: 'CLOSE_DIALOG',
|
||||
OPEN_ALERT: 'OPEN_ALERT',
|
||||
CLOSE_ALERT: 'CLOSE_ALERT',
|
||||
CLOSE_ALL_DIALOGS: 'CLOSE_ALL_DIALOGS',
|
||||
CLOSE_ALL_ALERTS: 'CLOSE_ALL_ALERTS',
|
||||
OPEN_DRAWER: 'OPEN_DRAWER',
|
||||
CLOSE_DRAWER: 'CLOSE_DRAWER',
|
||||
CHANGE_DASHBOARD_PAGE_TITLE: 'CHANGE_DASHBOARD_PAGE_TITLE',
|
||||
CHANGE_DASHBOARD_PAGE_HINT: 'CHANGE_DASHBOARD_PAGE_HINT',
|
||||
CHANGE_PREFERENCES_PAGE_TITLE: 'CHANGE_PREFERENCES_PAGE_TITLE',
|
||||
ALTER_DASHBOARD_PAGE_SUBTITLE: 'ALTER_DASHBOARD_PAGE_SUBTITLE',
|
||||
SET_TOPBAR_EDIT_VIEW: 'SET_TOPBAR_EDIT_VIEW',
|
||||
SIDEBAR_EXPEND_TOGGLE: 'SIDEBAR_EXPEND_TOGGLE',
|
||||
SET_DASHBOARD_BACK_LINK: 'SET_DASHBOARD_BACK_LINK',
|
||||
APP_IS_LOADING: 'APP_IS_LOADING',
|
||||
APP_INTL_IS_LOADING: 'APP_INTL_IS_LOADING'
|
||||
};
|
||||
Reference in New Issue
Block a user