@@ -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 , categorySelectIfNew } from "lib/utils/categories" ;
1515
1616import UploadModal from 'app/Inventory/UploadModal' ;
1717import { alertError , alertSuccess } from "../Notifications" ;
@@ -41,7 +41,8 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
4141 weight_unit : default_weight_unit ,
4242 price : undefined ,
4343 product_url : '' ,
44- newCategory : false
44+ newCategory : false ,
45+ excludeWeight : false
4546 } }
4647 validationSchema = { Yup . object ( ) . shape ( {
4748 name : Yup . string ( ) . required ( 'Item name is required' ) ,
@@ -69,6 +70,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
6970 const wasSubmitted = submitCount > 0 ;
7071 const weightUnit = values . weight_unit ;
7172 const categoryValue = categorySelectValue ( app . categories , values . categoryId ) ;
73+ let isNewCategory = categorySelectIfNew ( app . categories , values . categoryId ) ;
7274
7375 return (
7476 < SidebarContainer >
@@ -87,14 +89,24 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
8789 value = { categoryValue || null }
8890 onChange = { ( option : Option < number > ) => {
8991 const value = option ? option . value : undefined ;
90- const isNewCategory = Boolean ( option && option . __isNew__ ) ;
92+ isNewCategory = Boolean ( option && option . __isNew__ ) ;
9193 setFieldValue ( 'categoryId' , value ) ;
9294 setFieldValue ( 'newCategory' , isNewCategory ) ;
9395 } }
9496 error = { wasSubmitted && ! ! errors . categoryId }
9597 errorMsg = { errors . categoryId }
9698 clearable = { true }
9799 />
100+ { isNewCategory &&
101+ < SwitchInput
102+ label = "Exclude category from base weight"
103+ checked = { values . excludeWeight }
104+ checkedText = "Yes"
105+ uncheckedText = "No"
106+ tip = "All items added to this category will be exluded from base weight"
107+ onChange = { v => setFieldValue ( 'excludeWeight' , v ) }
108+ > </ SwitchInput >
109+ }
98110 < Input
99111 label = "Product Name"
100112 value = { values . product_name || '' }
@@ -172,4 +184,4 @@ const ItemFormWithProps = withApi<FormSpecs.ApiProps>(api => ({
172184 exportCsv : api . ItemService . exportCSV
173185} ) ) ( ItemForm ) ;
174186
175- export default ItemFormWithProps ;
187+ export default ItemFormWithProps ;
0 commit comments