Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test 'staging' #111

Merged
merged 17 commits into from
Nov 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add totalPrice when sending a request
MarianaES committed Nov 5, 2021
commit b6ac64a83232ff901a08b760cb9cc21806bfcdd9
4 changes: 2 additions & 2 deletions client/src/helpers/APICalls/requests.ts
Original file line number Diff line number Diff line change
@@ -16,13 +16,13 @@ export async function createRequest(
sitterId: string,
startDate: Date,
endDate: Date,
serviceType?: string,
totalPrice?: number,
serviceType?: string,
): Promise<RequestApiData> {
const fetchOptions: FetchOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sitterId, startDate, endDate, serviceType, totalPrice }),
body: JSON.stringify({ sitterId, startDate, endDate, totalPrice, serviceType }),
credentials: 'include',
};
return await fetch('/request/', fetchOptions)
11 changes: 9 additions & 2 deletions client/src/pages/SitterDetails/SitterDetails.tsx
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ import useStyles from './useStyles';
import { useParams } from 'react-router-dom';
import { Profile } from '../../interface/Profile';
import { getSitterProfile, getSitterReviews } from '../../helpers/APICalls/profile';
import { format, formatISO, parseISO } from 'date-fns';
import { eachDayOfInterval, format, formatISO, parseISO } from 'date-fns';
import { createRequest } from '../../helpers/APICalls/requests';
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date';
import { useSnackBar } from '../../context/useSnackbarContext';
@@ -102,7 +102,14 @@ function SitterDetails(): JSX.Element {
const endDate = convertToDateTime(dropOffDate, dropOffTime);
const selectedUserSitterId = profile?.user || '';

createRequest(selectedUserSitterId, startDate, endDate).then((data) => {
const numberOfDays = eachDayOfInterval({
start: startDate,
end: endDate,
}).length;

const totalPrice = profile?.ratePerDay ? numberOfDays * Number(profile?.ratePerDay) : numberOfDays * 40;

createRequest(selectedUserSitterId, startDate, endDate, totalPrice).then((data) => {
if (data.error) {
console.error({ error: data.error.message });
updateSnackBarMessage('Please log in and try again!');