mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Contact activate & inactivate.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import React from 'react';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useActivateContact } from 'hooks/query';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Contact activate alert.
|
||||
*/
|
||||
function ContactActivateAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { contactId, service },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: activateContact, isLoading } = useActivateContact();
|
||||
|
||||
// Handle activate contact alert cancel.
|
||||
const handleCancelActivateContact = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm contact activated.
|
||||
const handleConfirmContactActivate = () => {
|
||||
activateContact(contactId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_contact_has_been_activated_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch((error) => {})
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'activate'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelActivateContact}
|
||||
loading={isLoading}
|
||||
onConfirm={handleConfirmContactActivate}
|
||||
>
|
||||
<p>{intl.get('are_sure_to_activate_this_contact')}</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(ContactActivateAlert);
|
||||
@@ -0,0 +1,70 @@
|
||||
import React from 'react';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useInactivateContact } from 'hooks/query';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Contact inactivate alert.
|
||||
*/
|
||||
function ContactInactivateAlert({
|
||||
name,
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { contactId, service },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: inactivateContact, isLoading } = useInactivateContact();
|
||||
|
||||
// Handle cancel inactivate alert.
|
||||
const handleCancelInactivateContact = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm contact Inactive.
|
||||
const handleConfirmContactInactive = () => {
|
||||
inactivateContact(contactId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_contact_has_been_inactivated_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch((error) => {})
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'inactivate'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelInactivateContact}
|
||||
onConfirm={handleConfirmContactInactive}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
{intl.get('are_sure_to_inactive_this_contact', {
|
||||
name: service,
|
||||
})}
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(ContactInactivateAlert);
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import CustomerDeleteAlert from 'containers/Alerts/Customers/CustomerDeleteAlert';
|
||||
// import CustomerBulkDeleteAlert from 'containers/Alerts/Customers/CustomerBulkDeleteAlert';
|
||||
import ContactActivateAlert from '../../containers/Alerts/Contacts/ContactActivateAlert';
|
||||
import ContactInactivateAlert from '../../containers/Alerts/Contacts/ContactInactivateAlert';
|
||||
|
||||
/**
|
||||
* Customers alert.
|
||||
@@ -9,6 +11,8 @@ export default function ItemsAlerts() {
|
||||
return (
|
||||
<div>
|
||||
<CustomerDeleteAlert name={'customer-delete'} />
|
||||
<ContactActivateAlert name={'contact-activate'} />
|
||||
<ContactInactivateAlert name={'contact-inactivate'} />
|
||||
{/* <CustomerBulkDeleteAlert name={'customers-bulk-delete'} /> */}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -72,6 +72,19 @@ function CustomersTable({
|
||||
openDialog('contact-duplicate', { contactId: id });
|
||||
};
|
||||
|
||||
// Handle cancel/confirm inactive.
|
||||
const handleInactiveCustomer = ({ id, contact_service }) => {
|
||||
openAlert('contact-inactivate', {
|
||||
contactId: id,
|
||||
service: contact_service,
|
||||
});
|
||||
};
|
||||
|
||||
// Handle cancel/confirm activate.
|
||||
const handleActivateCustomer = ({ id, contact_service }) => {
|
||||
openAlert('contact-activate', { contactId: id, service: contact_service });
|
||||
};
|
||||
|
||||
if (isEmptyStatus) {
|
||||
return <CustomersEmptyStatus />;
|
||||
}
|
||||
@@ -102,6 +115,8 @@ function CustomersTable({
|
||||
onDelete: handleCustomerDelete,
|
||||
onEdit: handleCustomerEdit,
|
||||
onDuplicate: handleContactDuplicate,
|
||||
onInactivate: handleInactiveCustomer,
|
||||
onActivate: handleActivateCustomer,
|
||||
}}
|
||||
ContextMenu={ActionsMenu}
|
||||
/>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Position,
|
||||
Intent,
|
||||
} from '@blueprintjs/core';
|
||||
import { Icon, Money } from 'components';
|
||||
import { Icon, Money, If } from 'components';
|
||||
import { safeCallback } from 'utils';
|
||||
import { firstLettersArgs } from 'utils';
|
||||
import intl from 'react-intl-universal';
|
||||
@@ -18,10 +18,8 @@ import intl from 'react-intl-universal';
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
row: { original },
|
||||
payload: { onEdit, onDelete, onDuplicate },
|
||||
payload: { onEdit, onDelete, onDuplicate, onInactivate, onActivate },
|
||||
}) {
|
||||
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
@@ -39,6 +37,20 @@ export function ActionsMenu({
|
||||
text={intl.get('duplicate')}
|
||||
onClick={safeCallback(onDuplicate, original)}
|
||||
/>
|
||||
<If condition={original.active}>
|
||||
<MenuItem
|
||||
text={intl.get('inactivate_item')}
|
||||
icon={<Icon icon="pause-16" iconSize={16} />}
|
||||
onClick={safeCallback(onInactivate, original)}
|
||||
/>
|
||||
</If>
|
||||
<If condition={!original.active}>
|
||||
<MenuItem
|
||||
text={intl.get('activate_item')}
|
||||
icon={<Icon icon="play-16" iconSize={16} />}
|
||||
onClick={safeCallback(onActivate, original)}
|
||||
/>
|
||||
</If>
|
||||
<MenuItem
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={intl.get('delete_customer')}
|
||||
@@ -74,8 +86,6 @@ export function BalanceAccessor(row) {
|
||||
* Retrieve customers table columns.
|
||||
*/
|
||||
export function useCustomersTableColumns() {
|
||||
|
||||
|
||||
return useMemo(
|
||||
() => [
|
||||
{
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import React from 'react';
|
||||
import VendorDeleteAlert from 'containers/Alerts/Vendors/VendorDeleteAlert';
|
||||
import ContactActivateAlert from '../../containers/Alerts/Contacts/ContactActivateAlert';
|
||||
import ContactInactivateAlert from '../../containers/Alerts/Contacts/ContactInactivateAlert';
|
||||
|
||||
export default function VendorsAlerts() {
|
||||
return (
|
||||
<div>
|
||||
<VendorDeleteAlert name={'vendor-delete'} />
|
||||
<ContactActivateAlert name={'contact-activate'} />
|
||||
<ContactInactivateAlert name={'contact-inactivate'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,19 @@ function VendorsTable({
|
||||
history.push(`/vendors/${vendor.id}/edit`);
|
||||
};
|
||||
|
||||
// Handle cancel/confirm inactive.
|
||||
const handleInactiveVendor = ({ id, contact_service }) => {
|
||||
openAlert('contact-inactivate', {
|
||||
contactId: id,
|
||||
service: contact_service,
|
||||
});
|
||||
};
|
||||
|
||||
// Handle cancel/confirm activate.
|
||||
const handleActivateVendor = ({ id, contact_service }) => {
|
||||
openAlert('contact-activate', { contactId: id, service: contact_service });
|
||||
};
|
||||
|
||||
// Handle click delete vendor.
|
||||
const handleDeleteVendor = ({ id }) => {
|
||||
openAlert('vendor-delete', { vendorId: id });
|
||||
@@ -104,6 +117,8 @@ function VendorsTable({
|
||||
onEdit: handleEditVendor,
|
||||
onDelete: handleDeleteVendor,
|
||||
onDuplicate: handleContactDuplicate,
|
||||
onInactivate: handleInactiveVendor,
|
||||
onActivate: handleActivateVendor,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
Intent,
|
||||
} from '@blueprintjs/core';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Icon, Money } from 'components';
|
||||
import { Icon, Money, If } from 'components';
|
||||
import { safeCallback, firstLettersArgs } from 'utils';
|
||||
|
||||
/**
|
||||
@@ -17,10 +17,8 @@ import { safeCallback, firstLettersArgs } from 'utils';
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
row: { original },
|
||||
payload: { onEdit, onDelete, onDuplicate },
|
||||
payload: { onEdit, onDelete, onDuplicate, onInactivate, onActivate },
|
||||
}) {
|
||||
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
@@ -38,6 +36,20 @@ export function ActionsMenu({
|
||||
text={intl.get('duplicate')}
|
||||
onClick={safeCallback(onDuplicate, original)}
|
||||
/>
|
||||
<If condition={original.active}>
|
||||
<MenuItem
|
||||
text={intl.get('inactivate_item')}
|
||||
icon={<Icon icon="pause-16" iconSize={16} />}
|
||||
onClick={safeCallback(onInactivate, original)}
|
||||
/>
|
||||
</If>
|
||||
<If condition={!original.active}>
|
||||
<MenuItem
|
||||
text={intl.get('activate_item')}
|
||||
icon={<Icon icon="play-16" iconSize={16} />}
|
||||
onClick={safeCallback(onActivate, original)}
|
||||
/>
|
||||
</If>
|
||||
<MenuItem
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={intl.get('delete_vendor')}
|
||||
@@ -87,8 +99,6 @@ export function BalanceAccessor({ closing_balance, currency_code }) {
|
||||
* Retrieve the vendors table columns.
|
||||
*/
|
||||
export function useVendorsTableColumns() {
|
||||
|
||||
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
@@ -127,7 +137,7 @@ export function useVendorsTableColumns() {
|
||||
accessor: BalanceAccessor,
|
||||
className: 'receivable_balance',
|
||||
width: 100,
|
||||
}
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user