Changeset 0f5aa27 for frontend/src
- Timestamp:
- 02/04/24 16:57:49 (10 months ago)
- Branches:
- master
- Children:
- efaa053
- Parents:
- 07f4e8b
- Location:
- frontend/src
- Files:
-
- 3 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/App.js
r07f4e8b r0f5aa27 33 33 import ProfilesManagementPage from "./Pages/ProfilesManagementPage"; 34 34 import UserReservationsManagement from "./Pages/UserReservationsManagement"; 35 import LoginCallback from "./Components/LoginCallback"; 36 import ConnectedAccountsPage from "./Pages/ConnectedAccountsPage"; 35 37 36 38 … … 71 73 <Route path="/search/restaurant/:restaurantLocation/:date/:hourFrom/:hourTo/:numPeople" 72 74 element={<SearchPage type="restaurant"/>}/> 75 <Route path="/login-callback" element={<LoginCallback/>}></Route> 76 <Route path="/connected" element={<PrivateRoute><ConnectedAccountsPage/></PrivateRoute>}></Route> 73 77 </Routes> 74 78 </BrowserRouter> -
frontend/src/Components/Forms/AddItemMenuForm.js
r07f4e8b r0f5aa27 4 4 import useFormData from "../Hooks/useFormData"; 5 5 import useCreateMenu from "../Hooks/Restaurant/useCreateMenu" 6 import useCreate from "../Hooks/useCreate"; 6 7 7 8 const AddItemMenuForm = (props) => { … … 9 10 10 11 const edit = props.menu 12 console.log(props.menu) 11 13 const dummy = { 12 14 name: "", … … 23 25 edit ? props.menu : dummy 24 26 ); 27 const { createEntity } = useCreate(); 25 28 26 29 return ( … … 72 75 onClick={(e) => { 73 76 e.preventDefault(); 74 createMenu(props.Id, formData) 75 props.refresh((prevState) => { 76 return prevState + 1; 77 }) 77 if(!edit) { 78 createMenu(props.Id, formData, props.refresh) 79 } 80 else { 81 createEntity(`/menu/${props.menu.menuId}/edit`, formData, props.refresh) 82 } 83 78 84 }} 79 85 > -
frontend/src/Components/Forms/AddTripForm.js
r07f4e8b r0f5aa27 272 272 273 273 for (let i = 0; i < Object.values(routesForm).length; i++) { 274 console.log(findDependantRoutes(wayPointNames, routesForm, i))275 274 setDependencies(prevState => [...prevState, findDependantRoutes(wayPointNames, routesForm, i)]) 276 275 } 277 console.log('VO STATEOOOO')278 console.log(dependencies)279 276 routesSetFormData(routesForm) 280 277 setRoutes(routesVar) -
frontend/src/Components/Hooks/Restaurant/useCreateMenu.js
r07f4e8b r0f5aa27 7 7 const navigator = useNavigate(); 8 8 9 const createMenu = async (id, menu ) => {9 const createMenu = async (id, menu, dep) => { 10 10 console.log(menu) 11 11 console.log(id) … … 18 18 //navigator("/resources/restaurant/" + id) 19 19 //history.push('/restaurant'); 20 dep(prev => ++prev) 20 21 }) 21 22 .catch((err) => { -
frontend/src/Components/Hooks/User/useCreateUser.js
r07f4e8b r0f5aa27 10 10 .post(`/register`, user) 11 11 .then((res) => { 12 navigator("/login")12 window.location.href = "http://localhost:8080/login" 13 13 }) 14 14 .catch((err) => { -
frontend/src/Components/Hooks/User/useLogin.js
r07f4e8b r0f5aa27 1 import React from "react"; 2 1 import { useState } from "react"; 3 2 import axios from "../../../axios.js"; 4 import { Navigate, useAsyncValue, useNavigate } from "react-router-dom"; 5 import LoginForm from "../../Login/LoginForm.js"; 6 import {useAuth} from "../../Context/AuthContext"; 3 import {useAuth} from "../../Context/AuthContext"; // Assuming you have axios configured 7 4 8 5 const useLogin = () => { 6 const [loading, setLoading] = useState(false); 7 const [error, setError] = useState(null); 8 const Auth = useAuth(); 9 9 10 const navigator = useNavigate() 11 const Auth = useAuth(); 12 //const history = useNavigate(); 13 const login = async (loginData) => { 14 console.log({loginData}) 15 console.log(loginData) 16 await axios 17 .post(`/api/login`, { 18 username: loginData.email, 19 password: loginData.password 20 }, { 21 headers: { 22 "Content-Type": "application/x-www-form-urlencoded" 23 } 24 }) 25 .then((res) => { 26 console.log("RES LOGIN") 27 console.log(res) 28 if(res.status === 200) 29 { 30 const user = { 31 sessionId: res.data.auth.details.sessionId, 32 userId: res.data.auth.principal.userID, 33 username: res.data.auth.principal.username, 34 role: res.data.auth.principal.role, 35 name: res.data.auth.principal.name, 36 surname: res.data.auth.principal.surname, 37 } 38 Auth.userLogin(user); 39 console.log(user) 40 } 41 const sessionId = res.data.auth.details.sessionId; 42 const userId = res.data.auth.principal.userID; 10 const handleLoginCallback = async () => { 11 setLoading(true); 43 12 44 localStorage.setItem("sessionId", sessionId); 45 localStorage.setItem("userId", userId); 46 if(sessionId === null) 47 { 48 } 49 navigator("/home") 50 }) 51 .catch((err) => { 52 console.log(err); 53 }) 54 .finally(() => { 55 }); 56 } 13 try { 14 const response = await axios.get("http://localhost:8080/principal"); 15 16 // Extract the needed attributes from the response 17 const { id, role, username } = response.data; 18 19 Auth.userLogin({userId: id, username: username, role: role}) 20 21 } catch (err) { 22 setError(err.message); 23 } finally { 24 setLoading(false); 25 } 26 }; 57 27 58 28 return { 59 login 29 loading, 30 error, 31 handleLoginCallback, 60 32 }; 61 62 } 33 }; 63 34 64 35 export default useLogin; -
frontend/src/Components/Hooks/useCreate.js
r07f4e8b r0f5aa27 15 15 .then((res) => { 16 16 //history.push('/hotel'); 17 console.log(res)18 console.log("gotovo")19 17 getData(prev => ++prev) 20 18 getData2(prev => ++prev) -
frontend/src/Components/Layout/Navbar/Navigation.js
r07f4e8b r0f5aa27 63 63 style={{ backgroundColor: "#159895" }} 64 64 onClick={() => { 65 navigator("/login");65 window.location.href = ("http://localhost:8080/login"); 66 66 }} 67 67 > -
frontend/src/Components/Listings/HotelListing.js
r07f4e8b r0f5aa27 1 import {Col, Container, Image, Row, Button } from "react-bootstrap";1 import {Col, Container, Image, Row, Button, Badge} from "react-bootstrap"; 2 2 import {BsFillPersonFill} from "react-icons/bs"; 3 3 import {MdOutlineLocalOffer} from "react-icons/md"; … … 5 5 6 6 function HotelListing(props) { 7 8 const getMarketingMessage = (num) => { 9 switch (num){ 10 case 1: 11 return "Достапно само денес" 12 case 2: 13 return "Последна соба" 14 case 3: 15 return "Специјална цена" 16 } 17 } 18 7 19 console.log(props) 20 const randomInt = Math.floor(Math.random() * (3)) + 1; 8 21 return ( 9 22 <> … … 15 28 boxShadow: "0 3px 5px lightblue", 16 29 maxWidth: "60%", 30 backgroundColor: props.data.promoted ? "#e1f7fa" : "" 17 31 }} 18 32 > … … 31 45 <Col> 32 46 <Row> 33 <h3>{props.data.hotelName}</h3> 47 <h3>{props.data.hotelName} 48 {props.data.marketed && randomInt !== 3 && <h6><Badge bg="warning">{getMarketingMessage(randomInt)}</Badge></h6>} 49 {props.data.promoted && <h6><Badge bg="primary">Најпопуларно</Badge></h6>} 50 </h3> 34 51 </Row> 35 52 <Row> … … 90 107 > 91 108 <Row> 92 <h4>{props.data.totalPrice}$</h4> 109 <h4>{props.data.marketed && randomInt === 3 && <h6><Badge bg="warning">{getMarketingMessage(randomInt)}</Badge></h6>} 110 {props.data.totalPrice}$</h4> 93 111 </Row> 94 112 <Row className="w-100"> -
frontend/src/Components/Login/LoginForm.js
r07f4e8b r0f5aa27 5 5 import useLogin from "../Hooks/User/useLogin"; 6 6 import { Link } from "react-router-dom"; 7 import useCreate from "../Hooks/useCreate"; 8 import {useAuth} from "../Context/AuthContext"; 7 9 8 const LoginForm = ( ) => {10 const LoginForm = (props) => { 9 11 const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData( 10 12 { 11 email: "",13 username: "", 12 14 password: "", 13 15 } 14 16 ); 15 17 16 const { login } = useLogin(); 18 const { createEntity } = useCreate(); 19 const Auth = useAuth(); 17 20 18 21 return ( … … 27 30 type="email" 28 31 placeholder="Enter email" 29 name=" email"32 name="username" 30 33 onChange={onFormChange} 31 34 value={formData.email} 32 35 /> 33 <Form.Text className="text-muted">34 Вашите податоци никогаш нема да бидат споделени.35 </Form.Text>36 36 </Form.Group> 37 37 … … 46 46 /> 47 47 </Form.Group> 48 <Form.Group className="mb-3" controlId="formBasicCheckbox">49 <Form.Check type="checkbox" label="Check me out" />50 </Form.Group>51 <Link to={"/register"} style={{textDecoration: "none"}}>52 <Form.Text className="text-muted" style={{color: "#159895!important"}} >53 Регистритрај се54 </Form.Text>55 </Link>48 {/*<Form.Group className="mb-3" controlId="formBasicCheckbox">*/} 49 {/* <Form.Check type="checkbox" label="Check me out" />*/} 50 {/*</Form.Group>*/} 51 {/*<Link to={"/register"} style={{textDecoration: "none"}}>*/} 52 {/* <Form.Text className="text-muted" style={{color: "#159895!important"}} >*/} 53 {/* Регистритрај се*/} 54 {/* </Form.Text>*/} 55 {/*</Link>*/} 56 56 <Form.Group className="my-1"> 57 57 <Button … … 62 62 e.preventDefault(); 63 63 console.log(formData); 64 login(formData)64 createEntity(`/users/${Auth.getUser().userId}/connect`, formData, props.refresh) 65 65 }} 66 66 > … … 68 68 <AiFillLock /> 69 69 </span> 70 <span className="ikona mx-3"> Најави се</span>70 <span className="ikona mx-3">Поврзи</span> 71 71 </Button> 72 72 </Form.Group> -
frontend/src/Components/Misc/PrivateRoute.js
r07f4e8b r0f5aa27 5 5 function PrivateRoute({ children }) { 6 6 const { userIsAuthenticated } = useAuth() 7 return userIsAuthenticated() ? children : <Navigate to="/login" /> 7 if(userIsAuthenticated()) 8 { 9 return children; 10 } 11 else 12 { 13 window.location.href = "http://localhost:8080/login"; 14 } 15 return userIsAuthenticated() ? children : <Navigate to="http://localhost:8080/login" /> 8 16 } 9 17 -
frontend/src/Components/ProfilePage/DataForm.js
r07f4e8b r0f5aa27 11 11 12 12 const handleClose = () => setShow(false); 13 const handleShow = (e) => { 13 const handleShow = (e) => { 14 14 e.preventDefault(); 15 15 setShow(true); … … 29 29 <Form.Group as={Col} controlId="name"> 30 30 <Form.Label>Име</Form.Label> 31 <Form.Control type="text" value={props.data["name"]} /> 31 <Form.Control type="text" value={props.data["name"]} 32 name={"name"}/> 32 33 </Form.Group> 33 34 … … 38 39 placeholder="" 39 40 value={props.data["surname"]} 41 name={"surname"} 40 42 /> 41 43 </Form.Group> … … 45 47 <Form.Group as={Col} controlId="name"> 46 48 <Form.Label>Датум на раѓање</Form.Label> 47 <Form.Control type="date" value={props.data["dateOfBirth"]} /> 49 <Form.Control type="date" value={props.data["dateOfBirth"]} 50 name={"dateOfBirth"}/> 48 51 </Form.Group> 49 52 … … 54 57 placeholder="" 55 58 value={props.data["country"]} 59 name={"country"} 56 60 /> 57 61 </Form.Group> … … 60 64 <Form.Group className="mb-3" controlId="address"> 61 65 <Form.Label>Адреса</Form.Label> 62 <Form.Control type="text" value={props.data["address"]} /> 66 <Form.Control type="text" value={props.data["address"]} 67 name={"address"}/> 63 68 </Form.Group> 64 69 … … 66 71 <Form.Group as={Col} controlId="city"> 67 72 <Form.Label>Град</Form.Label> 68 <Form.Control type="text" value={props.data["city"]} /> 73 <Form.Control type="text" value={props.data["city"]} 74 name={"city"}/> 69 75 </Form.Group> 70 76 … … 75 81 placeholder="" 76 82 value={props.data["zip"]} 83 name={"zip"} 77 84 /> 78 85 </Form.Group> … … 82 89 <Form.Group as={Col} controlId="email"> 83 90 <Form.Label>Email</Form.Label> 84 <Form.Control type="email" value={props.data["email"]} /> 91 <Form.Control type="email" value={props.data["email"]} 92 name={"email"}/> 85 93 </Form.Group> 86 94 … … 91 99 placeholder="" 92 100 value={props.data["mobile"]} 101 name={"mobile"} 93 102 /> 94 103 </Form.Group> -
frontend/src/Components/RestaurantDetails/MenuItem.js
r07f4e8b r0f5aa27 6 6 7 7 const data = props.data; 8 console.log("dva orla")9 8 console.log(props) 10 9 return (<> -
frontend/src/Pages/NoBusinessRegisteredError.js
r07f4e8b r0f5aa27 14 14 const Auth = useAuth(); 15 15 const isLoggedIn = Auth.userIsAuthenticated(); 16 const userId = localStorage.getItem("userId")16 const userId = Auth.getUser().userId 17 17 const [registered, setRegistered] = useState(false); 18 18 let checked = false; … … 26 26 27 27 const { data: firma, isLoading: firmaIsLoading, getData: getFirmi} = useGet("/business/" + userId + "/unapproved", changed) 28 28 const { data, isLoading, getData} = useGet("/" + userId + "/hasBusiness") 29 29 30 30 31 useEffect(() => { … … 52 53 } 53 54 54 ! firmaIsLoading && firma && firma.length > 0 && firma[0].approved&& navigator("/resources/hotel")55 !isLoading && data && navigator("/resources/hotel") 55 56 56 57
Note:
See TracChangeset
for help on using the changeset viewer.