mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-06-06 18:09:00 +00:00
wip
This commit is contained in:
@@ -56,7 +56,7 @@ export function DataTable(props) {
|
||||
expandable = false,
|
||||
noInitialFetch = false,
|
||||
|
||||
pagesCount: controlledPageCount,
|
||||
rowsCount,
|
||||
|
||||
// Pagination props.
|
||||
initialPageIndex = 0,
|
||||
@@ -121,7 +121,7 @@ export function DataTable(props) {
|
||||
hiddenColumns: initialHiddenColumns,
|
||||
},
|
||||
manualPagination,
|
||||
pageCount: controlledPageCount,
|
||||
pageCount: rowsCount && pageSize > 0 ? Math.ceil(rowsCount / pageSize) : 0,
|
||||
getSubRows: (row) => row.children,
|
||||
manualSortBy,
|
||||
expandSubRows,
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function TablePagination() {
|
||||
pageCount,
|
||||
state: { pageIndex, pageSize },
|
||||
},
|
||||
props: { pagination, loading, onPaginationChange, hidePaginationNoPages },
|
||||
props: { pagination, loading, onPaginationChange, hidePaginationNoPages, rowsCount },
|
||||
} = useContext(TableContext);
|
||||
|
||||
const triggerOnPaginationChange = useCallback(
|
||||
@@ -59,7 +59,7 @@ export default function TablePagination() {
|
||||
showPagination && (
|
||||
<Pagination
|
||||
currentPage={pageIndex + 1}
|
||||
total={pageSize * pageCount}
|
||||
total={rowsCount ?? pageSize * pageCount}
|
||||
size={pageSize}
|
||||
onPageChange={handlePageChange}
|
||||
onPageSizeChange={handlePageSizeChange}
|
||||
|
||||
@@ -120,7 +120,7 @@ function ManualJournalsDataTable({
|
||||
<DataTable
|
||||
noInitialFetch={true}
|
||||
columns={columns}
|
||||
data={manualJournals}
|
||||
data={manualJournals ?? []}
|
||||
manualSortBy={true}
|
||||
selectionColumn={true}
|
||||
sticky={true}
|
||||
@@ -128,8 +128,8 @@ function ManualJournalsDataTable({
|
||||
headerLoading={isManualJournalsLoading}
|
||||
progressBarLoading={isManualJournalsFetching}
|
||||
pagination={true}
|
||||
initialPageSize={manualJournalsTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={manualJournalsTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
|
||||
@@ -15,7 +15,7 @@ function ManualJournalsListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetches the manual journals transactions with pagination meta.
|
||||
const {
|
||||
data: { manualJournals, pagination, filterMeta },
|
||||
data: manualJournalsData,
|
||||
isLoading: isManualJournalsLoading,
|
||||
isFetching: isManualJournalsFetching,
|
||||
} = useJournals(query, { keepPreviousData: true });
|
||||
@@ -29,16 +29,16 @@ function ManualJournalsListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(manualJournals) && !tableStateChanged && !isManualJournalsLoading;
|
||||
isEmpty(manualJournalsData?.data) && !tableStateChanged && !isManualJournalsLoading;
|
||||
|
||||
// Global state.
|
||||
const state = {
|
||||
manualJournals,
|
||||
pagination,
|
||||
manualJournals: manualJournalsData?.data,
|
||||
pagination: manualJournalsData?.pagination,
|
||||
journalsViews,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
|
||||
isManualJournalsLoading,
|
||||
isManualJournalsFetching,
|
||||
|
||||
@@ -59,7 +59,7 @@ function MakeJournalProvider({ journalId, query, ...props }) {
|
||||
|
||||
// Fetch the projects list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectFeatureCan });
|
||||
|
||||
@@ -74,7 +74,7 @@ function MakeJournalProvider({ journalId, query, ...props }) {
|
||||
contacts,
|
||||
currencies,
|
||||
manualJournal,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
branches,
|
||||
|
||||
createJournalMutate,
|
||||
|
||||
@@ -35,7 +35,7 @@ function AccountsChartProvider({ query, tableStateChanged, ...props }) {
|
||||
resourceMeta,
|
||||
resourceViews,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
|
||||
isAccountsLoading,
|
||||
isAccountsFetching,
|
||||
|
||||
@@ -105,7 +105,7 @@ function AccountsDataTable({
|
||||
<DataTable
|
||||
noInitialFetch={true}
|
||||
columns={columns}
|
||||
data={accounts}
|
||||
data={accounts ?? []}
|
||||
selectionColumn={true}
|
||||
expandable={true}
|
||||
sticky={true}
|
||||
|
||||
@@ -26,21 +26,21 @@ function CustomersListProvider({ tableState, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetches customers data with pagination meta.
|
||||
const {
|
||||
data: { customers, pagination, filterMeta },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
isFetching: isCustomersFetching,
|
||||
} = useCustomers(tableQuery, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(customers) && !isCustomersLoading && !tableStateChanged;
|
||||
isEmpty(customersData?.data) && !isCustomersLoading && !tableStateChanged;
|
||||
|
||||
const state = {
|
||||
customersViews,
|
||||
customers,
|
||||
pagination,
|
||||
customers: customersData?.data,
|
||||
pagination: customersData?.pagination,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
resourceMeta,
|
||||
isResourceMetaLoading,
|
||||
isResourceMetaFetching,
|
||||
|
||||
@@ -135,7 +135,7 @@ function CustomersTable({
|
||||
<DataTable
|
||||
noInitialFetch={true}
|
||||
columns={columns}
|
||||
data={customers}
|
||||
data={customers ?? []}
|
||||
loading={isCustomersLoading}
|
||||
headerLoading={isCustomersLoading}
|
||||
progressBarLoading={isCustomersFetching}
|
||||
@@ -145,10 +145,10 @@ function CustomersTable({
|
||||
sticky={true}
|
||||
spinnerProps={{ size: 30 }}
|
||||
pagination={true}
|
||||
initialPageSize={customersTableState.pageSize}
|
||||
initialPageSize={customersTableState?.pageSize ?? 10}
|
||||
manualSortBy={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
autoResetSelectedRows={false}
|
||||
autoResetSortBy={false}
|
||||
|
||||
@@ -28,12 +28,12 @@ function UserFormProvider({ userId, dialogName, ...props }) {
|
||||
|
||||
// Retrieve authenticated user information.
|
||||
const {
|
||||
data: { id },
|
||||
data: authAccountData,
|
||||
} = useAuthenticatedAccount();
|
||||
|
||||
const isEditMode = userId;
|
||||
|
||||
const isAuth = user.system_user_id == id
|
||||
const isAuth = user.system_user_id == authAccountData?.id
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
|
||||
@@ -30,7 +30,7 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
||||
|
||||
// Fetches customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers();
|
||||
|
||||
@@ -51,7 +51,7 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
||||
|
||||
// Fetch the projects list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -77,11 +77,11 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
||||
submitPayloadRef, // Expose ref for synchronous access
|
||||
|
||||
currencies,
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
expense,
|
||||
accounts,
|
||||
branches,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
|
||||
isCurrenciesLoading,
|
||||
isExpenseLoading,
|
||||
|
||||
@@ -118,7 +118,7 @@ function ExpensesDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={expenses}
|
||||
data={expenses || []}
|
||||
loading={isExpensesLoading}
|
||||
headerLoading={isExpensesLoading}
|
||||
progressBarLoading={isExpensesFetching}
|
||||
@@ -127,10 +127,10 @@ function ExpensesDataTable({
|
||||
sticky={true}
|
||||
onFetchData={handleFetchData}
|
||||
pagination={true}
|
||||
initialPageSize={expensesTableState.pageSize}
|
||||
initialPageSize={expensesTableState?.pageSize ?? 10}
|
||||
manualSortBy={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -18,7 +18,7 @@ function ExpensesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetches the expenses with pagination meta.
|
||||
const {
|
||||
data: { expenses, pagination, filterMeta },
|
||||
data: expensesData,
|
||||
isLoading: isExpensesLoading,
|
||||
isFetching: isExpensesFetching,
|
||||
} = useExpenses(query, { keepPreviousData: true });
|
||||
@@ -32,15 +32,15 @@ function ExpensesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(expenses) && !isExpensesLoading && !tableStateChanged;
|
||||
isEmpty(expensesData?.data) && !isExpensesLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
expensesViews,
|
||||
expenses,
|
||||
pagination,
|
||||
expenses: expensesData?.data,
|
||||
pagination: expensesData?.pagination,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
resourceMeta,
|
||||
isResourceMetaLoading,
|
||||
isResourceMetaFetching,
|
||||
|
||||
@@ -12,12 +12,12 @@ const APAgingSummaryGeneralContext = createContext();
|
||||
function APAgingSummaryGeneralProvider({ filter, ...props }) {
|
||||
// Retrieve the vendors list.
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isFetching: isVendorsLoading,
|
||||
} = useVendors();
|
||||
|
||||
const provider = {
|
||||
vendors,
|
||||
vendors: vendorsData?.vendors,
|
||||
isVendorsLoading,
|
||||
};
|
||||
// Loading state.
|
||||
|
||||
@@ -11,12 +11,12 @@ const ARAgingSummaryGeneralContext = createContext();
|
||||
function ARAgingSummaryGeneralProvider({ ...props }) {
|
||||
// Retrieve the customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers();
|
||||
|
||||
const provider = {
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
isCustomersLoading,
|
||||
};
|
||||
// Loading state.
|
||||
|
||||
@@ -11,7 +11,7 @@ const CustomersBalanceSummaryGeneralContext = createContext();
|
||||
function CustomersBalanceSummaryGeneralProvider({ ...props }) {
|
||||
// Fetches the customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isFetching: isCustomersFetching,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers();
|
||||
@@ -19,7 +19,7 @@ function CustomersBalanceSummaryGeneralProvider({ ...props }) {
|
||||
const provider = {
|
||||
isCustomersLoading,
|
||||
isCustomersFetching,
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
};
|
||||
|
||||
const loading = isCustomersLoading;
|
||||
|
||||
@@ -11,13 +11,13 @@ const CustomersTransactionsGeneralPanelContext = createContext();
|
||||
function CustomersTransactionsGeneralPanelProvider({ ...props }) {
|
||||
// Fetches the customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isFetching: isCustomersFetching,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers();
|
||||
|
||||
const provider = {
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
isCustomersLoading,
|
||||
isCustomersFetching,
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ const InventoryItemDetailsHeaderGeneralContext = React.createContext();
|
||||
function InventoryItemDetailsHeaderGeneralProvider({ ...props }) {
|
||||
// Handle fetching the items based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
isFetching: isItemsFetching,
|
||||
} = useItems({
|
||||
@@ -24,7 +24,7 @@ function InventoryItemDetailsHeaderGeneralProvider({ ...props }) {
|
||||
const provider = {
|
||||
isItemsFetching,
|
||||
isItemsLoading,
|
||||
items,
|
||||
items: itemsData?.items,
|
||||
};
|
||||
// Loading state.
|
||||
const loading = isItemsLoading;
|
||||
|
||||
@@ -8,7 +8,7 @@ const InventoryValuationGeneralPanelContext = React.createContext();
|
||||
function InventoryValuationGeneralPanelProvider({ query, ...props }) {
|
||||
// Handle fetching the items based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
isFetching: isItemsFetching,
|
||||
} = useItems({
|
||||
@@ -20,7 +20,7 @@ function InventoryValuationGeneralPanelProvider({ query, ...props }) {
|
||||
|
||||
// Provider data.
|
||||
const provider = {
|
||||
items,
|
||||
items: itemsData?.items,
|
||||
isItemsFetching,
|
||||
isItemsLoading,
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ function ProjectProfitabilitySummaryProvider({ filter, ...props }) {
|
||||
|
||||
// Fetch project list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects();
|
||||
|
||||
@@ -31,8 +31,8 @@ function ProjectProfitabilitySummaryProvider({ filter, ...props }) {
|
||||
isProjectProfitabilitySummaryFetching,
|
||||
isProjectProfitabilitySummaryLoading,
|
||||
refetchProjectProfitabilitySummary,
|
||||
projects,
|
||||
|
||||
projects: projectsData?.projects,
|
||||
|
||||
query,
|
||||
filter,
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ const PurchasesByItemsGeneralPanelContext = createContext();
|
||||
function PurchasesByItemsGeneralPanelProvider({ ...props }) {
|
||||
// Handle fetching the items based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
isFetching: isItemsFetching,
|
||||
} = useItems({
|
||||
@@ -18,7 +18,7 @@ function PurchasesByItemsGeneralPanelProvider({ ...props }) {
|
||||
});
|
||||
|
||||
const provider = {
|
||||
items,
|
||||
items: itemsData?.items,
|
||||
isItemsLoading,
|
||||
isItemsFetching,
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ const SalesByItemGeneralPanelContext = createContext();
|
||||
function SalesByItemGeneralPanelProvider({ query, ...props }) {
|
||||
// Handle fetching the items based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
isFetching: isItemsFetching,
|
||||
} = useItems({
|
||||
@@ -22,7 +22,7 @@ function SalesByItemGeneralPanelProvider({ query, ...props }) {
|
||||
});
|
||||
|
||||
const provider = {
|
||||
items,
|
||||
items: itemsData?.items,
|
||||
isItemsLoading,
|
||||
isItemsFetching,
|
||||
};
|
||||
|
||||
@@ -12,14 +12,14 @@ const VendorsBalanceSummaryGeneralPanelContext = React.createContext();
|
||||
function VendorsBalanceSummaryGeneralPanelProvider({ filter, ...props }) {
|
||||
// Fetch vendors list with pagination meta.
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
isFetching: isVendorsFetching,
|
||||
} = useVendors({ page_size: 1000000 });
|
||||
|
||||
// Provider.
|
||||
const provider = {
|
||||
vendors,
|
||||
vendors: vendorsData?.vendors,
|
||||
isVendorsFetching,
|
||||
isVendorsLoading,
|
||||
};
|
||||
|
||||
@@ -11,13 +11,13 @@ const VendorsTransactionsGeneralPanelContext = createContext();
|
||||
function VendorsTransactionsGeneralPanelProvider({ ...props }) {
|
||||
// Fetch vendors list based on the given query.
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
isFetching: isVendorsFetching,
|
||||
} = useVendors({ page_size: 100000 });
|
||||
|
||||
const provider = {
|
||||
vendors,
|
||||
vendors: vendorsData?.vendors,
|
||||
isVendorsLoading,
|
||||
isVendorsFetching,
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ function InventoryAdjustmentDataTable({
|
||||
return (
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={inventoryAdjustments}
|
||||
data={inventoryAdjustments ?? []}
|
||||
loading={isAdjustmentsLoading}
|
||||
headerLoading={isAdjustmentsLoading}
|
||||
progressBarLoading={isAdjustmentsFetching}
|
||||
@@ -92,8 +92,8 @@ function InventoryAdjustmentDataTable({
|
||||
manualSortBy={true}
|
||||
selectionColumn={true}
|
||||
pagination={true}
|
||||
initialPageSize={inventoryAdjustmentTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={inventoryAdjustmentTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onCellClick={handleCellClick}
|
||||
|
||||
@@ -13,15 +13,15 @@ function InventoryAdjustmentsProvider({ query, ...props }) {
|
||||
const {
|
||||
isLoading: isAdjustmentsLoading,
|
||||
isFetching: isAdjustmentsFetching,
|
||||
data: { inventoryAdjustments, pagination },
|
||||
data: inventoryAdjustmentsData,
|
||||
} = useInventoryAdjustments(query, { keepPreviousData: true });
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
inventoryAdjustments,
|
||||
inventoryAdjustments: inventoryAdjustmentsData?.inventoryAdjustments,
|
||||
isAdjustmentsLoading,
|
||||
isAdjustmentsFetching,
|
||||
pagination,
|
||||
pagination: inventoryAdjustmentsData?.pagination,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -28,7 +28,7 @@ function ItemFormProvider({ itemId, ...props }) {
|
||||
// Fetches the items categories list.
|
||||
const {
|
||||
isLoading: isItemsCategoriesLoading,
|
||||
data: { itemsCategories },
|
||||
data: itemsCategoriesData,
|
||||
} = useItemsCategories();
|
||||
|
||||
const { data: taxRates, isLoading: isTaxRatesLoading } = useTaxRates();
|
||||
@@ -71,7 +71,7 @@ function ItemFormProvider({ itemId, ...props }) {
|
||||
itemId,
|
||||
accounts,
|
||||
item,
|
||||
itemsCategories,
|
||||
itemsCategories: itemsCategoriesData?.itemsCategories,
|
||||
taxRates,
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
|
||||
@@ -140,7 +140,7 @@ function ItemsDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={items}
|
||||
data={items || []}
|
||||
loading={isItemsLoading}
|
||||
headerLoading={isItemsLoading}
|
||||
progressBarLoading={isItemsFetching}
|
||||
@@ -153,10 +153,10 @@ function ItemsDataTable({
|
||||
sticky={true}
|
||||
rowClassNames={rowClassNames}
|
||||
pagination={true}
|
||||
initialPageSize={itemsTableState.pageSize}
|
||||
initialPageSize={itemsTableState?.pageSize || 10}
|
||||
manualSortBy={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total || 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={true}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -31,7 +31,7 @@ function ItemsListProvider({ tableState, tableStateChanged, ...props }) {
|
||||
|
||||
// Handle fetching the items table based on the given query.
|
||||
const {
|
||||
data: { items, pagination, filterMeta },
|
||||
data: itemsData,
|
||||
isFetching: isItemsFetching,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems(
|
||||
@@ -42,14 +42,14 @@ function ItemsListProvider({ tableState, tableStateChanged, ...props }) {
|
||||
);
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus = !tableStateChanged && !isItemsLoading && isEmpty(items);
|
||||
const isEmptyStatus = !tableStateChanged && !isItemsLoading && isEmpty(itemsData?.data);
|
||||
|
||||
const state = {
|
||||
itemsViews,
|
||||
items,
|
||||
pagination,
|
||||
items: itemsData?.data,
|
||||
pagination: itemsData?.pagination,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
|
||||
isViewsLoading,
|
||||
isItemsLoading,
|
||||
|
||||
@@ -15,7 +15,7 @@ function ItemsCategoriesProvider({ tableState, ...props }) {
|
||||
|
||||
// Items categories list.
|
||||
const {
|
||||
data: { itemsCategories, pagination },
|
||||
data: itemsCategoriesData,
|
||||
isFetching: isCategoriesFetching,
|
||||
isLoading: isCategoriesLoading,
|
||||
} = useItemsCategories(query, { keepPreviousData: true });
|
||||
@@ -31,13 +31,13 @@ function ItemsCategoriesProvider({ tableState, ...props }) {
|
||||
isCategoriesFetching,
|
||||
isCategoriesLoading,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
resourceMeta,
|
||||
isResourceLoading,
|
||||
isResourceFetching,
|
||||
|
||||
itemsCategories,
|
||||
pagination,
|
||||
itemsCategories: itemsCategoriesData?.itemsCategories,
|
||||
pagination: itemsCategoriesData?.pagination,
|
||||
query,
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ function ProjectTaskProvider({ ...props }) {
|
||||
|
||||
// Handle fetch project tasks.
|
||||
const {
|
||||
data: { projectTasks },
|
||||
data: projectTasksData,
|
||||
isFetching: isProjectTasksFetching,
|
||||
isLoading: isProjectTasksLoading,
|
||||
} = useProjectTasks(projectId, {
|
||||
@@ -32,7 +32,7 @@ function ProjectTaskProvider({ ...props }) {
|
||||
const provider = {
|
||||
project,
|
||||
projectId,
|
||||
projectTasks,
|
||||
projectTasks: projectTasksData?.projectTasks,
|
||||
isProjectTasksFetching,
|
||||
isProjectTasksLoading,
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ function ProjectTimesheetsProvider({ ...props }) {
|
||||
|
||||
// fetch project time entries.
|
||||
const {
|
||||
data: { projectTimeEntries },
|
||||
data: projectTimeEntriesData,
|
||||
isLoading: isProjectTimeEntriesLoading,
|
||||
} = useProjectTimeEntries(projectId, {
|
||||
enabled: !!projectId,
|
||||
@@ -30,7 +30,7 @@ const {
|
||||
const provider = {
|
||||
projectId,
|
||||
project,
|
||||
projectTimeEntries,
|
||||
projectTimeEntries: projectTimeEntriesData?.projectTimeEntries,
|
||||
isProjectTimeEntriesLoading,
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ function ProjectFormProvider({
|
||||
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
@@ -35,7 +35,7 @@ function ProjectFormProvider({
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
dialogName,
|
||||
project,
|
||||
projectId,
|
||||
|
||||
@@ -32,7 +32,7 @@ function ProjectTimeEntryFormProvider({
|
||||
|
||||
// Handle fetch project tasks.
|
||||
const {
|
||||
data: { projectTasks },
|
||||
data: projectTasksData,
|
||||
} = useProjectTasks(project, {
|
||||
enabled: !!project,
|
||||
});
|
||||
@@ -45,7 +45,7 @@ function ProjectTimeEntryFormProvider({
|
||||
|
||||
// Fetch project list data table or list
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects();
|
||||
|
||||
@@ -54,10 +54,10 @@ function ProjectTimeEntryFormProvider({
|
||||
// provider payload.
|
||||
const provider = {
|
||||
dialogName,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
projectId,
|
||||
timesheetId,
|
||||
projectTasks,
|
||||
projectTasks: projectTasksData?.projectTasks,
|
||||
isNewMode,
|
||||
setProjectPayload,
|
||||
projectTimeEntry,
|
||||
|
||||
@@ -18,18 +18,18 @@ function ProjectsListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isFetching: isProjectsFetching,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(projects) && !tableStateChanged && !isProjectsLoading;
|
||||
isEmpty(projectsData?.data) && !tableStateChanged && !isProjectsLoading;
|
||||
|
||||
// provider payload.
|
||||
const provider = {
|
||||
projects,
|
||||
projects: projectsData?.data,
|
||||
|
||||
projectsViews,
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
||||
import { useRequestQuery } from '@/hooks/useQueryRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import useApiRequest from '@/hooks/useRequest';
|
||||
import t from './type';
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ function BillFormProvider({ billId, ...props }) {
|
||||
|
||||
// Handle fetch vendors data table
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
} = useVendors({ page_size: 10000 });
|
||||
|
||||
// Handle fetch Items data table or list
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
page_size: 10000,
|
||||
@@ -89,7 +89,7 @@ function BillFormProvider({ billId, ...props }) {
|
||||
|
||||
// Fetches the projects list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -114,12 +114,12 @@ function BillFormProvider({ billId, ...props }) {
|
||||
|
||||
const provider = {
|
||||
accounts,
|
||||
vendors,
|
||||
items,
|
||||
vendors: vendorsData?.vendors,
|
||||
items: itemsData?.items,
|
||||
bill,
|
||||
warehouses,
|
||||
branches,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
taxRates,
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
|
||||
@@ -26,22 +26,22 @@ function BillsListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { bills, pagination, filterMeta },
|
||||
data: billsData,
|
||||
isLoading: isBillsLoading,
|
||||
isFetching: isBillsFetching,
|
||||
} = useBills(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus = isEmpty(bills) && !isBillsLoading && !tableStateChanged;
|
||||
const isEmptyStatus = isEmpty(billsData?.data) && !isBillsLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
bills,
|
||||
pagination,
|
||||
bills: billsData?.data,
|
||||
pagination: billsData?.pagination,
|
||||
billsViews,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
isResourceLoading,
|
||||
isResourceFetching,
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ function BillsDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={bills}
|
||||
data={bills ?? []}
|
||||
loading={isBillsLoading}
|
||||
headerLoading={isBillsLoading}
|
||||
progressBarLoading={isBillsFetching}
|
||||
@@ -137,8 +137,8 @@ function BillsDataTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={billsTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={billsTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -34,7 +34,7 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
|
||||
// Handle fetching the items table based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
page_size: 10000,
|
||||
@@ -45,7 +45,7 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
|
||||
// Handle fetch vendors data table or list
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
} = useVendors({ page_size: 10000 });
|
||||
|
||||
@@ -95,8 +95,8 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
items,
|
||||
vendors,
|
||||
items: itemsData?.items,
|
||||
vendors: vendorsData?.vendors,
|
||||
vendorCredit,
|
||||
warehouses,
|
||||
branches,
|
||||
|
||||
@@ -129,7 +129,7 @@ function VendorsCreditNoteDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={vendorCredits}
|
||||
data={vendorCredits ?? []}
|
||||
loading={isVendorCreditsLoading}
|
||||
headerLoading={isVendorCreditsLoading}
|
||||
progressBarLoading={isVendorCreditsFetching}
|
||||
@@ -139,8 +139,8 @@ function VendorsCreditNoteDataTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={vendorsCreditNoteTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={vendorsCreditNoteTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -34,24 +34,24 @@ function VendorsCreditNoteListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch vendor credits list.
|
||||
const {
|
||||
data: { vendorCredits, pagination, filterMeta },
|
||||
data: vendorCreditsData,
|
||||
isLoading: isVendorCreditsLoading,
|
||||
isFetching: isVendorCreditsFetching,
|
||||
} = useVendorCredits(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(vendorCredits) && !isVendorCreditsLoading && !tableStateChanged;
|
||||
isEmpty(vendorCreditsData?.data) && !isVendorCreditsLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
vendorCredits,
|
||||
pagination,
|
||||
vendorCredits: vendorCreditsData?.data,
|
||||
pagination: vendorCreditsData?.pagination,
|
||||
VendorCreditsViews,
|
||||
refresh,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
isResourceLoading,
|
||||
isResourceFetching,
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ function PaymentMadeFormProvider({ query, paymentMadeId, ...props }) {
|
||||
|
||||
// Handle fetch Items data table or list.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isFetching: isItemsFetching,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({ page_size: 10000 });
|
||||
|
||||
// Handle fetch venders data table or list.
|
||||
const {
|
||||
data: { vendors },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
} = useVendors({ page_size: 10000 });
|
||||
|
||||
@@ -81,8 +81,8 @@ function PaymentMadeFormProvider({ query, paymentMadeId, ...props }) {
|
||||
accounts,
|
||||
paymentEntriesEditPage,
|
||||
paymentMadeEditPage,
|
||||
vendors,
|
||||
items,
|
||||
vendors: vendorsData?.vendors,
|
||||
items: itemsData?.items,
|
||||
branches,
|
||||
submitPayload,
|
||||
paymentVendorId,
|
||||
|
||||
@@ -29,23 +29,23 @@ function PaymentMadesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentMades, pagination, filterMeta },
|
||||
data: paymentMadesData,
|
||||
isLoading: isPaymentsLoading,
|
||||
isFetching: isPaymentsFetching,
|
||||
} = usePaymentMades(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(paymentMades) && !isPaymentsLoading && !tableStateChanged;
|
||||
isEmpty(paymentMadesData?.data) && !isPaymentsLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMades,
|
||||
pagination,
|
||||
filterMeta,
|
||||
paymentMades: paymentMadesData?.data,
|
||||
pagination: paymentMadesData?.pagination,
|
||||
filterMeta: paymentMadesData?.filter_meta,
|
||||
paymentMadesViews,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
resourceMeta,
|
||||
isResourceMetaLoading,
|
||||
isResourceMetaFetching,
|
||||
|
||||
@@ -102,7 +102,7 @@ function PaymentMadesTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={paymentMades}
|
||||
data={paymentMades ?? []}
|
||||
onFetchData={handleDataTableFetchData}
|
||||
loading={isPaymentsLoading}
|
||||
headerLoading={isPaymentsLoading}
|
||||
@@ -112,8 +112,8 @@ function PaymentMadesTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={paymentMadesTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={paymentMadesTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -23,14 +23,14 @@ function PaymentMadesProvider({ query, ...props }) {
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentMades, pagination },
|
||||
data: paymentMadesData,
|
||||
isLoading: isPaymentsLoading,
|
||||
} = usePaymentMades(query);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMades,
|
||||
pagination,
|
||||
paymentMades: paymentMadesData?.data,
|
||||
pagination: paymentMadesData?.pagination,
|
||||
paymentsFields,
|
||||
paymentsViews,
|
||||
|
||||
|
||||
@@ -45,13 +45,13 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
// Handle fetching the items table based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
page_size: 10000,
|
||||
@@ -122,8 +122,8 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
items,
|
||||
customers,
|
||||
items: itemsData?.items,
|
||||
customers: customersData?.customers,
|
||||
creditNote,
|
||||
branches,
|
||||
warehouses,
|
||||
|
||||
@@ -133,7 +133,7 @@ function CreditNotesDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={creditNotes}
|
||||
data={creditNotes ?? []}
|
||||
loading={isCreditNotesLoading}
|
||||
headerLoading={isCreditNotesLoading}
|
||||
progressBarLoading={isCreditNotesFetching}
|
||||
@@ -145,8 +145,8 @@ function CreditNotesDataTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={creditNoteTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={creditNoteTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -34,25 +34,25 @@ function CreditNotesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch credit note list.
|
||||
const {
|
||||
data: { creditNotes, pagination, filterMeta },
|
||||
data: creditNotesData,
|
||||
isFetching: isCreditNotesFetching,
|
||||
isLoading: isCreditNotesLoading,
|
||||
} = useCreditNotes(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.S
|
||||
const isEmptyStatus =
|
||||
isEmpty(creditNotes) && !isCreditNotesLoading && !tableStateChanged;
|
||||
isEmpty(creditNotesData?.data) && !isCreditNotesLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
creditNotes,
|
||||
pagination,
|
||||
creditNotes: creditNotesData?.data,
|
||||
pagination: creditNotesData?.pagination,
|
||||
|
||||
CreditNotesView,
|
||||
refresh,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
isResourceLoading,
|
||||
isResourceFetching,
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
|
||||
// Handle fetch Items data table or list
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isFetching: isItemsFetching,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
@@ -55,7 +55,7 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
@@ -75,7 +75,7 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
|
||||
// Fetches the projects list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -114,11 +114,11 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
const provider = {
|
||||
estimateId,
|
||||
estimate,
|
||||
items,
|
||||
customers,
|
||||
items: itemsData?.items,
|
||||
customers: customersData?.customers,
|
||||
branches,
|
||||
warehouses,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
isNewMode,
|
||||
|
||||
isItemsFetching,
|
||||
|
||||
@@ -145,7 +145,7 @@ function EstimatesDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={estimates}
|
||||
data={estimates ?? []}
|
||||
loading={isEstimatesLoading}
|
||||
headerLoading={isEstimatesLoading}
|
||||
progressBarLoading={isEstimatesFetching}
|
||||
@@ -157,9 +157,9 @@ function EstimatesDataTable({
|
||||
selectionColumn={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={estimatesTableState.pageSize}
|
||||
initialPageSize={estimatesTableState?.pageSize ?? 10}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -27,21 +27,21 @@ function EstimatesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetches estimates list according to the given custom view id.
|
||||
const {
|
||||
data: { estimates, pagination, filterMeta },
|
||||
data: estimatesData,
|
||||
isLoading: isEstimatesLoading,
|
||||
isFetching: isEstimatesFetching,
|
||||
} = useEstimates(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
!isEstimatesLoading && !tableStateChanged && isEmpty(estimates);
|
||||
!isEstimatesLoading && !tableStateChanged && isEmpty(estimatesData?.data);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
estimates,
|
||||
pagination,
|
||||
estimates: estimatesData?.data,
|
||||
pagination: estimatesData?.pagination,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
estimatesViews,
|
||||
|
||||
isResourceLoading,
|
||||
|
||||
@@ -56,7 +56,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
|
||||
// Fetch project list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -82,7 +82,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
|
||||
// Handle fetching the items table based on the given query.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
page_size: 10000,
|
||||
@@ -91,7 +91,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
@@ -142,15 +142,15 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
|
||||
const provider = {
|
||||
invoice,
|
||||
items,
|
||||
customers,
|
||||
items: itemsData?.items,
|
||||
customers: customersData?.customers,
|
||||
newInvoice,
|
||||
estimateId,
|
||||
invoiceId,
|
||||
submitPayload,
|
||||
branches,
|
||||
warehouses,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
taxRates,
|
||||
brandingTemplates,
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ function InvoicesDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={invoices}
|
||||
data={invoices ?? []}
|
||||
loading={isInvoicesLoading}
|
||||
headerLoading={isInvoicesLoading}
|
||||
progressBarLoading={isInvoicesFetching}
|
||||
@@ -155,9 +155,9 @@ function InvoicesDataTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={invoicesTableState.pageSize}
|
||||
initialPageSize={invoicesTableState?.pageSize ?? 10}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
autoResetSelectedRows={false}
|
||||
|
||||
@@ -25,21 +25,21 @@ function InvoicesListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch sale invoices of the given query.
|
||||
const {
|
||||
data: { invoices, pagination, filterMeta },
|
||||
data: invoicesData,
|
||||
isFetching: isInvoicesFetching,
|
||||
isLoading: isInvoicesLoading,
|
||||
} = useInvoices(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines whether the table should show empty state.
|
||||
const isEmptyStatus =
|
||||
isEmpty(invoices) && !tableStateChanged && !isInvoicesLoading;
|
||||
isEmpty(invoicesData?.data) && !tableStateChanged && !isInvoicesLoading;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
invoices,
|
||||
pagination,
|
||||
invoices: invoicesData?.data,
|
||||
pagination: invoicesData?.pagination,
|
||||
|
||||
invoicesFields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
invoicesFields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
invoicesViews,
|
||||
|
||||
isInvoicesLoading,
|
||||
|
||||
@@ -59,7 +59,7 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
|
||||
// Fetches customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
@@ -72,7 +72,7 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
|
||||
// Fetches the projects list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -110,9 +110,9 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
paymentReceiveEditPage,
|
||||
paymentEntriesEditPage,
|
||||
accounts,
|
||||
customers,
|
||||
customers: customersData?.customers,
|
||||
branches,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
|
||||
isPaymentLoading,
|
||||
isAccountsLoading,
|
||||
|
||||
@@ -29,23 +29,23 @@ function PaymentsReceivedListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentReceives, pagination, filterMeta },
|
||||
data: paymentReceivesData,
|
||||
isLoading: isPaymentReceivesLoading,
|
||||
isFetching: isPaymentReceivesFetching,
|
||||
} = usePaymentReceives(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
!isPaymentReceivesLoading && !tableStateChanged && isEmpty(paymentReceives);
|
||||
!isPaymentReceivesLoading && !tableStateChanged && isEmpty(paymentReceivesData?.data);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentReceives,
|
||||
paymentReceives: paymentReceivesData?.data,
|
||||
paymentReceivesViews,
|
||||
pagination,
|
||||
pagination: paymentReceivesData?.pagination,
|
||||
resourceMeta,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
|
||||
isEmptyStatus,
|
||||
isViewsLoading,
|
||||
|
||||
@@ -29,22 +29,22 @@ function PaymentsReceivedListProvider({ query, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch payment receives list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentReceives, pagination, filterMeta },
|
||||
data: paymentReceivesData,
|
||||
isLoading: isPaymentReceivesLoading,
|
||||
isFetching: isPaymentReceivesFetching,
|
||||
} = usePaymentReceives(query);
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(paymentReceives) && !isPaymentReceivesLoading && !tableStateChanged;
|
||||
isEmpty(paymentReceivesData?.data) && !isPaymentReceivesLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const state = {
|
||||
paymentReceives,
|
||||
pagination,
|
||||
paymentReceives: paymentReceivesData?.data,
|
||||
pagination: paymentReceivesData?.pagination,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
|
||||
paymentReceivesViews,
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ function PaymentsReceivedDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={paymentReceives}
|
||||
data={paymentReceives ?? []}
|
||||
loading={isPaymentReceivesLoading}
|
||||
headerLoading={isPaymentReceivesLoading}
|
||||
progressBarLoading={isPaymentReceivesFetching}
|
||||
@@ -135,8 +135,8 @@ function PaymentsReceivedDataTable({
|
||||
autoResetPage={false}
|
||||
pagination={true}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
initialPageSize={paymentReceivesTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={paymentReceivesTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -47,7 +47,7 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
|
||||
// Fetch customers list.
|
||||
const {
|
||||
data: { customers },
|
||||
data: customersData,
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
@@ -89,7 +89,7 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
|
||||
// Handle fetch Items data table or list.
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
page_size: 10000,
|
||||
@@ -97,7 +97,7 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
});
|
||||
// Fetch project list.
|
||||
const {
|
||||
data: { projects },
|
||||
data: projectsData,
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects({}, { enabled: !!isProjectsFeatureCan });
|
||||
|
||||
@@ -133,11 +133,11 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
receiptId,
|
||||
receipt,
|
||||
accounts,
|
||||
customers,
|
||||
items,
|
||||
customers: customersData?.customers,
|
||||
items: itemsData?.items,
|
||||
branches,
|
||||
warehouses,
|
||||
projects,
|
||||
projects: projectsData?.projects,
|
||||
submitPayload,
|
||||
|
||||
isNewMode,
|
||||
|
||||
@@ -23,24 +23,24 @@ function ReceiptsListProvider({ query, tableStateChanged, ...props }) {
|
||||
} = useResourceMeta('sale_receipt');
|
||||
|
||||
const {
|
||||
data: { receipts, pagination, filterMeta },
|
||||
data: receiptsData,
|
||||
isLoading: isReceiptsLoading,
|
||||
isFetching: isReceiptsFetching,
|
||||
} = useReceipts(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(receipts) && !tableStateChanged && !isReceiptsLoading;
|
||||
isEmpty(receiptsData?.data) && !tableStateChanged && !isReceiptsLoading;
|
||||
|
||||
const provider = {
|
||||
receipts,
|
||||
pagination,
|
||||
receipts: receiptsData?.data,
|
||||
pagination: receiptsData?.pagination,
|
||||
|
||||
receiptsViews,
|
||||
isViewsLoading,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
isResourceFetching,
|
||||
isResourceLoading,
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ function ReceiptsDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={receipts}
|
||||
data={receipts ?? []}
|
||||
loading={isReceiptsLoading}
|
||||
headerLoading={isReceiptsLoading}
|
||||
progressBarLoading={isReceiptsFetching}
|
||||
@@ -136,8 +136,8 @@ function ReceiptsDataTable({
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={receiptTableState.pageSize}
|
||||
pagesCount={pagination.pagesCount}
|
||||
initialPageSize={receiptTableState?.pageSize ?? 10}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
manualPagination={true}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
|
||||
@@ -15,7 +15,7 @@ function VendorsListProvider({ tableState, tableStateChanged, ...props }) {
|
||||
|
||||
// Fetch vendors list with pagination meta.
|
||||
const {
|
||||
data: { vendors, pagination, filterMeta },
|
||||
data: vendorsData,
|
||||
isLoading: isVendorsLoading,
|
||||
isFetching: isVendorsFetching,
|
||||
} = useVendors(tableQuery, { keepPreviousData: true });
|
||||
@@ -33,14 +33,14 @@ function VendorsListProvider({ tableState, tableStateChanged, ...props }) {
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(vendors) && !isVendorsLoading && !tableStateChanged;
|
||||
isEmpty(vendorsData?.data) && !isVendorsLoading && !tableStateChanged;
|
||||
|
||||
const provider = {
|
||||
vendors,
|
||||
pagination,
|
||||
vendors: vendorsData?.data,
|
||||
pagination: vendorsData?.pagination,
|
||||
vendorsViews,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
resourceMeta,
|
||||
isResourceMetaLoading,
|
||||
isResourceMetaFetching,
|
||||
|
||||
@@ -137,7 +137,7 @@ function VendorsTable({
|
||||
<DataTable
|
||||
noInitialFetch={true}
|
||||
columns={columns}
|
||||
data={vendors}
|
||||
data={vendors ?? []}
|
||||
loading={isVendorsLoading}
|
||||
headerLoading={isVendorsLoading}
|
||||
progressBarLoading={isVendorsFetching}
|
||||
@@ -146,9 +146,9 @@ function VendorsTable({
|
||||
expandable={false}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
initialPageSize={vendorsTableState.pageSize}
|
||||
initialPageSize={vendorsTableState?.pageSize ?? 10}
|
||||
manualSortBy={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
|
||||
@@ -26,7 +26,7 @@ function WarehouseTransferFormProvider({ warehouseTransferId, ...props }) {
|
||||
|
||||
// Handle fetch Items data table or list
|
||||
const {
|
||||
data: { items },
|
||||
data: itemsData,
|
||||
isFetching: isItemsFetching,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({
|
||||
@@ -82,7 +82,7 @@ function WarehouseTransferFormProvider({ warehouseTransferId, ...props }) {
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
items,
|
||||
items: itemsData?.items,
|
||||
warehouses,
|
||||
warehouseTransfer,
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ function WarehouseTransfersDataTable({
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={warehousesTransfers}
|
||||
data={warehousesTransfers ?? []}
|
||||
loading={isWarehouseTransfersLoading}
|
||||
headerLoading={isWarehouseTransfersLoading}
|
||||
progressBarLoading={isWarehouseTransfersFetching}
|
||||
@@ -123,7 +123,7 @@ function WarehouseTransfersDataTable({
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
rowsCount={pagination?.total ?? 0}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -26,14 +26,14 @@ function WarehouseTransfersListProvider({
|
||||
|
||||
// Fetch warehouse transfers list according to the given custom view id.
|
||||
const {
|
||||
data: { warehousesTransfers, pagination, filterMeta },
|
||||
data: warehousesTransfersData,
|
||||
isFetching: isWarehouseTransfersFetching,
|
||||
isLoading: isWarehouseTransfersLoading,
|
||||
} = useWarehousesTransfers(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(warehousesTransfers) &&
|
||||
isEmpty(warehousesTransfersData?.data) &&
|
||||
!tableStateChanged &&
|
||||
!isWarehouseTransfersLoading;
|
||||
|
||||
@@ -50,14 +50,14 @@ function WarehouseTransfersListProvider({
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
warehousesTransfers,
|
||||
pagination,
|
||||
warehousesTransfers: warehousesTransfersData?.data,
|
||||
pagination: warehousesTransfersData?.pagination,
|
||||
|
||||
WarehouseTransferView,
|
||||
refresh,
|
||||
|
||||
resourceMeta,
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
fields: resourceMeta?.fields ? getFieldsFromResourceMeta(resourceMeta.fields) : [],
|
||||
isResourceLoading,
|
||||
isResourceFetching,
|
||||
|
||||
|
||||
@@ -35,10 +35,14 @@ import {
|
||||
* Saves the response data to cookies.
|
||||
*/
|
||||
export function setAuthLoginCookies(data: AuthSigninResponse): void {
|
||||
setCookie('token', data.accessToken ?? '');
|
||||
setCookie('authenticated_user_id', String(data.userId ?? ''));
|
||||
setCookie('organization_id', data.organizationId ?? '');
|
||||
setCookie('tenant_id', String(data.tenantId ?? ''));
|
||||
// @ts-ignore
|
||||
setCookie('token', data.access_token ?? '');
|
||||
// @ts-ignore
|
||||
setCookie('authenticated_user_id', String(data.user_id ?? ''));
|
||||
// @ts-ignore
|
||||
setCookie('organization_id', data.organization_id ?? '');
|
||||
// @ts-ignore
|
||||
setCookie('tenant_id', String(data.tenant_id ?? ''));
|
||||
}
|
||||
|
||||
export function useAuthLogin(
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
fetchBillPaymentTransactions,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
@@ -50,12 +49,6 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
});
|
||||
};
|
||||
|
||||
export type BillsListResult = {
|
||||
bills: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function useCreateBill(
|
||||
props?: UseMutationOptions<void, Error, CreateBillBody>
|
||||
) {
|
||||
@@ -161,36 +154,14 @@ export function useValidateBulkDeleteBills(
|
||||
});
|
||||
}
|
||||
|
||||
/** API may return bills/data, pagination, and filter_meta (snake_case). */
|
||||
type BillsListResponseShape = {
|
||||
bills?: unknown[];
|
||||
data?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function isRecord(obj: unknown): obj is Record<string, unknown> {
|
||||
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
|
||||
}
|
||||
|
||||
function transformBillsList(res: BillsListResponse & BillsListResponseShape): BillsListResult {
|
||||
const bills = res.bills ?? res.data ?? [];
|
||||
const pagination = res.pagination ?? {};
|
||||
const filterMeta = res.filter_meta;
|
||||
return {
|
||||
bills: Array.isArray(bills) ? bills : [],
|
||||
pagination: transformPagination(pagination),
|
||||
filterMeta: isRecord(filterMeta) ? filterMeta : {},
|
||||
};
|
||||
}
|
||||
export function useBills(
|
||||
query?: GetBillsQuery,
|
||||
props?: Omit<UseQueryOptions<BillsListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<BillsListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
queryKey: [t.BILLS, query],
|
||||
queryFn: () => fetchBills(fetcher, query).then(transformBillsList),
|
||||
queryFn: () => fetchBills(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import {
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
@@ -172,27 +172,12 @@ export function useValidateBulkDeleteCreditNotes(
|
||||
});
|
||||
}
|
||||
|
||||
export type CreditNotesListResult = {
|
||||
creditNotes: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function transformCreditNotesList(res: CreditNotesListResponse): CreditNotesListResult {
|
||||
const data = res as { credit_notes?: unknown[]; pagination?: unknown; filter_meta?: Record<string, unknown> };
|
||||
return {
|
||||
creditNotes: data?.credit_notes ?? [],
|
||||
pagination: transformPagination(data?.pagination ?? {}),
|
||||
filterMeta: data?.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve credit notes list with pagination meta.
|
||||
*/
|
||||
export function useCreditNotes(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<UseQueryOptions<CreditNotesListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<CreditNotesListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
@@ -201,7 +186,7 @@ export function useCreditNotes(
|
||||
(fetchCreditNotes as (f: ReturnType<typeof useApiFetcher>, q?: Record<string, unknown>) => Promise<CreditNotesListResponse>)(
|
||||
fetcher,
|
||||
query
|
||||
).then(transformCreditNotesList),
|
||||
),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ import {
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import t from './types';
|
||||
|
||||
/**
|
||||
* Create a new currency.
|
||||
*/
|
||||
export function useCreateCurrency(
|
||||
props?: UseMutationOptions<void, Error, CreateCurrencyBody>
|
||||
) {
|
||||
@@ -38,9 +35,6 @@ export function useCreateCurrency(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the given currency by ID.
|
||||
*/
|
||||
export function useEditCurrency(
|
||||
props?: UseMutationOptions<void, Error, [number, EditCurrencyBody]>
|
||||
) {
|
||||
@@ -57,9 +51,6 @@ export function useEditCurrency(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given currency.
|
||||
*/
|
||||
export function useDeleteCurrency(
|
||||
props?: UseMutationOptions<void, Error, string>
|
||||
) {
|
||||
@@ -76,9 +67,6 @@ export function useDeleteCurrency(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the currencies list.
|
||||
*/
|
||||
export function useCurrencies(
|
||||
props?: Omit<UseQueryOptions<CurrenciesListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
|
||||
@@ -23,15 +23,9 @@ import {
|
||||
editCustomerOpeningBalance,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const defaultPagination = {
|
||||
pageSize: 20,
|
||||
page: 0,
|
||||
pagesCount: 0,
|
||||
};
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
queryClient.invalidateQueries({ queryKey: [t.CUSTOMERS] });
|
||||
queryClient.invalidateQueries({ queryKey: [t.ACCOUNTS] });
|
||||
@@ -44,24 +38,9 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES] });
|
||||
};
|
||||
|
||||
export type CustomersSelectorResult = {
|
||||
customers: unknown[];
|
||||
pagination: typeof defaultPagination;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function transformCustomersList(res: CustomersListResponse): CustomersSelectorResult {
|
||||
const data = res as { customers?: unknown[]; pagination?: unknown; filter_meta?: Record<string, unknown> };
|
||||
return {
|
||||
customers: data?.customers ?? [],
|
||||
pagination: transformPagination(data?.pagination ?? {}) as typeof defaultPagination,
|
||||
filterMeta: data?.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
export function useCustomers(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<UseQueryOptions<CustomersSelectorResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<CustomersListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
@@ -70,7 +49,7 @@ export function useCustomers(
|
||||
(fetchCustomers as (f: ReturnType<typeof useApiFetcher>, q?: Record<string, unknown>) => Promise<CustomersListResponse>)(
|
||||
fetcher,
|
||||
query
|
||||
).then(transformCustomersList),
|
||||
),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export type ValidateBulkDeleteEstimatesResponse = {
|
||||
nonDeletableIds: number[];
|
||||
};
|
||||
import useApiRequest, { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
|
||||
@@ -47,15 +47,6 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ITEM_ASSOCIATED_WITH_ESTIMATES] });
|
||||
};
|
||||
|
||||
export type EstimatesListResult = {
|
||||
estimates: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new sale estimate.
|
||||
*/
|
||||
export function useCreateEstimate(
|
||||
props?: UseMutationOptions<void, Error, CreateSaleEstimateBody>
|
||||
) {
|
||||
@@ -73,9 +64,6 @@ export function useCreateEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the given sale estimate.
|
||||
*/
|
||||
export function useEditEstimate(
|
||||
props?: UseMutationOptions<void, Error, [number, EditSaleEstimateBody]>
|
||||
) {
|
||||
@@ -93,18 +81,6 @@ export function useEditEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
function transformEstimates(data: SaleEstimatesListResponse): EstimatesListResult {
|
||||
const raw = data as { sales_estimates?: unknown[]; pagination?: unknown; filter_meta?: Record<string, unknown> };
|
||||
return {
|
||||
estimates: raw.sales_estimates ?? (raw as { data?: unknown[] }).data ?? [],
|
||||
pagination: transformPagination(raw.pagination ?? {}),
|
||||
filterMeta: raw.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale estimate details.
|
||||
*/
|
||||
export function useEstimate(
|
||||
id: number | null | undefined,
|
||||
props?: Omit<UseQueryOptions<SaleEstimate>, 'queryKey' | 'queryFn'>
|
||||
@@ -118,28 +94,19 @@ export function useEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale estimates list with pagination meta.
|
||||
*/
|
||||
export function useEstimates(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<
|
||||
UseQueryOptions<SaleEstimatesListResponse, Error, EstimatesListResult>,
|
||||
'queryKey' | 'queryFn' | 'select'
|
||||
>
|
||||
props?: Omit<UseQueryOptions<SaleEstimatesListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery<SaleEstimatesListResponse, Error, EstimatesListResult>({
|
||||
return useQuery({
|
||||
queryKey: [t.SALE_ESTIMATES, query],
|
||||
queryFn: () => fetchSaleEstimates(fetcher),
|
||||
select: transformEstimates,
|
||||
queryFn: () => fetchSaleEstimates(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given sale estimate.
|
||||
*/
|
||||
|
||||
export function useDeleteEstimate(
|
||||
props?: UseMutationOptions<void, Error, number>
|
||||
) {
|
||||
@@ -156,9 +123,6 @@ export function useDeleteEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple sale estimates in bulk.
|
||||
*/
|
||||
export function useBulkDeleteEstimates(
|
||||
props?: UseMutationOptions<void, Error, BulkDeleteEstimatesBody>
|
||||
) {
|
||||
@@ -187,9 +151,6 @@ export function useValidateBulkDeleteEstimates(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given estimate as delivered.
|
||||
*/
|
||||
export function useDeliverEstimate(
|
||||
props?: UseMutationOptions<void, Error, number>
|
||||
) {
|
||||
@@ -206,9 +167,6 @@ export function useDeliverEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given estimate as approved.
|
||||
*/
|
||||
export function useApproveEstimate(
|
||||
props?: UseMutationOptions<void, Error, number>
|
||||
) {
|
||||
@@ -225,9 +183,6 @@ export function useApproveEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given estimate as rejected.
|
||||
*/
|
||||
export function useRejectEstimate(
|
||||
props?: UseMutationOptions<void, Error, number>
|
||||
) {
|
||||
@@ -244,9 +199,6 @@ export function useRejectEstimate(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the estimate pdf document data.
|
||||
*/
|
||||
export function usePdfEstimate(estimateId: number) {
|
||||
return useRequestPdf({
|
||||
url: `sale-estimates/${estimateId}`,
|
||||
@@ -263,9 +215,6 @@ export function useRefreshEstimates() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify estimate by SMS.
|
||||
*/
|
||||
export function useCreateNotifyEstimateBySMS(
|
||||
props?: UseMutationOptions<void, Error, [number, Record<string, unknown>]>
|
||||
) {
|
||||
@@ -283,9 +232,6 @@ export function useCreateNotifyEstimateBySMS(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve estimate SMS detail.
|
||||
*/
|
||||
export function useEstimateSMSDetail(
|
||||
estimateId: number | null | undefined,
|
||||
props?: Record<string, unknown>,
|
||||
@@ -350,9 +296,6 @@ export interface SaleEstimateMailStateResponse {
|
||||
toOptions: Array<unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sale estimate mail state.
|
||||
*/
|
||||
export function useSaleEstimateMailState(
|
||||
estimateId: number,
|
||||
props?: UseQueryOptions<SaleEstimateMailStateResponse, Error>
|
||||
|
||||
@@ -17,15 +17,8 @@ import {
|
||||
validateBulkDeleteExpenses,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const defaultPagination = {
|
||||
pageSize: 20,
|
||||
page: 0,
|
||||
pagesCount: 0,
|
||||
};
|
||||
|
||||
// Common invalidate queries.
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
// Invalidate expenses.
|
||||
@@ -50,15 +43,6 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES] });
|
||||
};
|
||||
|
||||
function transformExpensesList(response: ExpensesListResponse) {
|
||||
const data = response as { expenses?: unknown[]; pagination?: unknown; filter_meta?: Record<string, unknown> };
|
||||
return {
|
||||
expenses: data?.expenses ?? [],
|
||||
pagination: transformPagination(data?.pagination ?? {}) as typeof defaultPagination,
|
||||
filterMeta: data?.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the expenses list.
|
||||
*/
|
||||
@@ -69,7 +53,7 @@ export function useExpenses(
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
queryKey: [t.EXPENSES, query],
|
||||
queryFn: () => fetchExpenses(fetcher, query).then(transformExpensesList),
|
||||
queryFn: () => fetchExpenses(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import {
|
||||
createQuickInventoryAdjustment,
|
||||
@@ -63,13 +62,6 @@ export function useDeleteInventoryAdjustment(props) {
|
||||
});
|
||||
}
|
||||
|
||||
const inventoryAdjustmentsTransformer = (response) => {
|
||||
return {
|
||||
inventoryAdjustments: response.data,
|
||||
pagination: transformPagination(response.pagination),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve inventory adjustment list with pagination meta.
|
||||
* Uses useRequestQuery because list endpoint query params may not be in OpenAPI.
|
||||
@@ -79,7 +71,6 @@ export function useInventoryAdjustments(query, props) {
|
||||
return useQuery({
|
||||
queryKey: ['inventory-adjustments', query],
|
||||
queryFn: () => fetchInventoryAdjustments(fetcher, query),
|
||||
select: inventoryAdjustmentsTransformer,
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import {
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import t from './types';
|
||||
@@ -165,46 +165,18 @@ export function useValidateBulkDeleteInvoices(
|
||||
});
|
||||
}
|
||||
|
||||
function transformInvoicesList(res: SaleInvoicesListResponse) {
|
||||
const data = res as {
|
||||
data?: unknown[];
|
||||
sales_invoices?: unknown[];
|
||||
salesInvoices?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
filterMeta?: Record<string, unknown>;
|
||||
};
|
||||
const invoices =
|
||||
data?.data ??
|
||||
data?.sales_invoices ??
|
||||
data?.salesInvoices ??
|
||||
[];
|
||||
return {
|
||||
invoices,
|
||||
pagination: transformPagination(data?.pagination ?? {}),
|
||||
filterMeta: data?.filter_meta ?? data?.filterMeta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useInvoices(
|
||||
query?: GetSaleInvoicesQuery,
|
||||
props?: UseQueryOptions<
|
||||
{
|
||||
invoices: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
},
|
||||
Error
|
||||
>
|
||||
props?: UseQueryOptions<SaleInvoicesListResponse, Error>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [t.SALE_INVOICES, query],
|
||||
queryFn: () => fetchSaleInvoices(fetcher, query).then(transformInvoicesList),
|
||||
queryFn: () => fetchSaleInvoices(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,26 +35,14 @@ import type {
|
||||
GetInventoryItemsCostResponse,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformResponse, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const DEFAULT_PAGINATION = {
|
||||
pageSize: 20,
|
||||
page: 0,
|
||||
pagesCount: 0,
|
||||
};
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
queryClient.invalidateQueries({ queryKey: [t.ITEMS] });
|
||||
queryClient.invalidateQueries({ queryKey: [t.ITEMS_CATEGORIES] });
|
||||
};
|
||||
|
||||
export type ItemsListResult = {
|
||||
items: unknown[];
|
||||
pagination: typeof DEFAULT_PAGINATION;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function useCreateItem(
|
||||
props?: UseMutationOptions<void, Error, CreateItemBody>
|
||||
) {
|
||||
@@ -166,24 +154,9 @@ export function useInactivateItem(
|
||||
});
|
||||
}
|
||||
|
||||
function transformItemsList(res: ItemsListResponse): ItemsListResult {
|
||||
const data = res as {
|
||||
items?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
items: data?.items ?? [],
|
||||
pagination: transformPagination(
|
||||
transformResponse(data?.pagination ?? {})
|
||||
) as typeof DEFAULT_PAGINATION,
|
||||
filterMeta: transformResponse(data?.filter_meta ?? {}) as Record<string, unknown>,
|
||||
};
|
||||
}
|
||||
|
||||
export function useItems(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<UseQueryOptions<ItemsListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<ItemsListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
@@ -192,7 +165,7 @@ export function useItems(
|
||||
(fetchItems as (f: ReturnType<typeof useApiFetcher>, q?: Record<string, unknown>) => Promise<ItemsListResponse>)(
|
||||
fetcher,
|
||||
query
|
||||
).then(transformItemsList),
|
||||
),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
queryClient.invalidateQueries({ queryKey: [t.LANDED_COST_TRANSACTION] });
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new landed cost.
|
||||
*/
|
||||
export function useCreateLandedCost(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const fetcher = useApiFetcher();
|
||||
@@ -33,9 +30,6 @@ export function useCreateLandedCost(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given landed cost.
|
||||
*/
|
||||
export function useDeleteLandedCost(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const fetcher = useApiFetcher();
|
||||
@@ -49,9 +43,6 @@ export function useDeleteLandedCost(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the landed cost transactions.
|
||||
*/
|
||||
export function useLandedCostTransaction(query, props) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
@@ -62,9 +53,6 @@ export function useLandedCostTransaction(query, props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the bill located landed cost transactions.
|
||||
*/
|
||||
export function useBillLocatedLandedCost(id, props) {
|
||||
const fetcher = useApiFetcher();
|
||||
|
||||
|
||||
@@ -25,15 +25,9 @@ import {
|
||||
validateBulkDeleteManualJournals,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
export type JournalsListResult = {
|
||||
manualJournals: ManualJournal[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
// Invalidate manual journals.
|
||||
queryClient.invalidateQueries({ queryKey: [t.MANUAL_JOURNALS] });
|
||||
@@ -166,30 +160,16 @@ export function usePublishJournal(
|
||||
});
|
||||
}
|
||||
|
||||
function transformJournalsList(data: ManualJournalsListResponse): JournalsListResult {
|
||||
const raw = data as {
|
||||
manual_journals?: ManualJournal[];
|
||||
manualJournals?: ManualJournal[];
|
||||
pagination?: Parameters<typeof transformPagination>[0];
|
||||
filter_meta?: Record<string, unknown>;
|
||||
filterMeta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
manualJournals: (raw?.manual_journals ?? raw?.manualJournals ?? []) as ManualJournal[],
|
||||
pagination: transformPagination(raw?.pagination ?? {}),
|
||||
filterMeta: raw?.filter_meta ?? raw?.filterMeta ?? {},
|
||||
};
|
||||
}
|
||||
export function useJournals(
|
||||
query?: ManualJournalsListQuery | null,
|
||||
props?: Omit<UseQueryOptions<JournalsListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<ManualJournalsListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [t.MANUAL_JOURNALS, query],
|
||||
queryFn: async () =>
|
||||
transformJournalsList(await fetchManualJournals(fetcher, query ?? {})),
|
||||
fetchManualJournals(fetcher, query ?? {}),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
fetchBillPaymentNewPageEntries,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const commonInvalidateQueries = (client: ReturnType<typeof useQueryClient>) => {
|
||||
@@ -40,37 +39,14 @@ const commonInvalidateQueries = (client: ReturnType<typeof useQueryClient>) => {
|
||||
client.invalidateQueries({ queryKey: [t.BILLS_PAYMENT_TRANSACTIONS] });
|
||||
};
|
||||
|
||||
export type PaymentMadesListResult = {
|
||||
paymentMades: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function transformPaymentMades(data: BillPaymentsListResponse): PaymentMadesListResult {
|
||||
const raw = data as {
|
||||
bill_payments?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
paymentMades: raw.bill_payments ?? (data as { data?: unknown[] })?.data ?? [],
|
||||
pagination: transformPagination(raw.pagination ?? {}),
|
||||
filterMeta: raw.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
export function usePaymentMades(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<
|
||||
UseQueryOptions<BillPaymentsListResponse, Error, PaymentMadesListResult>,
|
||||
'queryKey' | 'queryFn' | 'select'
|
||||
>
|
||||
props?: Omit<UseQueryOptions<BillPaymentsListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery<BillPaymentsListResponse, Error, PaymentMadesListResult>({
|
||||
return useQuery({
|
||||
queryKey: [t.PAYMENT_MADES, query],
|
||||
queryFn: () => fetchBillPayments(fetcher),
|
||||
select: transformPaymentMades,
|
||||
queryFn: () => fetchBillPayments(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export type ValidateBulkDeletePaymentsReceivedResponse = {
|
||||
};
|
||||
import useApiRequest, { useApiFetcher } from '../useRequest';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination, saveInvoke, transformToCamelCase } from '@/utils';
|
||||
import { saveInvoke, transformToCamelCase } from '@/utils';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import t from './types';
|
||||
|
||||
@@ -60,37 +60,14 @@ const commonInvalidateQueries = (client: ReturnType<typeof useQueryClient>) => {
|
||||
client.invalidateQueries({ queryKey: [t.SALE_INVOICE_PAYMENT_TRANSACTIONS] });
|
||||
};
|
||||
|
||||
export type PaymentReceivesListResult = {
|
||||
paymentReceives: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function transformPaymentReceives(data: PaymentsReceivedListResponse): PaymentReceivesListResult {
|
||||
const raw = data as {
|
||||
payment_receives?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
paymentReceives: raw.payment_receives ?? (data as { data?: unknown[] })?.data ?? [],
|
||||
pagination: transformPagination(raw.pagination ?? {}),
|
||||
filterMeta: raw.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
export function usePaymentReceives(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<
|
||||
UseQueryOptions<PaymentsReceivedListResponse, Error, PaymentReceivesListResult>,
|
||||
'queryKey' | 'queryFn' | 'select'
|
||||
>
|
||||
props?: Omit<UseQueryOptions<PaymentsReceivedListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery<PaymentsReceivedListResponse, Error, PaymentReceivesListResult>({
|
||||
return useQuery({
|
||||
queryKey: [t.PAYMENT_RECEIVES, query],
|
||||
queryFn: () => fetchPaymentsReceived(fetcher),
|
||||
select: transformPaymentReceives,
|
||||
queryFn: () => fetchPaymentsReceived(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
fetchSaleReceiptState,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import useApiRequest, { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import t from './types';
|
||||
@@ -151,38 +151,18 @@ export function useCloseReceipt(props?: UseMutationOptions<void, Error, number>)
|
||||
});
|
||||
}
|
||||
|
||||
function transformReceiptsList(res: SaleReceiptsListResponse) {
|
||||
const data = res as {
|
||||
data?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
receipts: data?.data ?? [],
|
||||
pagination: transformPagination(data?.pagination ?? {}),
|
||||
filterMeta: data?.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale receipts list with pagination meta.
|
||||
*/
|
||||
export function useReceipts(
|
||||
query?: Record<string, unknown>,
|
||||
props?: UseQueryOptions<
|
||||
{
|
||||
receipts: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
},
|
||||
Error
|
||||
>
|
||||
props?: UseQueryOptions<SaleReceiptsListResponse, Error>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [t.SALE_RECEIPTS, query],
|
||||
queryFn: () => fetchSaleReceipts(fetcher, query).then(transformReceiptsList),
|
||||
queryFn: () => fetchSaleReceipts(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
UseMutationOptions,
|
||||
UseQueryOptions,
|
||||
} from '@tanstack/react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import type {
|
||||
CreateVendorCreditBody,
|
||||
EditVendorCreditBody,
|
||||
@@ -34,7 +33,7 @@ import {
|
||||
deleteAppliedBillToVendorCredit,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
@@ -59,32 +58,6 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES] });
|
||||
};
|
||||
|
||||
export type VendorCreditsListResult = {
|
||||
vendorCredits: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const DEFAULT_VENDOR_CREDITS_PLACEHOLDER: VendorCreditsListResult = {
|
||||
vendorCredits: [],
|
||||
pagination: transformPagination({}),
|
||||
filterMeta: {},
|
||||
};
|
||||
|
||||
function transformVendorCreditsResponse(response: Record<string, unknown>): VendorCreditsListResult {
|
||||
const raw = response as {
|
||||
vendor_credits?: unknown[];
|
||||
vendorCredits?: unknown[];
|
||||
pagination?: unknown;
|
||||
filter_meta?: Record<string, unknown>;
|
||||
filterMeta?: Record<string, unknown>;
|
||||
};
|
||||
return {
|
||||
vendorCredits: raw.vendor_credits ?? raw.vendorCredits ?? [],
|
||||
pagination: transformPagination(raw.pagination ?? {}),
|
||||
filterMeta: raw.filter_meta ?? raw.filterMeta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new vendor credit.
|
||||
@@ -179,23 +152,15 @@ export function useValidateBulkDeleteVendorCredits(
|
||||
*/
|
||||
export function useVendorCredits(
|
||||
query?: GetVendorCreditsQuery,
|
||||
props?: Omit<UseQueryOptions<VendorCreditsListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<unknown>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
|
||||
const result = useQuery({
|
||||
return useQuery({
|
||||
queryKey: [t.VENDOR_CREDITS, query],
|
||||
queryFn: () =>
|
||||
fetchVendorCredits(fetcher, query).then((data: Record<string, unknown>) =>
|
||||
transformVendorCreditsResponse(data)
|
||||
),
|
||||
queryFn: () => fetchVendorCredits(fetcher, query),
|
||||
...props,
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
data: defaultTo(result.data, DEFAULT_VENDOR_CREDITS_PLACEHOLDER),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
editVendorOpeningBalance,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
@@ -35,24 +35,9 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES] });
|
||||
};
|
||||
|
||||
export type VendorsListResult = {
|
||||
vendors: unknown[];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function transformVendorsList(res: VendorsListResponse): VendorsListResult {
|
||||
const data = res as { vendors?: unknown[]; pagination?: unknown; filter_meta?: Record<string, unknown> };
|
||||
return {
|
||||
vendors: data?.vendors ?? [],
|
||||
pagination: transformPagination(data?.pagination ?? {}),
|
||||
filterMeta: data?.filter_meta ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
export function useVendors(
|
||||
query?: Record<string, unknown>,
|
||||
props?: Omit<UseQueryOptions<VendorsListResult>, 'queryKey' | 'queryFn'>
|
||||
props?: Omit<UseQueryOptions<VendorsListResponse>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const fetcher = useApiFetcher();
|
||||
return useQuery({
|
||||
@@ -61,7 +46,7 @@ export function useVendors(
|
||||
(fetchVendors as (f: ReturnType<typeof useApiFetcher>, q?: Record<string, unknown>) => Promise<VendorsListResponse>)(
|
||||
fetcher,
|
||||
query
|
||||
).then(transformVendorsList),
|
||||
),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ import type { ResourceViewResponse, ResourceMetaResponse } from '@bigcapital/sdk
|
||||
import { fetchResourceView, fetchResourceMeta } from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
|
||||
/**
|
||||
* Retrieve the resource views using sdk-ts.
|
||||
*/
|
||||
export function useResourceViews(
|
||||
resourceSlug: string | null | undefined,
|
||||
props?: Omit<UseQueryOptions<ResourceViewResponse>, 'queryKey' | 'queryFn'>
|
||||
@@ -15,14 +12,10 @@ export function useResourceViews(
|
||||
queryKey: ['RESOURCE_VIEW', resourceSlug],
|
||||
queryFn: () => fetchResourceView(fetcher, resourceSlug!),
|
||||
enabled: !!resourceSlug,
|
||||
select: (data) => (Array.isArray(data) ? data : (data as { data?: unknown })?.data ?? data),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the resource meta using sdk-ts.
|
||||
*/
|
||||
export function useResourceMeta(
|
||||
resourceSlug: string | null | undefined,
|
||||
props?: Omit<UseQueryOptions<ResourceMetaResponse>, 'queryKey' | 'queryFn'>
|
||||
@@ -32,7 +25,6 @@ export function useResourceMeta(
|
||||
queryKey: ['RESOURCE_META', resourceSlug],
|
||||
queryFn: () => fetchResourceMeta(fetcher, resourceSlug!),
|
||||
enabled: !!resourceSlug,
|
||||
select: (data) => (data as { resource_meta?: unknown })?.resource_meta ?? data ?? { fields: {} },
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,23 +21,11 @@ import {
|
||||
transferredWarehouseTransfer,
|
||||
} from '@bigcapital/sdk-ts';
|
||||
import { useApiFetcher } from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import t from './types';
|
||||
|
||||
/** Query params for listing warehouse transfers (pagination, filter, etc.). */
|
||||
type GetWarehouseTransfersQuery = Record<string, string | number | boolean | undefined>;
|
||||
|
||||
/** API list response may include filter even if schema does not. */
|
||||
type WarehouseTransfersListResponseWithFilter = WarehouseTransfersListResponse & {
|
||||
filter?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
type WarehousesTransferListResult = {
|
||||
warehousesTransfers: WarehouseTransfersListResponse['data'];
|
||||
pagination: ReturnType<typeof transformPagination>;
|
||||
filterMeta: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>) => {
|
||||
queryClient.invalidateQueries({ queryKey: [t.WAREHOUSE_TRANSFERS] });
|
||||
queryClient.invalidateQueries({ queryKey: [t.ITEM_WAREHOUSES_LOCATION] });
|
||||
@@ -45,16 +33,6 @@ const commonInvalidateQueries = (queryClient: ReturnType<typeof useQueryClient>)
|
||||
queryClient.invalidateQueries({ queryKey: [t.ITEM] });
|
||||
};
|
||||
|
||||
function transformWarehousesTransfer(
|
||||
res: WarehouseTransfersListResponseWithFilter
|
||||
): WarehousesTransferListResult {
|
||||
return {
|
||||
warehousesTransfers: res.data ?? [],
|
||||
pagination: transformPagination(res.pagination ?? {}),
|
||||
filterMeta: (res as WarehouseTransfersListResponseWithFilter).filter ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new warehouse transfer.
|
||||
*/
|
||||
@@ -114,7 +92,7 @@ export function useDeleteWarehouseTransfer(
|
||||
export function useWarehousesTransfers(
|
||||
query?: GetWarehouseTransfersQuery | null,
|
||||
props?: Omit<
|
||||
UseQueryOptions<WarehousesTransferListResult>,
|
||||
UseQueryOptions<WarehouseTransfersListResponse>,
|
||||
'queryKey' | 'queryFn'
|
||||
>
|
||||
) {
|
||||
@@ -126,8 +104,8 @@ export function useWarehousesTransfers(
|
||||
fetchWarehouseTransfers as (
|
||||
fetcher: unknown,
|
||||
query?: GetWarehouseTransfersQuery
|
||||
) => Promise<WarehouseTransfersListResponseWithFilter>
|
||||
)(fetcher, query ?? undefined).then(transformWarehousesTransfer),
|
||||
) => Promise<WarehouseTransfersListResponse>
|
||||
)(fetcher, query ?? undefined),
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -570,15 +570,6 @@ export const isTableEmptyStatus = ({ data, pagination, filterMeta }) => {
|
||||
].every((cond) => cond === true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transformes the pagination meta to table props.
|
||||
*/
|
||||
export function getPagesCountFromPaginationMeta(pagination) {
|
||||
const { pageSize, total } = pagination;
|
||||
|
||||
return Math.ceil(total / pageSize);
|
||||
}
|
||||
|
||||
function transformFilterRoles(filterRoles) {
|
||||
return JSON.stringify(filterRoles);
|
||||
}
|
||||
@@ -619,18 +610,6 @@ export function globalTableStateToTable(globalState) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the pagination meta repsonse.
|
||||
*/
|
||||
export function transformPagination(pagination) {
|
||||
const transformed = transformResponse(pagination);
|
||||
|
||||
return {
|
||||
...transformed,
|
||||
pagesCount: getPagesCountFromPaginationMeta(transformed),
|
||||
};
|
||||
}
|
||||
|
||||
export function removeRowsByIndex(rows, rowIndex) {
|
||||
const removeIndex = parseInt(rowIndex, 10);
|
||||
const newRows = rows.filter((row, index) => index !== removeIndex);
|
||||
|
||||
Reference in New Issue
Block a user