Skip to content

Commit

Permalink
dbAddReservation merger onto current
Browse files Browse the repository at this point in the history
  • Loading branch information
Lor3wp committed Dec 6, 2023
2 parents 0048923 + ffe0587 commit 955aa06
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 43 deletions.
33 changes: 28 additions & 5 deletions src/components/BankButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,41 @@ import { useState } from 'react';
import PopUpWarningModal from '../components/PopUpWarningModal';
import { useNavigate } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';

const BankButton = ({ logo, bankName, rentId }) => {
import useApi from '../hooks/useApi';
import { useStepper } from '../hooks/useStepper';
const BankButton = ({ logo, bankName, randomUUID }) => {
const [showWarningModal, setShowWarningModal] = useState(false);

const navigate = useNavigate();

const { t } = useTranslation();
const { userData } = useStepper();
const { postRequest } = useApi();

const handleClick = (bankName) => {
const handleClick = async (bankName) => {
if (bankName === 'HSY') {
handleOpenWarningModal();
} else {
navigate(`/rent-successful/${rentId}`);
try {
const bodyData = {
customerInfo: {
name: userData.firstName,
lastName: userData.lastName,
phoneNumber: userData.phoneNumber,
email: userData.emailAddress,
address: userData.streetName,
zipCode: userData.postalCode,
city: userData.cityName,
},
uuid: randomUUID,
};

const responce = await postRequest('add-reservation', bodyData);
console.log('BankButton.jsx 36', responce.updatedReservation._id);
navigate(`/rent-successful/${responce.updatedReservation._id}`);
} catch (error) {
console.log(error);
}
}
};

Expand Down Expand Up @@ -68,7 +91,7 @@ const BankButton = ({ logo, bankName, rentId }) => {
BankButton.propTypes = {
logo: PropTypes.any.isRequired,
bankName: PropTypes.string,
rentId: PropTypes.string.isRequired,
randomUUID: PropTypes.string.isRequired,
};

export default BankButton;
11 changes: 10 additions & 1 deletion src/components/BankType.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import PropTypes from 'prop-types';
import BankButton from './BankButton';
import styles from '../css/BankButton.module.css';

const BankType = ({ gridName, title, arrayName, paymentName, rentId }) => {
const BankType = ({
gridName,
title,
arrayName,
paymentName,
rentId,
randomUUID,
}) => {
return (
<div className={styles.titleButtonContainer}>
<h3>{title}</h3>
Expand All @@ -14,6 +21,7 @@ const BankType = ({ gridName, title, arrayName, paymentName, rentId }) => {
bankName={item.bankName}
key={item.bankName}
rentId={rentId}
randomUUID={randomUUID}
></BankButton>
</div>
))}
Expand All @@ -28,5 +36,6 @@ BankType.propTypes = {
arrayName: PropTypes.array,
paymentName: PropTypes.string,
rentId: PropTypes.string.isRequired,
randomUUID: PropTypes.string.isRequired,
};
export default BankType;
4 changes: 3 additions & 1 deletion src/components/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const RentCalendar = ({ futureDates, setSelectedDate }) => {
};

const handleChange = (date) => {
setSelectedDate(date);
date.setHours(date.getHours() + 12);
setSelectedDate(date);
console.log(date.getHours());
};

const tileDisabled = ({ date }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectProduct.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';
import { Button, Form } from 'react-bootstrap';
import productStyle from '../css/SelectProduct.module.css';
import timeStyle from '../css/SelectTime.module.css';
Expand Down
28 changes: 2 additions & 26 deletions src/components/UserForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import PopUpWarningModal from '../components/PopUpWarningModal';
import hsyLogo from '../assets/hsy_logo_dark.png';
import { useStepper } from '../hooks/useStepper';
import { useTranslation } from 'react-i18next';
import useApi from '../hooks/useApi';
const UserForm = ({ onSubmit, onPrevStep, randomUUID }) => {
const UserForm = ({ onSubmit, onPrevStep }) => {
const [validated, setValidated] = useState(false);
const [showInfoModal, setShowInfoModal] = useState(false);
const [showWarningModal, setShowWarningModal] = useState(false);
Expand All @@ -33,7 +32,6 @@ const UserForm = ({ onSubmit, onPrevStep, randomUUID }) => {
setAcceptTerms,
} = useStepper();

const { postRequest } = useApi();
const { t } = useTranslation();

const navigate = useNavigate();
Expand Down Expand Up @@ -176,7 +174,7 @@ const UserForm = ({ onSubmit, onPrevStep, randomUUID }) => {
navigate('/', { replace: true });
};

const handleConfirmRentInfo = async () => {
const handleConfirmRentInfo = () => {
onSubmit({
firstName: submitEvent.elements.firstName.value,
lastName: submitEvent.elements.lastName.value,
Expand All @@ -186,27 +184,6 @@ const UserForm = ({ onSubmit, onPrevStep, randomUUID }) => {
postalCode: submitEvent.elements.postalCode.value,
cityName: submitEvent.elements.cityName.value,
});

try {
const bodyData = {
customerInfo: {
name: submitEvent.elements.firstName.value,
lastName: submitEvent.elements.lastName.value,
phoneNumber: submitEvent.elements.phoneNumber.value,
email: submitEvent.elements.emailAddress.value,
addres: submitEvent.elements.streetName.value,
zipCode: submitEvent.elements.postalCode.value,
city: submitEvent.elements.cityName.value,
},
idPrepaid: false,
uuid: randomUUID,
};
console.log(bodyData);
const responce = await postRequest('add-reservation', bodyData);
console.log('UserForm.jsx 209', responce);
} catch (error) {
console.log(error);
}
};

const handleOpenTosModal = () => {
Expand Down Expand Up @@ -379,7 +356,6 @@ UserForm.propTypes = {
onSubmit: PropTypes.func.isRequired,
handleInfoModal: PropTypes.func,
onPrevStep: PropTypes.func.isRequired,
randomUUID: PropTypes.string.isRequired,
};

export default UserForm;
2 changes: 2 additions & 0 deletions src/hooks/useApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const useApi = () => {
try {
const response = await postRequest(endpoint, data);
handleApiSuccess(response);
return response;
} catch (error) {
handleApiError(error);
}
Expand All @@ -57,6 +58,7 @@ const useApi = () => {
try {
const response = await deleteRequest(endpoint, uuid);
handleApiSuccess(response);
return response;
} catch (error) {
handleApiError(error);
}
Expand Down
11 changes: 7 additions & 4 deletions src/pages/RentProcess.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const RentProcessPage = () => {
calculateReservationDeadline(),
);

const mockRentData = {
id: '656e0884162df1917d30e826',
};
const mockRentData = {
id: '656e0884162df1917d30e826',
};

const { t } = useTranslation();

Expand Down Expand Up @@ -145,27 +145,31 @@ const RentProcessPage = () => {
title={t('Mobiilimaksutavat')}
arrayName={mobileBanks}
paymentName={styles.mobilePayment}
randomUUID={randomUUID}
/>
<BankType
rentId={mockRentData.id}
gridName={styles.cardGrid}
title={t('Korttimaksutavat')}
arrayName={cardPayments}
paymentName={styles.cardPayment}
randomUUID={randomUUID}
/>
<BankType
rentId={mockRentData.id}
gridName={styles.bankGrid}
title={t('Pankkimaksutavat')}
arrayName={bankPayments}
paymentName={styles.bankPayment}
randomUUID={randomUUID}
/>
<BankType
rentId={mockRentData.id}
gridName={styles.irlGrid}
title={t('Maksu paikan päällä')}
arrayName={irlPayments}
paymentName={styles.irlPayment}
randomUUID={randomUUID}
/>
</div>
);
Expand Down Expand Up @@ -196,7 +200,6 @@ const RentProcessPage = () => {
handleWarningModal={handleWarningModal}
onSubmit={handleFormSubmit}
onPrevStep={handlePrevStep}
randomUUID={randomUUID}
/>
);
case 3:
Expand Down
6 changes: 1 addition & 5 deletions src/utils/axios.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import axios from 'axios';
import { NODE_ENV, PUBLIC_DOMAIN, PUBLIC_PORT } from './constants';

const baseURL =
NODE_ENV === 'production'
? 'https://hsytrailerapi.azurewebsites.net/api/'
: `http://${PUBLIC_DOMAIN ?? 'localhost'}:${PUBLIC_PORT ?? '3000'}/api/`;
const baseURL = 'https://hsytrailerapi.azurewebsites.net/api/';

const axiosInstance = axios.create({
baseURL: baseURL,
Expand Down

0 comments on commit 955aa06

Please sign in to comment.