fix(Branches & warehouses ): mark primary.

This commit is contained in:
elforjani13
2022-02-20 18:38:19 +02:00
parent 3a4c1adbd4
commit 05b0f5caac
8 changed files with 55 additions and 32 deletions

View File

@@ -3,7 +3,7 @@ import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { FormattedMessage as T } from 'components';
import { useMarkPrimaryBranches } from 'hooks/query';
import { useMarkBranchAsPrimary } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertActions from 'containers/Alert/withAlertActions';
@@ -25,7 +25,7 @@ function BranchMarkPrimaryAlert({
closeAlert,
}) {
const { mutateAsync: markPrimaryBranchMutate, isLoading } =
useMarkPrimaryBranches();
useMarkBranchAsPrimary();
// Handle cancel mark primary alert.
const handleCancelMarkPrimaryAlert = () => {
@@ -49,8 +49,8 @@ function BranchMarkPrimaryAlert({
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'make_primary'} />}
// cancelButtonText={<T id={'cancel'} />}
// confirmButtonText={<T id={'make_primary'} />}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancelMarkPrimaryAlert}

View File

@@ -3,7 +3,7 @@ import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core';
import { FormattedMessage as T } from 'components';
import { useMarkPrimaryWarehouse } from 'hooks/query';
import { useMarkWarehouseAsPrimary } from 'hooks/query';
import { AppToaster } from 'components';
import withAlertActions from 'containers/Alert/withAlertActions';
@@ -24,14 +24,14 @@ function WarehouseMarkPrimaryAlert({
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: markPrimaryWarehouseMutate, isLoading } =
useMarkPrimaryWarehouse();
// const { mutateAsync: markPrimaryWarehouseMutate, isLoading } =
// useMarkWarehouseAsPrimary();
// Handle cancel mark primary alert.
const handleCancelMarkPrimaryAlert = () => {
closeAlert(name);
};
console.log(warehouseId, 'XX');
// andle cancel mark primary confirm.
const handleConfirmMarkPrimaryWarehouse = () => {
markPrimaryWarehouseMutate(warehouseId)

View File

@@ -3,14 +3,14 @@ import React from 'react';
const BranchDeleteAlert = React.lazy(() =>
import('../../Alerts/Branches/BranchDeleteAlert'),
);
const BranchMarkPrimaryAlert = React.lazy(() =>
import('../../Alerts/Branches/BranchMarkPrimaryAlert'),
);
// const BranchMarkPrimaryAlert = React.lazy(() =>
// import('../../Alerts/Branches/BranchMarkPrimaryAlert'),
// );
export default [
{ name: 'branch-delete', component: BranchDeleteAlert },
{
name: 'branch-mark-primary',
component: BranchMarkPrimaryAlert,
},
// {
// name: 'branch-mark-primary',
// component: BranchMarkPrimaryAlert,
// },
];

View File

@@ -1,13 +1,16 @@
import React from 'react';
import intl from 'react-intl-universal';
import styled from 'styled-components';
import { Intent } from '@blueprintjs/core';
import 'style/pages/Preferences/branchesList.scss';
import { DataTable, Card } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import BranchesEmptyStatus from './BranchesEmptyStatus';
import { DataTable, Card, AppToaster } from 'components';
import { useBranchesTableColumns, ActionsMenu } from './components';
import { useBranchesContext } from './BranchesProvider';
import { useMarkBranchAsPrimary } from 'hooks/query';
import withDialogActions from 'containers/Dialog/withDialogActions';
import withAlertActions from 'containers/Alert/withAlertActions';
@@ -27,6 +30,9 @@ function BranchesDataTable({
// Table columns.
const columns = useBranchesTableColumns();
// MarkBranchAsPrimary
const { mutateAsync: markBranchAsPrimaryMutate } = useMarkBranchAsPrimary();
const { branches, isBranchesLoading, isBranchesFetching } =
useBranchesContext();
@@ -40,9 +46,14 @@ function BranchesDataTable({
openAlert('branch-delete', { branchId: id });
};
// Handle mark primary branch.
const handleMarkPrimaryBranch = ({ id }) => {
openAlert('branch-mark-primary', { branchId: id });
// Handle mark branch as primary.
const handleMarkBranchAsPrimary = ({ id }) => {
markBranchAsPrimaryMutate(id).then(() => {
AppToaster.show({
message: intl.get('branch.alert.mark_primary_message'),
intent: Intent.SUCCESS,
});
});
};
// if (type) {
@@ -63,7 +74,7 @@ function BranchesDataTable({
payload={{
onEdit: handleEditBranch,
onDelete: handleDeleteBranch,
onMarkPrimary: handleMarkPrimaryBranch,
onMarkPrimary: handleMarkBranchAsPrimary,
}}
/>
</BranchesTableCard>

View File

@@ -3,17 +3,17 @@ import React from 'react';
const WarehouseDeleteAlert = React.lazy(() =>
import('../../Alerts/Warehouses/WarehouseDeleteAlert'),
);
const WarehouseMarkPrimaryAlert = React.lazy(() =>
import('../../Alerts/Warehouses/WarehouseMarkPrimaryAlert'),
);
// const WarehouseMarkPrimaryAlert = React.lazy(() =>
// import('../../Alerts/Warehouses/WarehouseMarkPrimaryAlert'),
// );
/**
* Warehouses alerts.
*/
export default [
{ name: 'warehouse-delete', component: WarehouseDeleteAlert },
{
name: 'warehouse-mark-primary',
component: WarehouseMarkPrimaryAlert,
},
// {
// name: 'warehouse-mark-primary',
// component: WarehouseMarkPrimaryAlert,
// },
];

View File

@@ -1,7 +1,11 @@
import React from 'react';
import intl from 'react-intl-universal';
import { Intent } from '@blueprintjs/core';
import { ContextMenu2 } from '@blueprintjs/popover2';
import { AppToaster } from 'components';
import { WarehouseContextMenu, WarehousesGridItemBox } from './components';
import { useMarkWarehouseAsPrimary } from 'hooks/query';
import withAlertsActions from '../../Alert/withAlertActions';
import withDialogActions from '../../Dialog/withDialogActions';
@@ -19,6 +23,9 @@ function WarehouseGridItem({
warehouse,
}) {
const { mutateAsync: markWarehouseAsPrimaryMutate } =
useMarkWarehouseAsPrimary();
// Handle edit warehouse.
const handleEditWarehouse = () => {
openDialog('warehouse-form', { warehouseId: warehouse.id, action: 'edit' });
@@ -28,8 +35,13 @@ function WarehouseGridItem({
openAlert('warehouse-delete', { warehouseId: warehouse.id });
};
// Handle mark primary warehouse.
const handleMarkPrimaryWarehouse = () => {
openAlert('warehouse-mark-primary', { warehouseId: warehouse.id });
const handleMarkWarehouseAsPrimary = () => {
markWarehouseAsPrimaryMutate(warehouse.id).then(() => {
AppToaster.show({
message: intl.get('warehouse.alert.mark_primary_message'),
intent: Intent.SUCCESS,
});
});
};
return (
@@ -38,7 +50,7 @@ function WarehouseGridItem({
<WarehouseContextMenu
onEditClick={handleEditWarehouse}
onDeleteClick={handleDeleteWarehouse}
onMarkPrimary={handleMarkPrimaryWarehouse}
onMarkPrimary={handleMarkWarehouseAsPrimary}
/>
}
>