mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat(branches & warehouses): fix api.
This commit is contained in:
@@ -3,6 +3,8 @@ import { useLocation } from 'react-router-dom';
|
||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import { transformToEditForm } from './utils';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
|
||||
import {
|
||||
useCreditNote,
|
||||
@@ -25,6 +27,11 @@ function CreditNoteFormProvider({ creditNoteId, baseCurrency, ...props }) {
|
||||
const { state } = useLocation();
|
||||
const invoiceId = state?.invoiceId;
|
||||
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isWarehouseFeatureCan = featureCan(Features.Warehouses);
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
@@ -56,14 +63,14 @@ function CreditNoteFormProvider({ creditNoteId, baseCurrency, ...props }) {
|
||||
data: warehouses,
|
||||
isLoading: isWarehouesLoading,
|
||||
isSuccess: isWarehousesSuccess,
|
||||
} = useWarehouses();
|
||||
} = useWarehouses({}, { enabled: isWarehouseFeatureCan });
|
||||
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Handle fetching settings.
|
||||
useSettingsCreditNotes();
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
useCreateEstimate,
|
||||
useEditEstimate,
|
||||
} from 'hooks/query';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import { ITEMS_FILTER_ROLES } from './utils';
|
||||
|
||||
const EstimateFormContext = createContext();
|
||||
@@ -19,7 +21,12 @@ const EstimateFormContext = createContext();
|
||||
/**
|
||||
* Estimate form provider.
|
||||
*/
|
||||
function EstimateFormProvider({ estimateId, baseCurrency, ...props }) {
|
||||
function EstimateFormProvider({ query, estimateId, baseCurrency, ...props }) {
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isWarehouseFeatureCan = featureCan(Features.Warehouses);
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
const {
|
||||
data: estimate,
|
||||
isFetching: isEstimateFetching,
|
||||
@@ -48,14 +55,14 @@ function EstimateFormProvider({ estimateId, baseCurrency, ...props }) {
|
||||
data: warehouses,
|
||||
isLoading: isWarehouesLoading,
|
||||
isSuccess: isWarehousesSuccess,
|
||||
} = useWarehouses();
|
||||
} = useWarehouses(query, { enabled: isWarehouseFeatureCan });
|
||||
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Handle fetch settings.
|
||||
useSettingsEstimates();
|
||||
@@ -103,7 +110,7 @@ function EstimateFormProvider({ estimateId, baseCurrency, ...props }) {
|
||||
selectCustomer,
|
||||
setSelectCustomer,
|
||||
baseCurrency,
|
||||
|
||||
|
||||
createEstimateMutate,
|
||||
editEstimateMutate,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, { createContext, useState } from 'react';
|
||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import { transformToEditForm, ITEMS_FILTER_ROLES_QUERY } from './utils';
|
||||
import {
|
||||
@@ -24,6 +26,11 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
const { state } = useLocation();
|
||||
const estimateId = state?.action;
|
||||
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isWarehouseFeatureCan = featureCan(Features.Warehouses);
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, {
|
||||
enabled: !!invoiceId,
|
||||
});
|
||||
@@ -60,14 +67,14 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
data: warehouses,
|
||||
isLoading: isWarehouesLoading,
|
||||
isSuccess: isWarehousesSuccess,
|
||||
} = useWarehouses();
|
||||
} = useWarehouses({}, { enabled: isWarehouseFeatureCan });
|
||||
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Handle fetching settings.
|
||||
const { isLoading: isSettingsLoading } = useSettingsInvoices();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { createContext, useState } from 'react';
|
||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
||||
|
||||
import {isEqual, isUndefined } from 'lodash';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import {
|
||||
useReceipt,
|
||||
@@ -20,6 +21,11 @@ const ReceiptFormContext = createContext();
|
||||
* Receipt form provider.
|
||||
*/
|
||||
function ReceiptFormProvider({ receiptId, baseCurrency, ...props }) {
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isWarehouseFeatureCan = featureCan(Features.Warehouses);
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
// Fetch sale receipt details.
|
||||
const { data: receipt, isLoading: isReceiptLoading } = useReceipt(receiptId, {
|
||||
enabled: !!receiptId,
|
||||
@@ -38,14 +44,14 @@ function ReceiptFormProvider({ receiptId, baseCurrency, ...props }) {
|
||||
data: warehouses,
|
||||
isLoading: isWarehouesLoading,
|
||||
isSuccess: isWarehousesSuccess,
|
||||
} = useWarehouses();
|
||||
} = useWarehouses({}, { enabled: isWarehouseFeatureCan });
|
||||
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Filter all sellable items only.
|
||||
const stringifiedFilterRoles = React.useMemo(
|
||||
|
||||
Reference in New Issue
Block a user