mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat(dashboard): add features api.
This commit is contained in:
@@ -209,6 +209,10 @@ const BRANCHES = {
|
||||
BRANCH: 'BRANCH',
|
||||
};
|
||||
|
||||
const DASHBOARD = {
|
||||
DASHBOARD_META: 'DASHBOARD_META',
|
||||
};
|
||||
|
||||
export default {
|
||||
...ACCOUNTS,
|
||||
...BILLS,
|
||||
@@ -239,4 +243,5 @@ export default {
|
||||
...WAREHOUSES,
|
||||
...WAREHOUSE_TRANSFERS,
|
||||
...BRANCHES,
|
||||
...DASHBOARD,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useQueryTenant, useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useSetFeatureDashboardMeta } from '../state/feature';
|
||||
import t from './types';
|
||||
|
||||
// Common invalidate queries.
|
||||
@@ -126,8 +128,7 @@ export function useUser(id, props) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function useAuthenticatedAccount(props){
|
||||
export function useAuthenticatedAccount(props) {
|
||||
return useRequestQuery(
|
||||
['AuthenticatedAccount'],
|
||||
{
|
||||
@@ -146,8 +147,9 @@ export function useAuthenticatedAccount(props){
|
||||
* Fetches the dashboard meta.
|
||||
*/
|
||||
export function useDashboardMeta(props) {
|
||||
return useRequestQuery(
|
||||
['DashboardMeta'],
|
||||
const setFeatureDashboardMeta = useSetFeatureDashboardMeta();
|
||||
const state = useRequestQuery(
|
||||
[t.DASHBOARD_META],
|
||||
{
|
||||
method: 'get',
|
||||
url: 'dashboard/boot',
|
||||
@@ -155,7 +157,13 @@ export function useDashboardMeta(props) {
|
||||
{
|
||||
select: (res) => res.data.meta,
|
||||
defaultData: {},
|
||||
...props
|
||||
}
|
||||
)
|
||||
}
|
||||
...props,
|
||||
},
|
||||
useEffect(() => {
|
||||
if (state.isSuccess) {
|
||||
setFeatureDashboardMeta(state.data);
|
||||
}
|
||||
}, [setFeatureDashboardMeta]),
|
||||
);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useSelector } from 'react-redux';
|
||||
import React from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { setFeatureDashboardMeta } from '../../store/dashboard/dashboard.actions';
|
||||
|
||||
const featuresSelector = createSelector(
|
||||
(state) => state.dashboard.features,
|
||||
@@ -15,3 +17,17 @@ export const useFeatureCan = () => {
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets features.
|
||||
*/
|
||||
export const useSetFeatureDashboardMeta = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return React.useCallback(
|
||||
(features) => {
|
||||
dispatch(setFeatureDashboardMeta(features));
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user