Skip to content

Commit

Permalink
Updated the date validation part. Added .env.example to show environm…
Browse files Browse the repository at this point in the history
…ent variables
  • Loading branch information
ac030540 committed Aug 1, 2020
1 parent 71989ca commit 3a282b0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_SERVER_URL=http://localhost:4000
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"date-fns": "^2.15.0",
"prop-types": "^15.7.2",
"react": "^16.9.0",
"react-dom": "^16.9.0",
Expand Down
21 changes: 5 additions & 16 deletions src/routes/BookingPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from 'react';
import DoctorCard from '../components/DoctorCard';
import MessageCard from '../components/MessageCard';
import isAfter from 'date-fns/isAfter';
import isSameDay from 'date-fns/isSameDay';
import './BookingPage.css';

const BookingPage = (props) => {
Expand Down Expand Up @@ -61,6 +63,7 @@ const BookingPage = (props) => {
const currentDate = today.getDate();
const reg = /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,4})$/;
const enteredDateArray = dateOfAppointment.split('-');
console.log(enteredDateArray, currentYear, currentMonth, currentDate, "entered date array");
if (patientName === null || patientName === '') {
setMessage('Entered name is invalid');
setMessageType('alert-danger');
Expand All @@ -73,26 +76,12 @@ const BookingPage = (props) => {
setMessage('Entered address is invalid');
setMessageType('alert-danger');
invalidCount += 1;
} else if (enteredDateArray[0] < String(currentYear)) {
} else if (!isAfter(new Date(dateOfAppointment), new Date()) && !isSameDay(new Date(dateOfAppointment), new Date())) {
setMessage('Invalid date selected');
setMessageType('alert-danger');
invalidCount += 1;
} else if (enteredDateArray[0] === String(currentYear)) {
console.log('year matched');
if (enteredDateArray[1] < String(currentMonth)) {
setMessage('Invalid date selected');
setMessageType('alert-danger');
invalidCount += 1;
} else if (enteredDateArray[1] === String(currentMonth)) {
console.log('month matched');
if (enteredDateArray[2] < String(currentDate)) {
setMessage('Invalid date selected');
setMessageType('alert-danger');
invalidCount += 1;
}
}
}
if (String(contactNumber).length !== 10 || isNaN(contactNumber) || contactNumber === '') {
else if (String(contactNumber).length !== 10 || isNaN(contactNumber) || contactNumber === '') {
setMessage('Entered contact number is invalid');
setMessageType('alert-danger');
invalidCount += 1;
Expand Down

0 comments on commit 3a282b0

Please sign in to comment.