Skip to content

Commit

Permalink
Merge branch 'S3-y-cloudfront'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlv237 committed May 26, 2024
2 parents d13a8a3 + 9149807 commit 9a7a903
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 8 deletions.
47 changes: 47 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 @@ -16,6 +16,7 @@
"@auth0/auth0-react": "^2.2.4",
"axios": "^1.6.8",
"lint": "^1.1.2",
"query-string": "^9.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3"
Expand Down
5 changes: 5 additions & 0 deletions src/common/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Flights from "../flights/index";
import Search from "../flights/search";
import VistaCompras from "../flights/userBuys";
import Recomendation from "../flights/recomendations";
import Checkout from "../flights/checkout";

const ProtectedComponent = ({ component: Component }) => {
const { isAuthenticated } = useAuth0();
Expand Down Expand Up @@ -42,6 +43,10 @@ const PageRoutes = () => {
path="/recomendations"
element={<ProtectedComponent component={Recomendation} />}
/>
<Route
path="/checkout"
element={<ProtectedComponent component={Checkout} />}
/>
</Routes>
);
};
Expand Down
Empty file removed src/flights/aa.jsx
Empty file.
57 changes: 57 additions & 0 deletions src/flights/checkout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect, useState } from 'react';

Check failure on line 1 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

'React' is defined but never used

Check failure on line 1 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace `'react'` with `"react"`
import axios from 'axios';

Check failure on line 2 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace `'axios'` with `"axios"`
import queryString from 'query-string';

Check failure on line 3 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace `'query-string'` with `"query-string"`

const Checkout = () => {
const [transaction, setTransaction] = useState(null);

useEffect(() => {
const fetchTransaction = async () => {
try {
const { token_ws } = queryString.parse(window.location.search);
const response = await axios.get(`https://flightsbooking.me/transactions?token_ws=${token_ws}`);

Check failure on line 12 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace ``https://flightsbooking.me/transactions?token_ws=${token_ws}`` with `⏎··········`https://flightsbooking.me/transactions?token_ws=${token_ws}`,⏎········`
setTransaction(response.data);
} catch (error) {
console.error("Error fetching transaction:", error);
}
};

fetchTransaction();
}, []);

useEffect(() => {
const postTransaction = async () => {
try {
if (transaction && transaction.status === 'APROVED') {

Check failure on line 25 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace `'APROVED'` with `"APROVED"`
const data = {

Check failure on line 26 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Replace `············` with `··········`
email: user.email,

Check failure on line 27 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Delete `····`

Check failure on line 27 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

'user' is not defined
flights: id,

Check failure on line 28 in src/flights/checkout.jsx

View workflow job for this annotation

GitHub Actions / test-and-lint

Delete `····`
total_tickets_bought: ticketCount,
ip_flight: ipResponse.data.ip,
};
await axios.post('https://flightsbooking.me/buy', data);
}
} catch (error) {
console.error("Error posting transaction:", error);
}
};

postTransaction();
}, [transaction]);

if (!transaction) {
return <p>Loading...</p>;
}

return (
<div>
<h1>Checkout</h1>
<p>Email: {transaction.email}</p>
<p>Amount: {transaction.amount}</p>
<p>Status: {transaction.status}</p>

</div>
);
};

