From ac99a6ca75073b0dba43c1bd6abecb67fd5a709c Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 6 Dec 2021 16:28:42 +0200 Subject: [PATCH] feat: add status & opened alert in credit & vendor. --- .../CreditNotes/CreditNoteOpenedAlert.js | 68 +++++++ .../VendorCreditOpenedAlert.js | 69 +++++++ .../RefundCreditNoteForm.js | 2 +- .../RefundCreditNoteFormProvider.js | 4 +- .../RefundVendorCreditForm.js | 2 +- .../RefundVendorCreditFormProvider.js | 4 +- .../CreditNoteDetailActionsBar.js | 28 +-- .../VendorCreditDetailActionsBar.js | 28 +-- .../VendorCreditNoteFloatingActions.js | 181 ++++++++++-------- .../CreditNoteForm/VendorCreditNoteForm.js | 1 + .../VendorCreditNoteForm.schema.js | 1 + .../CreditNotes/CreditNoteForm/utils.js | 4 +- .../VendorsCreditNoteDataTable.js | 5 + .../CreditNotesLanding/components.js | 66 +++++-- .../CreditNotes/VendorCreditNotesAlerts.js | 8 + .../CreditNoteFloatingActions.js | 180 +++++++++-------- .../CreditNoteForm/CreditNoteForm.js | 1 + .../CreditNoteForm/CreditNoteForm.schema.js | 1 + .../Sales/CreditNotes/CreditNoteForm/utils.js | 8 +- .../Sales/CreditNotes/CreditNotesAlerts.js | 8 + .../CreditNotesDataTable.js | 6 + .../CreditNotesLanding/components.js | 67 +++++-- src/hooks/query/creditNote.js | 19 ++ src/hooks/query/vendorCredit.js | 22 +++ src/lang/en/index.json | 6 +- 25 files changed, 567 insertions(+), 222 deletions(-) create mode 100644 src/containers/Alerts/CreditNotes/CreditNoteOpenedAlert.js create mode 100644 src/containers/Alerts/VendorCeditNotes/VendorCreditOpenedAlert.js diff --git a/src/containers/Alerts/CreditNotes/CreditNoteOpenedAlert.js b/src/containers/Alerts/CreditNotes/CreditNoteOpenedAlert.js new file mode 100644 index 000000000..58b9e8554 --- /dev/null +++ b/src/containers/Alerts/CreditNotes/CreditNoteOpenedAlert.js @@ -0,0 +1,68 @@ +import React from 'react'; +import { FormattedMessage as T } from 'components'; +import intl from 'react-intl-universal'; +import { Intent, Alert } from '@blueprintjs/core'; + +import { useOpenCreditNote } from 'hooks/query'; +import { AppToaster } from 'components'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * Credit note opened alert. + */ +function CreditNoteOpenedAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { creditNoteId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: openCreditNoteMutate, isLoading } = useOpenCreditNote(); + + // Handle cancel opened credit note alert. + const handleAlertCancel = () => { + closeAlert(name); + }; + + // Handle confirm credit note opened. + const handleAlertConfirm = () => { + openCreditNoteMutate(creditNoteId) + .then(() => { + AppToaster.show({ + message: intl.get('credit_note_opened.alert.success_message'), + intent: Intent.SUCCESS, + }); + }) + .catch((error) => {}) + .finally(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={isOpen} + onCancel={handleAlertCancel} + onConfirm={handleAlertConfirm} + loading={isLoading} + > +

+ +

