This commit is contained in:
a.bouhuolia
2021-08-07 08:17:43 +02:00
17 changed files with 395 additions and 22 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);

View File

@@ -0,0 +1,71 @@
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { FormattedMessage as T } from 'components';
import intl from 'react-intl-universal';
import { usePublishInventoryAdjustment } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertActions from 'containers/Alert/withAlertActions';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
import { compose } from 'utils';
/**
* Inventory Adjustment publish alert.
*/
function InventoryAdjustmentPublishAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { inventoryId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: publishInventoryAdjustmentMutate, isLoading } =
usePublishInventoryAdjustment();
// Handle cancel inventory adjustment alert.
const handleCancelPublish = () => {
closeAlert(name);
};
// Handle publish inventory adjustment confirm.
const handleConfirmPublish = () => {
publishInventoryAdjustmentMutate(inventoryId)
.then(() => {
AppToaster.show({
message: intl.get('the_inventory_adjustment_has_been_published'),
intent: Intent.SUCCESS,
});
closeAlert(name);
})
.catch((error) => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'publish'} />}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancelPublish}
onConfirm={handleConfirmPublish}
loading={isLoading}
>
<p>
<T id={'are_sure_to_publish_this_inventory_adjustment'} />
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(InventoryAdjustmentPublishAlert);

View File

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

View File

@@ -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}
/>

View File

