diff --git a/src/components/BankButton.jsx b/src/components/BankButton.jsx index a112a9b..62bfdd0 100644 --- a/src/components/BankButton.jsx +++ b/src/components/BankButton.jsx @@ -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); + } } }; @@ -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; diff --git a/src/components/BankType.jsx b/src/components/BankType.jsx index 68b56bd..32d082d 100644 --- a/src/components/BankType.jsx +++ b/src/components/BankType.jsx @@ -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 (

{title}

@@ -14,6 +21,7 @@ const BankType = ({ gridName, title, arrayName, paymentName, rentId }) => { bankName={item.bankName} key={item.bankName} rentId={rentId} + randomUUID={randomUUID} >
))} @@ -28,5 +36,6 @@ BankType.propTypes = { arrayName: PropTypes.array, paymentName: PropTypes.string, rentId: PropTypes.string.isRequired, + randomUUID: PropTypes.string.isRequired, }; export default BankType; diff --git a/src/components/Calendar.jsx b/src/components/Calendar.jsx index 0992008..5a4be2b 100644 --- a/src/components/Calendar.jsx +++ b/src/components/Calendar.jsx @@ -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 }) => { diff --git a/src/components/SelectProduct.jsx b/src/components/SelectProduct.jsx index c5407b0..6e4806a 100644 --- a/src/components/SelectProduct.jsx +++ b/src/components/SelectProduct.jsx @@ -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'; diff --git a/src/components/UserForm.jsx b/src/components/UserForm.jsx index 0d4399c..170185d 100644 --- a/src/components/UserForm.jsx +++ b/src/components/UserForm.jsx @@ -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); @@ -33,7 +32,6 @@ const UserForm = ({ onSubmit, onPrevStep, randomUUID }) => { setAcceptTerms, } = useStepper(); - const { postRequest } = useApi(); const { t } = useTranslation(); const navigate = useNavigate(); @@ -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, @@ -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 = () => { @@ -379,7 +356,6 @@ UserForm.propTypes = { onSubmit: PropTypes.func.isRequired, handleInfoModal: PropTypes.func, onPrevStep: PropTypes.func.isRequired, - randomUUID: PropTypes.string.isRequired, }; export default UserForm; diff --git a/src/hooks/useApi.js b/src/hooks/useApi.js index 8af56d4..4ac4c67 100644 --- a/src/hooks/useApi.js +++ b/src/hooks/useApi.js @@ -49,6 +49,7 @@ const useApi = () => { try { const response = await postRequest(endpoint, data); handleApiSuccess(response); + return response; } catch (error) { handleApiError(error); } @@ -57,6 +58,7 @@ const useApi = () => { try { const response = await deleteRequest(endpoint, uuid); handleApiSuccess(response); + return response; } catch (error) { handleApiError(error); } diff --git a/src/pages/RentProcess.jsx b/src/pages/RentProcess.jsx index 6dfd83f..8cd0a9f 100644 --- a/src/pages/RentProcess.jsx +++ b/src/pages/RentProcess.jsx @@ -40,9 +40,9 @@ const RentProcessPage = () => { calculateReservationDeadline(), ); - const mockRentData = { - id: '656e0884162df1917d30e826', - }; + const mockRentData = { + id: '656e0884162df1917d30e826', + }; const { t } = useTranslation(); @@ -145,6 +145,7 @@ const RentProcessPage = () => { title={t('Mobiilimaksutavat')} arrayName={mobileBanks} paymentName={styles.mobilePayment} + randomUUID={randomUUID} /> { title={t('Korttimaksutavat')} arrayName={cardPayments} paymentName={styles.cardPayment} + randomUUID={randomUUID} /> { title={t('Pankkimaksutavat')} arrayName={bankPayments} paymentName={styles.bankPayment} + randomUUID={randomUUID} /> { title={t('Maksu paikan päällä')} arrayName={irlPayments} paymentName={styles.irlPayment} + randomUUID={randomUUID} /> ); @@ -196,7 +200,6 @@ const RentProcessPage = () => { handleWarningModal={handleWarningModal} onSubmit={handleFormSubmit} onPrevStep={handlePrevStep} - randomUUID={randomUUID} /> ); case 3: diff --git a/src/utils/axios.js b/src/utils/axios.js index eb25be9..d4dd889 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -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,