mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
wip
This commit is contained in:
@@ -60,6 +60,9 @@ import VendorCreditBulkDeleteDialog from '@/containers/Dialogs/VendorCredits/Ven
|
||||
import ManualJournalBulkDeleteDialog from '@/containers/Dialogs/ManualJournals/ManualJournalBulkDeleteDialog';
|
||||
import ExpenseBulkDeleteDialog from '@/containers/Dialogs/Expenses/ExpenseBulkDeleteDialog';
|
||||
import AccountBulkDeleteDialog from '@/containers/Dialogs/Accounts/AccountBulkDeleteDialog';
|
||||
import ItemBulkDeleteDialog from '@/containers/Dialogs/Items/ItemBulkDeleteDialog';
|
||||
import CustomerBulkDeleteDialog from '@/containers/Dialogs/Customers/CustomerBulkDeleteDialog';
|
||||
import VendorBulkDeleteDialog from '@/containers/Dialogs/Vendors/VendorBulkDeleteDialog';
|
||||
|
||||
/**
|
||||
* Dialogs container.
|
||||
@@ -167,6 +170,9 @@ export default function DialogsContainer() {
|
||||
/>
|
||||
<ExpenseBulkDeleteDialog dialogName={DialogsName.ExpenseBulkDelete} />
|
||||
<AccountBulkDeleteDialog dialogName={DialogsName.AccountBulkDelete} />
|
||||
<ItemBulkDeleteDialog dialogName={DialogsName.ItemBulkDelete} />
|
||||
<CustomerBulkDeleteDialog dialogName={DialogsName.CustomerBulkDelete} />
|
||||
<VendorBulkDeleteDialog dialogName={DialogsName.VendorBulkDelete} />
|
||||
<ExportDialog dialogName={DialogsName.Export} />
|
||||
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
|
||||
<DisconnectBankAccountDialog
|
||||
|
||||
@@ -59,6 +59,9 @@ export enum DialogsName {
|
||||
ManualJournalBulkDelete = 'manual-journals-bulk-delete',
|
||||
ExpenseBulkDelete = 'expenses-bulk-delete',
|
||||
AccountBulkDelete = 'accounts-bulk-delete',
|
||||
ItemBulkDelete = 'items-bulk-delete',
|
||||
CustomerBulkDelete = 'customers-bulk-delete',
|
||||
VendorBulkDelete = 'vendors-bulk-delete',
|
||||
InvoiceMail = 'invoice-mail',
|
||||
EstimateMail = 'estimate-mail',
|
||||
ReceiptMail = 'receipt-mail',
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { AppToaster, FormattedMessage as T } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { size } from 'lodash';
|
||||
|
||||
import { useBulkDeleteItems } from '@/hooks/query/items';
|
||||
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Item bulk delete alert.
|
||||
*/
|
||||
function ItemBulkDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemsIds },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteItems, isLoading } = useBulkDeleteItems();
|
||||
|
||||
// handle cancel item bulk delete alert.
|
||||
const handleCancelBulkDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
// Handle confirm items bulk delete.
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteItems(itemsIds)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_items_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch((errors) => { });
|
||||
};
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={
|
||||
<T id={'delete_count'} values={{ count: size(itemsIds) }} />
|
||||
}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelBulkDelete}
|
||||
onConfirm={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'once_delete_these_items_you_will_not_able_restore_them'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(ItemBulkDeleteAlert);
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
If,
|
||||
Icon,
|
||||
Can,
|
||||
FormattedMessage as T,
|
||||
@@ -29,7 +28,6 @@ import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-
|
||||
|
||||
import withCustomers from './withCustomers';
|
||||
import withCustomersActions from './withCustomersActions';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -37,6 +35,8 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { CustomerAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
import { compose } from '@/utils';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useBulkDeleteCustomersDialog } from './hooks/use-bulk-delete-customers-dialog';
|
||||
|
||||
/**
|
||||
* Customers actions bar.
|
||||
@@ -50,9 +50,6 @@ function CustomerActionsBar({
|
||||
setCustomersTableState,
|
||||
accountsInactiveMode,
|
||||
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
|
||||
// #withSettings
|
||||
customersTableSize,
|
||||
|
||||
@@ -62,6 +59,9 @@ function CustomerActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) {
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteCustomers } =
|
||||
useBulkDeleteCustomersDialog();
|
||||
|
||||
// History context.
|
||||
const history = useHistory();
|
||||
|
||||
@@ -80,7 +80,7 @@ function CustomerActionsBar({
|
||||
|
||||
// Handle Customers bulk delete button click.,
|
||||
const handleBulkDelete = () => {
|
||||
openAlert('customers-bulk-delete', { customersIds: customersSelectedRows });
|
||||
openBulkDeleteDialog(customersSelectedRows);
|
||||
};
|
||||
|
||||
const handleTabChange = (view) => {
|
||||
@@ -118,6 +118,23 @@ function CustomerActionsBar({
|
||||
downloadExportPdf({ resource: 'Customer' });
|
||||
};
|
||||
|
||||
if (!isEmpty(customersSelectedRows)) {
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteCustomers}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
@@ -129,7 +146,7 @@ function CustomerActionsBar({
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Can I={CustomerAction.Create} a={AbilitySubject.Item}>
|
||||
<Can I={CustomerAction.Create} a={AbilitySubject.Customer}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
@@ -153,16 +170,6 @@ function CustomerActionsBar({
|
||||
/>
|
||||
</AdvancedFilterPopover>
|
||||
|
||||
<If condition={customersSelectedRows.length}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
/>
|
||||
</If>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
@@ -217,6 +224,5 @@ export default compose(
|
||||
withSettings(({ customersSettings }) => ({
|
||||
customersTableSize: customersSettings?.tableSize,
|
||||
})),
|
||||
withAlertActions,
|
||||
withDialogActions,
|
||||
)(CustomerActionsBar);
|
||||
|
||||
@@ -24,13 +24,15 @@ function CustomersList({
|
||||
|
||||
// #withCustomersActions
|
||||
resetCustomersTableState,
|
||||
resetCustomersSelectedRows,
|
||||
}) {
|
||||
// Resets the accounts table state once the page unmount.
|
||||
useEffect(
|
||||
() => () => {
|
||||
resetCustomersTableState();
|
||||
resetCustomersSelectedRows();
|
||||
},
|
||||
[resetCustomersTableState],
|
||||
[resetCustomersSelectedRows, resetCustomersTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -32,6 +32,7 @@ import { DRAWERS } from '@/constants/drawers';
|
||||
function CustomersTable({
|
||||
// #withCustomersActions
|
||||
setCustomersTableState,
|
||||
setCustomersSelectedRows,
|
||||
|
||||
// #withCustomers
|
||||
customersTableState,
|
||||
@@ -78,6 +79,14 @@ function CustomersTable({
|
||||
[setCustomersTableState],
|
||||
);
|
||||
|
||||
const handleSelectedRowsChange = React.useCallback(
|
||||
(selectedFlatRows) => {
|
||||
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||
setCustomersSelectedRows(selectedIds);
|
||||
},
|
||||
[setCustomersSelectedRows],
|
||||
);
|
||||
|
||||
// Handles the customer delete action.
|
||||
const handleCustomerDelete = ({ id }) => {
|
||||
openAlert('customer-delete', { contactId: id });
|
||||
@@ -140,6 +149,8 @@ function CustomersTable({
|
||||
manualSortBy={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
autoResetSelectedRows={false}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteCustomers } from '@/hooks/query/customers';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteCustomersDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteCustomers();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.CustomerBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ export default (mapState) => {
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
customersSelectedRows: state.customers.selectedRows,
|
||||
customersTableState: getCustomersTableState(state, props),
|
||||
customersTableStateChanged: customersTableStateChanged(state, props),
|
||||
};
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setCustomersTableState,
|
||||
resetCustomersTableState
|
||||
resetCustomersTableState,
|
||||
setCustomersSelectedRows,
|
||||
resetCustomersSelectedRows,
|
||||
} from '@/store/customers/customers.actions';
|
||||
|
||||
export const mapDispatchToProps = (dispatch) => ({
|
||||
setCustomersTableState: (state) => dispatch(setCustomersTableState(state)),
|
||||
resetCustomersTableState: () => dispatch(resetCustomersTableState()),
|
||||
setCustomersSelectedRows: (selectedRows) =>
|
||||
dispatch(setCustomersSelectedRows(selectedRows)),
|
||||
resetCustomersSelectedRows: () => dispatch(resetCustomersSelectedRows()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteAccounts } from '@/hooks/query/accounts';
|
||||
@@ -45,7 +44,6 @@ function AccountBulkDeleteDialog({
|
||||
message: intl.get('the_accounts_has_been_successfully_deleted'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('accounts-table');
|
||||
setAccountsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteBills } from '@/hooks/query/bills';
|
||||
@@ -44,7 +43,6 @@ function BillBulkDeleteDialog({
|
||||
message: intl.get('the_bills_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('bills-table');
|
||||
setBillsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteCreditNotes } from '@/hooks/query/creditNote';
|
||||
@@ -45,7 +44,6 @@ function CreditNoteBulkDeleteDialog({
|
||||
message: intl.get('the_credit_notes_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('credit-notes-table');
|
||||
setCreditNotesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteCustomers } from '@/hooks/query/customers';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withCustomersActions from '@/containers/Customers/CustomersLanding/withCustomersActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function CustomerBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withCustomersActions
|
||||
setCustomersSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteCustomers, isLoading } =
|
||||
useBulkDeleteCustomers();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteCustomers({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_customers_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setCustomersSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_customer_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_customer_singular')}
|
||||
resourcePluralLabel={intl.get('resource_customer_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withCustomersActions,
|
||||
)(CustomerBulkDeleteDialog);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteEstimates } from '@/hooks/query/estimates';
|
||||
@@ -45,7 +44,6 @@ function EstimateBulkDeleteDialog({
|
||||
message: intl.get('the_estimates_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('estimates-table');
|
||||
setEstimatesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteExpenses } from '@/hooks/query/expenses';
|
||||
@@ -45,7 +44,6 @@ function ExpenseBulkDeleteDialog({
|
||||
message: intl.get('the_expenses_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('expenses-table');
|
||||
setExpensesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -50,7 +49,6 @@ function InvoiceBulkDeleteDialog({
|
||||
message: intl.get('the_invoices_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('invoices-table');
|
||||
resetInvoicesSelectedRows();
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteItems } from '@/hooks/query/items';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withItemsActions from '@/containers/Items/withItemsActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function ItemBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withItemsActions
|
||||
setItemsSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteItems, isLoading } = useBulkDeleteItems();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteItems({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_items_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setItemsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_item_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_item_singular')}
|
||||
resourcePluralLabel={intl.get('resource_item_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withItemsActions,
|
||||
)(ItemBulkDeleteDialog);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteManualJournals } from '@/hooks/query/manualJournals';
|
||||
@@ -45,7 +44,6 @@ function ManualJournalBulkDeleteDialog({
|
||||
message: intl.get('the_journals_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('manual-journals-table');
|
||||
setManualJournalsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeletePaymentReceives } from '@/hooks/query/paymentReceives';
|
||||
@@ -47,7 +46,6 @@ function PaymentReceivedBulkDeleteDialog({
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('payments-received-table');
|
||||
setPaymentReceivesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteReceipts } from '@/hooks/query/receipts';
|
||||
@@ -45,7 +44,6 @@ function ReceiptBulkDeleteDialog({
|
||||
message: intl.get('the_receipts_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('sale-receipts-table');
|
||||
setReceiptsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteVendorCredits } from '@/hooks/query/vendorCredit';
|
||||
@@ -47,7 +46,6 @@ function VendorCreditBulkDeleteDialog({
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('vendor-credits-table');
|
||||
setVendorsCreditNoteSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteVendors } from '@/hooks/query/vendors';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withVendorsActions from '@/containers/Vendors/VendorsLanding/withVendorsActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function VendorBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withVendorsActions
|
||||
setVendorsSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteVendors, isLoading } = useBulkDeleteVendors();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteVendors({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_vendors_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setVendorsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_vendor_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_vendor_singular')}
|
||||
resourcePluralLabel={intl.get('resource_vendor_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withVendorsActions,
|
||||
)(VendorBulkDeleteDialog);
|
||||
|
||||
@@ -31,7 +31,6 @@ import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-
|
||||
|
||||
import withItems from './withItems';
|
||||
import withItemsActions from './withItemsActions';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withDialogActions from '../Dialog/withDialogActions';
|
||||
@@ -39,6 +38,7 @@ import withDialogActions from '../Dialog/withDialogActions';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { compose } from '@/utils';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useBulkDeleteItemsDialog } from './hooks/use-bulk-delete-items-dialog';
|
||||
|
||||
/**
|
||||
* Items actions bar.
|
||||
@@ -52,9 +52,6 @@ function ItemsActionsBar({
|
||||
setItemsTableState,
|
||||
itemsInactiveMode,
|
||||
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
|
||||
// #withSettings
|
||||
itemsTableSize,
|
||||
|
||||
@@ -64,6 +61,9 @@ function ItemsActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) {
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteItems } =
|
||||
useBulkDeleteItemsDialog();
|
||||
|
||||
// Items list context.
|
||||
const { itemsViews, fields } = useItemsListContext();
|
||||
|
||||
@@ -88,7 +88,7 @@ function ItemsActionsBar({
|
||||
|
||||
// Handle cancel/confirm items bulk.
|
||||
const handleBulkDelete = () => {
|
||||
openAlert('items-bulk-delete', { itemsIds: itemsSelectedRows });
|
||||
openBulkDeleteDialog(itemsSelectedRows);
|
||||
};
|
||||
|
||||
// Handle inactive switch changing.
|
||||
@@ -129,6 +129,7 @@ function ItemsActionsBar({
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteItems}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
@@ -224,6 +225,5 @@ export default compose(
|
||||
itemsTableSize: itemsSettings.tableSize,
|
||||
})),
|
||||
withItemsActions,
|
||||
withAlertActions,
|
||||
withDialogActions,
|
||||
)(ItemsActionsBar);
|
||||
|
||||
@@ -13,10 +13,6 @@ const ItemActivateAlert = React.lazy(
|
||||
() => import('@/containers/Alerts/Items/ItemActivateAlert'),
|
||||
);
|
||||
|
||||
const ItemBulkDeleteAlert = React.lazy(
|
||||
() => import('@/containers/Alerts/Items/ItemBulkDeleteAlert'),
|
||||
);
|
||||
|
||||
const cancelUnlockingPartialAlert = React.lazy(
|
||||
() =>
|
||||
import(
|
||||
@@ -40,8 +36,4 @@ export default [
|
||||
name: 'item-activate',
|
||||
component: ItemActivateAlert,
|
||||
},
|
||||
{
|
||||
name: 'items-bulk-delete',
|
||||
component: ItemBulkDeleteAlert,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteItems } from '@/hooks/query/items';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteItemsDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteItems();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.ItemBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import {
|
||||
If,
|
||||
Can,
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
@@ -28,6 +27,8 @@ import { useRefreshVendors } from '@/hooks/query/vendors';
|
||||
import { useVendorsListContext } from './VendorsListProvider';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
|
||||
import { useBulkDeleteVendorsDialog } from './hooks/use-bulk-delete-vendors-dialog';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import withVendors from './withVendors';
|
||||
import withVendorsActions from './withVendorsActions';
|
||||
@@ -43,6 +44,7 @@ import { DialogsName } from '@/constants/dialogs';
|
||||
*/
|
||||
function VendorActionsBar({
|
||||
// #withVendors
|
||||
vendorsSelectedRows = [],
|
||||
vendorsFilterConditions,
|
||||
|
||||
// #withVendorActions
|
||||
@@ -59,6 +61,9 @@ function VendorActionsBar({
|
||||
openDialog,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteVendors } =
|
||||
useBulkDeleteVendorsDialog();
|
||||
|
||||
|
||||
// Vendors list context.
|
||||
const { vendorsViews, fields } = useVendorsListContext();
|
||||
@@ -102,6 +107,27 @@ function VendorActionsBar({
|
||||
downloadExportPdf({ resource: 'Vendor' });
|
||||
};
|
||||
|
||||
const handleBulkDelete = () => {
|
||||
openBulkDeleteDialog(vendorsSelectedRows);
|
||||
};
|
||||
|
||||
if (!isEmpty(vendorsSelectedRows)) {
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteVendors}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
@@ -111,7 +137,7 @@ function VendorActionsBar({
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Can I={VendorActionsBar.Create} a={AbilitySubject.Vendor}>
|
||||
<Can I={VendorAction.Create} a={AbilitySubject.Vendor}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
@@ -135,15 +161,6 @@ function VendorActionsBar({
|
||||
/>
|
||||
</AdvancedFilterPopover>
|
||||
|
||||
<If condition={false}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
/>
|
||||
</If>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
@@ -191,7 +208,8 @@ function VendorActionsBar({
|
||||
export default compose(
|
||||
withVendorsActions,
|
||||
withSettingsActions,
|
||||
withVendors(({ vendorsTableState }) => ({
|
||||
withVendors(({ vendorsTableState, vendorsSelectedRows }) => ({
|
||||
vendorsSelectedRows,
|
||||
vendorsInactiveMode: vendorsTableState.inactiveMode,
|
||||
vendorsFilterConditions: vendorsTableState.filterRoles,
|
||||
})),
|
||||
|
||||
@@ -24,13 +24,15 @@ function VendorsList({
|
||||
|
||||
// #withVendorsActions
|
||||
resetVendorsTableState,
|
||||
resetVendorsSelectedRows,
|
||||
}) {
|
||||
// Resets the vendors table state once the page unmount.
|
||||
useEffect(
|
||||
() => () => {
|
||||
resetVendorsTableState();
|
||||
resetVendorsSelectedRows();
|
||||
},
|
||||
[resetVendorsTableState],
|
||||
[resetVendorsSelectedRows, resetVendorsTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -31,6 +31,7 @@ import { DRAWERS } from '@/constants/drawers';
|
||||
function VendorsTable({
|
||||
// #withVendorsActions
|
||||
setVendorsTableState,
|
||||
setVendorsSelectedRows,
|
||||
|
||||
// #withVendors
|
||||
vendorsTableState,
|
||||
@@ -118,6 +119,14 @@ function VendorsTable({
|
||||
[setVendorsTableState],
|
||||
);
|
||||
|
||||
const handleSelectedRowsChange = React.useCallback(
|
||||
(selectedFlatRows) => {
|
||||
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||
setVendorsSelectedRows(selectedIds);
|
||||
},
|
||||
[setVendorsSelectedRows],
|
||||
);
|
||||
|
||||
// Display empty status instead of the table.
|
||||
if (isEmptyStatus) {
|
||||
return <VendorsEmptyStatus />;
|
||||
@@ -142,6 +151,8 @@ function VendorsTable({
|
||||
pagesCount={pagination.pagesCount}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
autoResetSelectedRows={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteVendors } from '@/hooks/query/vendors';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteVendorsDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteVendors();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.VendorBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ export default (mapState) => {
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
vendorsSelectedRows: state.vendors.selectedRows,
|
||||
vendorsTableState: getVendorsTableState(state, props),
|
||||
vendorsTableStateChanged: vendorsTableStateChanged(state, props),
|
||||
};
|
||||
|
||||
@@ -3,11 +3,16 @@ import { connect } from 'react-redux';
|
||||
import {
|
||||
setVendorsTableState,
|
||||
resetVendorsTableState,
|
||||
setVendorsSelectedRows,
|
||||
resetVendorsSelectedRows,
|
||||
} from '@/store/vendors/vendors.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setVendorsTableState: (queries) => dispatch(setVendorsTableState(queries)),
|
||||
resetVendorsTableState: () => dispatch(resetVendorsTableState()),
|
||||
setVendorsSelectedRows: (selectedRows) =>
|
||||
dispatch(setVendorsSelectedRows(selectedRows)),
|
||||
resetVendorsSelectedRows: () => dispatch(resetVendorsSelectedRows()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -16,6 +16,7 @@ export const useBulkDeleteDialog = (
|
||||
if (!ids?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { deletableCount = 0, nonDeletableCount = 0 } =
|
||||
await validateBulkDelete(ids);
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ export function useBulkDeleteAccounts(props) {
|
||||
}) =>
|
||||
apiRequest.post('accounts/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -128,7 +128,7 @@ export function useBulkDeleteCreditNotes(props) {
|
||||
}) =>
|
||||
apiRequest.post('credit-notes/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
|
||||
@@ -100,6 +100,49 @@ export function useDeleteCustomer(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple customers in bulk.
|
||||
*/
|
||||
export function useBulkDeleteCustomers(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('customers/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
onSuccess: () => {
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which customers can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteCustomers(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('customers/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new customer.
|
||||
*/
|
||||
|
||||
@@ -141,7 +141,7 @@ export function useBulkDeleteEstimates(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-estimates/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -119,7 +119,7 @@ export function useBulkDeleteExpenses(props) {
|
||||
}) =>
|
||||
apiRequest.post('expenses/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -142,7 +142,7 @@ export function useBulkDeleteInvoices(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-invoices/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { transformPagination, transformResponse } from '@/utils';
|
||||
import { transformPagination, transformResponse, transformToCamelCase } from '@/utils';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
@@ -81,7 +81,17 @@ export function useBulkDeleteItems(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) => apiRequest.post('items/bulk-delete', { ids }),
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('items/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
@@ -92,6 +102,21 @@ export function useBulkDeleteItems(props) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which items can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteItems(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('items/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the given item.
|
||||
*/
|
||||
|
||||
@@ -105,7 +105,7 @@ export function useBulkDeleteManualJournals(props) {
|
||||
}) =>
|
||||
apiRequest.post('manual-journals/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -167,7 +167,7 @@ export function useBulkDeletePaymentReceives(props) {
|
||||
}) =>
|
||||
apiRequest.post('payments-received/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -121,7 +121,7 @@ export function useBulkDeleteReceipts(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-receipts/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -130,7 +130,7 @@ export function useBulkDeleteVendorCredits(props) {
|
||||
}) =>
|
||||
apiRequest.post('vendor-credits/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import t from './types';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
|
||||
@@ -88,6 +88,49 @@ export function useDeleteVendor(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple vendors in bulk.
|
||||
*/
|
||||
export function useBulkDeleteVendors(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('vendors/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which vendors can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteVendors(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('vendors/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new vendor.
|
||||
*/
|
||||
|
||||
@@ -512,6 +512,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"you_could_not_delete_account_has_child_accounts": "لا يمكنك حذف حساب لديه حسابات فرعية.",
|
||||
"journal_entry": "القيد",
|
||||
"estimate": "رقم العرض",
|
||||
@@ -730,6 +736,7 @@
|
||||
"vendors_list": "قائمة الموردين",
|
||||
"the_vendor_has_been_created_successfully": "تم اضافة مورد جديد بنجاح.",
|
||||
"the_vendor_has_been_deleted_successfully": "تم حذف المورد بنجاح.",
|
||||
"the_vendors_has_been_deleted_successfully": "تم حذف الموردين بنجاح.",
|
||||
"the_item_vendor_has_been_edited_successfully": "تم تعديل المورد بنجاح.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "بمجرد حذف هذا المورد ، لن تتمكن من استعادته لاحقًا. هل أنت متأكد أنك تريد حذف؟",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "بمجرد حذف هؤلاء الموردين ، لن تتمكن من استعادتهم لاحقًا. هل أنت متأكد أنك تريد حذفها؟",
|
||||
|
||||
@@ -557,6 +557,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"receipts_list": "Receipts List",
|
||||
"receipts": "Receipts",
|
||||
"receipt": "Receipt #",
|
||||
@@ -720,6 +726,7 @@
|
||||
"vendors_list": "Vendors List",
|
||||
"the_vendor_has_been_created_successfully": "The vendor has been successfully created.",
|
||||
"the_vendor_has_been_deleted_successfully": "The vendor has been deleted successfully.",
|
||||
"the_vendors_has_been_deleted_successfully": "The vendors have been deleted successfully.",
|
||||
"the_item_vendor_has_been_edited_successfully": "The item vendor has been edited successfully.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "Once you delete this vendor, you won't be able to restore it later. Are you sure you want to delete this vendor?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "Once you delete these vendors, you won't be able to retrieve them later. Are you sure you want to delete them?",
|
||||
|
||||
@@ -512,6 +512,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"you_could_not_delete_account_has_child_accounts": "No pudiste eliminar la cuenta que tiene cuentas secundarias.",
|
||||
"journal_entry": "Asiento de diario",
|
||||
"estimate": "Estimación #",
|
||||
@@ -725,6 +731,7 @@
|
||||
"vendors_list": "Lista de proveedores",
|
||||
"the_vendor_has_been_created_successfully": "El proveedor ha sido creado exitosamente.",
|
||||
"the_vendor_has_been_deleted_successfully": "El proveedor ha sido eliminado exitosamente.",
|
||||
"the_vendors_has_been_deleted_successfully": "Los proveedores han sido eliminados exitosamente.",
|
||||
"the_item_vendor_has_been_edited_successfully": "El proveedor del artículo ha sido editado exitosamente.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "Una vez que elimines este proveedor, no podrás restaurarlo más tarde. ¿Estás seguro de que quieres eliminar este proveedor?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "Una vez que elimines estos proveedores, no podrás recuperarlos más tarde. ¿Estás seguro de que quieres eliminarlos?",
|
||||
|
||||
@@ -502,6 +502,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"journal_entry": "Journalanteckning",
|
||||
"estimate": "Uppskattning #",
|
||||
"estimate_date": "Uppskattning Datum",
|
||||
@@ -711,6 +717,7 @@
|
||||
"vendors_list": "Lista över leverantörer",
|
||||
"the_vendor_has_been_created_successfully": "Leverantören har skapats på ett framgångsrikt sätt.",
|
||||
"the_vendor_has_been_deleted_successfully": "Leverantören har tagits bort framgångsrikt.",
|
||||
"the_vendors_has_been_deleted_successfully": "Leverantörerna har raderats framgångsrikt.",
|
||||
"the_item_vendor_has_been_edited_successfully": "Artikelns leverantör har redigerats framgångsrikt.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "När du har tagit bort den här leverantören kan du inte återställa den senare. Är du säker på att du vill ta bort den här leverantören?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "När du har tagit bort dessa leverantörer kommer du inte att kunna hämta dem senare. Är du säker på att du vill ta bort dem?",
|
||||
|
||||
@@ -15,4 +15,17 @@ export const resetCustomersTableState = () => {
|
||||
return {
|
||||
type: t.CUSTOMERS_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const setCustomersSelectedRows = (selectedRows) => {
|
||||
return {
|
||||
type: 'CUSTOMERS/SET_SELECTED_ROWS',
|
||||
payload: selectedRows,
|
||||
};
|
||||
};
|
||||
|
||||
export const resetCustomersSelectedRows = () => {
|
||||
return {
|
||||
type: 'CUSTOMERS/RESET_SELECTED_ROWS',
|
||||
};
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Default table query state.
|
||||
export const defaultTableQueryState = {
|
||||
@@ -16,10 +17,21 @@ export const defaultTableQueryState = {
|
||||
// initial data.
|
||||
const initialState = {
|
||||
tableState: defaultTableQueryState,
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('CUSTOMERS', defaultTableQueryState),
|
||||
|
||||
['CUSTOMERS/SET_SELECTED_ROWS']: (state, action) => {
|
||||
state.selectedRows = action.payload;
|
||||
},
|
||||
|
||||
['CUSTOMERS/RESET_SELECTED_ROWS']: (state) => {
|
||||
state.selectedRows = [];
|
||||
},
|
||||
|
||||
[t.RESET]: () => initialState,
|
||||
});
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:estimates';
|
||||
|
||||
@@ -12,4 +12,17 @@ export const resetVendorsTableState = () => {
|
||||
return {
|
||||
type: t.VENDORS_TABLE_STATE_RESET,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const setVendorsSelectedRows = (selectedRows) => {
|
||||
return {
|
||||
type: 'VENDORS/SET_SELECTED_ROWS',
|
||||
payload: selectedRows,
|
||||
};
|
||||
};
|
||||
|
||||
export const resetVendorsSelectedRows = () => {
|
||||
return {
|
||||
type: 'VENDORS/RESET_SELECTED_ROWS',
|
||||
};
|
||||
};
|
||||
@@ -15,6 +15,7 @@ export const defaultTableQueryState = {
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQueryState,
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:vendors';
|
||||
@@ -28,8 +29,17 @@ const CONFIG = {
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('VENDORS', defaultTableQueryState),
|
||||
|
||||
['VENDORS/SET_SELECTED_ROWS']: (state, action) => {
|
||||
state.selectedRows = action.payload;
|
||||
},
|
||||
|
||||
['VENDORS/RESET_SELECTED_ROWS']: (state) => {
|
||||
state.selectedRows = [];
|
||||
},
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
return initialState;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user