Skip to content

Commit

Permalink
Testing environment variables for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
basshamut committed Jun 27, 2024
1 parent a075e25 commit e322713
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/forms/login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Dialog} from 'primereact/dialog'
import {InputText} from "primereact/inputtext"
import {useState} from "react"
import {useNavigate} from "react-router-dom"
import {startSession} from "../../../utils/session.jsx"
import {getApplicationDomain, startSession} from "../../../utils/session.jsx"
import background from "/Shotokan_Fondo.svg"


Expand All @@ -20,7 +20,7 @@ export default function Login() {

function doLogin() {
if (validateEmail(user)) {
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()
console.log("Domain: " + domain)
fetch(domain + '/api/users/login', {
method: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/forms/meet/MeetRegisterForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from "primereact/button";
import { useState } from "react";
import { Calendar } from "primereact/calendar";
import styled from 'styled-components';
import {getBase64CredentialsFromSession} from "../../../utils/session";
import {getApplicationDomain, getBase64CredentialsFromSession} from "../../../utils/session";

const RegisterContainer = styled.div`
background-image: radial-gradient(circle at left top, var(--primary-400), var(--primary-700));
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function MeetRegisterForm() {
const [date, setDate] = useState(today);
const [url, setUrl] = useState('');
const [price, setPrice] = useState(0);
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()
const base64Credentials = getBase64CredentialsFromSession()

function saveMeet() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/forms/register/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useState} from "react"
import background from "/Shotokan_Fondo.svg"
import {Calendar} from "primereact/calendar"
import {useNavigate} from "react-router-dom";
import {getApplicationDomain} from "../../../utils/session";

export default function Register() {
const [visible, setVisible] = useState(true)
Expand All @@ -14,7 +15,7 @@ export default function Register() {
const [confirmPassword, setConfirmPassword] = useState("")
const [errors, setErrors] = useState({})
const navigate = useNavigate()
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()

const today = new Date()
const majorityAgeDate = new Date(today.getFullYear() - 18, 0, 1)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/payment/CheckoutForm.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useCallback} from "react"
import {loadStripe} from '@stripe/stripe-js'
import {format} from "date-fns"
import {getBase64CredentialsFromSession, getSession} from "../../utils/session.jsx";
import {getApplicationDomain, getBase64CredentialsFromSession, getSession} from "../../utils/session.jsx";

// eslint-disable-next-line react/prop-types
export default function CheckoutForm({meet}) {
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()

const stripePromise = loadStripe("pk_test_51PSHknKnVUk9u0R7xWznb2PU2LeYeOgFXDVB14wP4BvJQBJ3RdH0ZLF801Ka7oLlNd7pFV7VZndQa2soCDluMFf200UugFXgnD")
const user = getSession()
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/useFetchMeets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect, useState} from 'react';
import {getBase64CredentialsFromSession} from "../utils/session";
import {getApplicationDomain, getBase64CredentialsFromSession} from "../utils/session";

function useFetchMeets(isUser, hasSession) {
const [meets, setMeets] = useState([]);
Expand All @@ -9,7 +9,7 @@ function useFetchMeets(isUser, hasSession) {
useEffect(() => {
async function fetchMeets() {
try {
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()
console.log("Domain: " + domain)
const response = await fetch(domain + '/api/meets/all', {
headers: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/useSavePurchase.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {useEffect, useState} from "react"
import {getBase64CredentialsFromSession} from "../utils/session";
import {getApplicationDomain, getBase64CredentialsFromSession} from "../utils/session";

function useSavePurchase(isSuccess, meetId, userId) {
const [response, setResponse] = useState({})
const [error, setError] = useState(null);
const domain = import.meta.env.VITE_API_URL
const domain = getApplicationDomain()
const base64Credentials = getBase64CredentialsFromSession()

useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/utils/session.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export const isAdmin = () => {
export const getBase64CredentialsFromSession = () => {
const sessionData = getSession()
return btoa(sessionData.email + ':' + sessionData.password)
}
}

export const getApplicationDomain = () => {
return import.meta.env.VITE_API_URL ? import.meta.env.VITE_API_URL : 'http://86.38.204.61'
}

0 comments on commit e322713

Please sign in to comment.