mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
fix: edit item form.
This commit is contained in:
@@ -41,6 +41,7 @@ const defaultInitialValues = {
|
||||
purchasable: true,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Item form.
|
||||
*/
|
||||
@@ -119,14 +120,13 @@ function ItemForm({
|
||||
then: Yup.number().required(),
|
||||
otherwise: Yup.number().nullable(),
|
||||
})
|
||||
.label(formatMessage({ id: 'Inventory account' })),
|
||||
.label(formatMessage({ id: 'inventory_account' })),
|
||||
category_id: Yup.number().positive().nullable(),
|
||||
stock: Yup.string() || Yup.boolean(),
|
||||
sellable: Yup.boolean().required(),
|
||||
purchasable: Yup.boolean().required(),
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Initial values in create and edit mode.
|
||||
*/
|
||||
@@ -150,6 +150,14 @@ function ItemForm({
|
||||
: changePageTitle(formatMessage({ id: 'new_item' }));
|
||||
}, [changePageTitle, isNewMode, formatMessage]);
|
||||
|
||||
const transformApiErrors = (errors) => {
|
||||
const fields = {};
|
||||
if (errors.find(e => e.type === 'ITEM.NAME.ALREADY.EXISTS')) {
|
||||
fields.name = formatMessage({ id: 'the_name_used_before' })
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, resetForm, setErrors }) => {
|
||||
setSubmitting(true);
|
||||
@@ -173,8 +181,13 @@ function ItemForm({
|
||||
history.push('/items');
|
||||
queryCache.removeQueries(['items-table']);
|
||||
};
|
||||
const onError = (response) => {
|
||||
const onError = ({ response }) => {
|
||||
setSubmitting(false);
|
||||
|
||||
if (response.data.errors) {
|
||||
const _errors = transformApiErrors(response.data.errors);
|
||||
setErrors({ ..._errors });
|
||||
}
|
||||
};
|
||||
if (isNewMode) {
|
||||
requestSubmitItem(form).then(onSuccess).catch(onError);
|
||||
@@ -204,7 +217,7 @@ function ItemForm({
|
||||
} else {
|
||||
changePageSubtitle('');
|
||||
}
|
||||
}, [values.item_type]);
|
||||
}, [values.item_type, changePageSubtitle, formatMessage]);
|
||||
|
||||
const initialAttachmentFiles = useMemo(() => {
|
||||
return itemDetail && itemDetail.media
|
||||
@@ -240,24 +253,24 @@ function ItemForm({
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div class={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||
<ItemFormPrimarySection
|
||||
errors={errors}
|
||||
touched={touched}
|
||||
values={values}
|
||||
getFieldProps={getFieldProps}
|
||||
setFieldValue={setFieldValue}
|
||||
errors={errors}
|
||||
touched={touched}
|
||||
values={values}
|
||||
/>
|
||||
<ItemFormBody
|
||||
getFieldProps={getFieldProps}
|
||||
touched={touched}
|
||||
errors={errors}
|
||||
values={values}
|
||||
getFieldProps={getFieldProps}
|
||||
setFieldValue={setFieldValue}
|
||||
/>
|
||||
<ItemFormInventorySection
|
||||
errors={errors}
|
||||
touched={touched}
|
||||
setFieldValue={setFieldValue}
|
||||
values={values}
|
||||
setFieldValue={setFieldValue}
|
||||
getFieldProps={getFieldProps}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
Position,
|
||||
Tooltip,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import {
|
||||
CategoriesSelectList,
|
||||
ErrorMessage,
|
||||
@@ -83,7 +83,7 @@ function ItemFormPrimarySection({
|
||||
/>
|
||||
<Radio
|
||||
label={<T id={'non_inventory'} />}
|
||||
value="non_inventory"
|
||||
value="non-inventory"
|
||||
/>
|
||||
</RadioGroup>
|
||||
</FormGroup>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
MenuDivider,
|
||||
Position,
|
||||
Intent,
|
||||
Tag,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Icon, DataTable, Money, If, Choose } from 'components';
|
||||
@@ -15,6 +16,7 @@ import LoadingIndicator from 'components/LoadingIndicator';
|
||||
import withItems from 'containers/Items/withItems';
|
||||
import { compose } from 'utils';
|
||||
|
||||
|
||||
const ItemsDataTable = ({
|
||||
loading,
|
||||
|
||||
@@ -87,43 +89,58 @@ const ItemsDataTable = ({
|
||||
{
|
||||
Header: formatMessage({ id: 'item_name' }),
|
||||
accessor: 'name',
|
||||
className: 'actions',
|
||||
className: 'name',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'sku' }),
|
||||
Header: formatMessage({ id: 'item_code' }),
|
||||
accessor: 'sku',
|
||||
className: 'sku',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'item_type' }),
|
||||
accessor: (row) =>
|
||||
row.type ? (
|
||||
<Tag minimal={true} round={true} intent={Intent.NONE}>
|
||||
{formatMessage({ id: row.type })}
|
||||
</Tag>
|
||||
) : (
|
||||
''
|
||||
),
|
||||
className: 'item_type',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'category' }),
|
||||
accessor: 'category.name',
|
||||
className: 'category',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'sell_price' }),
|
||||
accessor: (row) => <Money amount={row.sell_price} currency={'USD'} />,
|
||||
className: 'sell-price',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'cost_price' }),
|
||||
accessor: (row) => <Money amount={row.cost_price} currency={'USD'} />,
|
||||
className: 'cost-price',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'quantity_on_hand' }),
|
||||
accessor: 'quantity_on_hand',
|
||||
className: 'quantity_on_hand',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'average_rate' }),
|
||||
accessor: 'average_cost_rate',
|
||||
className: 'average_cost_rate',
|
||||
width: 140,
|
||||
},
|
||||
// {
|
||||
// Header: 'Cost Account',
|
||||
// accessor: 'cost_account.name',
|
||||
// className: "cost-account",
|
||||
// },
|
||||
// {
|
||||
// Header: 'Sell Account',
|
||||
// accessor: 'sell_account.name',
|
||||
// className: "sell-account",
|
||||
// },
|
||||
// {
|
||||
// Header: 'Inventory Account',
|
||||
// accessor: 'inventory_account.name',
|
||||
// className: "inventory-account",
|
||||
// },
|
||||
{
|
||||
id: 'actions',
|
||||
Cell: ({ cell }) => (
|
||||
|
||||
@@ -189,8 +189,6 @@ function ItemsList({
|
||||
return (
|
||||
<DashboardInsider
|
||||
loading={fetchResourceViews.isFetching || fetchResourceFields.isFetching}
|
||||
// isLoading={fetchHook.isFetching}
|
||||
|
||||
name={'items-list'}
|
||||
>
|
||||
<ItemsActionsBar
|
||||
|
||||
Reference in New Issue
Block a user