Skip to content

Commit

Permalink
UPDATED
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeaseen committed Jul 1, 2021
1 parent aa257f9 commit 8269d7a
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 29 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"files": {
"main.css": "/static/css/main.26e2f06d.chunk.css",
"main.js": "/static/js/main.a5ff8f08.chunk.js",
"main.js.map": "/static/js/main.a5ff8f08.chunk.js.map",
"main.js": "/static/js/main.0c1e9b2a.chunk.js",
"main.js.map": "/static/js/main.0c1e9b2a.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.91236b34.js",
"runtime-main.js.map": "/static/js/runtime-main.91236b34.js.map",
"static/css/2.61b4cb56.chunk.css": "/static/css/2.61b4cb56.chunk.css",
"static/js/2.bfe51195.chunk.js": "/static/js/2.bfe51195.chunk.js",
"static/js/2.bfe51195.chunk.js.map": "/static/js/2.bfe51195.chunk.js.map",
"static/js/2.cf35512c.chunk.js": "/static/js/2.cf35512c.chunk.js",
"static/js/2.cf35512c.chunk.js.map": "/static/js/2.cf35512c.chunk.js.map",
"index.html": "/index.html",
"static/css/2.61b4cb56.chunk.css.map": "/static/css/2.61b4cb56.chunk.css.map",
"static/css/main.26e2f06d.chunk.css.map": "/static/css/main.26e2f06d.chunk.css.map",
"static/js/2.bfe51195.chunk.js.LICENSE.txt": "/static/js/2.bfe51195.chunk.js.LICENSE.txt"
"static/js/2.cf35512c.chunk.js.LICENSE.txt": "/static/js/2.cf35512c.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.91236b34.js",
"static/css/2.61b4cb56.chunk.css",
"static/js/2.bfe51195.chunk.js",
"static/js/2.cf35512c.chunk.js",
"static/css/main.26e2f06d.chunk.css",
"static/js/main.a5ff8f08.chunk.js"
"static/js/main.0c1e9b2a.chunk.js"
]
}
2 changes: 1 addition & 1 deletion client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon-194x194.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>EventPlanner</title><link href="/static/css/2.61b4cb56.chunk.css" rel="stylesheet"><link href="/static/css/main.26e2f06d.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],p=0,s=[];p<l.length;p++)f=l[p],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(c&&c(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpfrontend-react"]=this["webpackJsonpfrontend-react"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var c=a;t()}([])</script><script src="/static/js/2.bfe51195.chunk.js"></script><script src="/static/js/main.a5ff8f08.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon-194x194.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>EventPlanner</title><link href="/static/css/2.61b4cb56.chunk.css" rel="stylesheet"><link href="/static/css/main.26e2f06d.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],p=0,s=[];p<l.length;p++)f=l[p],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(c&&c(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpfrontend-react"]=this["webpackJsonpfrontend-react"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var c=a;t()}([])</script><script src="/static/js/2.cf35512c.chunk.js"></script><script src="/static/js/main.0c1e9b2a.chunk.js"></script></body></html>
3 changes: 0 additions & 3 deletions client/build/static/js/2.bfe51195.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion client/build/static/js/2.bfe51195.chunk.js.map

This file was deleted.

3 changes: 3 additions & 0 deletions client/build/static/js/2.cf35512c.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/js/2.cf35512c.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client/build/static/js/main.0c1e9b2a.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/js/main.0c1e9b2a.chunk.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions client/build/static/js/main.a5ff8f08.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion client/build/static/js/main.a5ff8f08.chunk.js.map

This file was deleted.

65 changes: 55 additions & 10 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
import { useState } from 'react'
import { useState, useEffect, useContext } from 'react'

import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom'
import {
BrowserRouter,
Route,
Switch,
Redirect,
useHistory
} from 'react-router-dom'

import './App.css'
import AuthPage from './components/screens/Auth'
import BookingsPage from './components/screens/Bookings'
import EventsPage from './components/screens/Events'
import MainNavigation from './components/Navigation/MainNavber'
import AuthContext from './context/auth-context'
import Swal from 'sweetalert2'

const Routing = () => {
const contextType = useContext(AuthContext)
const history = useHistory()
useEffect(() => {
let localtoken = localStorage.getItem('localToken')
if (typeof localtoken !== 'string') {
localtoken = null
}

let localuserId = localStorage.getItem('localUserId')
if (typeof localuserId !== 'string') {
localuserId = null
}

let localtokenExpiration = localStorage.getItem('localTokenExpiration')
if (typeof localtokenExpiration !== 'string') {
localtokenExpiration = null
}

//console.log(localtoken, localuserId, localtokenExpiration)

if (localtoken && localuserId && localtokenExpiration) {
contextType.login(localtoken, localuserId, localtokenExpiration)
} else {
history.push('/auth')
}
// eslint-disable-next-line
}, [])

const Routing = (props: { token: null | string }) => {
return (
<Switch>
{props.token && <Redirect from="/" to="/events" exact />}
{props.token && <Redirect from="/auth" to="/events" exact />}
{contextType.token && <Redirect from="/" to="/events" exact />}
{contextType.token && <Redirect from="/auth" to="/events" exact />}

{!props.token && <Route exact path="/auth" component={AuthPage} />}
<Route exact path="/auth" component={AuthPage} />

<Route exact path="/events" component={EventsPage} />
{props.token && <Route exact path="/bookings" component={BookingsPage} />}
<Route exact path="/bookings" component={BookingsPage} />

{!props.token && <Redirect to="/auth" exact />}
<Route exact path="/events" component={EventsPage} />
</Switch>
)
}
Expand All @@ -29,15 +63,25 @@ function App() {
//const history = useHistory()
const [token, setToken] = useState<null | string>(null)
const [userId, setUserId] = useState<null | string>(null)
const [tokenExpiration, setTokenExpiration] = useState<null | string>(null)

const login = (token: string, userId: string, tokenExpiration: string) => {
setToken(token)
setUserId(userId)
setTokenExpiration(tokenExpiration)
}

const logout = () => {
setToken(null)
setUserId(null)
localStorage.clear()
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Logged out successfully',
showConfirmButton: false,
timer: 1500
})
}

return (
Expand All @@ -46,12 +90,13 @@ function App() {
value={{
token: token,
userId: userId,
tokenExpiration: tokenExpiration,
login: login,
logout: logout
}}
>
<MainNavigation />
<Routing token={token} />
<Routing />
</AuthContext.Provider>
</BrowserRouter>
)
Expand Down
9 changes: 9 additions & 0 deletions client/src/components/Bookings/BookingChart/BookingChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ const bookingsChart = (props: any) => {
top: 0
}
},
options: {
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
legend: {
display: true,
position: 'right',
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Navigation/MainNavber.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AuthContext from '../../context/auth-context'
import './MainNavigation.css'

const mainNavigation = (props) => (

<AuthContext.Consumer>
{(context) => {
return (
Expand Down
11 changes: 10 additions & 1 deletion client/src/components/screens/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,22 @@ const AuthPage = () => {
resData.data.login.tokenExpiration
)

localStorage.setItem('localToken', resData.data.login.token)
localStorage.setItem('localUserId', resData.data.login.userId)
localStorage.setItem(
'localTokenExpiration',
resData.data.login.tokenExpiration
)


Swal.fire({
position: 'top-end',
icon: 'success',
title: ' Logged in Successfully',
showConfirmButton: false,
timer: 5000
timer: 1200
})

return
} else if (resData.data.createUser) {
Swal.fire({
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/screens/Bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BookingsChart from '../../components/Bookings/BookingChart/BookingChart'
import BookingsControls from '../../components/Bookings/BookingsControls/BookingsControls'
import Swal from 'sweetalert2'
const BookingsPage = () => {
// eslint-disable-next-line
const contextType = useContext(AuthContext)
const [isLoading, setIsLoading] = useState<boolean>(false)
const [bookings, setBookings] = React.useState<any[]>([])
Expand Down Expand Up @@ -48,7 +49,7 @@ const BookingsPage = () => {
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + contextType.token
Authorization: 'Bearer ' + localStorage.getItem('localToken')
}
})
.then((res) => res.json())
Expand Down Expand Up @@ -93,7 +94,7 @@ const BookingsPage = () => {
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + contextType.token
Authorization: 'Bearer ' + localStorage.getItem('localToken')
}
})
.then((res) => res.json())
Expand All @@ -119,7 +120,7 @@ const BookingsPage = () => {
//setIsLoading(false)
})
.catch((err) => {
console.log(err)
//console.log(err)
//setIsLoading(false)
})
}
Expand Down
1 change: 1 addition & 0 deletions client/src/context/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { userContextState } from './type'
const contextDefaultValues: userContextState = {
token: null,
userId: null,
tokenExpiration: null,
login: (token: string, userId: string, tokenExpiration: string) => {},
logout: () => {}
}
Expand Down
1 change: 1 addition & 0 deletions client/src/context/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type userContextState = {
token: null | string
userId: null | string
tokenExpiration: null | string
login: (token: string, userId: string, tokenExpiration: string) => void
logout: () => void
}

0 comments on commit 8269d7a

Please sign in to comment.