diff --git a/src/containers/Alerts/Warehouses/WarehouseDeleteAlert.js b/src/containers/Alerts/Warehouses/WarehouseDeleteAlert.js
new file mode 100644
index 000000000..9d4cb0c83
--- /dev/null
+++ b/src/containers/Alerts/Warehouses/WarehouseDeleteAlert.js
@@ -0,0 +1,77 @@
+import React from 'react';
+import intl from 'react-intl-universal';
+import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
+import { Intent, Alert } from '@blueprintjs/core';
+import { AppToaster } from 'components';
+import { useDeleteWarehouse } from 'hooks/query';
+
+import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
+import withAlertActions from 'containers/Alert/withAlertActions';
+
+import { compose } from 'utils';
+
+/**
+ * Warehouse delete alert
+ * @returns
+ */
+function WarehouseDeleteAlert({
+ name,
+
+ // #withAlertStoreConnect
+ isOpen,
+ payload: { warehouseId },
+
+ // #withAlertActions
+ closeAlert,
+}) {
+ const { mutateAsync: deleteWarehouseMutate, isLoading } =
+ useDeleteWarehouse();
+
+ // handle cancel delete warehouse alert.
+ const handleCancelDeleteAlert = () => {
+ closeAlert(name);
+ };
+
+ // handleConfirm delete invoice
+ const handleConfirmWarehouseDelete = () => {
+ deleteWarehouseMutate(warehouseId)
+ .then(() => {
+ AppToaster.show({
+ message: intl.get('warehouse.alert.delete_message'),
+ intent: Intent.SUCCESS,
+ });
+ })
+ .catch(
+ ({
+ response: {
+ data: { errors },
+ },
+ }) => {},
+ )
+ .finally(() => {
+ closeAlert(name);
+ });
+ };
+
+ return (
+ }
+ confirmButtonText={}
+ icon="trash"
+ intent={Intent.DANGER}
+ isOpen={isOpen}
+ onCancel={handleCancelDeleteAlert}
+ onConfirm={handleConfirmWarehouseDelete}
+ loading={isLoading}
+ >
+
+
+
+
+ );
+}
+
+export default compose(
+ withAlertStoreConnect(),
+ withAlertActions,
+)(WarehouseDeleteAlert);
diff --git a/src/containers/AlertsContainer/registered.js b/src/containers/AlertsContainer/registered.js
index 57d66288a..c023ebf0c 100644
--- a/src/containers/AlertsContainer/registered.js
+++ b/src/containers/AlertsContainer/registered.js
@@ -19,7 +19,8 @@ import CurrenciesAlerts from '../Preferences/Currencies/CurrenciesAlerts';
import RolesAlerts from '../Preferences/Users/Roles/RolesAlerts';
import CreditNotesAlerts from '../Sales/CreditNotes/CreditNotesAlerts';
import VendorCreditNotesAlerts from '../Purchases/CreditNotes/VendorCreditNotesAlerts';
-import TransactionsLockingAlerts from '../TransactionsLocking/TransactionsLockingAlerts'
+import TransactionsLockingAlerts from '../TransactionsLocking/TransactionsLockingAlerts';
+import WarehousesAlerts from '../Preferences/Warehouses/WarehousesAlerts';
export default [
...AccountsAlerts,
@@ -43,5 +44,6 @@ export default [
...RolesAlerts,
...CreditNotesAlerts,
...VendorCreditNotesAlerts,
- ...TransactionsLockingAlerts
+ ...TransactionsLockingAlerts,
+ ...WarehousesAlerts,
];
diff --git a/src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js b/src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js
index 1c5474fce..e4c369d6b 100644
--- a/src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js
+++ b/src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js
@@ -1,20 +1,26 @@
import React from 'react';
-import { Formik } from 'formik';
+import intl from 'react-intl-universal';
+import { Formik } from 'formik';
+import { Intent } from '@blueprintjs/core';
+
+import { AppToaster } from 'components';
import { CreateWarehouseFormSchema } from './WarehouseForm.schema';
import { useWarehouseFormContext } from './WarehouseFormProvider';
import WarehouseFormContent from './WarehouseFormContent';
import withDialogActions from 'containers/Dialog/withDialogActions';
-import { compose } from 'utils';
+import { compose, transformToForm } from 'utils';
const defaultInitialValues = {
- warehouse_name: '',
- warehouse_address_1: '',
- warehouse_address_2: '',
- warehouse_address_city: '',
- warehouse_address_country: '',
+ name: '',
+ code: '',
+ address: '',
+ city: '',
+ country: '',
phone_number: '',
+ website: '',
+ email: '',
};
/**
@@ -25,13 +31,50 @@ function WarehouseForm({
// #withDialogActions
closeDialog,
}) {
+ const {
+ dialogName,
+ warehouse,
+ warehouseId,
+ createWarehouseMutate,
+ editWarehouseMutate,
+ } = useWarehouseFormContext();
+
// Initial form values.
const initialValues = {
...defaultInitialValues,
+ ...transformToForm(warehouse, defaultInitialValues),
};
// Handles the form submit.
- const handleFormSubmit = (values, { setSubmitting, setErrors }) => {};
+ const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
+ const form = { ...values };
+
+ // Handle request response success.
+ const onSuccess = (response) => {
+ AppToaster.show({
+ message: intl.get('warehouse.dialog.success_message'),
+ intent: Intent.SUCCESS,
+ });
+ closeDialog(dialogName);
+ };
+
+ // Handle request response errors.
+ const onError = ({
+ response: {
+ data: { errors },
+ },
+ }) => {
+ if (errors) {
+ }
+ setSubmitting(false);
+ };
+
+ if (warehouseId) {
+ editWarehouseMutate([warehouseId, form]).then(onSuccess).catch(onError);
+ } else {
+ createWarehouseMutate(form).then(onSuccess).catch(onError);
+ }
+ };
return (
+
);
diff --git a/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormFields.js b/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormFields.js
index b1097462e..d86cc8bcf 100644
--- a/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormFields.js
+++ b/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormFields.js
@@ -22,28 +22,44 @@ export default function WarehouseFormFields() {
return (
{/*------------ Warehouse Name -----------*/}
-
+
{({ form, field, meta: { error, touched } }) => (
}
labelInfo={}
intent={inputIntent({ error, touched })}
inline={true}
- helperText={}
+ helperText={}
className={'form-group--warehouse_name'}
>
)}
+
+ {/*------------ Warehouse Code -----------*/}
+
+ {({ form, field, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ className={'form-group--warehouse_name'}
+ >
+
+
+ )}
+
+
{/*------------ Warehouse Address -----------*/}
-
+
{({ form, field, meta: { error, touched } }) => (
}
+ helperText={}
className={'form-group--warehouse_address_1'}
>
-
- {({ form, field, meta: { error, touched } }) => (
- }
- className={'form-group--warehouse_address_2'}
- >
-
-
- )}
-
{/*------------ Warehouse Address City & Country-----------*/}
}
>
-
+
{({ field, meta: { error, touched } }) => (
)}
-
+
{({ field, meta: { error, touched } }) => (
+
{/*------------ Phone Number -----------*/}
{({ form, field, meta: { error, touched } }) => (
@@ -117,6 +116,36 @@ export default function WarehouseFormFields() {
)}
+
+ {/*------------ Email -----------*/}
+
+ {({ form, field, meta: { error, touched } }) => (
+ }
+ className={'form-group--warehouse_name'}
+ >
+
+
+ )}
+
+
+ {/*------------ Website -----------*/}
+
+ {({ form, field, meta: { error, touched } }) => (
+ }
+ className={'form-group--warehouse_name'}
+ >
+
+
+ )}
+
);
}
diff --git a/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormProvider.js b/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormProvider.js
index 336a2f93f..901468fbd 100644
--- a/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormProvider.js
+++ b/src/containers/Dialogs/WarehouseFormDialog/WarehouseFormProvider.js
@@ -1,22 +1,44 @@
import React from 'react';
import { DialogContent } from 'components';
-// import {} from 'hooks/query';
+import {
+ useCreateWarehouse,
+ useEditWarehouse,
+ useWarehouse,
+} from 'hooks/query';
+import { useLocation } from 'react-router-dom';
const WarehouseFormContext = React.createContext();
/**
* Warehouse form provider.
*/
-function WarehouseFormProvider({ dialogName, ...props }) {
+function WarehouseFormProvider({ dialogName, warehouseId, ...props }) {
+ const { state } = useLocation();
+
+ console.log(state, 'XXX');
+ // Create and edit warehouse mutations.
+ const { mutateAsync: createWarehouseMutate } = useCreateWarehouse();
+ const { mutateAsync: editWarehouseMutate } = useEditWarehouse();
+
+ // Handle fetch invoice detail.
+ const { data: warehouse, isLoading: isWarehouseLoading } = useWarehouse(
+ warehouseId,
+ {
+ enabled: !!warehouseId,
+ },
+ );
+
// State provider.
const provider = {
dialogName,
+ warehouse,
+ warehouseId,
+ createWarehouseMutate,
+ editWarehouseMutate,
};
return (
-
+
);
diff --git a/src/containers/Dialogs/WarehouseFormDialog/index.js b/src/containers/Dialogs/WarehouseFormDialog/index.js
index 0f886e56d..f03486120 100644
--- a/src/containers/Dialogs/WarehouseFormDialog/index.js
+++ b/src/containers/Dialogs/WarehouseFormDialog/index.js
@@ -12,18 +12,31 @@ const WarehouseFormDialogContent = React.lazy(() =>
/**
* Warehouse form form dialog.
*/
-function WarehouseFormDialog({ dialogName, isOpen }) {
+function WarehouseFormDialog({
+ dialogName,
+ payload: { warehouseId = null, action },
+ isOpen,
+}) {
return (
}
+ title={
+ action == 'edit' ? (
+
+ ) : (
+
+ )
+ }
isOpen={isOpen}
canEscapeJeyClose={true}
autoFocus={true}
className={'dialog--warehouse-form'}
>
-
+
);
diff --git a/src/containers/Preferences/Warehouses/Warehouses.js b/src/containers/Preferences/Warehouses/Warehouses.js
index 90446212d..30e1c0388 100644
--- a/src/containers/Preferences/Warehouses/Warehouses.js
+++ b/src/containers/Preferences/Warehouses/Warehouses.js
@@ -1,63 +1,30 @@
import React from 'react';
+import intl from 'react-intl-universal';
import styled from 'styled-components';
-import { ContextMenu2 } from '@blueprintjs/popover2';
+import { useWarehousesContext } from './WarehousesProvider';
import WarehousesGridItems from './WarehousesGridItems';
-import { WarehouseContextMenu } from './components';
-import withAlertsActions from '../../Alert/withAlertActions';
-import withDialogActions from '../../Dialog/withDialogActions';
-import { compose } from 'utils';
+import withDashboardActions from 'containers/Dashboard/withDashboardActions';
-const WAREHOUSE = [
- {
- title: 'Warehouse #1',
- code: '1001',
- city: 'City',
- country: 'Country',
- email: 'email@emial.com',
- phone: '09xxxxxxxx',
- },
- {
- title: 'Warehouse #2',
- code: '100',
- city: 'City',
- country: 'Country',
- email: 'email@emial.com',
- phone: '09xxxxxxxx',
- },
- {
- title: 'Warehouse #2',
- code: '100',
- city: 'City',
- country: 'Country',
- email: 'email@emial.com',
- phone: '09xxxxxxxx',
- },
-];
+import { compose } from 'utils';
/**
* Warehouses.
* @returns
*/
function Warehouses({
- // #withAlertsActions
- openAlert,
- // #withDialogActions
- openDialog,
+ // #withDashboardActions
+ changePreferencesPageTitle,
}) {
- return (
- }>
-
-
-
-
- );
+ const { warehouses } = useWarehousesContext();
+
+ React.useEffect(() => {
+ changePreferencesPageTitle(intl.get('warehouses.label'));
+ }, [changePreferencesPageTitle]);
+
+ return warehouses.map((warehouse) => (
+
+ ));
}
-export default compose(withAlertsActions, withDialogActions)(Warehouses);
-
-const WarehouseGridWrap = styled.div`
- display: flex;
- flex-wrap: wrap;
- margin: 15px;
-`;
+export default compose(withDashboardActions)(Warehouses);
diff --git a/src/containers/Preferences/Warehouses/WarehousesAlerts.js b/src/containers/Preferences/Warehouses/WarehousesAlerts.js
new file mode 100644
index 000000000..7e19d865a
--- /dev/null
+++ b/src/containers/Preferences/Warehouses/WarehousesAlerts.js
@@ -0,0 +1,10 @@
+import React from 'react';
+
+const WarehouseDeleteAlert = React.lazy(() =>
+ import('../../Alerts/Warehouses/WarehouseDeleteAlert'),
+);
+
+/**
+ * Warehouses alerts.
+ */
+export default [{ name: 'warehouse-delete', component: WarehouseDeleteAlert }];
diff --git a/src/containers/Preferences/Warehouses/WarehousesGridItems.js b/src/containers/Preferences/Warehouses/WarehousesGridItems.js
index 8ade20f5d..edc33ff22 100644
--- a/src/containers/Preferences/Warehouses/WarehousesGridItems.js
+++ b/src/containers/Preferences/Warehouses/WarehousesGridItems.js
@@ -1,74 +1,56 @@
import React from 'react';
import styled from 'styled-components';
+import { ContextMenu2 } from '@blueprintjs/popover2';
+
+import { WarehouseContextMenu, WarehousesGrid } from './components';
+
+import withAlertsActions from '../../Alert/withAlertActions';
+import withDialogActions from '../../Dialog/withDialogActions';
+import { compose } from 'utils';
+
+/**
+ * Warehouse grid items.
+ * @returns
+ */
+function WarehousesGridItems({
+ // #withAlertsActions
+ openAlert,
+ // #withDialogActions
+ openDialog,
+
+ warehouse,
+}) {
+ // Handle edit warehouse.
+ const handleEditWarehouse = () => {
+ openDialog('warehouse-form', { warehouseId: warehouse.id, action: 'edit' });
+ };
+
+ // Handle delete warehouse.
+ const handleDeleteWarehouse = () => {
+ openAlert('warehouse-delete', { warehouseId: warehouse.id });
+ };
-function WarehousesGrid({ warehouse }) {
return (
-
-
- {warehouse.title}
- {warehouse.code}
-
- {warehouse.city}
- {warehouse.country}
- {warehouse.email}
- {warehouse.phone}
-
+
+ }
+ >
+
+
);
}
-/**
- * Warehouse Grid.
- * @returns
- */
-function WarehousesGridItems({ warehouses }) {
- return warehouses.map((warehouse) => (
-
- ));
-}
-export default WarehousesGridItems;
+export default compose(
+ withAlertsActions,
+ withDialogActions,
+)(WarehousesGridItems);
-const WarehouseGrid = styled.div`
+const WarehouseGridWrap = styled.div`
display: flex;
- flex-direction: column;
- border-radius: 3px;
- width: 300px; // 453px
- height: 160px; //225px
- background: #fff;
- margin: 5px;
- padding: 16px 12px 10px;
- border: 1px solid #c8cad0; //#CFD1D6
- transition: all 0.1s ease-in-out;
-
- &:hover {
- border-color: #0153cc;
- }
-`;
-
-const WarehouseTitle = styled.div`
- font-size: 14px; //22px
- font-style: inherit;
- color: #000;
- white-space: nowrap;
- font-weight: 500;
- line-height: 1;
-`;
-
-const WarehouseHeader = styled.div`
- margin: 4px 0px 15px;
-`;
-
-const WarehouseCode = styled.div`
- display: inline-block;
- font-size: 11px;
- color: #6b7176;
-`;
-
-const WarehouseInfoItem = styled.div`
- display: inline-block;
- font-size: 12px;
- color: #000;
- line-height: 1.3rem;
- overflow: hidden;
- text-overflow: ellipsis;
- margin: 0;
+ flex-wrap: wrap;
+ margin: 15px;
`;
diff --git a/src/containers/Preferences/Warehouses/WarehousesList.js b/src/containers/Preferences/Warehouses/WarehousesList.js
deleted file mode 100644
index 094e0d5d4..000000000
--- a/src/containers/Preferences/Warehouses/WarehousesList.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from 'react';
-import intl from 'react-intl-universal';
-
-import Warehouses from './Warehouses';
-import withDashboardActions from 'containers/Dashboard/withDashboardActions';
-
-import { compose } from 'utils';
-
-/**
- * Warehouses List.
- * @returns
- */
-function WarehousesList({
- // #withDashboardActions
- changePreferencesPageTitle,
-}) {
- React.useEffect(() => {
- changePreferencesPageTitle(intl.get('warehouses.label'));
- }, [changePreferencesPageTitle]);
-
- return ;
-}
-
-export default compose(withDashboardActions)(WarehousesList);
diff --git a/src/containers/Preferences/Warehouses/WarehousesProvider.js b/src/containers/Preferences/Warehouses/WarehousesProvider.js
index c42465b91..3b2320431 100644
--- a/src/containers/Preferences/Warehouses/WarehousesProvider.js
+++ b/src/containers/Preferences/Warehouses/WarehousesProvider.js
@@ -1,7 +1,9 @@
import React from 'react';
+import styled from 'styled-components';
import classNames from 'classnames';
import { CLASSES } from 'common/classes';
-import styled from 'styled-components';
+import { useWarehouses } from 'hooks/query';
+import PreferencesPageLoader from '../PreferencesPageLoader';
const WarehousesContext = React.createContext();
@@ -9,12 +11,24 @@ const WarehousesContext = React.createContext();
* Warehouses data provider.
*/
function WarehousesProvider({ ...props }) {
+ // Fetch warehouses list.
+ const { data: warehouses, isLoading: isWarehouesLoading } = useWarehouses();
+
// Provider state.
- const provider = {};
+ const provider = {
+ warehouses,
+ isWarehouesLoading,
+ };
return (
-
+
+ {isWarehouesLoading ? (
+
+ ) : (
+
+ )}
+
);
}
@@ -22,3 +36,9 @@ function WarehousesProvider({ ...props }) {
const useWarehousesContext = () => React.useContext(WarehousesContext);
export { WarehousesProvider, useWarehousesContext };
+
+const WarehousePreference = styled.div`
+ display: flex;
+ flex-wrap: wrap;
+ margin: 15px;
+`;
diff --git a/src/containers/Preferences/Warehouses/components.js b/src/containers/Preferences/Warehouses/components.js
index 1ab35654b..7027343b5 100644
--- a/src/containers/Preferences/Warehouses/components.js
+++ b/src/containers/Preferences/Warehouses/components.js
@@ -1,5 +1,6 @@
import React from 'react';
import intl from 'react-intl-universal';
+import styled from 'styled-components';
import { Menu, MenuItem, MenuDivider, Intent } from '@blueprintjs/core';
import { If, Icon, Can } from '../../../components';
@@ -35,3 +36,64 @@ export function WarehouseContextMenu({
);
}
+
+export function WarehousesGrid({ warehouse }) {
+ return (
+
+
+ {warehouse.name}
+ {warehouse.code}
+
+ {warehouse.city}
+ {warehouse.country}
+ {warehouse.email}
+ {warehouse.phone_number}
+
+ );
+}
+
+const WarehouseGrid = styled.div`
+ display: flex;
+ flex-direction: column;
+ border-radius: 3px;
+ width: 280px; // 453px
+ height: 160px; //225px
+ background: #fff;
+ margin: 5px;
+ padding: 16px 12px 10px;
+ border: 1px solid #c8cad0; //#CFD1D6
+ transition: all 0.1s ease-in-out;
+
+ &:hover {
+ border-color: #0153cc;
+ }
+`;
+
+const WarehouseTitle = styled.div`
+ font-size: 14px; //22px
+ font-style: inherit;
+ color: #000;
+ white-space: nowrap;
+ font-weight: 500;
+ line-height: 1;
+`;
+
+const WarehouseHeader = styled.div`
+ margin: 4px 0px 15px;
+`;
+
+const WarehouseCode = styled.div`
+ display: inline-block;
+ font-size: 11px;
+ color: #6b7176;
+`;
+
+const WarehouseInfoItem = styled.div`
+ display: inline-block;
+ font-size: 12px;
+ color: #000;
+ line-height: 1.3rem;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ margin: 0;
+`;
diff --git a/src/containers/Preferences/Warehouses/index.js b/src/containers/Preferences/Warehouses/index.js
index 65ec45d5a..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 Warehouses from './WarehousesList';
+import Warehouses from './Warehouses';
/**
* Warehouses Preferences.
diff --git a/src/hooks/query/index.js b/src/hooks/query/index.js
index 629f4f1b4..b27ebd2b5 100644
--- a/src/hooks/query/index.js
+++ b/src/hooks/query/index.js
@@ -33,3 +33,4 @@ export * from './roles';
export * from './creditNote';
export * from './vendorCredit';
export * from './transactionsLocking';
+export * from './warehouses'
diff --git a/src/hooks/query/types.js b/src/hooks/query/types.js
index d98f99db8..27d7e3f77 100644
--- a/src/hooks/query/types.js
+++ b/src/hooks/query/types.js
@@ -191,6 +191,11 @@ const TARNSACTIONS_LOCKING = {
TRANSACTIONS_LOCKING: 'TRANSACTIONS_LOCKING',
};
+const WAREHOUSES = {
+ WAREHOUSE: 'WAREHOUSE',
+ WAREHOUSES: 'WAREHOUSES',
+};
+
export default {
...ACCOUNTS,
...BILLS,
@@ -218,4 +223,5 @@ export default {
...CREDIT_NOTES,
...VENDOR_CREDIT_NOTES,
...TARNSACTIONS_LOCKING,
+ ...WAREHOUSES
};
diff --git a/src/hooks/query/warehouses.js b/src/hooks/query/warehouses.js
new file mode 100644
index 000000000..4aea65efe
--- /dev/null
+++ b/src/hooks/query/warehouses.js
@@ -0,0 +1,99 @@
+import { useQueryClient, useMutation } from 'react-query';
+import { useRequestQuery } from '../useQueryRequest';
+import useApiRequest from '../useRequest';
+import t from './types';
+
+// Common invalidate queries.
+const commonInvalidateQueries = (queryClient) => {
+ // Invalidate warehouses.
+ queryClient.invalidateQueries(t.WAREHOUSES);
+ queryClient.invalidateQueries(t.WAREHOUSE);
+};
+
+/**
+ * Create a new warehouse.
+ */
+export function useCreateWarehouse(props) {
+ const queryClient = useQueryClient();
+ const apiRequest = useApiRequest();
+
+ return useMutation((values) => apiRequest.post('warehouses', values), {
+ onSuccess: (res, values) => {
+ // Common invalidate queries.
+ commonInvalidateQueries(queryClient);
+ },
+ ...props,
+ });
+}
+
+/**
+ * Edits the given warehouse.
+ */
+export function useEditWarehouse(props) {
+ const queryClient = useQueryClient();
+ const apiRequest = useApiRequest();
+
+ return useMutation(
+ ([id, values]) => apiRequest.post(`warehouses/${id}`, values),
+ {
+ onSuccess: (res, [id, values]) => {
+ // Invalidate specific sale invoice.
+ queryClient.invalidateQueries([t.WAREHOUSE, id]);
+
+ // Common invalidate queries.
+ commonInvalidateQueries(queryClient);
+ },
+ ...props,
+ },
+ );
+}
+
+/**
+ * Deletes the given warehouse.
+ */
+export function useDeleteWarehouse(props) {
+ const queryClient = useQueryClient();
+ const apiRequest = useApiRequest();
+
+ return useMutation((id) => apiRequest.delete(`warehouses/${id}`), {
+ onSuccess: (res, id) => {
+ // Invalidate specific warehoue.
+ queryClient.invalidateQueries([t.WAREHOUSE, id]);
+
+ // Common invalidate queries.
+ commonInvalidateQueries(queryClient);
+ },
+ ...props,
+ });
+}
+
+/**
+ * Retrieve Warehoues list.
+ */
+export function useWarehouses(query, props) {
+ return useRequestQuery(
+ [t.WAREHOUSES, query],
+ { method: 'get', url: 'warehouses', params: query },
+ {
+ select: (res) => res.data.warehouses,
+ defaultData: [],
+ ...props,
+ },
+ );
+}
+
+/**
+ * Retrieve the warehouse details.
+ * @param {number}
+ */
+export function useWarehouse(id, props, requestProps) {
+ return useRequestQuery(
+ [t.WAREHOUSE, id],
+ { method: 'get', url: `warehouses/${id}`, ...requestProps },
+ {
+ select: (res) => res.data.warehouse,
+ defaultData: {},
+ ...props,
+ },
+ );
+}
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index a78695c85..0bf96dab9 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1775,19 +1775,26 @@
"warehouses.label": "Warehouses",
"warehouses.label.new_warehouse": "New Warehouse",
- "warehouse.dialog.label":"New Warehouse",
- "warehouse.dialog.label.warehouse_name":"Warehouse Name",
- "warehouse.dialog.label.warehouse_address":"Address",
- "warehouse.dialog.label.warehouse_address_1":"Address 1",
- "warehouse.dialog.label.warehouse_address_2":"Address 2",
- "warehouse.dialog.label.city":"City",
- "warehouse.dialog.label.country":"Country",
- "warehouse.dialog.label.phone_number":"Phone Number",
- "warehouse_locations.label":"Warehouses Locations",
- "warehouse_locations.column.warehouse_name":"Warehouse name",
- "warehouse_locations.column.quantity":"Quantity",
- "warehouse_locations.column.available_for_sale":"Available for sale",
- "warehouses.action.edit_warehouse":"Edit Warehouse",
- "warehouses.action.delete_warehouse":"Delete Warehouse",
- "warehouses.action.make_as_parimary":"Mark as Primary"
+ "warehouse.dialog.label.new_warehouse": "New Warehouse",
+ "warehouse.dialog.label.edit_warehouse": "Edit Warehouse",
+ "warehouse.dialog.label.warehouse_name": "Warehouse Name",
+ "warehouse.dialog.label.warehouse_address": "Address",
+ "warehouse.dialog.label.warehouse_address_1": "Address",
+ "warehouse.dialog.label.warehouse_address_2": "Address 2",
+ "warehouse.dialog.label.city": "City",
+ "warehouse.dialog.label.country": "Country",
+ "warehouse.dialog.label.phone_number": "Phone Number",
+ "warehouse.dialog.label.code": "Code",
+ "warehouse.dialog.label.email": "Email",
+ "warehouse.dialog.label.website": "Website",
+ "warehouse.dialog.success_message": "The warehouse has been created successfully.",
+ "warehouse_locations.label": "Warehouses Locations",
+ "warehouse_locations.column.warehouse_name": "Warehouse name",
+ "warehouse_locations.column.quantity": "Quantity",
+ "warehouse_locations.column.available_for_sale": "Available for sale",
+ "warehouses.action.edit_warehouse": "Edit Warehouse",
+ "warehouses.action.delete_warehouse": "Delete Warehouse",
+ "warehouses.action.make_as_parimary": "Mark as Primary",
+ "warehouse.alert.delete_message":"The warehouse has been deleted successfully",
+ "warehouse.once_delete_this_warehouse":"Once you delete this warehouse, you won't be able to restore it later. Are you sure you want to delete this warehouse?"
}
\ No newline at end of file