This commit is contained in:
a.bouhuolia
2021-09-12 17:49:31 +02:00
21 changed files with 111 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
@@ -9,6 +9,7 @@ import { handleDeleteErrors } from 'containers/Accounts/utils';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useDeleteAccount } from 'hooks/query';
import { compose } from 'utils';
@@ -25,6 +26,9 @@ function AccountDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { isLoading, mutateAsync: deleteAccount } = useDeleteAccount();
@@ -41,11 +45,18 @@ function AccountDeleteAlert({
intent: Intent.SUCCESS,
});
closeAlert(name);
closeDrawer('account-drawer');
})
.catch(({ response: { data: { errors } } }) => {
handleDeleteErrors(errors);
closeAlert(name);
});
.catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
closeAlert(name);
},
);
};
return (
@@ -71,4 +82,5 @@ function AccountDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(AccountDeleteAlert);

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { handleDeleteErrors } from 'containers/Purchases/Bills/BillForm/utils';
import { useDeleteBill } from 'hooks/query';
@@ -23,8 +24,10 @@ function BillDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { isLoading, mutateAsync: deleteBillMutate } = useDeleteBill();
// Handle cancel Bill
@@ -40,6 +43,8 @@ function BillDeleteAlert({
message: intl.get('the_bill_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('bill-drawer');
})
.catch(
({
@@ -76,4 +81,5 @@ function BillDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(BillDeleteAlert);

View File

@@ -1,6 +1,6 @@
import React, { useCallback } from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { useDeleteEstimate } from 'hooks/query';
@@ -9,6 +9,7 @@ import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
@@ -24,8 +25,10 @@ function EstimateDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteEstimateMutate, isLoading } = useDeleteEstimate();
// handle cancel delete alert.
@@ -41,6 +44,7 @@ function EstimateDeleteAlert({
message: intl.get('the_estimate_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('estimate-detail-drawer');
})
.catch(({ errors }) => {})
.finally(() => {
@@ -71,4 +75,5 @@ function EstimateDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(EstimateDeleteAlert);

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useDeleteExpense } from 'hooks/query';
import { compose } from 'utils';
@@ -20,6 +21,9 @@ function ExpenseDeleteAlert({
// #withAlertStoreConnect
isOpen,
payload: { expenseId },
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteExpenseMutate, isLoading } = useDeleteExpense();
@@ -38,7 +42,7 @@ function ExpenseDeleteAlert({
}),
intent: Intent.SUCCESS,
});
closeAlert('expense-delete');
closeDrawer('expense-drawer');
})
.catch(
({
@@ -57,7 +61,10 @@ function ExpenseDeleteAlert({
});
}
},
);
)
.finally(() => {
closeAlert('expense-delete');
});
};
return (
@@ -81,4 +88,5 @@ function ExpenseDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(ExpenseDeleteAlert);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
import { useDeleteInvoice } from 'hooks/query';
@@ -9,6 +9,7 @@ import { handleDeleteErrors } from 'containers/Sales/Invoices/InvoicesLanding/co
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
@@ -24,8 +25,10 @@ function InvoiceDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteInvoiceMutate, isLoading } = useDeleteInvoice();
// handle cancel delete invoice alert.
@@ -41,10 +44,17 @@ function InvoiceDeleteAlert({
message: intl.get('the_invoice_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('invoice-detail-drawer');
})
.catch(({ response: { data: { errors } } }) => {
handleDeleteErrors(errors);
})
.catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
},
)
.finally(() => {
closeAlert(name);
});
@@ -73,4 +83,5 @@ function InvoiceDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(InvoiceDeleteAlert);

View File

