feat: Contact activate & inactivate.

This commit is contained in:
elforjani3
2021-08-06 17:30:07 +02:00
parent 7d07238c6a
commit 0dc8f43ac7
12 changed files with 276 additions and 17 deletions

View File

@@ -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);

View File

@@ -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);