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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -117,7 +117,7 @@ export function useActivateBranches(props) {
/** /**
* Mark primary the given branch. * Mark primary the given branch.
*/ */
export function useMarkPrimaryBranches(props) { export function useMarkBranchAsPrimary(props) {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const apiRequest = useApiRequest(); const apiRequest = useApiRequest();

View File

@@ -237,7 +237,7 @@ export function useActivateWarehouses(props) {
/** /**
* Mark primary the given branch. * Mark primary the given branch.
*/ */
export function useMarkPrimaryWarehouse(props) { export function useMarkWarehouseAsPrimary(props) {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const apiRequest = useApiRequest(); const apiRequest = useApiRequest();