From ffd6629b805e26ce46262d0c18889d8edafd6d62 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:37:03 +0200 Subject: [PATCH] feat(warehousetTransfer ): add warehouse status. --- .../TransferredWarehouseTransferAlert.js | 71 ++++++++++++++ .../WarehouseMarkPrimaryAlert.js | 0 .../WarehouseTransferDeleteAlert.js | 0 .../WarehouseTransferInitiateAlert.js | 71 ++++++++++++++ .../WarehouseTransferFloatingActions.js | 96 ++++++++++++++----- .../WarehouseTransferForm.js | 6 +- .../WarehouseTransferForm.schema.js | 2 + .../WarehouseTransferForm/utils.js | 2 + .../WarehouseTransfersDataTable.js | 11 +++ .../WarehouseTransfersLanding/components.js | 66 +++++++++++-- .../WarehousesTransfersAlerts.js | 20 +++- src/hooks/query/warehouses.js | 47 +++++++++ src/lang/en/index.json | 13 ++- 13 files changed, 369 insertions(+), 36 deletions(-) create mode 100644 src/containers/Alerts/WarehousesTransfer/TransferredWarehouseTransferAlert.js rename src/containers/Alerts/{Warehouses => WarehousesTransfer}/WarehouseMarkPrimaryAlert.js (100%) rename src/containers/Alerts/{Warehouses => WarehousesTransfer}/WarehouseTransferDeleteAlert.js (100%) create mode 100644 src/containers/Alerts/WarehousesTransfer/WarehouseTransferInitiateAlert.js diff --git a/src/containers/Alerts/WarehousesTransfer/TransferredWarehouseTransferAlert.js b/src/containers/Alerts/WarehousesTransfer/TransferredWarehouseTransferAlert.js new file mode 100644 index 000000000..a649c44b0 --- /dev/null +++ b/src/containers/Alerts/WarehousesTransfer/TransferredWarehouseTransferAlert.js @@ -0,0 +1,71 @@ +import React from 'react'; +import { FormattedMessage as T } from 'components'; +import intl from 'react-intl-universal'; +import { Intent, Alert } from '@blueprintjs/core'; + +import { useTransferredWarehouseTransfer } from 'hooks/query'; +import { AppToaster } from 'components'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * warehouse transfer transferred alert. + * @returns + */ +function TransferredWarehouseTransferAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { warehouseTransferId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: transferredWarehouseTransferMutate, isLoading } = + useTransferredWarehouseTransfer(); + + // handle cancel alert. + const handleCancelAlert = () => { + closeAlert(name); + }; + + // Handle confirm alert. + const handleConfirmTransferred = () => { + transferredWarehouseTransferMutate(warehouseTransferId) + .then(() => { + AppToaster.show({ + message: intl.get('warehouse_transfer.alert.transferred_warehouse'), + intent: Intent.SUCCESS, + }); + }) + .catch((error) => {}) + .finally(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={isOpen} + onCancel={handleCancelAlert} + onConfirm={handleConfirmTransferred} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(TransferredWarehouseTransferAlert); diff --git a/src/containers/Alerts/Warehouses/WarehouseMarkPrimaryAlert.js b/src/containers/Alerts/WarehousesTransfer/WarehouseMarkPrimaryAlert.js similarity index 100% rename from src/containers/Alerts/Warehouses/WarehouseMarkPrimaryAlert.js rename to src/containers/Alerts/WarehousesTransfer/WarehouseMarkPrimaryAlert.js diff --git a/src/containers/Alerts/Warehouses/WarehouseTransferDeleteAlert.js b/src/containers/Alerts/WarehousesTransfer/WarehouseTransferDeleteAlert.js similarity index 100% rename from src/containers/Alerts/Warehouses/WarehouseTransferDeleteAlert.js rename to src/containers/Alerts/WarehousesTransfer/WarehouseTransferDeleteAlert.js diff --git a/src/containers/Alerts/WarehousesTransfer/WarehouseTransferInitiateAlert.js b/src/containers/Alerts/WarehousesTransfer/WarehouseTransferInitiateAlert.js new file mode 100644 index 000000000..699f89e03 --- /dev/null +++ b/src/containers/Alerts/WarehousesTransfer/WarehouseTransferInitiateAlert.js @@ -0,0 +1,71 @@ +import React from 'react'; +import { FormattedMessage as T } from 'components'; +import intl from 'react-intl-universal'; +import { Intent, Alert } from '@blueprintjs/core'; + +import { useInitiateWarehouseTransfer } from 'hooks/query'; +import { AppToaster } from 'components'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * warehouse transfer initiate alert. + * @returns + */ +function WarehouseTransferInitiateAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { warehouseTransferId }, + + // #withAlertActions + closeAlert, +}) { + const { mutateAsync: initialWarehouseTransferMutate, isLoading } = + useInitiateWarehouseTransfer(); + + // handle cancel alert. + const handleCancelAlert = () => { + closeAlert(name); + }; + + // Handle confirm alert. + const handleConfirmInitiated = () => { + initialWarehouseTransferMutate(warehouseTransferId) + .then(() => { + AppToaster.show({ + message: intl.get('warehouse_transfer.alert.initiate_warehouse'), + intent: Intent.SUCCESS, + }); + }) + .catch((error) => {}) + .finally(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={isOpen} + onCancel={handleCancelAlert} + onConfirm={handleConfirmInitiated} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(WarehouseTransferInitiateAlert); diff --git a/src/containers/WarehouseTransfers/WarehouseTransferForm/WarehouseTransferFloatingActions.js b/src/containers/WarehouseTransfers/WarehouseTransferForm/WarehouseTransferFloatingActions.js index 9362a1ce5..bb8964055 100644 --- a/src/containers/WarehouseTransfers/WarehouseTransferForm/WarehouseTransferFloatingActions.js +++ b/src/containers/WarehouseTransfers/WarehouseTransferForm/WarehouseTransferFloatingActions.js @@ -10,7 +10,7 @@ import { Menu, MenuItem, } from '@blueprintjs/core'; -import { FormattedMessage as T } from 'components'; +import { If, FormattedMessage as T } from 'components'; import classNames from 'classnames'; import { useFormikContext } from 'formik'; import { CLASSES } from 'common/classes'; @@ -26,15 +26,43 @@ export default function WarehouseTransferFloatingActions() { const history = useHistory(); // Formik form context. - const { isSubmitting, submitForm, resetForm, values, errors } = - useFormikContext(); + const { isSubmitting, submitForm, resetForm } = useFormikContext(); // Warehouse tansfer form context. - const { isNewMode, setSubmitPayload } = useWarehouseTransferFormContext(); + const { warehouseTransfer, setSubmitPayload } = + useWarehouseTransferFormContext(); - // Handle submit button click. - const handleSubmitBtnClick = (event) => { - setSubmitPayload({ redirect: true }); + // Handle submit initiate button click. + const handleSubmitInitiateBtnClick = (event) => { + setSubmitPayload({ redirect: true, initiate: true, deliver: false }); + submitForm(); + }; + + // Handle submit transferred button click. + const handleSubmitTransferredBtnClick = (event) => { + setSubmitPayload({ redirect: true, initiate: true, deliver: true }); + submitForm(); + }; + + // Handle submit as draft button click. + const handleSubmitDraftBtnClick = (event) => { + setSubmitPayload({ redirect: true, initiate: false, deliver: false }); + submitForm(); + }; + // Handle submit as draft & new button click. + const handleSubmitDraftAndNewBtnClick = (event) => { + setSubmitPayload({ + redirect: false, + initiate: false, + deliver: false, + resetForm: true, + }); + submitForm(); + }; + + // Handle submit as draft & continue editing button click. + const handleSubmitDraftContinueEditingBtnClick = (event) => { + setSubmitPayload({ redirect: false, deliver: false, initiate: false }); submitForm(); }; @@ -43,12 +71,6 @@ export default function WarehouseTransferFloatingActions() { resetForm(); }; - // Handle submit & new button click. - const handleSubmitAndNewClick = (event) => { - setSubmitPayload({ redirect: false, resetForm: true }); - submitForm(); - }; - // Handle cancel button click. const handleCancelBtnClick = (event) => { history.goBack(); @@ -56,27 +78,23 @@ export default function WarehouseTransferFloatingActions() { return (
- {/* ----------- Save and New ----------- */} + {/* ----------- Save Intitate & transferred ----------- */}