diff --git a/src/containers/Preferences/Warehouses/Warehouses.js b/src/containers/Preferences/Warehouses/Warehouses.js
index 936d954c1..9ba390158 100644
--- a/src/containers/Preferences/Warehouses/Warehouses.js
+++ b/src/containers/Preferences/Warehouses/Warehouses.js
@@ -1,18 +1,28 @@
import React from 'react';
import intl from 'react-intl-universal';
-import styled from 'styled-components';
-import { useWarehousesContext } from './WarehousesProvider';
-import WarehousesGridItems from './WarehousesGridItems';
+import '../../../style/pages/Preferences/warehousesList.scss';
+
+import WarehousesGrid from './WarehousesGrid';
+import withDashboardActions from 'containers/Dashboard/withDashboardActions';
+import { compose } from 'utils';
/**
* Warehouses.
* @returns
*/
-export default function Warehouses() {
- const { warehouses } = useWarehousesContext();
+function Warehouses({
+ // #withDashboardActions
+ changePreferencesPageTitle,
+}) {
+ React.useEffect(() => {
+ changePreferencesPageTitle(intl.get('warehouses.label'));
+ }, [changePreferencesPageTitle]);
- return warehouses.map((warehouse) => (
-
- ));
+ return (
+
+
+
+ );
}
+export default compose(withDashboardActions)(Warehouses);
diff --git a/src/containers/Preferences/Warehouses/WarehousesGrid.js b/src/containers/Preferences/Warehouses/WarehousesGrid.js
new file mode 100644
index 000000000..4f0e8797d
--- /dev/null
+++ b/src/containers/Preferences/Warehouses/WarehousesGrid.js
@@ -0,0 +1,28 @@
+import React from 'react';
+import { isEmpty } from 'lodash';
+import WarehousesEmptyStatus from './WarehousesEmptyStatus';
+import { useWarehousesContext } from './WarehousesProvider';
+import { WarehousesList, WarehousesSkeleton } from './components';
+import WarehousesGridItems from './WarehousesGridItems';
+
+/**
+ * Warehouses grid.
+ */
+export default function WarehousesGrid() {
+ // Retrieve list context.
+ const { warehouses, isWarehouesLoading } = useWarehousesContext();
+
+ return (
+
+
+ {isWarehouesLoading ? (
+
+ ) : isEmpty(warehouses) ? (
+
+ ) : (
+
+ )}
+
+
+ );
+}
diff --git a/src/containers/Preferences/Warehouses/WarehousesGridItems.js b/src/containers/Preferences/Warehouses/WarehousesGridItems.js
index 31219b5a2..86d4732e7 100644
--- a/src/containers/Preferences/Warehouses/WarehousesGridItems.js
+++ b/src/containers/Preferences/Warehouses/WarehousesGridItems.js
@@ -1,5 +1,4 @@
import React from 'react';
-import styled from 'styled-components';
import { ContextMenu2 } from '@blueprintjs/popover2';
import { WarehouseContextMenu, WarehousesGrid } from './components';
@@ -10,10 +9,9 @@ import withDialogActions from '../../Dialog/withDialogActions';
import { compose } from 'utils';
/**
- * Warehouse grid items.
- * @returns
+ * warehouse grid item.
*/
-function WarehousesGridItems({
+function WarehouseGridItem({
// #withAlertsActions
openAlert,
// #withDialogActions
@@ -21,8 +19,6 @@ function WarehousesGridItems({
warehouse,
}) {
- const { isWarehouesLoading } = useWarehousesContext();
-
// Handle edit warehouse.
const handleEditWarehouse = () => {
openDialog('warehouse-form', { warehouseId: warehouse.id, action: 'edit' });
@@ -48,18 +44,28 @@ function WarehousesGridItems({
/>
}
>
-
+
);
}
-export default compose(
+const WarehousesGridItem = compose(
withAlertsActions,
withDialogActions,
-)(WarehousesGridItems);
+)(WarehouseGridItem);
-const WarehouseGridWrap = styled.div`
- display: flex;
- flex-wrap: wrap;
- margin: 15px;
-`;
+/**
+ * warehouses grid items,
+ */
+export default function WarehousesGridItems({ warehouses }) {
+ return warehouses.map((warehouse) => (
+
+ ));
+}
diff --git a/src/containers/Preferences/Warehouses/WarehousesList.js b/src/containers/Preferences/Warehouses/WarehousesList.js
deleted file mode 100644
index c2e6c7816..000000000
--- a/src/containers/Preferences/Warehouses/WarehousesList.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import React from 'react';
-import styled from 'styled-components';
-import intl from 'react-intl-universal';
-
-import '../../../style/pages/Preferences/warehousesList.scss';
-import Warehouses from './Warehouses';
-import WarehousesEmptyStatus from './WarehousesEmptyStatus';
-import withDashboardActions from 'containers/Dashboard/withDashboardActions';
-
-import { compose } from 'utils';
-
-function WarehousesList({
- // #withDashboardActions
- changePreferencesPageTitle,
-}) {
- React.useEffect(() => {
- changePreferencesPageTitle(intl.get('warehouses.label'));
- }, [changePreferencesPageTitle]);
-
- // if (type) {
- // return ;
- // }
-
- return (
-
-
-
- );
-}
-
-export default compose(withDashboardActions)(WarehousesList);
-
-const WarehousesListRoot = styled.div`
- display: flex;
- flex-wrap: wrap;
- margin: 15px;
-`;
diff --git a/src/containers/Preferences/Warehouses/WarehousesProvider.js b/src/containers/Preferences/Warehouses/WarehousesProvider.js
index 69ba03b5f..a2f3b9fc3 100644
--- a/src/containers/Preferences/Warehouses/WarehousesProvider.js
+++ b/src/containers/Preferences/Warehouses/WarehousesProvider.js
@@ -2,7 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import classNames from 'classnames';
import { CLASSES } from 'common/classes';
-import { useWarehouses } from 'hooks/query';
+import { useWarehouses, useCashflowAccounts } from 'hooks/query';
import PreferencesPageLoader from '../PreferencesPageLoader';
const WarehousesContext = React.createContext();
@@ -10,9 +10,12 @@ const WarehousesContext = React.createContext();
/**
* Warehouses data provider.
*/
-function WarehousesProvider({ ...props }) {
+function WarehousesProvider({ query, ...props }) {
// Fetch warehouses list.
- const { data: warehouses, isLoading: isWarehouesLoading } = useWarehouses();
+ const { data: warehouses, isLoading: isWarehouesLoading } = useWarehouses(
+ query,
+ { keepPreviousData: true },
+ );
// Provider state.
const provider = {
@@ -28,11 +31,7 @@ function WarehousesProvider({ ...props }) {
)}
>
- {/* {isWarehouesLoading ? (
-
- ) : ( */}
-
- {/* )} */}
+
);
diff --git a/src/containers/Preferences/Warehouses/components.js b/src/containers/Preferences/Warehouses/components.js
index b37ad8e06..fed2f157e 100644
--- a/src/containers/Preferences/Warehouses/components.js
+++ b/src/containers/Preferences/Warehouses/components.js
@@ -1,13 +1,19 @@
import React from 'react';
import intl from 'react-intl-universal';
import styled from 'styled-components';
-import { Classes } from '@blueprintjs/core';
+import {
+ Menu,
+ MenuItem,
+ MenuDivider,
+ Intent,
+ Classes,
+} from '@blueprintjs/core';
import clsx from 'classnames';
-
-import { Menu, MenuItem, MenuDivider, Intent } from '@blueprintjs/core';
import { If, Icon, Can } from '../../../components';
import { safeCallback } from 'utils';
+const WAREHOUSES_SKELETON_N = 9;
+
/**
* Warehouse context menu.
*/
@@ -39,15 +45,23 @@ export function WarehouseContextMenu({
);
}
-export function WarehousesGrid({ warehouse, loading }) {
+export function WarehousesGrid({
+ title,
+ code,
+ city,
+ country,
+ email,
+ phone_number,
+ loading,
+}) {
return (
- {warehouse.name}
+ {title}
- {warehouse.code}
+ {code}
{!loading && }
@@ -55,23 +69,44 @@ export function WarehousesGrid({ warehouse, loading }) {
- {warehouse.city}
+ {city}
- {warehouse.country}
+ {country}
- {warehouse.email}
+ {email}
- {warehouse.phone_number}
+ {phone_number}
);
}
-const WarehouseGridWrapper = styled.div`
+export function WarehousesSkeleton() {
+ return [...Array(WAREHOUSES_SKELETON_N)].map((key, value) => (
+
+ ));
+}
+
+export const WarehousesList = styled.div`
+ display: flex;
+ flex-wrap: wrap;
+ margin: 15px;
+ height: 100%;
+`;
+
+export const WarehouseGridWrapper = styled.div`
display: flex;
flex-direction: column;
flex-shrink: 0;
@@ -89,12 +124,12 @@ const WarehouseGridWrapper = styled.div`
}
`;
-const WarehouseHeader = styled.div`
+export const WarehouseHeader = styled.div`
position: relative;
padding: 16px 12px 10px;
`;
-const WarehouseTitle = styled.div`
+export const WarehouseTitle = styled.div`
font-size: 14px; //22px
font-style: inherit;
color: #000;
diff --git a/src/containers/Preferences/Warehouses/index.js b/src/containers/Preferences/Warehouses/index.js
index e3d8066e4..5a7270e10 100644
--- a/src/containers/Preferences/Warehouses/index.js
+++ b/src/containers/Preferences/Warehouses/index.js
@@ -1,6 +1,6 @@
import React from 'react';
import { WarehousesProvider } from './WarehousesProvider';
-import WarehousesList from './WarehousesList';
+import Warehouses from './Warehouses';
/**
* Warehouses Preferences.
@@ -9,7 +9,7 @@ import WarehousesList from './WarehousesList';
export default function WarehousesPerences() {
return (
-
+
);
}