@@ -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(
() => [
{

View File

@@ -39,6 +39,11 @@ function InventoryAdjustmentDataTable({
openAlert('inventory-adjustment-delete', { inventoryId: id });
};
// Handle the inventory adjustment publish action.
const handlePublishInventoryAdjustment = ({ id }) => {
openAlert('inventory-adjustment-publish', { inventoryId: id });
};
// Inventory adjustments columns.
const columns = useInventoryAdjustmentsColumns();
@@ -72,6 +77,7 @@ function InventoryAdjustmentDataTable({
autoResetPage={false}
payload={{
onDelete: handleDeleteAdjustment,
onPublish: handlePublishInventoryAdjustment,
}}
ContextMenu={ActionsMenu}
noResults={intl.get('there_is_no_inventory_adjustments_transactions_yet')}

View File

@@ -1,10 +1,12 @@
import React from 'react';
import InventoryAdjustmentDeleteAlert from 'containers/Alerts/Items/InventoryAdjustmentDeleteAlert';
import InventoryAdjustmentPublishAlert from 'containers/Alerts/Items/InventoryAdjustmentPublishAlert';
export default function InventoryAdjustmentsAlerts() {
return (
<div className={'inventory-adjustments-alert'}>
<InventoryAdjustmentDeleteAlert name={'inventory-adjustment-delete'} />
<InventoryAdjustmentPublishAlert name={'inventory-adjustment-publish'} />
</div>
);
}

View File

@@ -12,7 +12,7 @@ import {
import intl from 'react-intl-universal';
import moment from 'moment';
import { FormattedMessage as T } from 'components';
import { FormattedMessage as T } from 'components';
import { isNumber } from 'lodash';
import { Icon, Money, If } from 'components';
import { isBlank, safeCallback } from 'utils';
@@ -93,7 +93,7 @@ export const ItemTypeAccessor = (row) => {
export const ActionsMenu = ({
row: { original },
payload: { onDelete },
payload: { onDelete, onPublish },
}) => {
return (
<Menu>
@@ -102,6 +102,13 @@ export const ActionsMenu = ({
text={intl.get('view_details')}
/>
<MenuDivider />
<If condition={!original.is_published}>
<MenuItem
icon={<Icon icon={'arrow-to-top'} size={16} />}
text={intl.get('publish_expense')}
onClick={safeCallback(onPublish, original)}
/>
</If>
<MenuItem
text={intl.get('delete_adjustment')}
intent={Intent.DANGER}
@@ -113,12 +120,13 @@ export const ActionsMenu = ({
};
export const ActionsCell = (props) => {
return (<Popover
content={<ActionsMenu {...props} />}
position={Position.RIGHT_BOTTOM}
>
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
</Popover>
return (
<Popover
content={<ActionsMenu {...props} />}
position={Position.RIGHT_BOTTOM}
>
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
</Popover>
);
};
@@ -126,8 +134,6 @@ export const ActionsCell = (props) => {
* Retrieve inventory adjustments columns.
*/
export const useInventoryAdjustmentsColumns = () => {
return React.useMemo(
() => [
{

View File

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

View File

@@ -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,
}}
/>
);

View File

@@ -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,7 +17,7 @@ import { safeCallback, firstLettersArgs } from 'utils';
*/
export function ActionsMenu({
row: { original },
payload: { onEdit, onDelete, onDuplicate },
payload: { onEdit, onDelete, onDuplicate, onInactivate, onActivate },
}) {
return (
<Menu>
@@ -36,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')}
@@ -123,7 +137,7 @@ export function useVendorsTableColumns() {
accessor: BalanceAccessor,
className: 'receivable_balance',
width: 100,
}
},
],
[],
);

View File

@@ -1,5 +1,15 @@
import { useMutation, useQueryClient } from 'react-query';
import useApiRequest from '../useRequest';
import { useQueryTenant } from '../useQueryRequest';
import t from './types';
// Common invalidate queries.
const commonInvalidateQueries = (queryClient) => {
// Invalidate vendors.
queryClient.invalidateQueries(t.VENDORS);
// Invalidate customers.
queryClient.invalidateQueries(t.CUSTOMERS);
};
/**
* Retrieve the contact duplicate.
@@ -33,3 +43,41 @@ export function useAutoCompleteContacts(props) {
},
);
}
/**
* Activate the given Contact.
*/
export function useActivateContact(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation((id) => apiRequest.post(`contacts/${id}/activate`), {
onSuccess: (res, id) => {
// Invalidate specific contact.
queryClient.invalidateQueries([t.CONTACT, id]);
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
});
}
/**
* Inactivate the given contact.
*/
export function useInactivateContact(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation((id) => apiRequest.post(`contacts/${id}/inactivate`), {
onSuccess: (res, id) => {
// Invalidate specific item.
queryClient.invalidateQueries([t.CONTACT, id]);
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
});
}

View File

@@ -84,3 +84,24 @@ export function useInventoryAdjustments(query, props) {
},
);
}
/**
* Publishes the given inventory adjustment.
*/
export function usePublishInventoryAdjustment(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.post(`inventory_adjustments/${id}/publish`),
{
onSuccess: (res, id) => {
// Invalidate specific inventory adjustment.
queryClient.invalidateQueries([t.INVENTORY_ADJUSTMENT, id]);
commonInvalidateQueries(queryClient);
},
...props,
},
);
}

View File

@@ -60,6 +60,7 @@ const SALE_RECEIPTS = {
const INVENTORY_ADJUSTMENTS = {
INVENTORY_ADJUSTMENTS: 'INVENTORY_ADJUSTMENTS',
INVENTORY_ADJUSTMENT: 'INVENTORY_ADJUSTMENT',
};
const CURRENCIES = {
@@ -125,6 +126,11 @@ const LANDED_COSTS = {
LANDED_COST_TRANSACTION: 'LANDED_COST_TRANSACTION',
};
const CONTACTS = {
CONTACTS: 'CONTACTS',
CONTACT: 'CONTACT',
};
export default {
...ACCOUNTS,
...BILLS,
@@ -146,4 +152,5 @@ export default {
...EXPENSES,
...MANUAL_JOURNALS,
...LANDED_COSTS,
...CONTACTS,
};

View File

@@ -1198,5 +1198,12 @@
"non-inventory":"غير مخزون",
"terms_conditions":"الشروط والأحكام",
"your_invoice_numbers_are_set_on_auto_increment_mod_are_you_sure_changing_this_setting":"Your invoice numbers are set on auto-increment mod. Are you sure changing this setting?",
"auto_incrementing_number":"Auto-incrementing number"
}
"auto_incrementing_number":"Auto-incrementing number",
"the_inventory_adjustment_has_been_published": "تم نشر تسوية المخزون",
"are_sure_to_publish_this_inventory_adjustment": "هل أنت متأكد أنك تريد نشر هذا المخزون ؟",
"the_contact_has_been_activated_successfully": "تم تفعيل جهة اتصال بنجاح.",
"the_contact_has_been_inactivated_successfully": "تم إلغاء تنشيط جهة اتصال بنجاح.",
"are_sure_to_inactive_this_contact": "هل أنت متأكد أنك تريد إلغاء تنشيط جهة اتصال؟ ستكون قادرًا على تنشيطه لاحقًا",
"are_sure_to_activate_this_contact": "هل أنت متأكد أنك تريد تفعيل جهة اتصال؟ ستتمكن من تعطيله لاحقًا"
}

View File

@@ -1185,5 +1185,11 @@
"non-inventory":"Non-Inventory",
"terms_conditions":"Terms conditions",
"your_invoice_numbers_are_set_on_auto_increment_mod_are_you_sure_changing_this_setting":"Your invoice numbers are set on auto-increment mod. Are you sure changing this setting?",
"auto_incrementing_number":"Auto-incrementing number"
"auto_incrementing_number":"Auto-incrementing number",
"the_inventory_adjustment_has_been_published": "The Inventory adjustment has been published",
"are_sure_to_publish_this_inventory_adjustment": "Are you sure you want to publish this inventory?",
"the_contact_has_been_activated_successfully": "The contact has been inactivated successfully.",
"the_contact_has_been_inactivated_successfully": "The contact has been inactivated successfully.",
"are_sure_to_inactive_this_contact": "Are you sure you want to inactive this contact ? You will be able to activate it later",
"are_sure_to_activate_this_contact": "Are you sure you want to activate this contact ? You will be able to inactivate it later"
}