mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
refactoring: migrating to react-query to manage service-side state.
This commit is contained in:
70
client/src/containers/Alerts/Bills/BillDeleteAlert.js
Normal file
70
client/src/containers/Alerts/Bills/BillDeleteAlert.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
useIntl,
|
||||
} from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { useDeleteBill } from 'hooks/query';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Bill delete alert.
|
||||
*/
|
||||
function BillDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { billId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const { isLoading, mutateAsync: deleteBillMutate } = useDeleteBill();
|
||||
|
||||
// handle cancel Bill
|
||||
const handleCancel = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// handleConfirm delete invoice
|
||||
const handleConfirmBillDelete = () => {
|
||||
deleteBillMutate(billId).then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_bill_has_been_deleted_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'delete'} />}
|
||||
icon={'trash'}
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancel}
|
||||
onConfirm={handleConfirmBillDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'once_delete_this_bill_you_will_able_to_restore_it'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(BillDeleteAlert);
|
||||
69
client/src/containers/Alerts/Bills/BillOpenAlert.js
Normal file
69
client/src/containers/Alerts/Bills/BillOpenAlert.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import React from 'react';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { useOpenBill } from 'hooks/query';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Bill open alert.
|
||||
*/
|
||||
function BillOpenAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { billId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const { isLoading, mutateAsync: openBillMutate } = useOpenBill();
|
||||
|
||||
// Handle cancel open bill alert.
|
||||
const handleCancelOpenBill = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm bill open.
|
||||
const handleConfirmBillOpen = () => {
|
||||
openBillMutate(billId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_bill_has_been_opened_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.finally((error) => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'open'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelOpenBill}
|
||||
onConfirm={handleConfirmBillOpen}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'are_sure_to_open_this_bill'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(BillOpenAlert);
|
||||
Reference in New Issue
Block a user