Skip to content

Commit

Permalink
allow null values for occupants and unitNum
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveTrost committed Dec 22, 2020
1 parent f9becbf commit 25a939d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/views/AddTenant/addTenant.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ const validationSchema = Yup.object().shape({
.min(7, "*Phone Number must have at least 7 characters")
.max(20, "*Phone Number can't be longer than 20 characters")
.required("*Phone Number is required"),
unitNum: Yup.string()
.required("*Unit Number is required"),
occupants: Yup.number()
.required("*Number of Occupants is required"),
unitNum: Yup.string(),
occupants: Yup.number(),
});

const makeAuthHeaders = ({ user }) => ({ headers: { 'Authorization': `Bearer ${user.accessJwt}` } });
Expand Down Expand Up @@ -96,13 +94,8 @@ export const AddTenant = () => {
};

const handleFormSubmit = (data) => {
let body = {
...data,
propertyID: propertySelection[0].key,
staffIDs: staffSelections && staffSelections.map(staff => staff.key)
};
axios
.post(`/api/tenants`, body, makeAuthHeaders(context))
.post(`/api/tenants`, data, makeAuthHeaders(context))
.then((response) => {
Toast("Tenant Created Successfully!", "success");
})
Expand Down Expand Up @@ -187,9 +180,15 @@ export const AddTenant = () => {
onSubmit={(values, { setSubmitting, resetForm }) => {
const toSubmit = {
...values,
dateTimeStart,
dateTimeEnd,
occupants: values.occupants || null,
unitNum: values.unitNum || null,
propertyID: propertySelection[0].key,
staffIDs: staffSelections && staffSelections.map(staff => staff.key)
};
if (dateTimeStart !== dateTimeEnd) {
toSubmit.dateTimeStart = dateTimeStart;
toSubmit.dateTimeEnd = dateTimeEnd;
}

setSubmitting(true);
handleFormSubmit(toSubmit);
Expand Down

0 comments on commit 25a939d

Please sign in to comment.