mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
fix(webapp): warehouses select component
This commit is contained in:
@@ -1,75 +1,21 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { MenuItem, Button } from '@blueprintjs/core';
|
|
||||||
import { FSelect } from '../Forms';
|
import { FSelect } from '../Forms';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Warehouse select field.
|
||||||
* @param {*} query
|
|
||||||
* @param {*} warehouse
|
|
||||||
* @param {*} _index
|
|
||||||
* @param {*} exactMatch
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const warehouseItemPredicate = (query, warehouse, _index, exactMatch) => {
|
|
||||||
const normalizedTitle = warehouse.name.toLowerCase();
|
|
||||||
const normalizedQuery = query.toLowerCase();
|
|
||||||
|
|
||||||
if (exactMatch) {
|
|
||||||
return normalizedTitle === normalizedQuery;
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
`${warehouse.code}. ${normalizedTitle}`.indexOf(normalizedQuery) >= 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} film
|
|
||||||
* @param {*} param1
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const warehouseItemRenderer = (
|
|
||||||
warehouse,
|
|
||||||
{ handleClick, modifiers, query },
|
|
||||||
) => {
|
|
||||||
const text = `${warehouse.name}`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<MenuItem
|
|
||||||
active={modifiers.active}
|
|
||||||
disabled={modifiers.disabled}
|
|
||||||
label={warehouse.code}
|
|
||||||
key={warehouse.id}
|
|
||||||
onClick={handleClick}
|
|
||||||
text={text}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const warehouseSelectProps = {
|
|
||||||
itemPredicate: warehouseItemPredicate,
|
|
||||||
itemRenderer: warehouseItemRenderer,
|
|
||||||
valueAccessor: 'id',
|
|
||||||
labelAccessor: 'name',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function WarehouseSelect({ warehouses, ...rest }) {
|
export function WarehouseSelect({ warehouses, ...rest }) {
|
||||||
return <FSelect {...warehouseSelectProps} {...rest} items={warehouses} />;
|
return (
|
||||||
}
|
<FSelect
|
||||||
|
valueAccessor={'id'}
|
||||||
/**
|
labelAccessor={'code'}
|
||||||
*
|
textAccessor={'name'}
|
||||||
* @param {*} param0
|
popoverProps={{ minimal: true, usePortal: true, inline: false }}
|
||||||
* @returns
|
{...rest}
|
||||||
*/
|
items={warehouses}
|
||||||
export function WarehouseSelectButton({ label, ...rest }) {
|
/>
|
||||||
return <Button text={label} />;
|
);
|
||||||
}
|
}
|
||||||
@@ -71,12 +71,6 @@ export const SidebarMenu = [
|
|||||||
ability: InventoryAdjustmentAction.View,
|
ability: InventoryAdjustmentAction.View,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
text: <T id={'sidebar.warehouse_transfer'} />,
|
|
||||||
href: '/warehouses-transfers',
|
|
||||||
type: ISidebarMenuItemType.Link,
|
|
||||||
feature: Features.Warehouses,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text: <T id={'category_list'} />,
|
text: <T id={'category_list'} />,
|
||||||
href: '/items/categories',
|
href: '/items/categories',
|
||||||
@@ -86,6 +80,12 @@ export const SidebarMenu = [
|
|||||||
ability: ItemAction.View,
|
ability: ItemAction.View,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: <T id={'sidebar.warehouse_transfer'} />,
|
||||||
|
href: '/warehouses-transfers',
|
||||||
|
type: ISidebarMenuItemType.Link,
|
||||||
|
feature: Features.Warehouses,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,12 +101,6 @@ export const SidebarMenu = [
|
|||||||
ability: ItemAction.Create,
|
ability: ItemAction.Create,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
text: <T id={'sidebar.new_warehouse_transfer'} />,
|
|
||||||
href: '/warehouses-transfers/new',
|
|
||||||
type: ISidebarMenuItemType.Link,
|
|
||||||
feature: Features.Warehouses,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text: <T id={'sidebar.new_service'} />,
|
text: <T id={'sidebar.new_service'} />,
|
||||||
href: '/items/new',
|
href: '/items/new',
|
||||||
@@ -126,6 +120,12 @@ export const SidebarMenu = [
|
|||||||
ability: ItemAction.Create,
|
ability: ItemAction.Create,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: <T id={'sidebar.new_warehouse_transfer'} />,
|
||||||
|
href: '/warehouses-transfers/new',
|
||||||
|
type: ISidebarMenuItemType.Link,
|
||||||
|
feature: Features.Warehouses,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
BranchSelect,
|
BranchSelect,
|
||||||
WarehouseSelect,
|
WarehouseSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
WarehouseSelectButton,
|
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import {
|
import {
|
||||||
@@ -94,7 +93,6 @@ export default function InventoryAdjustmentFormDialogFields() {
|
|||||||
<WarehouseSelect
|
<WarehouseSelect
|
||||||
name={'warehouse_id'}
|
name={'warehouse_id'}
|
||||||
warehouses={warehouses}
|
warehouses={warehouses}
|
||||||
input={WarehouseSelectButton}
|
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|||||||
@@ -6,19 +6,18 @@ import {
|
|||||||
Position,
|
Position,
|
||||||
ControlGroup,
|
ControlGroup,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
import { FastField, Field, ErrorMessage } from 'formik';
|
||||||
import { FFormGroup, FormattedMessage as T } from '@/components';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
|
import {
|
||||||
|
FFormGroup,
|
||||||
|
FormattedMessage as T,
|
||||||
|
WarehouseSelect,
|
||||||
|
} from '@/components';
|
||||||
import { momentFormatter, compose, tansformDateValue } from '@/utils';
|
import { momentFormatter, compose, tansformDateValue } from '@/utils';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import {
|
import { FieldRequiredHint, Icon, InputPrependButton } from '@/components';
|
||||||
AccountsSelect,
|
|
||||||
FieldRequiredHint,
|
|
||||||
Icon,
|
|
||||||
InputPrependButton,
|
|
||||||
} from '@/components';
|
|
||||||
import { inputIntent, handleDateChange } from '@/utils';
|
import { inputIntent, handleDateChange } from '@/utils';
|
||||||
import { useWarehouseTransferFormContext } from './WarehouseTransferFormProvider';
|
import { useWarehouseTransferFormContext } from './WarehouseTransferFormProvider';
|
||||||
import { useObserveTransferNoSettings } from './utils';
|
import { useObserveTransferNoSettings } from './utils';
|
||||||
@@ -140,9 +139,9 @@ function WarehouseTransferFormHeaderFields({
|
|||||||
inline={true}
|
inline={true}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
>
|
>
|
||||||
<AccountsSelect
|
<WarehouseSelect
|
||||||
name={'from_warehouse_id'}
|
name={'from_warehouse_id'}
|
||||||
items={warehouses}
|
warehouses={warehouses}
|
||||||
placeholder={<T id={'select_warehouse_transfer'} />}
|
placeholder={<T id={'select_warehouse_transfer'} />}
|
||||||
allowCreate={true}
|
allowCreate={true}
|
||||||
fill={true}
|
fill={true}
|
||||||
@@ -156,9 +155,9 @@ function WarehouseTransferFormHeaderFields({
|
|||||||
inline={true}
|
inline={true}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
>
|
>
|
||||||
<AccountsSelect
|
<WarehouseSelect
|
||||||
name={'to_warehouse_id'}
|
name={'to_warehouse_id'}
|
||||||
items={warehouses}
|
warehouses={warehouses}
|
||||||
placeholder={<T id={'select_warehouse_transfer'} />}
|
placeholder={<T id={'select_warehouse_transfer'} />}
|
||||||
fill={true}
|
fill={true}
|
||||||
allowCreate={true}
|
allowCreate={true}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
|
|
||||||
// Invalidate item warehouses.
|
// Invalidate item warehouses.
|
||||||
queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION);
|
queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION);
|
||||||
|
|
||||||
|
// Invalidate items.
|
||||||
|
queryClient.invalidateQueries(t.ITEMS);
|
||||||
|
queryClient.invalidateQueries(t.ITEM);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user