@@ -1,14 +1,13 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import {
useDeleteInventoryAdjustment
} from 'hooks/query';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useDeleteInventoryAdjustment } from 'hooks/query';
import { compose } from 'utils';
@@ -24,12 +23,12 @@ function InventoryAdjustmentDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const {
mutateAsync: deleteInventoryAdjMutate,
isLoading
} = useDeleteInventoryAdjustment();
const { mutateAsync: deleteInventoryAdjMutate, isLoading } =
useDeleteInventoryAdjustment();
// handle cancel delete alert.
const handleCancelInventoryAdjustmentDelete = () => {
@@ -44,6 +43,7 @@ function InventoryAdjustmentDeleteAlert({
message: intl.get('the_adjustment_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('inventory-adjustment-drawer');
})
.catch((errors) => {})
.finally(() => {
@@ -76,4 +76,5 @@ function InventoryAdjustmentDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(InventoryAdjustmentDeleteAlert);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
@@ -10,6 +10,7 @@ import { useDeleteItem } from 'hooks/query';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withItemsActions from 'containers/Items/withItemsActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
@@ -28,9 +29,11 @@ function ItemDeleteAlert({
// #withItemsActions
setItemsTableState,
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteItem, isLoading } = useDeleteItem();
// Handle cancel delete item alert.
const handleCancelItemDelete = () => {
@@ -47,6 +50,7 @@ function ItemDeleteAlert({
});
// Reset to page number one.
setItemsTableState({ page: 1 });
closeDrawer('item-detail-drawer');
})
.catch(
({
@@ -86,4 +90,5 @@ export default compose(
withAlertStoreConnect(),
withAlertActions,
withItemsActions,
withDrawerActions,
)(ItemDeleteAlert);

View File

@@ -8,6 +8,7 @@ import { AppToaster } from 'components';
import withAlertActions from 'containers/Alert/withAlertActions';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
@@ -23,8 +24,10 @@ function JournalDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const { mutateAsync: deleteJournalMutate, isLoading } = useDeleteJournal();
// Handle cancel delete manual journal.
@@ -37,13 +40,13 @@ function JournalDeleteAlert({
deleteJournalMutate(manualJournalId)
.then(() => {
AppToaster.show({
message: intl.get(
'the_journal_has_been_deleted_successfully',
{ number: journalNumber },
),
message: intl.get('the_journal_has_been_deleted_successfully', {
number: journalNumber,
}),
intent: Intent.SUCCESS,
});
closeAlert(name);
closeDrawer('journal-drawer');
})
.catch(() => {
closeAlert(name);
@@ -71,4 +74,5 @@ function JournalDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions
)(JournalDeleteAlert);

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useDeletePaymentMade } from 'hooks/query';
@@ -23,12 +24,12 @@ function PaymentMadeDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const {
mutateAsync: deletePaymentMadeMutate,
isLoading,
} = useDeletePaymentMade();
const { mutateAsync: deletePaymentMadeMutate, isLoading } =
useDeletePaymentMade();
// Handle cancel payment made.
const handleCancelPaymentMadeDelete = () => {};
@@ -41,6 +42,7 @@ function PaymentMadeDeleteAlert({
message: intl.get('the_payment_made_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('payment-made-detail-drawer');
})
.finally(() => {
closeAlert(name);
@@ -68,4 +70,5 @@ function PaymentMadeDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions,
)(PaymentMadeDeleteAlert);

View File

@@ -1,14 +1,14 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { useDeleteReceipt } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
@@ -24,12 +24,11 @@ function NameDeleteAlert({
// #withAlertActions
closeAlert,
// #withDrawerActions
closeDrawer,
}) {
const {
mutateAsync: deleteReceiptMutate,
isLoading
} = useDeleteReceipt();
const { mutateAsync: deleteReceiptMutate, isLoading } = useDeleteReceipt();
// Handle cancel delete alert.
const handleCancelDeleteAlert = () => {
@@ -44,6 +43,7 @@ function NameDeleteAlert({
message: intl.get('the_receipt_has_been_deleted_successfully'),
intent: Intent.SUCCESS,
});
closeDrawer('receipt-detail-drawer');
})
.catch(() => {})
.finally(() => {
@@ -74,4 +74,5 @@ function NameDeleteAlert({
export default compose(
withAlertStoreConnect(),
withAlertActions,
withDrawerActions
)(NameDeleteAlert);

View File

@@ -92,7 +92,7 @@ function CustomersTable({
// Handle view detail contact.
const handleViewDetailCustomer = ({ id }) => {
openDrawer('contact-detail-drawer', { customerId: id });
openDrawer('customer-details-drawer', { customerId: id });
};
// Handle cell click.

View File

@@ -12,7 +12,6 @@ import { FormattedMessage as T } from 'components';
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import withDialogActions from 'containers/Dialog/withDialogActions';
import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { safeCallback } from 'utils';
@@ -28,9 +27,6 @@ function AccountDrawerActionBar({
// #withAlertsDialog
openAlert,
// #withDrawerActions
closeDrawer,
}) {
// Account drawer context.
const { account } = useAccountDrawerContext();
@@ -52,7 +48,6 @@ function AccountDrawerActionBar({
// Handle delete action account.
const onDeleteAccount = () => {
openAlert('account-delete', { accountId: account.id });
closeDrawer('account-drawer');
};
return (
@@ -85,5 +80,4 @@ function AccountDrawerActionBar({
export default compose(
withDialogActions,
withAlertsActions,
withDrawerActions,
)(AccountDrawerActionBar);

View File

@@ -36,16 +36,13 @@ function BillDetailActionsBar({
// Handle edit bill.
const onEditBill = () => {
return billId
? (history.push(`/bills/${billId}/edit`), closeDrawer('bill-drawer'))
: null;
history.push(`/bills/${billId}/edit`);
closeDrawer('bill-drawer');
};
// Handle delete bill.
const onDeleteBill = () => {
return billId
? (openAlert('bill-delete', { billId }), closeDrawer('bill-drawer'))
: null;
openAlert('bill-delete', { billId });
};
return (

View File

@@ -45,7 +45,6 @@ function EstimateDetailActionsBar({
// Handle delete sale estimate.
const handleDeleteEstimate = () => {
openAlert('estimate-delete', { estimateId });
closeDrawer('estimate-detail-drawer');
};
// Handle print estimate.

View File

@@ -39,7 +39,6 @@ function ExpenseDrawerActionBar({
// Handle the expense delete action.
const handleDeleteExpense = () => {
openAlert('expense-delete', { expenseId: expense.id });
closeDrawer('expense-drawer');
};
return (

View File

@@ -6,7 +6,6 @@ import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import { useInventoryAdjustmentDrawerContext } from './InventoryAdjustmentDrawerProvider';
import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { Icon, FormattedMessage as T } from 'components';
@@ -18,16 +17,12 @@ import { compose } from 'utils';
function InventoryAdjustmentDetailActionsBar({
// #withAlertsActions
openAlert,
// #withDrawerActions
closeDrawer,
}) {
const { inventoryId } = useInventoryAdjustmentDrawerContext();
// Handle delete inventory adjustment.
const handleDeleteInventoryAdjustment = () => {
openAlert('inventory-adjustment-delete', { inventoryId });
closeDrawer('inventory-adjustment-drawer');
};
return (
@@ -45,7 +40,4 @@ function InventoryAdjustmentDetailActionsBar({
);
}
export default compose(
withDrawerActions,
withAlertsActions,
)(InventoryAdjustmentDetailActionsBar);
export default compose(withAlertsActions)(InventoryAdjustmentDetailActionsBar);

View File

@@ -47,7 +47,6 @@ function InvoiceDetailActionsBar({
// Handle delete sale invoice.
const handleDeleteInvoice = () => {
openAlert('invoice-delete', { invoiceId });
closeDrawer('invoice-detail-drawer');
};
// Handle print invoices.

View File

@@ -34,18 +34,13 @@ function ReceiptDetailActionBar({
// Handle edit sale receipt.
const onEditReceipt = () => {
return receiptId
? (history.push(`/receipts/${receiptId}/edit`),
closeDrawer('receipt-detail-drawer'))
: null;
history.push(`/receipts/${receiptId}/edit`);
closeDrawer('receipt-detail-drawer');
};
// Handle delete sale receipt.
const onDeleteReceipt = () => {
return receiptId
? (openAlert('receipt-delete', { receiptId }),
closeDrawer('receipt-detail-drawer'))
: null;
openAlert('receipt-delete', { receiptId });
};
// Handle print receipt.
const onPrintReceipt = () => {

View File

@@ -113,8 +113,8 @@ function EstimateForm({
AppToaster.show({
message: intl.get(
isNewMode
? 'the_estimate_has_been_edited_successfully'
: 'the_estimate_has_been_created_successfully',
? 'the_estimate_has_been_created_successfully'
: 'the_estimate_has_been_edited_successfully',
{ number: values.estimate_number },
),
intent: Intent.SUCCESS,

View File

@@ -25,10 +25,7 @@ export default function InvoiceFloatingActions() {
const history = useHistory();
// Formik context.
const { isSubmitting } = useFormikContext();
// Formik context.
const { resetForm, submitForm } = useFormikContext();
const { resetForm, submitForm, isSubmitting } = useFormikContext();
// Invoice form context.
const { setSubmitPayload, invoice } = useInvoiceFormContext();

View File

@@ -177,7 +177,7 @@ export default compose(
withSettings(({ invoiceSettings }) => ({
invoiceNextNumber: invoiceSettings?.nextNumber,
invoiceNumberPrefix: invoiceSettings?.numberPrefix,
invoiceIncrementMode: invoiceSettings?.incrementMode,
invoiceIncrementMode: invoiceSettings?.autoIncrement,
})),
withCurrentOrganization(),
)(InvoiceForm);