@@ -3,15 +3,15 @@ import * as Yup from 'yup';
33import FileDownload from 'js-file-download' ;
44import { Formik , FormikProps } from "formik" ;
55import { Row , Col , Button } from "antd" ;
6- import { Input , Select , SelectCreatable , Option } from ' ../FormFields' ;
6+ import { Input , Select , SelectCreatable , Option , SwitchInput } from " ../FormFields" ;
77
88import { AppContext } from 'AppContext' ;
99import { CreateItem , ItemConstants } from "types/item" ;
1010import { FormSpecs } from "./types" ;
1111
1212import withApi from 'app/components/higher-order/with-api' ;
1313import { categoryOptions , weightUnitOptions } from "lib/utils/form" ;
14- import { categorySelectValue } from "lib/utils/categories" ;
14+ import { categorySelectValue , categoryCheckIfNew } from "lib/utils/categories" ;
1515
1616import UploadModal from 'app/Inventory/UploadModal' ;
1717import { alertError , alertSuccess } from "../Notifications" ;
@@ -42,6 +42,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
4242 price : undefined ,
4343 product_url : '' ,
4444 newCategory : false ,
45+ excludeWeight : false ,
4546 notes : ''
4647 } }
4748 validationSchema = { Yup . object ( ) . shape ( {
@@ -70,6 +71,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
7071 const wasSubmitted = submitCount > 0 ;
7172 const weightUnit = values . weight_unit ;
7273 const categoryValue = categorySelectValue ( app . categories , values . categoryId ) ;
74+ let isNewCategory = categoryCheckIfNew ( app . categories , values . categoryId ) ;
7375
7476 return (
7577 < SidebarContainer >
@@ -88,14 +90,23 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
8890 value = { categoryValue || null }
8991 onChange = { ( option : Option < number > ) => {
9092 const value = option ? option . value : undefined ;
91- const isNewCategory = Boolean ( option && option . __isNew__ ) ;
93+ isNewCategory = Boolean ( option && option . __isNew__ ) ;
9294 setFieldValue ( 'categoryId' , value ) ;
9395 setFieldValue ( 'newCategory' , isNewCategory ) ;
9496 } }
9597 error = { wasSubmitted && ! ! errors . categoryId }
9698 errorMsg = { errors . categoryId }
9799 clearable = { true }
98100 />
101+ { isNewCategory &&
102+ < SwitchInput
103+ label = "Exclude category from base weight"
104+ checked = { values . excludeWeight }
105+ checkedText = "Yes"
106+ uncheckedText = "No"
107+ tip = "All items added to this category will be excluded from base weight"
108+ onChange = { v => setFieldValue ( 'excludeWeight' , v ) } />
109+ }
99110 < Input
100111 label = "Product Name"
101112 value = { values . product_name || '' }
0 commit comments