Skip to content

Commit

Permalink
added basic validation to application flow
Browse files Browse the repository at this point in the history
now checks for valid info on first page
  • Loading branch information
Lionsluke committed Oct 7, 2024
1 parent 0faf5de commit 7081bbb
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const RenterApplication = forwardRef(({ providedProperty }, ref) => {
// variables and methods for opening and closing dialog
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
applicant.lease_start_date = dayjs().add(1, 'month'); // a month from today
applicant.adults = 2;
applicant.kids = 0;
applicant.pets = 0;
setOpen(true);
};
const handleClose = () => {
Expand Down Expand Up @@ -269,7 +273,7 @@ const RenterApplication = forwardRef(({ providedProperty }, ref) => {
label="Duration of Lease"
defaultValue={formData.lease_duration}
onBlur={handleChange}
error={formErrors.first_name}
error={formErrors.lease_duration}
MenuProps={{PaperProps: { style: { maxHeight: 300}}}}
>
{[...Array(48)].map((_, index) => (
Expand All @@ -286,7 +290,7 @@ const RenterApplication = forwardRef(({ providedProperty }, ref) => {
name="lease_start_date" label="Lease Start Date"
defaultValue={dayjs(formData.lease_start_date,'DD/MM/YYYY')} format="DD/MM/YYYY"
onBlur={handleChange}
error={formErrors.date_of_birth}
error={formErrors.lease_start_date}
/>
</LocalizationProvider>
</Grid>
Expand All @@ -299,23 +303,23 @@ const RenterApplication = forwardRef(({ providedProperty }, ref) => {
name="adults" id="outlined-required"
label="Adults" defaultValue={formData.adults}
onBlur={handleChange}
error={formErrors.mobile}
error={formErrors.adults}
/>
</Grid>
<Grid item xs={2}>
<TextField fullWidth required
name="kids" id="outlined-required"
label="Children" defaultValue={formData.kids}
onBlur={handleChange}
error={formErrors.email}
error={formErrors.kids}
/>
</Grid>
<Grid item xs={2}>
<TextField fullWidth required
name="pets" id="outlined-required"
label="Pets" defaultValue={formData.pets}
onBlur={handleChange}
error={formErrors.email}
error={formErrors.pets}
/>
</Grid>
</Grid>
Expand All @@ -329,7 +333,14 @@ const RenterApplication = forwardRef(({ providedProperty }, ref) => {
function rentalInformationValidation(applicantData) {
let failureFlag = false;

if (!(dayjs(applicantData.lease_start_date,'DD/MM/YYYY').isAfter(dayjs()))) {
if (applicantData.lease_duration == null) {
renterInformationErrors.lease_duration = true;
failureFlag = true;
} else {
renterInformationErrors.lease_duration = false;
}

if (!(dayjs(applicantData.lease_start_date, 'DD/MM/YYYY').isAfter(dayjs(), 'day'))) {
renterInformationErrors.lease_start_date = true;
failureFlag = true;
} else {
Expand Down

0 comments on commit 7081bbb

Please sign in to comment.