Changeset 0f5aa27 for frontend


Ignore:
Timestamp:
02/04/24 16:57:49 (5 months ago)
Author:
darsov2 <62809499+darsov2@…>
Branches:
master
Children:
efaa053
Parents:
07f4e8b
Message:

ouath, mailing impl

Location:
frontend/src
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/App.js

    r07f4e8b r0f5aa27  
    3333import ProfilesManagementPage from "./Pages/ProfilesManagementPage";
    3434import UserReservationsManagement from "./Pages/UserReservationsManagement";
     35import LoginCallback from "./Components/LoginCallback";
     36import ConnectedAccountsPage from "./Pages/ConnectedAccountsPage";
    3537
    3638
     
    7173                        <Route path="/search/restaurant/:restaurantLocation/:date/:hourFrom/:hourTo/:numPeople"
    7274                               element={<SearchPage type="restaurant"/>}/>
     75                        <Route path="/login-callback" element={<LoginCallback/>}></Route>
     76                        <Route path="/connected" element={<PrivateRoute><ConnectedAccountsPage/></PrivateRoute>}></Route>
    7377                    </Routes>
    7478                </BrowserRouter>
  • frontend/src/Components/Forms/AddItemMenuForm.js

    r07f4e8b r0f5aa27  
    44import useFormData from "../Hooks/useFormData";
    55import useCreateMenu from "../Hooks/Restaurant/useCreateMenu"
     6import useCreate from "../Hooks/useCreate";
    67
    78const AddItemMenuForm = (props) => {
     
    910
    1011  const edit = props.menu
     12  console.log(props.menu)
    1113  const dummy =     {
    1214    name: "",
     
    2325    edit ? props.menu : dummy
    2426  );
     27  const { createEntity } = useCreate();
    2528
    2629  return (
     
    7275              onClick={(e) => {
    7376                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
    7884              }}
    7985            >
  • frontend/src/Components/Forms/AddTripForm.js

    r07f4e8b r0f5aa27  
    272272
    273273                                    for (let i = 0; i < Object.values(routesForm).length; i++) {
    274                                         console.log(findDependantRoutes(wayPointNames, routesForm, i))
    275274                                        setDependencies(prevState => [...prevState, findDependantRoutes(wayPointNames, routesForm, i)])
    276275                                    }
    277                                     console.log('VO STATEOOOO')
    278                                     console.log(dependencies)
    279276                                    routesSetFormData(routesForm)
    280277                                    setRoutes(routesVar)
  • frontend/src/Components/Hooks/Restaurant/useCreateMenu.js

    r07f4e8b r0f5aa27  
    77        const navigator = useNavigate();
    88
    9     const createMenu = async (id, menu) => {
     9    const createMenu = async (id, menu, dep) => {
    1010                console.log(menu)
    1111        console.log(id)
     
    1818                                        //navigator("/resources/restaurant/" + id)
    1919                        //history.push('/restaurant');
     20                                        dep(prev => ++prev)
    2021                    })
    2122                    .catch((err) => {
  • frontend/src/Components/Hooks/User/useCreateUser.js

    r07f4e8b r0f5aa27  
    1010                    .post(`/register`, user)
    1111                    .then((res) => {
    12                         navigator("/login")
     12                        window.location.href = "http://localhost:8080/login"
    1313                    })
    1414                    .catch((err) => {
  • frontend/src/Components/Hooks/User/useLogin.js

    r07f4e8b r0f5aa27  
    1 import React from "react";
    2 
     1import { useState } from "react";
    32import 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";
     3import {useAuth} from "../../Context/AuthContext"; // Assuming you have axios configured
    74
    85const useLogin = () => {
     6        const [loading, setLoading] = useState(false);
     7        const [error, setError] = useState(null);
     8        const Auth = useAuth();
    99
    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);
    4312
    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        };
    5727
    5828        return {
    59                 login
     29                loading,
     30                error,
     31                handleLoginCallback,
    6032        };
    61 
    62 }
     33};
    6334
    6435export default useLogin;
  • frontend/src/Components/Hooks/useCreate.js

    r07f4e8b r0f5aa27  
    1515            .then((res) => {
    1616                //history.push('/hotel');
    17                 console.log(res)
    18                 console.log("gotovo")
    1917                getData(prev => ++prev)
    2018                getData2(prev => ++prev)
  • frontend/src/Components/Layout/Navbar/Navigation.js

    r07f4e8b r0f5aa27  
    6363                  style={{ backgroundColor: "#159895" }}
    6464                  onClick={() => {
    65                     navigator("/login");
     65                    window.location.href = ("http://localhost:8080/login");
    6666                  }}
    6767                >
  • frontend/src/Components/Listings/HotelListing.js

    r07f4e8b r0f5aa27  
    1 import {Col, Container, Image, Row, Button} from "react-bootstrap";
     1import {Col, Container, Image, Row, Button, Badge} from "react-bootstrap";
    22import {BsFillPersonFill} from "react-icons/bs";
    33import {MdOutlineLocalOffer} from "react-icons/md";
     
    55
    66function 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
    719    console.log(props)
     20    const randomInt = Math.floor(Math.random() * (3)) + 1;
    821    return (
    922        <>
     
    1528                    boxShadow: "0 3px 5px lightblue",
    1629                    maxWidth: "60%",
     30                    backgroundColor: props.data.promoted ? "#e1f7fa" : ""
    1731                }}
    1832            >
     
    3145                    <Col>
    3246                        <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>
    3451                        </Row>
    3552                        <Row>
     
    90107                                >
    91108                                    <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>
    93111                                    </Row>
    94112                                    <Row className="w-100">
  • frontend/src/Components/Login/LoginForm.js

    r07f4e8b r0f5aa27  
    55import useLogin from "../Hooks/User/useLogin";
    66import { Link } from "react-router-dom";
     7import useCreate from "../Hooks/useCreate";
     8import {useAuth} from "../Context/AuthContext";
    79
    8 const LoginForm = () => {
     10const LoginForm = (props) => {
    911  const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData(
    1012    {
    11       email: "",
     13      username: "",
    1214      password: "",
    1315    }
    1416  );
    1517
    16   const { login } = useLogin();
     18  const { createEntity } = useCreate();
     19  const Auth = useAuth();
    1720
    1821  return (
     
    2730            type="email"
    2831            placeholder="Enter email"
    29             name="email"
     32            name="username"
    3033            onChange={onFormChange}
    3134            value={formData.email}
    3235          />
    33           <Form.Text className="text-muted">
    34             Вашите податоци никогаш нема да бидат споделени.
    35           </Form.Text>
    3636        </Form.Group>
    3737
     
    4646          />
    4747        </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>*/}
    5656        <Form.Group className="my-1">
    5757          <Button
     
    6262              e.preventDefault();
    6363              console.log(formData);
    64               login(formData)
     64              createEntity(`/users/${Auth.getUser().userId}/connect`, formData, props.refresh)
    6565            }}
    6666          >
     
    6868              <AiFillLock />
    6969            </span>
    70             <span className="ikona mx-3">Најави се</span>
     70            <span className="ikona mx-3">Поврзи</span>
    7171          </Button>
    7272        </Form.Group>
  • frontend/src/Components/Misc/PrivateRoute.js

    r07f4e8b r0f5aa27  
    55function PrivateRoute({ children }) {
    66  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" />
    816}
    917
  • frontend/src/Components/ProfilePage/DataForm.js

    r07f4e8b r0f5aa27  
    1111
    1212  const handleClose = () =>  setShow(false);
    13   const handleShow = (e) => { 
     13  const handleShow = (e) => {
    1414    e.preventDefault();
    1515    setShow(true);
     
    2929            <Form.Group as={Col} controlId="name">
    3030              <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"}/>
    3233            </Form.Group>
    3334
     
    3839                placeholder=""
    3940                value={props.data["surname"]}
     41                name={"surname"}
    4042              />
    4143            </Form.Group>
     
    4547            <Form.Group as={Col} controlId="name">
    4648              <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"}/>
    4851            </Form.Group>
    4952
     
    5457                placeholder=""
    5558                value={props.data["country"]}
     59                name={"country"}
    5660              />
    5761            </Form.Group>
     
    6064          <Form.Group className="mb-3" controlId="address">
    6165            <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"}/>
    6368          </Form.Group>
    6469
     
    6671            <Form.Group as={Col} controlId="city">
    6772              <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"}/>
    6975            </Form.Group>
    7076
     
    7581                placeholder=""
    7682                value={props.data["zip"]}
     83                name={"zip"}
    7784              />
    7885            </Form.Group>
     
    8289            <Form.Group as={Col} controlId="email">
    8390              <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"}/>
    8593            </Form.Group>
    8694
     
    9199                placeholder=""
    92100                value={props.data["mobile"]}
     101                name={"mobile"}
    93102              />
    94103            </Form.Group>
  • frontend/src/Components/RestaurantDetails/MenuItem.js

    r07f4e8b r0f5aa27  
    66
    77    const data = props.data;
    8     console.log("dva orla")
    98    console.log(props)
    109    return (<>
  • frontend/src/Pages/NoBusinessRegisteredError.js

    r07f4e8b r0f5aa27  
    1414  const Auth = useAuth();
    1515  const isLoggedIn = Auth.userIsAuthenticated();
    16   const userId = localStorage.getItem("userId")
     16  const userId = Auth.getUser().userId
    1717  const [registered, setRegistered] = useState(false);
    1818  let checked = false;
     
    2626 
    2727  const { data: firma, isLoading: firmaIsLoading, getData: getFirmi} = useGet("/business/" + userId + "/unapproved", changed)
    28  
     28  const { data, isLoading, getData} = useGet("/" + userId + "/hasBusiness")
     29
    2930
    3031  useEffect(() => {
     
    5253  }
    5354
    54   !firmaIsLoading && firma && firma.length > 0 && firma[0].approved && navigator("/resources/hotel")
     55  !isLoading && data && navigator("/resources/hotel")
    5556 
    5657
Note: See TracChangeset for help on using the changeset viewer.