-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontend/#062 user dashboard #115
Changes from 7 commits
768ea39
641b6fd
92ec1cb
f31fe97
483d055
4e0da44
4a1a17f
07f5939
ae5cce3
d7e260a
60c71ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import api from '../../services/Api'; | ||
import { ORDER_ERROR, GET_ORDER, DELETE_ORDER } from '../types'; | ||
|
||
// Get order | ||
export const getUsersOrder = async (id) => { | ||
try { | ||
const res = await api.get(`users/me/orders/${id}`); | ||
return res; | ||
// TODO: define if there is a need for reducer | ||
} catch (error) { | ||
if (error.response) { | ||
console.log(error.response.data); | ||
} else if (error.request) { | ||
console.log(error.request); | ||
} else { | ||
console.log('Error', error.message); | ||
} | ||
console.log(error.config); | ||
return false; | ||
} | ||
}; | ||
|
||
// Delete order | ||
export const deleteUsersOrder = async (id, dispatch) => { | ||
try { | ||
await api.delete(`users/me/orders/${id}`); | ||
const user = api.get(`users/me/`); | ||
return user; | ||
// TODO: define if there is a need for reducer | ||
} catch (error) { | ||
if (error.response) { | ||
console.log(error.response.data); | ||
} else if (error.request) { | ||
console.log(error.request); | ||
} else { | ||
console.log('Error', error.message); | ||
} | ||
console.log(error.config); | ||
return false; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { useContext, useState } from 'react'; | ||
import './style.scss'; | ||
import { Link } from 'react-router-dom'; | ||
import { Link, Redirect } from 'react-router-dom'; | ||
import { logout } from '../../actions/Auth'; | ||
import { AuthContext } from '../../context/Auth'; | ||
import { ThemeContext } from '../../context/Theme'; | ||
import AppTheme from '../../context/Theme/themeColors'; | ||
import ThemeToggler from '../ThemeToggler'; | ||
|
||
function Navbar() { | ||
function Navbar(props) { | ||
const { userContext, dispatchUserContext } = useContext(AuthContext); | ||
const { isAuthenticated, user } = userContext; | ||
const theme = useContext(ThemeContext)[0]; | ||
|
@@ -18,8 +18,8 @@ function Navbar() { | |
if (!isLoggedOut) { | ||
alert('Could not log out user. Try again'); | ||
} | ||
return <Redirect to="/movies" />; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you make a redirect on Navbar level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After logging out, whoever is at the page is redirected to the landing page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but is he\she on a Navbar page? 🧐 What I mean is that navbar is not the best place to put authorization logic |
||
}; | ||
// console.log(isAuthenticated); | ||
const unauthenticatedNavBar = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a component, use PascalCase |
||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skip the return |
||
<> | ||
|
@@ -39,10 +39,7 @@ function Navbar() { | |
<Link to="/users/me"> | ||
<li className="navbar__list-item">Me</li> | ||
</Link> | ||
<Link to="/users/orders"> | ||
<li className="navbar__list-item">Orders</li> | ||
</Link> | ||
{user.isAdmin ? ( | ||
{user && user.isAdmin ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIR this is an unauthenticated nav, so why you put admin case in here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually authenticated, starts at line 36. |
||
<Link to="/admin"> | ||
<li className="navbar__list-item">Admin</li> | ||
</Link> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
@import '../../styles/variables'; | ||
.navbar { | ||
background-color: $color-secondary; | ||
font-family: $font-primary; | ||
font-size: $font-size-secondary; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you use those props?