Skip to content

Commit

Permalink
register page logs in user and login is working again
Browse files Browse the repository at this point in the history
  • Loading branch information
eschremp committed Apr 24, 2024
1 parent f43d4d6 commit da85bb0
Show file tree
Hide file tree
Showing 20 changed files with 622 additions and 101 deletions.
408 changes: 408 additions & 0 deletions ReactFrontEnd/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ReactFrontEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
"global": "^4.4.0",
"localforage": "^1.10.0",
"match-sorter": "^6.3.4",
"prime-react": "^1.0.0",
"react": "^18.2.0",
"react-cookie": "^7.1.4",
"react-datepicker": "^6.9.0",
"react-dom": "^18.2.0",
"react-dropdown": "^1.11.0",
"react-icons": "^5.0.1",
"react-leaflet": "^4.2.1",
"react-query": "^3.39.3",
Expand Down
6 changes: 1 addition & 5 deletions ReactFrontEnd/src/Components/CreateReview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const CreateReview = () => {
//breaks down JSON into single park object
const parkDetails = singlePark.data[0]

const user = {
id: 2,
username: "paulUser",
password: "userPaul",
};
const user = window.localStorage.getItem("User");

const [review, setReview] = useState({
id: "",
Expand Down
4 changes: 3 additions & 1 deletion ReactFrontEnd/src/Components/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import Header from './Header'
import Footer from './Footer'
import { useQuery, useQueryClient } from "@tanstack/react-query"
import axios from 'axios'
import { states } from '../constants/Enum'


function Home() {


console.log(states);
return (
<>
<div className="bg-nps-green-300 h-lvh">
Expand Down
23 changes: 21 additions & 2 deletions ReactFrontEnd/src/Components/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@ import { Link } from 'react-router-dom'
import Slideshow from './Slideshow'
import Header from './Header'
import axios from 'axios';
import Itinerary from './Itinerary';
import LoginService from '../Services/LoginService';

function Register() {
const [user, setUser] = useState({username: "", password: "", role: "user"});
const [user, setUser] = useState({username: "", password: ""});
const SERVER_API_BASE_URL = "http://localhost:8080";
const axiosInstance = axios.create({
withCredentials: true,
baseURL: SERVER_API_BASE_URL,
headers: {
"Cache-Control": "no-cache",
"Accept-Language": "en",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "http://localhost:5173",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
"Authorization": null,

}});

const handleSubmit = (event) => {
event.preventDefault();
axios.post("http://localhost:8080/register", user).then((response) => {
axiosInstance.post("/register", user).then((response) => {
console.log(response.status, response.data)
if(response.status == 201){
LoginService.login(user,axiosInstance);
}
})

};
Expand Down
46 changes: 39 additions & 7 deletions ReactFrontEnd/src/Components/SearchForm.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
import React, {useRef, useEffect} from 'react';
import React, {useRef, useEffect, useState} from 'react';
import { FaSearch } from "react-icons/fa"
import { useNavigate } from 'react-router-dom'
import { useGlobalContext } from '../context'
//import "./SearchForm.css";
import './SearchHeader.css'
import {states} from "../constants/Enum"
import { Axios } from 'axios';
import GlobalAPI from "../Services/GlobalAPI"



const SearchForm = () => {

const {setSearchTerm} = useGlobalContext();
const {setSearchState} = useGlobalContext();
const {setActivity} = useGlobalContext();
const searchState = useRef('');
const searchText = useRef('');
const searchActivity = useRef('');
const [activityList, setActivityList] = useState([]);
useEffect(() => {
getActivityList();
}, [])
const getActivityList = () => {
GlobalAPI.getActivities.then(response => {
setActivityList(response.data.data);
})
}

const navigate = useNavigate();

useEffect(() => searchText.current.focus(), []);
useEffect(() => {searchText.current.focus(); searchState.current.focus(); searchActivity.current.focus(); []});
const handleSubmit = (e) => {
e.preventDefault(); //actually allows the search not just hte defualt
let tempSearchTerm = searchText
let tempSearchTerm = searchText
setSearchState(searchState.current.value);
setActivity(searchActivity.current.value);
if(tempSearchTerm.length === 0){
setSearchTerm("yellowstone"); //defualt searchterm
setSearchTerm(""); //defualt searchterm

} else {
setSearchTerm(searchText.current.value);
}

navigate("/parksearch/search");
};

//^^^what makes the button clickable

//creates the search container
Expand All @@ -34,12 +55,23 @@ const SearchForm = () => {
<div className='container'>
<div className='search-form-content'>
<form className='search-form' onSubmit={handleSubmit}>
<div className='search-form-elem flex flex-sb bg-white'>
<input type = "text" className='form-control text-gray-500 w-full' placeholder='Yellowstone Park ...' ref = {searchText}/>

<label htmlFor="state">Search by state:</label>
<select name="state" id = "state" ref={searchState} className='text-black' >
{states.map((state, index) => <option value = {state.abbreviation} key={index}>{state.name}</option> )}
</select>
<label htmlFor="activity">Search by activity:</label>
<select name="activity" id = "activity" ref={searchActivity} className='text-black' >
<option value = "" key="defaultActivity">All Activities</option>
{activityList.map((activity, index) => <option value = {activity.id} key={index}>{activity.name}</option> )}
</select>
<div className='search-form-elem flex flex-sb bg-white text-black'>
<input type = "text" className='form-control text-gray-500 w-full' placeholder='Search by keyword' ref = {searchText}/>
<button type = "submit" className='flex flex-c' onClick={handleSubmit}>
<FaSearch className='text-black' size = {32} />
</button>
</div>

</form>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions ReactFrontEnd/src/Components/StateDropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import {states} from "../constants/Enum"
import { useGlobalContext } from '../context'
import React, {useRef, useEffect} from 'react';




export default StateDropdown = () => {

const {setSearchState} = useGlobalContext();
const searchState = useRef('');



return (
<>
<label for="state">Search by state:</label>

<select name="state" id = "state" ref={searchState} />
{states.map((state) => <option value = {state.abbreviation}>{state.name}</option> )}
</>
)}
23 changes: 21 additions & 2 deletions ReactFrontEnd/src/Services/FavoritesServices.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import React from "react";
import axios from "axios";

const FAVORITES_BASE_API_URL = "http://localhost:8080/api/v1/favorites";
const FAVORITES_API_BASE_URL = "http://localhost:8080/api/v1/favorites";

//const FAVORITES_API_LIST_URL = "http://localhost:8080/api/v1/addFavorites";

const axiosInstance = axios.create({
withCredentials: true,
baseURL: FAVORITES_API_BASE_URL,
headers: {
"Cache-Control": "no-cache",
"Accept-Language": "en",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "http://localhost:5173",
"Access-Control-Allow-Methods": "POST, GET",
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
"Authorization": window.localStorage.getItem("Auth")
}});




class FavoritesServices {
createFavorite(favorites) {
return axios.post(FAVORITES_BASE_API_URL, favorites);
return axiosInstance.post(favorites);
}


getFavorites() {
return axios.get(FAVORITES_BASE_API_URL);
}
Expand Down
6 changes: 5 additions & 1 deletion ReactFrontEnd/src/Services/GlobalAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useQuery } from "@tanstack/react-query";
const parkBaseURL="https://developer.nps.gov/api/v1"
const getParkInfoURL="https://developer.nps.gov/api/v1/parks?parkCode="
const api_key=import.meta.env.VITE_REACT_APP_NPS_API_KEY;
const getActivitiesURL = parkBaseURL+"/activities?api_key="+api_key;

//parks?parkCode=arch&api_key=Wrk46hd2qqrRis6VpJA8CT12EeDczzGa9dYRBjYk

Expand All @@ -16,6 +17,9 @@ const getImages=axios.get(parkBaseURL+"/multimedia/galleries/assets?limit="+num+
let parkCode = "arch";
const getParks=axios.get(getParkInfoURL+parkCode+"&api_key="+api_key);

//calls activities API
const getActivities = axios.get(getActivitiesURL);

export default {
getImages,getParks,
getImages,getParks, getActivities
}
7 changes: 3 additions & 4 deletions ReactFrontEnd/src/Services/ReviewServices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ const axiosInstance = axios.create({
"Access-Control-Allow-Origin": "http://localhost:5173",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers":
"Content-Type, Authorization, X-Requested-With",
Authorization: window.localStorage.getItem("Auth"),
"Content-Type, Authorization, X-Requested-With",
"Authorization": window.localStorage.getItem("Auth"),
},
});

class ReviewService {
createReview(review) {
console.log(window.localStorage.getItem("Auth"));
return axiosInstance.post(REVIEW_API_BASE_URL, review);
return axiosInstance.post(review);
}

getReviewsByUserId(id) {
Expand Down
106 changes: 52 additions & 54 deletions ReactFrontEnd/src/constants/Enum.jsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import React from "react";
import { Axios } from "axios";

const UsStates = function() {
const states =
[{"name":"Alabama","abbreviation":"AL"},
{"name":"Alaska","abbreviation":"AK"},
{"name":"Arizona","abbreviation":"AZ"},
{"name":"Arkansas","abbreviation":"AR"},
{"name":"California","abbreviation":"CA"},
{"name":"Colorado","abbreviation":"CO"},
{"name":"Connecticut","abbreviation":"CT"},
{"name":"Delaware","abbreviation":"DE"},
{"name":"Florida","abbreviation":"FL"},
{"name":"Georgia","abbreviation":"GA"},
{"name":"Hawaii","abbreviation":"HI"},
{"name":"Idaho","abbreviation":"ID"},
{"name":"Illinois","abbreviation":"IL"},
{"name":"Indiana","abbreviation":"IN"},
{"name":"Iowa","abbreviation":"IA"},
{"name":"Kansas","abbreviation":"KS"},
{"name":"Kentucky","abbreviation":"KY"},
{"name":"Louisiana","abbreviation":"LA"},
{"name":"Maine","abbreviation":"ME"},
{"name":"Maryland","abbreviation":"MD"},
{"name":"Massachusetts","abbreviation":"MA"},
{"name":"Michigan","abbreviation":"MI"},
{"name":"Minnesota","abbreviation":"MN"},
{"name":"Mississippi","abbreviation":"MS"},
{"name":"Missouri","abbreviation":"MO"},
{"name":"Montana","abbreviation":"MT"},
{"name":"Nebraska","abbreviation":"NE"},
{"name":"Nevada","abbreviation":"NV"},
{"name":"New Hampshire","abbreviation":"NH"},
{"name":"New Jersey","abbreviation":"NJ"},
{"name":"New Mexico","abbreviation":"NM"},
{"name":"New York","abbreviation":"NY"},
{"name":"North Carolina","abbreviation":"NC"},
{"name":"North Dakota","abbreviation":"ND"},
{"name":"Ohio","abbreviation":"OH"},
{"name":"Oklahoma","abbreviation":"OK"},
{"name":"Oregon","abbreviation":"OR"},
{"name":"Pennsylvania","abbreviation":"PA"},
{"name":"Rhode Island","abbreviation":"RI"},
{"name":"South Carolina","abbreviation":"SC"},
{"name":"South Dakota","abbreviation":"SD"},
{"name":"Tennessee","abbreviation":"TN"},
{"name":"Texas","abbreviation":"TX"},
{"name":"Utah","abbreviation":"UT"},
{"name":"Vermont","abbreviation":"VT"},
{"name":"Virginia","abbreviation":"VA"},
{"name":"Washington","abbreviation":"WA"},
{"name":"West Virginia","abbreviation":"WV"},
{"name":"Wisconsin","abbreviation":"WI"},
{"name":"Wyoming","abbreviation":"WY"}]


}
export const states =
[{name: "All States", abbreviation: ""},
{name:"Alabama",abbreviation:"AL"},
{name:"Alaska",abbreviation:"AK"},
{name:"Arizona",abbreviation:"AZ"},
{name:"Arkansas",abbreviation:"AR"},
{name:"California",abbreviation:"CA"},
{name:"Colorado",abbreviation:"CO"},
{name:"Connecticut",abbreviation:"CT"},
{name:"Delaware",abbreviation:"DE"},
{name:"Florida",abbreviation:"FL"},
{name:"Georgia",abbreviation:"GA"},
{name:"Hawaii",abbreviation:"HI"},
{name:"Idaho",abbreviation:"ID"},
{name:"Illinois",abbreviation:"IL"},
{name:"Indiana",abbreviation:"IN"},
{name:"Iowa",abbreviation:"IA"},
{name:"Kansas",abbreviation:"KS"},
{name:"Kentucky",abbreviation:"KY"},
{name:"Louisiana",abbreviation:"LA"},
{name:"Maine",abbreviation:"ME"},
{name:"Maryland",abbreviation:"MD"},
{name:"Massachusetts",abbreviation:"MA"},
{name:"Michigan",abbreviation:"MI"},
{name:"Minnesota",abbreviation:"MN"},
{name:"Mississippi",abbreviation:"MS"},
{name:"Missouri",abbreviation:"MO"},
{name:"Montana",abbreviation:"MT"},
{name:"Nebraska",abbreviation:"NE"},
{name:"Nevada",abbreviation:"NV"},
{name:"New Hampshire",abbreviation:"NH"},
{name:"New Jersey",abbreviation:"NJ"},
{name:"New Mexico",abbreviation:"NM"},
{name:"New York",abbreviation:"NY"},
{name:"North Carolina",abbreviation:"NC"},
{name:"North Dakota",abbreviation:"ND"},
{name:"Ohio",abbreviation:"OH"},
{name:"Oklahoma",abbreviation:"OK"},
{name:"Oregon",abbreviation:"OR"},
{name:"Pennsylvania",abbreviation:"PA"},
{name:"Rhode Island",abbreviation:"RI"},
{name:"South Carolina",abbreviation:"SC"},
{name:"South Dakota",abbreviation:"SD"},
{name:"Tennessee",abbreviation:"TN"},
{name:"Texas",abbreviation:"TX"},
{name:"Utah",abbreviation:"UT"},
{name:"Vermont",abbreviation:"VT"},
{name:"Virginia",abbreviation:"VA"},
{name:"Washington",abbreviation:"WA"},
{name:"West Virginia",abbreviation:"WV"},
{name:"Wisconsin",abbreviation:"WI"},
{name:"Wyoming",abbreviation:"WY"}]

0 comments on commit da85bb0

Please sign in to comment.