Skip to content

Commit 25a939d

Browse files
committed
allow null values for occupants and unitNum
1 parent f9becbf commit 25a939d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/views/AddTenant/addTenant.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3230
const 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

Comments
 (0)