diff --git a/packages/webapp/src/constants/adjustmentType.tsx b/packages/webapp/src/constants/adjustmentType.tsx deleted file mode 100644 index 1d4bf7b65..000000000 --- a/packages/webapp/src/constants/adjustmentType.tsx +++ /dev/null @@ -1,7 +0,0 @@ -// @ts-nocheck -import intl from 'react-intl-universal'; - -export default [ - { name: intl.get('decrement'), value: 'decrement' }, - { name: intl.get('increment'), value: 'increment' }, -] \ No newline at end of file diff --git a/packages/webapp/src/constants/index.tsx b/packages/webapp/src/constants/index.tsx index 344a70c87..cd69f471e 100644 --- a/packages/webapp/src/constants/index.tsx +++ b/packages/webapp/src/constants/index.tsx @@ -4,7 +4,6 @@ export * from './tableStyle'; export * from './features'; export * from './cellTypes'; export * from './classes'; -export * from './adjustmentType'; export * from './cashflowOptions'; export const Align = { Left: 'left', Right: 'right', Center: 'center' }; diff --git a/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.tsx b/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.tsx index e745d3d59..8c6edfd9c 100644 --- a/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.tsx +++ b/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.tsx @@ -34,16 +34,17 @@ import { toSafeNumber, } from '@/utils'; import { Features, CLASSES } from '@/constants'; -import adjustmentType from '@/constants/adjustmentType'; import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider'; +import { useFeatureCan } from '@/hooks/state'; + +import InventoryAdjustmentQuantityFields from './InventoryAdjustmentQuantityFields'; import { diffQuantity, useSetPrimaryBranchToForm, useSetPrimaryWarehouseToForm, + useGetAdjustmentTypeOptions, } from './utils'; -import { useFeatureCan } from '@/hooks/state'; -import InventoryAdjustmentQuantityFields from './InventoryAdjustmentQuantityFields'; /** * Inventory adjustment form dialogs fields. @@ -52,6 +53,9 @@ export default function InventoryAdjustmentFormDialogFields() { // Features guard. const { featureCan } = useFeatureCan(); + // Retrieves memorized adjustment types options. + const adjustmentTypes = useGetAdjustmentTypeOptions(); + const dateFieldRef = useAutofocus(); // Inventory adjustment dialog context. @@ -149,7 +153,7 @@ export default function InventoryAdjustmentFormDialogFields() { className={classNames(CLASSES.FILL, 'form-group--type')} > { const result = diffQuantity( toSafeNumber(values.quantity), diff --git a/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.tsx b/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.tsx index 0e6d7799f..05e61ddd9 100644 --- a/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.tsx +++ b/packages/webapp/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.tsx @@ -1,5 +1,6 @@ // @ts-nocheck -import React from 'react'; +import React, { useMemo } from 'react'; +import intl from 'react-intl-universal'; import { useFormikContext } from 'formik'; import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider'; import { first } from 'lodash'; @@ -48,3 +49,12 @@ export const useSetPrimaryBranchToForm = () => { } }, [isBranchesSuccess, setFieldValue, branches]); }; + +export const getAdjustmentTypeOptions = () => [ + { name: intl.get('decrement'), value: 'decrement' }, + { name: intl.get('increment'), value: 'increment' }, +]; + +export const useGetAdjustmentTypeOptions = () => { + return useMemo(() => getAdjustmentTypeOptions(), []); +}; diff --git a/packages/webapp/src/store/inventoryAdjustments/inventoryAdjustment.type.tsx b/packages/webapp/src/store/inventoryAdjustments/inventoryAdjustment.type.tsx index 1d53f6d96..872f7a5f5 100644 --- a/packages/webapp/src/store/inventoryAdjustments/inventoryAdjustment.type.tsx +++ b/packages/webapp/src/store/inventoryAdjustments/inventoryAdjustment.type.tsx @@ -1,5 +1,6 @@ // @ts-nocheck export default { - INVENTORY_ADJUSTMENTS_TABLE_STATE_SET: 'INVENTORY_ADJUSTMENTS/TABLE_STATE_SET', -}; \ No newline at end of file + INVENTORY_ADJUSTMENTS_TABLE_STATE_SET: + 'INVENTORY_ADJUSTMENTS/TABLE_STATE_SET', +};