export default Checkout;
2 changes: 1 addition & 1 deletion src/flights/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Flights = () => {
const fetchFlights = async () => {
try {
const response = await fetch(
`https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/flights${location.search}`,
`https://flightsbooking.me/flights${location.search}`,
);
const data = await response.json();
setFlights(data);
Expand Down
2 changes: 1 addition & 1 deletion src/flights/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Search = () => {
useEffect(() => {
if (isAuthenticated) {
axios.post(
"https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/users",
"https://flightsbooking.me/users",
{
name: "None",
email: user.email,
Expand Down
30 changes: 28 additions & 2 deletions src/flights/show.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Flight = () => {
const fetchFlight = async () => {
try {
const response = await fetch(
`https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/flights/${id}`,
`https://flightsbooking.me/flights/${id}`,
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -38,18 +38,43 @@ const Flight = () => {

const handleBuyFlight = async () => {
try {

const ipResponse = await axios.get(
`https://ipinfo.io/json?token=9704d049333821`,
);
console.log(ipResponse.data);

const transaction_data = {
email: user.email,
flightId: id,
total_tickets_bought: ticketCount,
ip_flight: ipResponse.data.ip,
};

console.log("Transaction data:", transaction_data)

const response_webpay = await axios.post(
"https://flightsbooking.me/transactions",
transaction_data,
{
headers: {
"Content-Type": "application/json",
},
},
);

const webpay_url = response_webpay.data.url;
const token = response_webpay.data.token;

window.location.href = webpay_url +"?token_ws="+ token;

const data = {
email: user.email,
flights: id,
total_tickets_bought: ticketCount,
ip_flight: ipResponse.data.ip,
};
const url = `https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/buy`;
const url = `https://flightsbooking.me/buy`;

const response = await axios.post(url, data, {
headers: {
Expand All @@ -59,6 +84,7 @@ const Flight = () => {

console.log("Server response:", response.data);
window.location.href = "/my_flights";

} catch (error) {
console.error("Error buying flight:", error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/flights/userBuys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const VistaCompras = () => {
const fetchData = async () => {
try {
const response = await axios.get(
`https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/purchases/${user.email}`,
`https://flightsbooking.me/purchases/${user.email}`,
);
setData(response.data);
console.log("Server response:", response.data);

const flightResponses = await Promise.all(
response.data.map((item) =>
axios.get(
`https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/flights/${item.flight}`,
`https://flightsbooking.me/flights/${item.flight}`,
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions src/flights/userflights.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const UserFlights = () => {

useEffect(() => {
const fetchPurchases = async () => {
const url = `https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/purchases/${user.email}`;
const url = `flightsbooking.me/purchases/${user.email}`;

try {
const response = await fetch(url, {
Expand Down Expand Up @@ -44,7 +44,7 @@ const UserFlights = () => {
const getFlightById = async (flightId) => {
try {
const response = await axios.get(
`https://8ujhmk0td0.execute-api.us-east-2.amazonaws.com/Produccion2/flights/${flightId}`,
`https://flightsbooking.me/flights/${flightId}`,
);
return response.data;
} catch (error) {
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ debug@^4.1.0, debug@^4.3.1, debug@^4.3.2:
dependencies:
ms "2.1.2"

decode-uri-component@^0.4.1:
version "0.4.1"
resolved "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.4.1.tgz"
integrity sha512-+8VxcR21HhTy8nOt6jf20w0c9CADrw1O8d+VZ/YzzCt4bJ3uBjw+D1q2osAB8RnpwwaeYBxy0HyKQxD5JBMuuQ==

deep-is@^0.1.3:
version "0.1.4"
resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz"
Expand Down Expand Up @@ -1109,6 +1114,11 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

filter-obj@^5.1.0:
version "5.1.0"
resolved "https://registry.npmjs.org/filter-obj/-/filter-obj-5.1.0.tgz"
integrity sha512-qWeTREPoT7I0bifpPUXtxkZJ1XJzxWtfoWWkdVGqa+eCr3SHW/Ocp89o8vLvbUuQnadybJpjOKu4V+RwO6sGng==

find-up@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz"
Expand Down Expand Up @@ -1833,6 +1843,15 @@ punycode@^2.1.0:
resolved "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz"
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==

query-string@^9.0.0:
version "9.0.0"
resolved "https://registry.npmjs.org/query-string/-/query-string-9.0.0.tgz"
integrity sha512-4EWwcRGsO2H+yzq6ddHcVqkCQ2EFUSfDMEjF8ryp8ReymyZhIuaFRGLomeOQLkrzacMHoyky2HW0Qe30UbzkKw==
dependencies:
decode-uri-component "^0.4.1"
filter-obj "^5.1.0"
split-on-first "^3.0.0"

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz"
Expand Down Expand Up @@ -2039,6 +2058,11 @@ source-map-js@^1.2.0:
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz"
integrity sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==

split-on-first@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/split-on-first/-/split-on-first-3.0.0.tgz"
integrity sha512-qxQJTx2ryR0Dw0ITYyekNQWpz6f8dGd7vffGNflQQ3Iqj9NJ6qiZ7ELpZsJ/QBhIVAiDfXdag3+Gp8RvWa62AA==

string.prototype.matchall@^4.0.10:
version "4.0.11"
resolved "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz"
Expand Down

0 comments on commit 9a7a903

Please sign in to comment.