feat: bulk transcations delete

This commit is contained in:
Ahmed Bouhuolia
2025-11-03 21:40:24 +02:00
parent 8161439365
commit a0bc9db9a6
107 changed files with 2213 additions and 156 deletions

View File

@@ -8,6 +8,10 @@ const JournalPublishAlert = React.lazy(
() => import('@/containers/Alerts/ManualJournals/JournalPublishAlert'),
);
const JournalBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/ManualJournals/JournalBulkDeleteAlert'),
);
/**
* Manual journals alerts.
*/
@@ -15,4 +19,5 @@ const JournalPublishAlert = React.lazy(
export default [
{ name: 'journal-delete', component: JournalDeleteAlert },
{ name: 'journal-publish', component: JournalPublishAlert },
{ name: 'journals-bulk-delete', component: JournalBulkDeleteAlert },
];

View File

@@ -102,13 +102,13 @@ export const StatusAccessor = (row) => {
return (
<Choose>
<Choose.When condition={!!row.is_published}>
<Tag round>
<Tag round minimal>
<T id={'published'} />
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag intent={Intent.WARNING} round>
<Tag intent={Intent.WARNING} round minimal>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -182,6 +182,7 @@ function AccountsActionsBar({
intent={Intent.DANGER}
onClick={handleBulkDelete}
/>
<NavbarDivider />
</If>
<Button

View File

@@ -10,9 +10,21 @@ const AccountInactivateAlert = React.lazy(
const AccountActivateAlert = React.lazy(
() => import('@/containers/Alerts/Accounts/AccountActivateAlert'),
);
const AccountBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Accounts/AccountBulkDeleteAlert'),
);
const AccountBulkActivateAlert = React.lazy(
() => import('@/containers/Alerts/Accounts/AccountBulkActivateAlert'),
);
const AccountBulkInactivateAlert = React.lazy(
() => import('@/containers/Alerts/Accounts/AccountBulkInactivateAlert'),
);
export default [
{ name: 'account-delete', component: AccountDeleteAlert },
{ name: 'account-inactivate', component: AccountInactivateAlert },
{ name: 'account-activate', component: AccountActivateAlert },
{ name: 'accounts-bulk-delete', component: AccountBulkDeleteAlert },
{ name: 'accounts-bulk-activate', component: AccountBulkActivateAlert },
{ name: 'accounts-bulk-inactivate', component: AccountBulkInactivateAlert },
];

View File

@@ -22,6 +22,7 @@ import withSettings from '@/containers/Settings/withSettings';
import withAlertsActions from '@/containers/Alert/withAlertActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import withAccountsTableActions from './withAccountsTableActions';
import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers';
@@ -40,6 +41,9 @@ function AccountsDataTable({
// #withSettings
accountsTableSize,
// #withAccountsTableActions
setAccountsSelectedRows,
}) {
const { isAccountsLoading, isAccountsFetching, accounts } =
useAccountsChartContext();
@@ -91,6 +95,12 @@ function AccountsDataTable({
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.ACCOUNTS);
// Handle selected rows change.
const handleSelectedRowsChange = (selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setAccountsSelectedRows(selectedIds);
};
return (
<DataTable
noInitialFetch={true}
@@ -118,6 +128,7 @@ function AccountsDataTable({
vListrowHeight={accountsTableSize == 'small' ? 40 : 42}
vListOverscanRowCount={0}
onCellClick={handleCellClick}
onSelectedRowsChange={handleSelectedRowsChange}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
size={accountsTableSize}
@@ -137,6 +148,7 @@ export default compose(
withAlertsActions,
withDrawerActions,
withDialogActions,
withAccountsTableActions,
withSettings(({ accountsSettings }) => ({
accountsTableSize: accountsSettings.tableSize,
})),

View File

@@ -13,6 +13,7 @@ export default (mapState) => {
const mapped = {
accountsTableState: getAccountsTableState(state, props),
accountsTableStateChanged: accountsTableStateChanged(state, props),
accountsSelectedRows: state.accounts?.selectedRows || [],
};
return mapState ? mapState(mapped, state, props) : mapped;
};

View File

@@ -3,11 +3,14 @@ import { connect } from 'react-redux';
import {
setAccountsTableState,
resetAccountsTableState,
setAccountsSelectedRows,
} from '@/store/accounts/accounts.actions';
const mapActionsToProps = (dispatch) => ({
setAccountsTableState: (queries) => dispatch(setAccountsTableState(queries)),
resetAccountsTableState: () => dispatch(resetAccountsTableState()),
setAccountsSelectedRows: (selectedRows) =>
dispatch(setAccountsSelectedRows(selectedRows)),
});
export default connect(null, mapActionsToProps);

View File

@@ -5,7 +5,6 @@ import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { FormattedMessage as T, AppToaster } from '@/components';
import withAccountsActions from '@/containers/Accounts/withAccountsActions';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
@@ -19,6 +18,7 @@ function AccountBulkActivateAlert({
// #withAlertActions
closeAlert,
// TODO: Implement bulk activate accounts hook and use it here
requestBulkActivateAccounts,
}) {
const [isLoading, setLoading] = useState(false);
@@ -40,7 +40,7 @@ function AccountBulkActivateAlert({
});
queryCache.invalidateQueries('accounts-table');
})
.catch((errors) => {})
.catch((errors) => { })
.finally(() => {
setLoading(false);
closeAlert(name);
@@ -67,5 +67,4 @@ function AccountBulkActivateAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withAccountsActions,
)(AccountBulkActivateAlert);

View File

@@ -1,5 +1,5 @@
// @ts-nocheck
import React, { useState } from 'react';
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
@@ -7,8 +7,8 @@ import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { handleDeleteErrors } from '@/containers/Accounts/utils';
import { useBulkDeleteAccounts } from '@/hooks/query/accounts';
import withAccountsActions from '@/containers/Accounts/withAccountsActions';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
@@ -27,42 +27,34 @@ function AccountBulkDeleteAlert({
// #withAlertActions
closeAlert,
// #withAccountsActions
requestDeleteBulkAccounts,
}) {
const [isLoading, setLoading] = useState(false);
const selectedRowsCount = 0;
const { mutateAsync: bulkDeleteAccounts, isLoading } = useBulkDeleteAccounts();
const handleCancel = () => {
closeAlert(name);
};
// Handle confirm accounts bulk delete.
const handleConfirmBulkDelete = () => {
setLoading(true);
requestDeleteBulkAccounts(accountsIds)
bulkDeleteAccounts(accountsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_accounts_has_been_successfully_deleted'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('accounts-table');
closeAlert(name);
})
.catch((errors) => {
handleDeleteErrors(errors);
})
.finally(() => {
setLoading(false);
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={`${intl.get('delete')} (${selectedRowsCount})`}
confirmButtonText={
<T id={'delete_count'} values={{ count: accountsIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
@@ -80,5 +72,4 @@ function AccountBulkDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withAccountsActions,
)(AccountBulkDeleteAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteBills } from '@/hooks/query/bills';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Bill bulk delete alert.
*/
function BillBulkDeleteAlert({
name,
isOpen,
payload: { billsIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteBills, isLoading } = useBulkDeleteBills();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteBills(billsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_bills_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('bills-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: billsIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_bills_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(BillBulkDeleteAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteCreditNotes } from '@/hooks/query/creditNote';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Credit note bulk delete alert.
*/
function CreditNoteBulkDeleteAlert({
name,
isOpen,
payload: { creditNotesIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteCreditNotes, isLoading } = useBulkDeleteCreditNotes();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteCreditNotes(creditNotesIds)
.then(() => {
AppToaster.show({
message: intl.get('the_credit_notes_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('credit-notes-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: creditNotesIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_credit_notes_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(CreditNoteBulkDeleteAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteEstimates } from '@/hooks/query/estimates';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Estimate bulk delete alert.
*/
function EstimateBulkDeleteAlert({
name,
isOpen,
payload: { estimatesIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteEstimates, isLoading } = useBulkDeleteEstimates();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteEstimates(estimatesIds)
.then(() => {
AppToaster.show({
message: intl.get('the_estimates_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('estimates-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: estimatesIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_estimates_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(EstimateBulkDeleteAlert);

View File

@@ -3,8 +3,10 @@ import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteExpenses } from '@/hooks/query/expenses';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
@@ -15,44 +17,43 @@ import { compose } from '@/utils';
*/
function ExpenseBulkDeleteAlert({
closeAlert,
// #withAlertStoreConnect
name,
payload: { expenseId, selectedCount },
payload: { expensesIds },
isOpen,
}) {
// Handle confirm journals bulk delete.
const handleConfirmBulkDelete = () => {
// requestDeleteBulkExpenses(bulkDelete)
// .then(() => {
// AppToaster.show({
// message: formatMessage(
// { id: 'the_expenses_have_been_deleted_successfully' },
// { count: selectedRowsCount },
// ),
// intent: Intent.SUCCESS,
// });
// })
// .catch((error) => {
// });
const { mutateAsync: bulkDeleteExpenses, isLoading } = useBulkDeleteExpenses();
const handleCancel = () => {
closeAlert(name);
};
// Handle cancel bulk delete alert.
const handleCancelBulkDelete = () => {
closeAlert(name);
const handleConfirmBulkDelete = () => {
bulkDeleteExpenses(expensesIds)
.then(() => {
AppToaster.show({
message: intl.get('the_expenses_have_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('expenses-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: selectedCount }} />
<T id={'delete_count'} values={{ count: expensesIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancelBulkDelete}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_expenses_you_will_not_able_restore_them'} />

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteInvoices } from '@/hooks/query/invoices';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Invoice bulk delete alert.
*/
function InvoiceBulkDeleteAlert({
name,
isOpen,
payload: { invoicesIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteInvoices, isLoading } = useBulkDeleteInvoices();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteInvoices(invoicesIds)
.then(() => {
AppToaster.show({
message: intl.get('the_invoices_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('invoices-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: invoicesIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_invoices_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(InvoiceBulkDeleteAlert);

View File

@@ -1,11 +1,11 @@
// @ts-nocheck
import React, { useState } from 'react';
import {AppToaster, FormattedMessage as T } from '@/components';
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 withItemsActions from '@/containers/Items/withItemsActions';
import { useBulkDeleteItems } from '@/hooks/query/items';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
@@ -21,14 +21,10 @@ function ItemBulkDeleteAlert({
isOpen,
payload: { itemsIds },
// #withItemsActions
requestDeleteBulkItems,
// #withAlertActions
closeAlert,
}) {
const [isLoading, setLoading] = useState(false);
const { mutateAsync: bulkDeleteItems, isLoading } = useBulkDeleteItems();
// handle cancel item bulk delete alert.
const handleCancelBulkDelete = () => {
@@ -36,19 +32,15 @@ function ItemBulkDeleteAlert({
};
// Handle confirm items bulk delete.
const handleConfirmBulkDelete = () => {
setLoading(true);
requestDeleteBulkItems(itemsIds)
bulkDeleteItems(itemsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_items_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
})
.catch((errors) => {})
.finally(() => {
setLoading(false);
closeAlert(name);
});
})
.catch((errors) => { });
};
return (
<Alert
@@ -73,5 +65,4 @@ function ItemBulkDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withItemsActions,
)(ItemBulkDeleteAlert);

View File

@@ -1,43 +1,59 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteManualJournals } from '@/hooks/query/manualJournals';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
function JournalBulkDeleteAlert({}) {
// Handle confirm journals bulk delete.
const handleConfirmBulkDelete = useCallback(() => {
requestDeleteBulkManualJournals(bulkDelete)
.then(() => {
setBulkDelete(false);
AppToaster.show({
message: formatMessage(
{ id: 'the_journals_has_been_deleted_successfully' },
{ count: selectedRowsCount },
),
intent: Intent.SUCCESS,
});
})
.catch((error) => {
setBulkDelete(false);
/**
* Manual journal bulk delete alert.
*/
function JournalBulkDeleteAlert({
name,
isOpen,
payload: { journalsIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteManualJournals, isLoading } = useBulkDeleteManualJournals();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteManualJournals(journalsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_journals_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
}, [
requestDeleteBulkManualJournals,
bulkDelete,
formatMessage,
selectedRowsCount,
]);
queryCache.invalidateQueries('manual-journals-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: selectedRowsCount }} />
<T id={'delete_count'} values={{ count: journalsIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={bulkDelete}
onCancel={handleCancelBulkDelete}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_journals_you_will_not_able_restore_them'} />
@@ -45,3 +61,8 @@ function JournalBulkDeleteAlert({}) {
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(JournalBulkDeleteAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeletePaymentReceives } from '@/hooks/query/paymentReceives';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Payment received bulk delete alert.
*/
function PaymentReceivedBulkDeleteAlert({
name,
isOpen,
payload: { paymentsReceivedIds },
closeAlert,
}) {
const { mutateAsync: bulkDeletePaymentReceives, isLoading } = useBulkDeletePaymentReceives();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeletePaymentReceives(paymentsReceivedIds)
.then(() => {
AppToaster.show({
message: intl.get('the_payments_received_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('payments-received-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: paymentsReceivedIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_payments_received_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(PaymentReceivedBulkDeleteAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { FormattedMessage as T } from '@/components';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { AppToaster } from '@/components';
import { useBulkDeleteVendorCredits } from '@/hooks/query/vendorCredit';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
/**
* Vendor credit bulk delete alert.
*/
function VendorCreditBulkDeleteAlert({
name,
isOpen,
payload: { vendorCreditsIds },
closeAlert,
}) {
const { mutateAsync: bulkDeleteVendorCredits, isLoading } = useBulkDeleteVendorCredits();
const handleCancel = () => {
closeAlert(name);
};
const handleConfirmBulkDelete = () => {
bulkDeleteVendorCredits(vendorCreditsIds)
.then(() => {
AppToaster.show({
message: intl.get('the_vendor_credits_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
queryCache.invalidateQueries('vendor-credits-table');
closeAlert(name);
})
.catch((errors) => {
// Handle errors
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={
<T id={'delete_count'} values={{ count: vendorCreditsIds?.length || 0 }} />
}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancel}
onConfirm={handleConfirmBulkDelete}
loading={isLoading}
>
<p>
<T id={'once_delete_these_vendor_credits_you_will_not_able_restore_them'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(VendorCreditBulkDeleteAlert);

View File

@@ -61,13 +61,13 @@ function ExpenseForm({
() => ({
...(!isEmpty(expense)
? {
...transformToEditForm(expense, defaultExpense),
}
...transformToEditForm(expense, defaultExpense),
}
: {
...defaultExpense,
currency_code: base_currency,
payment_account_id: defaultTo(preferredPaymentAccount, ''),
}),
...defaultExpense,
currency_code: base_currency,
payment_account_id: defaultTo(preferredPaymentAccount, ''),
}),
}),
[expense, base_currency, preferredPaymentAccount],
);
@@ -82,6 +82,7 @@ function ExpenseForm({
message: intl.get('amount_cannot_be_zero_or_empty'),
intent: Intent.DANGER,
});
setSubmitting(false);
return;
}

View File

@@ -8,10 +8,15 @@ const ExpensePublishAlert = React.lazy(
() => import('@/containers/Alerts/Expenses/ExpensePublishAlert'),
);
const ExpenseBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Expenses/ExpenseBulkDeleteAlert'),
);
/**
* Accounts alert.
*/
export default [
{ name: 'expense-delete', component: ExpenseDeleteAlert },
{ name: 'expense-publish', component: ExpensePublishAlert },
{ name: 'expenses-bulk-delete', component: ExpenseBulkDeleteAlert },
];

View File

@@ -101,7 +101,7 @@ export function ActionsCell(props) {
*/
export function PublishAccessor(row) {
return row.is_published ? (
<Tag round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'published'} />
</Tag>
) : (

View File

@@ -31,6 +31,7 @@ import { DRAWERS } from '@/constants/drawers';
function ItemsDataTable({
// #withItemsActions
setItemsTableState,
setItemsSelectedRows,
// #withDialogAction
openDialog,
@@ -81,6 +82,15 @@ function ItemsDataTable({
[setItemsTableState],
);
// Handle selected rows change.
const handleSelectedRowsChange = React.useCallback(
(selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setItemsSelectedRows(selectedIds);
},
[setItemsSelectedRows],
);
// Handle delete action Item.
const handleDeleteItem = ({ id }) => {
openAlert('item-delete', { itemId: id });
@@ -136,6 +146,8 @@ function ItemsDataTable({
progressBarLoading={isItemsFetching}
noInitialFetch={true}
selectionColumn={true}
onSelectedRowsChange={handleSelectedRowsChange}
autoResetSelectedRows={false}
spinnerProps={{ size: 30 }}
expandable={false}
sticky={true}
@@ -179,5 +191,5 @@ export default compose(
withSettings(({ itemsSettings }) => ({
itemsTableSize: itemsSettings.tableSize,
})),
withItems(({ itemsTableState }) => ({ itemsTableState }))
withItems(({ itemsTableState }) => ({ itemsTableState }))
)(ItemsDataTable);

View File

@@ -72,7 +72,7 @@ export const SellPriceCell = ({ cell: { value } }) => {
export const ItemTypeAccessor = (row) => {
return row.type_formatted ? (
<Tag round intent={Intent.NONE}>
<Tag round minimal intent={Intent.NONE}>
{row.type_formatted}
</Tag>
) : null;

View File

@@ -3,11 +3,13 @@ import { connect } from 'react-redux';
import {
setItemsTableState,
resetItemsTableState,
setItemsSelectedRows,
} from '@/store/items/items.actions';
export const mapDispatchToProps = (dispatch) => ({
setItemsTableState: (queries) => dispatch(setItemsTableState(queries)),
resetItemsTableState: () => dispatch(resetItemsTableState()),
setItemsSelectedRows: (selectedRows) => dispatch(setItemsSelectedRows(selectedRows)),
});
export default connect(null, mapDispatchToProps);

View File

@@ -12,6 +12,10 @@ const BillLocatedLandedCostDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Bills/BillLocatedLandedCostDeleteAlert'),
);
const BillBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Bills/BillBulkDeleteAlert'),
);
export default [
{ name: 'bill-delete', component: BillDeleteAlert },
{ name: 'bill-open', component: BillOpenAlert },
@@ -19,4 +23,5 @@ export default [
name: 'bill-located-cost-delete',
component: BillLocatedLandedCostDeleteAlert,
},
{ name: 'bills-bulk-delete', component: BillBulkDeleteAlert },
];

View File

@@ -106,7 +106,7 @@ export function StatusAccessor(bill) {
<div className={'status-accessor'}>
<Choose>
<Choose.When condition={bill.is_fully_paid && bill.is_open}>
<Tag round intent={Intent.SUCCESS}>
<Tag round minimal intent={Intent.SUCCESS}>
<T id={'paid'} />
</Tag>
</Choose.When>
@@ -114,18 +114,18 @@ export function StatusAccessor(bill) {
<Choose.When condition={bill.is_open}>
<Choose>
<Choose.When condition={bill.is_overdue}>
<Tag round intent={Intent.DANGER}>
<Tag round minimal intent={Intent.DANGER}>
{intl.get('overdue_by', { overdue: bill.overdue_days })}
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag round intent={Intent.WARNING}>
<Tag round minimal intent={Intent.WARNING}>
{intl.get('due_in', { due: bill.remaining_days })}
</Tag>
</Choose.Otherwise>
</Choose>
<If condition={bill.is_partially_paid}>
<Tag round intent={Intent.PRIMARY}>
<Tag round minimal intent={Intent.PRIMARY}>
{intl.get('day_partially_paid', {
due: formattedAmount(bill.due_amount, bill.currency_code),
})}
@@ -134,7 +134,7 @@ export function StatusAccessor(bill) {
</Choose.When>
<Choose.Otherwise>
<Tag round>
<Tag round minimal>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -81,19 +81,19 @@ export function StatusAccessor(creditNote) {
<div>
<Choose>
<Choose.When condition={creditNote.is_open}>
<Tag intent={Intent.WARNING} round>
<Tag intent={Intent.WARNING} round minimal>
<T id={'open'} />
</Tag>
</Choose.When>
<Choose.When condition={creditNote.is_closed}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'closed'} />
</Tag>
</Choose.When>
<Choose.When condition={creditNote.is_draft}>
<Tag round>
<Tag round minimal>
<T id={'draft'} />
</Tag>
</Choose.When>

View File

@@ -23,6 +23,11 @@ const ReconcileVendorCreditDeleteAlert = React.lazy(
),
);
const VendorCreditBulkDeleteAlert = React.lazy(
() =>
import('@/containers/Alerts/VendorCeditNotes/VendorCreditBulkDeleteAlert'),
);
/**
* Vendor Credit notes alerts.
*/
@@ -43,4 +48,8 @@ export default [
name: 'reconcile-vendor-delete',
component: ReconcileVendorCreditDeleteAlert,
},
{
name: 'vendor-credits-bulk-delete',
component: VendorCreditBulkDeleteAlert,
},
];

View File

@@ -18,6 +18,10 @@ const ReconcileCreditDeleteAlert = React.lazy(
import('@/containers/Alerts/CreditNotes/ReconcileCreditNoteDeleteAlert'),
);
const CreditNoteBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/CreditNotes/CreditNoteBulkDeleteAlert'),
);
/**
* Credit notes alerts.
*/
@@ -38,4 +42,8 @@ export default [
name: 'reconcile-credit-delete',
component: ReconcileCreditDeleteAlert,
},
{
name: 'credit-notes-bulk-delete',
component: CreditNoteBulkDeleteAlert,
},
];

View File

@@ -33,6 +33,7 @@ import { DRAWERS } from '@/constants/drawers';
function CreditNotesDataTable({
// #withCreditNotesActions
setCreditNotesTableState,
setCreditNotesSelectedRows,
// #withAlertsActions
openAlert,
@@ -79,6 +80,15 @@ function CreditNotesDataTable({
[setCreditNotesTableState],
);
// Handle selected rows change.
const handleSelectedRowsChange = React.useCallback(
(selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setCreditNotesSelectedRows(selectedIds);
},
[setCreditNotesSelectedRows],
);
// Display create note empty status instead of the table.
if (isEmptyStatus) {
return <CreditNoteEmptyStatus />;
@@ -128,6 +138,8 @@ function CreditNotesDataTable({
headerLoading={isCreditNotesLoading}
progressBarLoading={isCreditNotesFetching}
onFetchData={handleDataTableFetchData}
onSelectedRowsChange={handleSelectedRowsChange}
autoResetSelectedRows={false}
manualSortBy={true}
selectionColumn={true}
noInitialFetch={true}

View File

@@ -80,19 +80,19 @@ export function StatusAccessor(creditNote) {
<div>
<Choose>
<Choose.When condition={creditNote.is_open}>
<Tag intent={Intent.WARNING} round>
<Tag intent={Intent.WARNING} round minimal>
<T id={'open'} />
</Tag>
</Choose.When>
<Choose.When condition={creditNote.is_closed}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'closed'} />
</Tag>
</Choose.When>
<Choose.When condition={creditNote.is_draft}>
<Tag intent={Intent.NONE} round>
<Tag intent={Intent.NONE} round minimal>
<T id={'draft'} />
</Tag>
</Choose.When>

View File

@@ -13,6 +13,7 @@ export default (mapState) => {
const mapped = {
creditNoteTableState: getCreditNoteTableState(state, props),
creditNoteTableStateChanged: isCreditNoteTableChanged(state, props),
creditNotesSelectedRows: state.creditNotes?.selectedRows || [],
};
return mapState ? mapState(mapped, state, props) : mapped;
};

View File

@@ -3,12 +3,14 @@ import { connect } from 'react-redux';
import {
setCreditNoteTableState,
resetCreditNoteTableState,
setCreditNotesSelectedRows,
} from '@/store/CreditNote/creditNote.actions';
const mapDipatchToProps = (dispatch) => ({
setCreditNotesTableState: (queries) =>
dispatch(setCreditNoteTableState(queries)),
resetCreditNotesTableState: () => dispatch(resetCreditNoteTableState()),
setCreditNotesSelectedRows: (selectedRows) => dispatch(setCreditNotesSelectedRows(selectedRows)),
});
export default connect(null, mapDipatchToProps);

View File

@@ -14,6 +14,10 @@ const EstimateRejectAlert = React.lazy(
() => import('@/containers/Alerts/Estimates/EstimateRejectAlert'),
);
const EstimateBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Estimates/EstimateBulkDeleteAlert'),
);
/**
* Estimates alert.
*/
@@ -22,4 +26,5 @@ export default [
{ name: 'estimate-deliver', component: EstimateDeliveredAlert },
{ name: 'estimate-Approve', component: EstimateApproveAlert },
{ name: 'estimate-reject', component: EstimateRejectAlert },
{ name: 'estimates-bulk-delete', component: EstimateBulkDeleteAlert },
];

View File

@@ -33,6 +33,7 @@ import withEstimatesActions from './withEstimatesActions';
import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { useEstimatesListContext } from './EstimatesListProvider';
import { useRefreshEstimates } from '@/hooks/query/estimates';
@@ -43,6 +44,7 @@ import { compose } from '@/utils';
import { DialogsName } from '@/constants/dialogs';
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { DRAWERS } from '@/constants/drawers';
import { isEmpty } from 'lodash';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
@@ -57,6 +59,7 @@ function EstimateActionsBar({
// #withEstimates
estimatesFilterRoles,
estimatesSelectedRows = [],
// #withSettings
estimatesTableSize,
@@ -69,6 +72,9 @@ function EstimateActionsBar({
// #withSettingsActions
addSetting,
// #withAlertActions
openAlert,
}) {
const history = useHistory();
@@ -116,6 +122,11 @@ function EstimateActionsBar({
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleEstimate' });
};
// Handle bulk estimates delete.
const handleBulkDelete = () => {
openAlert('estimates-bulk-delete', { estimatesIds: estimatesSelectedRows });
};
return (
<DashboardActionsBar>
<NavbarGroup>
@@ -150,13 +161,13 @@ function EstimateActionsBar({
/>
</AdvancedFilterPopover>
<If condition={false}>
<If condition={!isEmpty(estimatesSelectedRows)}>
<Button
className={Classes.MINIMAL}
icon={<Icon icon={'trash-16'} iconSize={16} />}
text={<T id={'delete'} />}
intent={Intent.DANGER}
// onClick={handleBulkDelete}
onClick={handleBulkDelete}
/>
</If>
<Button
@@ -218,8 +229,10 @@ function EstimateActionsBar({
export default compose(
withEstimatesActions,
withSettingsActions,
withEstimates(({ estimatesTableState }) => ({
withAlertActions,
withEstimates(({ estimatesTableState, estimatesSelectedRows }) => ({
estimatesFilterRoles: estimatesTableState.filterRoles,
estimatesSelectedRows: estimatesSelectedRows || [],
})),
withSettings(({ estimatesSettings }) => ({
estimatesTableSize: estimatesSettings?.tableSize,

View File

@@ -31,6 +31,7 @@ import { DialogsName } from '@/constants/dialogs';
function EstimatesDataTable({
// #withEstimatesActions
setEstimatesTableState,
setEstimatesSelectedRows,
// #withAlertsActions
openAlert,
@@ -126,6 +127,15 @@ function EstimatesDataTable({
[setEstimatesTableState],
);
// Handle selected rows change.
const handleSelectedRowsChange = useCallback(
(selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setEstimatesSelectedRows(selectedIds);
},
[setEstimatesSelectedRows],
);
// Display empty status instead of the table.
if (isEmptyStatus) {
return <EstimatesEmptyStatus />;
@@ -140,6 +150,8 @@ function EstimatesDataTable({
headerLoading={isEstimatesLoading}
progressBarLoading={isEstimatesFetching}
onFetchData={handleFetchData}
onSelectedRowsChange={handleSelectedRowsChange}
autoResetSelectedRows={false}
noInitialFetch={true}
manualSortBy={true}
selectionColumn={true}

View File

@@ -22,27 +22,31 @@ import { safeCallback } from '@/utils';
export const statusAccessor = (row) => (
<Choose>
<Choose.When condition={row.is_approved}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'approved'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_rejected}>
<Tag intent={Intent.DANGER} round>
<Tag intent={Intent.DANGER} round minimal>
<T id={'rejected'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_expired}>
<Tag intent={Intent.WARNING} round>
<Tag intent={Intent.WARNING} round minimal>
<T id={'estimate.status.expired'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_delivered}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'delivered'} />
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag round>
<Tag round minimal>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -13,6 +13,7 @@ export default (mapState) => {
const mapped = {
estimatesTableState: getEstimatesTableState(state, props),
estimatesTableStateChanged: isEstimatesTableStateChanged(state, props),
estimatesSelectedRows: state.estimates?.selectedRows || [],
};
return mapState ? mapState(mapped, state, props) : mapped;
};

View File

@@ -3,11 +3,13 @@ import { connect } from 'react-redux';
import {
setEstimatesTableState,
resetEstimatesTableState,
setEstimatesSelectedRows,
} from '@/store/Estimate/estimates.actions';
const mapDispatchToProps = (dispatch) => ({
setEstimatesTableState: (state) => dispatch(setEstimatesTableState(state)),
resetEstimatesTableState: () => dispatch(resetEstimatesTableState()),
setEstimatesSelectedRows: (selectedRows) => dispatch(setEstimatesSelectedRows(selectedRows)),
});
export default connect(null, mapDispatchToProps);

View File

@@ -12,6 +12,10 @@ const CancelBadDebtAlert = React.lazy(
() => import('@/containers/Alerts/Invoices/CancelBadDebtAlert'),
);
const InvoiceBulkDeleteAlert = React.lazy(
() => import('@/containers/Alerts/Invoices/InvoiceBulkDeleteAlert'),
);
/**
* Invoices alert.
*/
@@ -19,4 +23,5 @@ export default [
{ name: 'invoice-delete', component: InvoiceDeleteAlert },
{ name: 'invoice-deliver', component: InvoiceDeliverAlert },
{ name: 'cancel-bad-debt', component: CancelBadDebtAlert },
{ name: 'invoices-bulk-delete', component: InvoiceBulkDeleteAlert },
];

View File

@@ -34,11 +34,13 @@ import withInvoices from './withInvoices';
import withInvoiceActions from './withInvoiceActions';
import withSettings from '@/containers/Settings/withSettings';
import withSettingsActions from '@/containers/Settings/withSettingsActions';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { compose } from '@/utils';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { DialogsName } from '@/constants/dialogs';
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { DRAWERS } from '@/constants/drawers';
import { isEmpty } from 'lodash';
/**
* Invoices table actions bar.
@@ -49,6 +51,7 @@ function InvoiceActionsBar({
// #withInvoices
invoicesFilterRoles,
invoicesSelectedRows = [],
// #withSettings
invoicesTableSize,
@@ -61,6 +64,9 @@ function InvoiceActionsBar({
// #withDrawerActions
openDrawer,
// #withAlertActions
openAlert,
}) {
const history = useHistory();
@@ -112,6 +118,11 @@ function InvoiceActionsBar({
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleInvoice' });
};
// Handle bulk invoices delete.
const handleBulkDelete = () => {
openAlert('invoices-bulk-delete', { invoicesIds: invoicesSelectedRows });
};
return (
<DashboardActionsBar>
<NavbarGroup>
@@ -145,12 +156,13 @@ function InvoiceActionsBar({
<NavbarDivider />
<If condition={false}>
<If condition={!isEmpty(invoicesSelectedRows)}>
<Button
className={Classes.MINIMAL}
icon={<Icon icon={'trash-16'} iconSize={16} />}
text={<T id={'delete'} />}
intent={Intent.DANGER}
onClick={handleBulkDelete}
/>
</If>
<Button
@@ -211,8 +223,10 @@ function InvoiceActionsBar({
export default compose(
withInvoiceActions,
withSettingsActions,
withAlertActions,
withInvoices(({ invoicesTableState }) => ({
invoicesFilterRoles: invoicesTableState.filterRoles,
invoicesSelectedRows: invoicesTableState?.selectedRows || [],
})),
withSettings(({ invoiceSettings }) => ({
invoicesTableSize: invoiceSettings?.tableSize,

View File

@@ -34,6 +34,7 @@ import { DialogsName } from '@/constants/dialogs';
function InvoicesDataTable({
// #withInvoicesActions
setInvoicesTableState,
setInvoicesSelectedRows,
// #withInvoices
invoicesTableState,
@@ -125,6 +126,15 @@ function InvoicesDataTable({
[setInvoicesTableState],
);
// Handle selected rows change.
const handleSelectedRowsChange = useCallback(
(selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setInvoicesSelectedRows(selectedIds);
},
[setInvoicesSelectedRows],
);
// Display invoice empty status instead of the table.
if (isEmptyStatus) {
return <InvoicesEmptyStatus />;
@@ -141,6 +151,7 @@ function InvoicesDataTable({
onFetchData={handleDataTableFetchData}
manualSortBy={true}
selectionColumn={true}
onSelectedRowsChange={handleSelectedRowsChange}
noInitialFetch={true}
sticky={true}
pagination={true}
@@ -149,6 +160,7 @@ function InvoicesDataTable({
pagesCount={pagination.pagesCount}
autoResetSortBy={false}
autoResetPage={false}
autoResetSelectedRows={false}
TableLoadingRenderer={TableSkeletonRows}
TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu}

View File

@@ -1,12 +1,6 @@
// @ts-nocheck
import React from 'react';
import {
Intent,
Tag,
Menu,
MenuItem,
MenuDivider,
} from '@blueprintjs/core';
import { Intent, Tag, Menu, MenuItem, MenuDivider } from '@blueprintjs/core';
import intl from 'react-intl-universal';
import clsx from 'classnames';
import { CLASSES } from '@/constants/classes';
@@ -30,36 +24,33 @@ export function InvoiceStatus({ invoice }) {
return (
<Choose>
<Choose.When condition={invoice.is_fully_paid && invoice.is_delivered}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'paid'} />
</Tag>
</Choose.When>
<Choose.When condition={invoice.is_delivered}>
<Choose>
<Choose.When condition={invoice.is_overdue}>
<Tag intent={Intent.DANGER} round>
{intl.get('overdue_by', { overdue: invoice.overdue_days })}
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag intent={Intent.WARNING} round>
{intl.get('due_in', { due: invoice.remaining_days })}
</Tag>
</Choose.Otherwise>
</Choose>
<Choose.When condition={invoice.is_delivered && invoice.is_overdue}>
<Tag intent={Intent.DANGER} round minimal>
{intl.get('overdue_by', { overdue: invoice.overdue_days })}
</Tag>
</Choose.When>
<If condition={invoice.is_partially_paid}>
<Tag intent={Intent.PRIMARY} round>
{intl.get('day_partially_paid', {
due: formattedAmount(invoice.due_amount, invoice.currency_code),
})}
</Tag>
</If>
<Choose.When condition={invoice.is_delivered && !invoice.is_overdue}>
<Tag intent={Intent.WARNING} round minimal>
{intl.get('due_in', { due: invoice.remaining_days })}
</Tag>
</Choose.When>
<Choose.When condition={invoice.is_partially_paid}>
<Tag intent={Intent.PRIMARY} round minimal>
{intl.get('day_partially_paid', {
due: formattedAmount(invoice.due_amount, invoice.currency_code),
})}
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag round>
<Tag round minimal>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -2,12 +2,14 @@
import { connect } from 'react-redux';
import {
setInvoicesTableState,
resetInvoicesTableState
resetInvoicesTableState,
setInvoicesSelectedRows,
} from '@/store/Invoice/invoices.actions';
const mapDipatchToProps = (dispatch) => ({
setInvoicesTableState: (queries) => dispatch(setInvoicesTableState(queries)),
resetInvoicesTableState: () => dispatch(resetInvoicesTableState()),
setInvoicesSelectedRows: (selectedRows) => dispatch(setInvoicesSelectedRows(selectedRows)),
});
export default connect(null, mapDipatchToProps);

View File

@@ -13,6 +13,7 @@ export default (mapState) => {
const mapped = {
invoicesTableState: getInvoicesTableState(state, props),
invoicesTableStateChanged: isInvoicesTableStateChanged(state, props),
invoicesSelectedRows: state.invoices?.selectedRows || [],
};
return mapState ? mapState(mapped, state, props) : mapped;
};

View File

@@ -5,9 +5,18 @@ const PaymentReceivedDeleteAlert = React.lazy(
() => import('@/containers/Alerts/PaymentReceived/PaymentReceivedDeleteAlert'),
);
const PaymentReceivedBulkDeleteAlert = React.lazy(
() =>
import('@/containers/Alerts/PaymentReceived/PaymentReceivedBulkDeleteAlert'),
);
/**
* PaymentReceives alert.
*/
export default [
{ name: 'payment-received-delete', component: PaymentReceivedDeleteAlert },
{
name: 'payments-received-bulk-delete',
component: PaymentReceivedBulkDeleteAlert,
},
];

View File

@@ -96,13 +96,13 @@ export function StatusAccessor(receipt) {
return (
<Choose>
<Choose.When condition={receipt.is_closed}>
<Tag intent={Intent.SUCCESS} round>
<Tag intent={Intent.SUCCESS} round minimal>
<T id={'closed'} />
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag intent={Intent.WARNING} round>
<Tag intent={Intent.WARNING} round minimal>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -150,6 +150,40 @@ export function useInactivateAccount(props) {
});
}
/**
* Deletes multiple accounts in bulk.
*/
export function useBulkDeleteAccounts(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('accounts/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Validates which accounts can be deleted in bulk.
*/
export function useValidateBulkDeleteAccounts(props) {
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) =>
apiRequest.post('accounts/validate-bulk-delete', { ids }),
{
...props,
},
);
}
/**
* Retrieve account transactions.
*/

View File

@@ -121,6 +121,25 @@ export function useDeleteBill(props) {
});
}
/**
* Deletes multiple bills in bulk.
*/
export function useBulkDeleteBills(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('bills/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
const transformBillsResponse = (response) => ({
bills: response.data.bills,
pagination: transformPagination(response.data.pagination),

View File

@@ -111,6 +111,25 @@ export function useDeleteCreditNote(props) {
});
}
/**
* Deletes multiple credit notes in bulk.
*/
export function useBulkDeleteCreditNotes(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('credit-notes/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
const transformCreditNotes = (res) => ({
creditNotes: res.data.credit_notes,
pagination: transformPagination(res.data.pagination),

View File

@@ -124,6 +124,25 @@ export function useDeleteEstimate(props) {
});
}
/**
* Deletes multiple sale estimates in bulk.
*/
export function useBulkDeleteEstimates(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('sale-estimates/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Mark the given estimate as delivered.
*/

View File

@@ -102,6 +102,25 @@ export function useDeleteExpense(props) {
});
}
/**
* Deletes multiple expenses in bulk.
*/
export function useBulkDeleteExpenses(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('expenses/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Edits the given expense.
*/

View File

@@ -125,6 +125,25 @@ export function useDeleteInvoice(props) {
});
}
/**
* Deletes multiple sale invoices in bulk.
*/
export function useBulkDeleteInvoices(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('sale-invoices/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
const transformInvoices = (res) => ({
invoices: res.data.sales_invoices,
pagination: transformPagination(res.data.pagination),

View File

@@ -73,6 +73,25 @@ export function useDeleteItem(props) {
});
}
/**
* Deletes multiple items in bulk.
*/
export function useBulkDeleteItems(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('items/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Activate the given item.
*/

View File

@@ -88,6 +88,25 @@ export function useDeleteJournal(props) {
});
}
/**
* Deletes multiple manual journals in bulk.
*/
export function useBulkDeleteManualJournals(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('manual-journals/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Publishes the given manual journal.
*/

View File

@@ -150,6 +150,25 @@ export function useDeletePaymentReceive(props) {
);
}
/**
* Deletes multiple payments received in bulk.
*/
export function useBulkDeletePaymentReceives(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('payments-received/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
/**
* Retrieve specific payment receive.
* @param {number} id - Payment receive.

View File

@@ -113,6 +113,25 @@ export function useDeleteVendorCredit(props) {
);
}
/**
* Deletes multiple vendor credits in bulk.
*/
export function useBulkDeleteVendorCredits(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(ids: number[]) => apiRequest.post('vendor-credits/bulk-delete', { ids }),
{
onSuccess: () => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
const transformVendorCreditsResponse = (response) => ({
vendorCredits: response.data.vendor_credits,
pagination: transformPagination(response.data.pagination),

View File

@@ -14,3 +14,9 @@ export const resetBillsTableState = () => {
};
};
export const setBillsSelectedRows = (selectedRows) => {
return {
type: 'BILLS/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:bills';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('BILLS', defaultTableQuery),
[`BILLS/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -14,4 +14,9 @@ export const resetCreditNoteTableState = () => {
};
};
export const setSelectedRowsItems = () => {};
export const setCreditNotesSelectedRows = (selectedRows) => {
return {
type: 'CREDIT_NOTES/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:credit_notes';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('CREDIT_NOTES', defaultTableQuery),
[`CREDIT_NOTES/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -13,3 +13,10 @@ export const resetEstimatesTableState = () => {
type: t.ESTIMATES_TABLE_STATE_RESET,
};
}
export const setEstimatesSelectedRows = (selectedRows) => {
return {
type: 'ESTIMATES/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:estimates';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('ESTIMATES', defaultTableQuery),
[`ESTIMATES/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -14,4 +14,9 @@ export const resetInvoicesTableState= () => {
};
}
export const setSelectedRowsItems = () => {};
export const setInvoicesSelectedRows = (selectedRows) => {
return {
type: 'INVOICES/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:invoices';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('INVOICES', defaultTableQuery),
[`INVOICES/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -13,3 +13,10 @@ export const resetPaymentReceivesTableState = () => {
type: t.PAYMENT_RECEIVES_TABLE_STATE_RESET
};
}
export const setPaymentReceivesSelectedRows = (selectedRows) => {
return {
type: 'PAYMENT_RECEIVES/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:paymentReceives';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('PAYMENT_RECEIVES', defaultTableQuery),
[`PAYMENT_RECEIVES/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:vendor_credits';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('VENDOR_CREDITS', defaultTableQuery),
[`VENDOR_CREDITS/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -14,4 +14,9 @@ export const resetVendorCreditTableState = () => {
};
};
export const setSelectedRowsItems = () => {};
export const setVendorCreditsSelectedRows = (selectedRows) => {
return {
type: 'VENDOR_CREDITS/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -15,4 +15,14 @@ export const resetAccountsTableState = () => {
return {
type: t.ACCOUNTS_TABLE_STATE_RESET,
};
};
/**
* Sets the selected rows for accounts table.
*/
export const setAccountsSelectedRows = (selectedRows) => {
return {
type: 'ACCOUNTS/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -13,6 +13,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:accounts';
@@ -26,6 +27,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('ACCOUNTS', defaultTableQuery),
[`ACCOUNTS/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -18,3 +18,9 @@ export const resetExpensesTableState = () => {
};
};
export const setExpensesSelectedRows = (selectedRows) => {
return {
type: 'EXPENSES/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -16,6 +16,7 @@ export const defaultTableQuery = {
// Initial state.
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:expenses';
@@ -29,6 +30,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('EXPENSES', defaultTableQuery),
[`EXPENSES/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -15,4 +15,9 @@ export const resetItemsTableState = () => {
};
}
export const setSelectedRowsItems = () => {};
export const setItemsSelectedRows = (selectedRows) => {
return {
type: 'ITEMS/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -29,6 +29,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('ITEMS', defaultTableQuery),
[`ITEMS/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},

View File

@@ -7,3 +7,10 @@ export const setManualJournalsTableState = (queries) => {
payload: { queries },
};
};
export const setManualJournalsSelectedRows = (selectedRows) => {
return {
type: 'MANUAL_JOURNALS/SET_SELECTED_ROWS',
payload: selectedRows,
};
};

View File

@@ -14,6 +14,7 @@ export const defaultTableQuery = {
const initialState = {
tableState: defaultTableQuery,
selectedRows: [],
};
const STORAGE_KEY = 'bigcapital:manualJournals';
@@ -27,6 +28,10 @@ const CONFIG = {
const reducerInstance = createReducer(initialState, {
...createTableStateReducers('MANUAL_JOURNALS', defaultTableQuery),
[`MANUAL_JOURNALS/SET_SELECTED_ROWS`]: (state, action) => {
state.selectedRows = action.payload;
},
[t.RESET]: () => {
purgeStoredState(CONFIG);
},