@@ -23,10 +23,8 @@ const validationSchema = Yup.object().shape({
2323 . min ( 7 , "*Phone Number must have at least 7 characters" )
2424 . max ( 20 , "*Phone Number can't be longer than 20 characters" )
2525 . required ( "*Phone Number is required" ) ,
26- unitNum : Yup . string ( )
27- . required ( "*Unit Number is required" ) ,
28- occupants : Yup . number ( )
29- . required ( "*Number of Occupants is required" ) ,
26+ unitNum : Yup . string ( ) ,
27+ occupants : Yup . number ( ) ,
3028} ) ;
3129
3230const makeAuthHeaders = ( { user } ) => ( { headers : { 'Authorization' : `Bearer ${ user . accessJwt } ` } } ) ;
@@ -96,13 +94,8 @@ export const AddTenant = () => {
9694 } ;
9795
9896 const handleFormSubmit = ( data ) => {
99- let body = {
100- ...data ,
101- propertyID : propertySelection [ 0 ] . key ,
102- staffIDs : staffSelections && staffSelections . map ( staff => staff . key )
103- } ;
10497 axios
105- . post ( `/api/tenants` , body , makeAuthHeaders ( context ) )
98+ . post ( `/api/tenants` , data , makeAuthHeaders ( context ) )
10699 . then ( ( response ) => {
107100 Toast ( "Tenant Created Successfully!" , "success" ) ;
108101 } )
@@ -187,9 +180,15 @@ export const AddTenant = () => {
187180 onSubmit = { ( values , { setSubmitting, resetForm } ) => {
188181 const toSubmit = {
189182 ...values ,
190- dateTimeStart,
191- dateTimeEnd,
183+ occupants : values . occupants || null ,
184+ unitNum : values . unitNum || null ,
185+ propertyID : propertySelection [ 0 ] . key ,
186+ staffIDs : staffSelections && staffSelections . map ( staff => staff . key )
192187 } ;
188+ if ( dateTimeStart !== dateTimeEnd ) {
189+ toSubmit . dateTimeStart = dateTimeStart ;
190+ toSubmit . dateTimeEnd = dateTimeEnd ;
191+ }
193192
194193 setSubmitting ( true ) ;
195194 handleFormSubmit ( toSubmit ) ;
0 commit comments