mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat(branche & warehouse ) add mark primary alert.
This commit is contained in:
70
src/containers/Alerts/Branches/BranchMarkPrimaryAlert.js
Normal file
70
src/containers/Alerts/Branches/BranchMarkPrimaryAlert.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'components';
|
||||||
|
|
||||||
|
import { useMarkPrimaryBranches } from 'hooks/query';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* branch mark primary alert.
|
||||||
|
*/
|
||||||
|
function BranchMarkPrimaryAlert({
|
||||||
|
name,
|
||||||
|
|
||||||
|
// #withAlertStoreConnect
|
||||||
|
isOpen,
|
||||||
|
payload: { branchId },
|
||||||
|
|
||||||
|
// #withAlertActions
|
||||||
|
closeAlert,
|
||||||
|
}) {
|
||||||
|
const { mutateAsync: markPrimaryBranchMutate, isLoading } =
|
||||||
|
useMarkPrimaryBranches();
|
||||||
|
|
||||||
|
// Handle cancel mark primary alert.
|
||||||
|
const handleCancelMarkPrimaryAlert = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// andle cancel mark primary confirm.
|
||||||
|
const handleConfirmMarkPrimaryBranch = () => {
|
||||||
|
markPrimaryBranchMutate(branchId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('branch.alert.mark_primary_message'),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeAlert(name);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'make_primary'} />}
|
||||||
|
intent={Intent.WARNING}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelMarkPrimaryAlert}
|
||||||
|
onConfirm={handleConfirmMarkPrimaryBranch}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'branch.alert.are_you_sure_you_want_to_make'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
)(BranchMarkPrimaryAlert);
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'components';
|
||||||
|
|
||||||
|
import { useMarkPrimaryWarehouse } from 'hooks/query';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* warehouse mark primary alert.
|
||||||
|
*/
|
||||||
|
function WarehouseMarkPrimaryAlert({
|
||||||
|
name,
|
||||||
|
|
||||||
|
// #withAlertStoreConnect
|
||||||
|
isOpen,
|
||||||
|
payload: { warehouseId },
|
||||||
|
|
||||||
|
// #withAlertActions
|
||||||
|
closeAlert,
|
||||||
|
}) {
|
||||||
|
const { mutateAsync: markPrimaryWarehouseMutate, isLoading } =
|
||||||
|
useMarkPrimaryWarehouse();
|
||||||
|
|
||||||
|
// Handle cancel mark primary alert.
|
||||||
|
const handleCancelMarkPrimaryAlert = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// andle cancel mark primary confirm.
|
||||||
|
const handleConfirmMarkPrimaryWarehouse = () => {
|
||||||
|
markPrimaryWarehouseMutate(warehouseId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('warehouse.alert.mark_primary_message'),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeAlert(name);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'make_primary'} />}
|
||||||
|
intent={Intent.WARNING}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelMarkPrimaryAlert}
|
||||||
|
onConfirm={handleConfirmMarkPrimaryWarehouse}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'warehouse.alert.are_you_sure_you_want_to_make'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
)(WarehouseMarkPrimaryAlert);
|
||||||
@@ -3,5 +3,14 @@ import React from 'react';
|
|||||||
const BranchDeleteAlert = React.lazy(() =>
|
const BranchDeleteAlert = React.lazy(() =>
|
||||||
import('../../Alerts/Branches/BranchDeleteAlert'),
|
import('../../Alerts/Branches/BranchDeleteAlert'),
|
||||||
);
|
);
|
||||||
|
const BranchMarkPrimaryAlert = React.lazy(() =>
|
||||||
|
import('../../Alerts/Branches/BranchMarkPrimaryAlert'),
|
||||||
|
);
|
||||||
|
|
||||||
export default [{ name: 'branch-delete', component: BranchDeleteAlert }];
|
export default [
|
||||||
|
{ name: 'branch-delete', component: BranchDeleteAlert },
|
||||||
|
{
|
||||||
|
name: 'branch-mark-primary',
|
||||||
|
component: BranchMarkPrimaryAlert,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|||||||
@@ -27,22 +27,27 @@ function BranchesDataTable({
|
|||||||
// Table columns.
|
// Table columns.
|
||||||
const columns = useBranchesTableColumns();
|
const columns = useBranchesTableColumns();
|
||||||
|
|
||||||
const Time = true;
|
|
||||||
|
|
||||||
const { branches, isBranchesLoading, isBranchesFetching } =
|
const { branches, isBranchesLoading, isBranchesFetching } =
|
||||||
useBranchesContext();
|
useBranchesContext();
|
||||||
|
|
||||||
|
// Handle edit branch.
|
||||||
const handleEditBranch = ({ id }) => {
|
const handleEditBranch = ({ id }) => {
|
||||||
openDialog('branch-form', { branchId: id, action: 'edit' });
|
openDialog('branch-form', { branchId: id, action: 'edit' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle delete branch.
|
||||||
const handleDeleteBranch = ({ id }) => {
|
const handleDeleteBranch = ({ id }) => {
|
||||||
openAlert('branch-delete', { branchId: id });
|
openAlert('branch-delete', { branchId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Time) {
|
// Handle mark primary branch.
|
||||||
return <BranchesEmptyStatus />;
|
const handleMarkPrimaryBranch = ({ id }) => {
|
||||||
}
|
openAlert('branch-mark-primary', { branchId: id });
|
||||||
|
};
|
||||||
|
|
||||||
|
// if (type) {
|
||||||
|
// return <BranchesEmptyStatus />;
|
||||||
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BranchesTableCard>
|
<BranchesTableCard>
|
||||||
@@ -58,6 +63,7 @@ function BranchesDataTable({
|
|||||||
payload={{
|
payload={{
|
||||||
onEdit: handleEditBranch,
|
onEdit: handleEditBranch,
|
||||||
onDelete: handleDeleteBranch,
|
onDelete: handleDeleteBranch,
|
||||||
|
onMarkPrimary: handleMarkPrimaryBranch,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</BranchesTableCard>
|
</BranchesTableCard>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { Icon } from 'components';
|
|||||||
* Context menu of Branches.
|
* Context menu of Branches.
|
||||||
*/
|
*/
|
||||||
export function ActionsMenu({
|
export function ActionsMenu({
|
||||||
payload: { onEdit, onDelete },
|
payload: { onEdit, onDelete, onMarkPrimary },
|
||||||
row: { original },
|
row: { original },
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
@@ -19,6 +19,11 @@ export function ActionsMenu({
|
|||||||
text={intl.get('branches.action.edit_branch')}
|
text={intl.get('branches.action.edit_branch')}
|
||||||
onClick={safeCallback(onEdit, original)}
|
onClick={safeCallback(onEdit, original)}
|
||||||
/>
|
/>
|
||||||
|
<MenuItem
|
||||||
|
icon={<Icon icon="check" />}
|
||||||
|
text={intl.get('branches.action.mark_as_primary')}
|
||||||
|
onClick={safeCallback(onMarkPrimary, original)}
|
||||||
|
/>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
|
|||||||
@@ -3,8 +3,17 @@ import React from 'react';
|
|||||||
const WarehouseDeleteAlert = React.lazy(() =>
|
const WarehouseDeleteAlert = React.lazy(() =>
|
||||||
import('../../Alerts/Warehouses/WarehouseDeleteAlert'),
|
import('../../Alerts/Warehouses/WarehouseDeleteAlert'),
|
||||||
);
|
);
|
||||||
|
const WarehouseMarkPrimaryAlert = React.lazy(() =>
|
||||||
|
import('../../Alerts/Warehouses/WarehouseMarkPrimaryAlert'),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warehouses alerts.
|
* Warehouses alerts.
|
||||||
*/
|
*/
|
||||||
export default [{ name: 'warehouse-delete', component: WarehouseDeleteAlert }];
|
export default [
|
||||||
|
{ name: 'warehouse-delete', component: WarehouseDeleteAlert },
|
||||||
|
{
|
||||||
|
name: 'warehouse-mark-primary',
|
||||||
|
component: WarehouseMarkPrimaryAlert,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|||||||
@@ -30,12 +30,18 @@ function WarehousesGridItems({
|
|||||||
openAlert('warehouse-delete', { warehouseId: warehouse.id });
|
openAlert('warehouse-delete', { warehouseId: warehouse.id });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle mark primary warehouse.
|
||||||
|
const handleMarkPrimaryWarehouse = () => {
|
||||||
|
openAlert('warehouse-mark-primary', { warehouseId: warehouse.id });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextMenu2
|
<ContextMenu2
|
||||||
content={
|
content={
|
||||||
<WarehouseContextMenu
|
<WarehouseContextMenu
|
||||||
onEditClick={handleEditWarehouse}
|
onEditClick={handleEditWarehouse}
|
||||||
onDeleteClick={handleDeleteWarehouse}
|
onDeleteClick={handleDeleteWarehouse}
|
||||||
|
onMarkPrimary={handleMarkPrimaryWarehouse}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ function WarehousesList({
|
|||||||
changePreferencesPageTitle(intl.get('warehouses.label'));
|
changePreferencesPageTitle(intl.get('warehouses.label'));
|
||||||
}, [changePreferencesPageTitle]);
|
}, [changePreferencesPageTitle]);
|
||||||
|
|
||||||
// if () {
|
// if (type) {
|
||||||
// return <WarehousesEmptyStatus />;
|
// return <WarehousesEmptyStatus />;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ function WarehousesProvider({ ...props }) {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{isWarehouesLoading ? (
|
{/* {isWarehouesLoading ? (
|
||||||
<PreferencesPageLoader />
|
<PreferencesPageLoader />
|
||||||
) : (
|
) : ( */}
|
||||||
<WarehousesContext.Provider value={provider} {...props} />
|
<WarehousesContext.Provider value={provider} {...props} />
|
||||||
)}
|
{/* )} */}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function WarehouseContextMenu({
|
|||||||
onClick={safeCallback(onEditClick)}
|
onClick={safeCallback(onEditClick)}
|
||||||
/>
|
/>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon="pen-18" />}
|
icon={<Icon icon="check" />}
|
||||||
text={intl.get('warehouses.action.make_as_parimary')}
|
text={intl.get('warehouses.action.make_as_parimary')}
|
||||||
onClick={safeCallback(onPrimary)}
|
onClick={safeCallback(onPrimary)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -113,3 +113,21 @@ export function useActivateBranches(props) {
|
|||||||
...props,
|
...props,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark primary the given branch.
|
||||||
|
*/
|
||||||
|
export function useMarkPrimaryBranches(props) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useMutation((id) => apiRequest.post(`branches/${id}/mark-primary`), {
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Invalidate specific inventory adjustment.
|
||||||
|
queryClient.invalidateQueries([t.BRANCH, id]);
|
||||||
|
|
||||||
|
commonInvalidateQueries(queryClient);
|
||||||
|
},
|
||||||
|
...props,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -233,3 +233,21 @@ export function useActivateWarehouses(props) {
|
|||||||
...props,
|
...props,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark primary the given branch.
|
||||||
|
*/
|
||||||
|
export function useMarkPrimaryWarehouse(props) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useMutation((id) => apiRequest.post(`warehouses/${id}/mark-primary`), {
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Invalidate specific inventory adjustment.
|
||||||
|
queryClient.invalidateQueries([t.WAREHOUSE, id]);
|
||||||
|
|
||||||
|
commonInvalidateQueries(queryClient);
|
||||||
|
},
|
||||||
|
...props,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1829,6 +1829,7 @@
|
|||||||
"branches.label.new_branch": "New Branch",
|
"branches.label.new_branch": "New Branch",
|
||||||
"branches.action.edit_branch": "Edit Branch",
|
"branches.action.edit_branch": "Edit Branch",
|
||||||
"branches.action.delete_branch": "Delete Branch",
|
"branches.action.delete_branch": "Delete Branch",
|
||||||
|
"branches.action.mark_as_primary": "Make as Primary",
|
||||||
"branches.column.branch_name": "Branch name",
|
"branches.column.branch_name": "Branch name",
|
||||||
"branches.column.address": "Address",
|
"branches.column.address": "Address",
|
||||||
"branches.column.phone_number": "Phone number",
|
"branches.column.phone_number": "Phone number",
|
||||||
@@ -1848,5 +1849,12 @@
|
|||||||
"branch.alert.delete_message": "The branch has been deleted successfully",
|
"branch.alert.delete_message": "The branch has been deleted successfully",
|
||||||
"branch.once_delete_this_branch": "Once you delete this branch, you won't be able to restore it later. Are you sure you want to delete this branch?",
|
"branch.once_delete_this_branch": "Once you delete this branch, you won't be able to restore it later. Are you sure you want to delete this branch?",
|
||||||
"realized_gain_or_loss.label": "Realized Gain or Loss",
|
"realized_gain_or_loss.label": "Realized Gain or Loss",
|
||||||
"unrealized_gain_or_loss.label":"Unrealized Gain or Loss"
|
"unrealized_gain_or_loss.label": "Unrealized Gain or Loss",
|
||||||
|
"branch_activate.dialog_success_message": "Multi-branches feature has been activated successfully.",
|
||||||
|
"branch.alert.mark_primary_message": "The branch has been marked as primary.",
|
||||||
|
"branch.alert.are_you_sure_you_want_to_make": "Are you sure you want to make a primary branch?",
|
||||||
|
"warehouse_activate.dialog_success_message": "Multi-branches feature has been activated successfully.",
|
||||||
|
"warehouse.alert.mark_primary_message": "The given warehouse has been marked as primary.",
|
||||||
|
"warehouse.alert.are_you_sure_you_want_to_make": "Are you sure you want to make a primary warehouse?",
|
||||||
|
"make_primary": "Make Primary"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user