diff --git a/client/src/components/profile/ProfileRequestForm.js b/client/src/components/profile/ProfileRequestForm.js
index 60fcae5..cb83622 100644
--- a/client/src/components/profile/ProfileRequestForm.js
+++ b/client/src/components/profile/ProfileRequestForm.js
@@ -8,12 +8,17 @@ import {
TextField,
Typography,
makeStyles,
+ FormControl,
+ Select,
+ InputLabel,
+ MenuItem,
} from "@material-ui/core";
import {
AuthDispatchContext,
AuthStateContext,
} from "../../context/AuthContext";
import { createRequest } from "../../actions/request";
+import { format, isBefore, isSameDay, parseISO } from "date-fns";
import Alert from "../Alert";
import { CLEAR_ERRORS } from "../../actions/types";
@@ -42,7 +47,7 @@ const useStyles = makeStyles(() => ({
},
}));
-function ProfileRequestForm({ sitterId }) {
+function ProfileRequestForm({ sitterId, sitterPrice, sitterAvailability }) {
const classes = useStyles();
// Get dispatch method and state from auth context
@@ -78,6 +83,9 @@ function ProfileRequestForm({ sitterId }) {
}
}, [alerts]);
+ const checkDate = (date) => {
+ return isSameDay(parseISO(date.start), parseISO(startDate));
+ };
//clear any errors initially
useEffect(() => {
dispatch({ type: CLEAR_ERRORS });
@@ -90,13 +98,13 @@ function ProfileRequestForm({ sitterId }) {
}, [errors]);
// Handle change in 'Drop Off' (start) date input
- const handleStartDateChange = e => {
+ const handleStartDateChange = (e) => {
const formattedStartDate = moment(
new Date(`${e.target.value}T${startTime}`)
).format();
setStartDate(e.target.value);
-
+ const result = sitterAvailability.find(checkDate);
// If start date is later than end date, change end date to same day as start date.
if (e.target.value > endDate) {
const formattedEndDate = moment(
@@ -117,7 +125,7 @@ function ProfileRequestForm({ sitterId }) {
};
// Handle change in 'Pick Up' (end) date input
- const handleEndDateChange = e => {
+ const handleEndDateChange = (e) => {
const formattedEndDate = moment(
new Date(`${e.target.value}T${endTime}`)
).format();
@@ -146,7 +154,7 @@ function ProfileRequestForm({ sitterId }) {
};
// Handle change in 'Drop off' (start) time input
- const handleStartTimeChange = e => {
+ const handleStartTimeChange = (e) => {
const formattedStartDate = moment(
new Date(`${startDate}T${e.target.value}`)
).format();
@@ -160,7 +168,7 @@ function ProfileRequestForm({ sitterId }) {
};
// Handle change in 'Pick Up' (start) time input.
- const handleEndTimeChange = e => {
+ const handleEndTimeChange = (e) => {
const formattedEndDate = moment(
new Date(`${endDate}T${e.target.value}`)
).format();
@@ -173,19 +181,20 @@ function ProfileRequestForm({ sitterId }) {
});
};
- const handleSubmit = async e => {
+ const handleSubmit = async (e) => {
setRequestSending(true);
e.preventDefault();
+ console.log(requestFormData);
createRequest(dispatch, requestFormData);
};
return (
<>
-
- $14/hr
+
+ ${sitterPrice}/hr
DROP OFF
+
+ Date
+
+
+ {/*
handleStartDateChange(e)}
- variant="outlined"
- >
+ onChange={(e) => handleStartDateChange(e)}
+ variant='outlined'
+ >*/}
{
+ onChange={(e) => {
handleStartTimeChange(e);
}}
/>
@@ -223,39 +254,61 @@ function ProfileRequestForm({ sitterId }) {
PICK UP
+
+ Date
+
+
+ {/*
handleEndDateChange(e)}
- >
+ onChange={(e) => handleEndDateChange(e)}
+ >*/}
{
+ variant='outlined'
+ onChange={(e) => {
handleEndTimeChange(e);
}}
/>