feat(warehouse): add credit & edit & delete warehouse.

This commit is contained in:
elforjani13
2022-02-01 21:05:54 +02:00
parent 0d11ea7c5e
commit fc097378cb
19 changed files with 524 additions and 203 deletions

View File

@@ -0,0 +1,77 @@
import React from 'react';
import intl from 'react-intl-universal';
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
import { useDeleteWarehouse } from 'hooks/query';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
* Warehouse delete alert
* @returns
*/
function WarehouseDeleteAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { warehouseId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: deleteWarehouseMutate, isLoading } =
useDeleteWarehouse();
// handle cancel delete warehouse alert.
const handleCancelDeleteAlert = () => {
closeAlert(name);
};
// handleConfirm delete invoice
const handleConfirmWarehouseDelete = () => {
deleteWarehouseMutate(warehouseId)
.then(() => {
AppToaster.show({
message: intl.get('warehouse.alert.delete_message'),
intent: Intent.SUCCESS,
});
})
.catch(
({
response: {
data: { errors },
},
}) => {},
)
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'delete'} />}
icon="trash"
intent={Intent.DANGER}
isOpen={isOpen}
onCancel={handleCancelDeleteAlert}
onConfirm={handleConfirmWarehouseDelete}
loading={isLoading}
>
<p>
<FormattedHTMLMessage id={'warehouse.once_delete_this_warehouse'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(WarehouseDeleteAlert);