+
+ ); +} +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(CreditNoteOpenedAlert); diff --git a/src/containers/Alerts/VendorCeditNotes/VendorCreditOpenedAlert.js b/src/containers/Alerts/VendorCeditNotes/VendorCreditOpenedAlert.js new file mode 100644 index 000000000..56c0fe5bf --- /dev/null +++ b/src/containers/Alerts/VendorCeditNotes/VendorCreditOpenedAlert.js @@ -0,0 +1,69 @@ +import React from 'react'; +import { FormattedMessage as T } from 'components'; +import intl from 'react-intl-universal'; +import { Intent, Alert } from '@blueprintjs/core'; + +import { useOpenVendorCredit } from 'hooks/query'; +import { AppToaster } from 'components'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * Vendor credit opened alert. + */ +function VendorCreditOpenedAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { vendorCreditId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: openVendorCreditMutate, isLoading } = + useOpenVendorCredit(); + + // Handle cancel opened credit note alert. + const handleAlertCancel = () => { + closeAlert(name); + }; + + // Handle confirm vendor credit as opened. + const handleAlertConfirm = () => { + openVendorCreditMutate(vendorCreditId) + .then(() => { + AppToaster.show({ + message: intl.get('vendor_credit_opened.alert.success_message'), + intent: Intent.SUCCESS, + }); + }) + .catch((error) => {}) + .finally(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={isOpen} + onCancel={handleAlertCancel} + onConfirm={handleAlertConfirm} + loading={isLoading} + > +

+ +

+
+ ); +} +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(VendorCreditOpenedAlert); diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js index d717dc0d0..05600768f 100644 --- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js +++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js @@ -41,7 +41,7 @@ function RefundCreditNoteForm({ // Handles the form submit. const handleFormSubmit = (values, { setSubmitting, setFieldError }) => { const form = { - ...omit(values, ['currency_code', 'formatted_amount']), + ...omit(values, ['currency_code', 'credits_remaining']), }; // Handle request response success. diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormProvider.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormProvider.js index 596bd4dd0..978421272 100644 --- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormProvider.js +++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormProvider.js @@ -31,8 +31,8 @@ function RefundCreditNoteFormProvider({ creditNoteId, dialogName, ...props }) { // State provider. const provider = { creditNote: { - ...pick(creditNote, ['id', 'formatted_amount', 'currency_code']), - amount: creditNote.formatted_amount, + ...pick(creditNote, ['id', 'credits_remaining', 'currency_code']), + amount: creditNote.credits_remaining, }, accounts, dialogName, diff --git a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditForm.js b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditForm.js index 048c3beb5..0882a4dd8 100644 --- a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditForm.js +++ b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditForm.js @@ -41,7 +41,7 @@ function RefundVendorCreditForm({ // Handles the form submit. const handleFormSubmit = (values, { setSubmitting, setFieldError }) => { const form = { - ...omit(values, ['currency_code', 'formatted_amount']), + ...omit(values, ['currency_code', 'credits_remaining']), }; // Handle request response success. diff --git a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js index c9cb6e779..0f97aa814 100644 --- a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js +++ b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js @@ -31,8 +31,8 @@ function RefundVendorCreditFormProvider({ // State provider. const provider = { vendorCredit: { - ...pick(vendorCredit, ['id', 'formatted_amount', 'currency_code']), - amount: vendorCredit.formatted_amount, + ...pick(vendorCredit, ['id', 'credits_remaining', 'currency_code']), + amount: vendorCredit.credits_remaining, }, accounts, dialogName, diff --git a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js index b6e876638..dbe27e0c1 100644 --- a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js +++ b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js @@ -15,7 +15,13 @@ import withDialogActions from 'containers/Dialog/withDialogActions'; import withAlertsActions from 'containers/Alert/withAlertActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; -import { Icon, FormattedMessage as T, MoreMenuItems, Can } from 'components'; +import { + Icon, + FormattedMessage as T, + If, + MoreMenuItems, + Can, +} from 'components'; import { compose } from 'utils'; @@ -32,7 +38,7 @@ function CreditNoteDetailActionsBar({ // #withDrawerActions closeDrawer, }) { - const { creditNoteId } = useCreditNoteDetailDrawerContext(); + const { creditNoteId, creditNote } = useCreditNoteDetailDrawerContext(); const history = useHistory(); @@ -61,15 +67,15 @@ function CreditNoteDetailActionsBar({ onClick={handleEditCreditNote} /> -