Commit 8df77e2d authored by Kevin Kaminski's avatar Kevin Kaminski

[AFP-87] 🚧 Working on Local Storage and adding google info [@kkaminski]

parent af5981b8
import React from 'react' import React from 'react'
const AccountForm = () => { const AccountForm = (props: any) => {
return ( return (
<div> <div>
<h3>Account</h3> <h3>Account</h3>
......
import React from 'react' import React from 'react'
import { GoogleLogin, useGoogleLogin } from 'react-google-login'; import { GoogleLogin } from 'react-google-login';
const Login = () => { const Login = () => {
const storage = window.localStorage; const storage = window.localStorage;
const loginSuccess = (response: any) => { const loginSuccess = (response: any) => {
console.log(response);
const {email, familyName:lastName, givenName:firstName} = response.profileObj;
storage.setItem("loggedIn", "true");
storage.setItem("userFirstName", firstName);
storage.setItem("userLastName", lastName);
storage.setItem("userEmail", email);
storage.setItem("tokenId", response.tokenId); storage.setItem("tokenId", response.tokenId);
const apiUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + response.tokenId
fetch(apiUrl).then((response) => response.json()).then((data) => {
console.log(data)
})
console.log("Log in succesful", storage); console.log("Log in succesful", storage);
} }
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import {useGoogleLogin} from 'react-google-login' import { GoogleAuthService } from 'services'
import {AccountForm} from 'components' import {AccountForm} from 'components'
const AccountPage = () => { const AccountPage = () => {
let clientId = ""; const storage = window.localStorage
const userInfo = useGoogleLogin({clientId}) const [userInfo, setUserInfo] = useState();
GoogleAuthService.checkGoogleToken(storage.tokenId).then((data) => setUserInfo(data))
return ( return (
<div> <div>
<AccountForm /> <AccountForm props={userInfo}/>
</div> </div>
) )
} }
......
...@@ -5,7 +5,12 @@ import { Order } from 'Order'; ...@@ -5,7 +5,12 @@ import { Order } from 'Order';
import { useAllOrders } from 'hooks' import { useAllOrders } from 'hooks'
const OrderIndexPage = () => { const OrderIndexPage = () => {
const { orders } = useAllOrders(); // const { orders } = useAllOrders();
let [orders, setOrders] = useState([]);
useEffect(() => {
OrderService.allOrders().then((data) => setOrders(data));
}, [])
const orderDetailsArr = orders.map((order: Order, idx: any) => { const orderDetailsArr = orders.map((order: Order, idx: any) => {
return <tr key={idx}><OrderDetails return <tr key={idx}><OrderDetails
......
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import {OrderShowDetails} from 'components'; import {OrderShowDetails} from 'components';
import { Order, Item } from 'Order'; import { Order, Item } from 'Order';
<<<<<<< HEAD
import { useOrder } from 'hooks' import { useOrder } from 'hooks'
const OrderShowPage = () => { const OrderShowPage = () => {
const { id } = useParams<any>(); const { id } = useParams<any>();
const { order} = useOrder(id) const { order} = useOrder(id)
=======
import { OrderService } from 'services'
const OrderShowPage = (props: any) => {
const location = props.match.params.id;
const apiUrl = 'http://localhost:8080/api/orders/' + location;
const [order, setOrder] = useState<Order>();
const [items, setItems] = useState<Item[]>()
useEffect(() => {
OrderService.orderById(apiUrl).then((data) => {
setOrder(data)
setItems(data.orderItems);
})
}, [apiUrl])
>>>>>>> [AFP-87] :construction: Working on Local Storage and adding google info [@kkaminski]
if (!order) { if (!order) {
return(<></>); return(<></>);
......
export const checkGoogleToken = (tokenId: any) => {
const apiUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + tokenId
return fetch(apiUrl).then((response) => response.json())
}
export default {
checkGoogleToken
}
\ No newline at end of file
import orderList from './mock-order-data' import orderList from './mock-order-data'
import { Order } from 'Order'; import { Order } from 'Order';
export const allOrders = () => new Promise<Order[]>((res, rej) => { export const allOrders = () => {
setTimeout(() => { res(orderList) }, 2000) const apiUrl = 'http://localhost:8080/api/orders';
}); return fetch(apiUrl).then((response) => response.json())
}
export const orderById = (id: string) => new Promise<Order>((res, rej) => { export const orderById = (apiUrl: string) => {
setTimeout(() => { return fetch(apiUrl).then((response) => response.json())
const orderData = orderList.filter((order) => { }
return order.id === id;
})
res(orderData[0])
}, 2000)
})
export default { export default {
......
export {default as OrderService} from './OrderService' export {default as OrderService} from './OrderService'
export {default as GoogleAuthService } from './GoogleAuthService'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment