summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/containers
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/containers')
-rw-r--r--opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js2
-rw-r--r--opendc-web/opendc-web-ui/src/containers/auth/Login.js35
-rw-r--r--opendc-web/opendc-web-ui/src/containers/auth/Logout.js7
-rw-r--r--opendc-web/opendc-web-ui/src/containers/auth/ProfileName.js10
-rw-r--r--opendc-web/opendc-web-ui/src/containers/projects/ProjectListContainer.js34
-rw-r--r--opendc-web/opendc-web-ui/src/containers/projects/VisibleProjectAuthList.js37
6 files changed, 46 insertions, 79 deletions
diff --git a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js
index 7aaa1886..e1be51dc 100644
--- a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js
+++ b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js
@@ -60,7 +60,7 @@ const ScenarioListContainer = ({ portfolioId }) => {
/>
<NewScenarioModalComponent
show={isVisible}
- currentPortfolioId={currentProjectId}
+ currentPortfolioId={portfolioId}
currentPortfolioScenarioIds={scenarios.map((s) => s._id)}
traces={traces}
schedulers={schedulers}
diff --git a/opendc-web/opendc-web-ui/src/containers/auth/Login.js b/opendc-web/opendc-web-ui/src/containers/auth/Login.js
index b0da0d0e..8459ef5f 100644
--- a/opendc-web/opendc-web-ui/src/containers/auth/Login.js
+++ b/opendc-web/opendc-web-ui/src/containers/auth/Login.js
@@ -1,43 +1,18 @@
import React from 'react'
-import GoogleLogin from 'react-google-login'
-import { useDispatch } from 'react-redux'
-import { logIn } from '../../redux/actions/auth'
import { Button } from 'reactstrap'
+import { useAuth } from '../../auth'
function Login({ visible, className }) {
- const dispatch = useDispatch()
-
- const onLogin = (payload) => dispatch(logIn(payload))
- const onAuthResponse = (response) => {
- onLogin({
- email: response.getBasicProfile().getEmail(),
- givenName: response.getBasicProfile().getGivenName(),
- familyName: response.getBasicProfile().getFamilyName(),
- googleId: response.googleId,
- authToken: response.getAuthResponse().id_token,
- expiresAt: response.getAuthResponse().expires_at,
- })
- }
- const onAuthFailure = (error) => {
- // TODO Show error alert
- console.error(error)
- }
+ const { loginWithRedirect } = useAuth()
if (!visible) {
return <span />
}
return (
- <GoogleLogin
- clientId={process.env.NEXT_PUBLIC_OAUTH_CLIENT_ID}
- onSuccess={onAuthResponse}
- onFailure={onAuthFailure}
- render={(renderProps) => (
- <Button color="primary" onClick={renderProps.onClick} className={className}>
- <span aria-hidden className="fa fa-google" /> Login with Google
- </Button>
- )}
- />
+ <Button color="primary" onClick={() => loginWithRedirect()} className={className}>
+ <span aria-hidden className="fa fa-sign-in" /> Sign In
+ </Button>
)
}
diff --git a/opendc-web/opendc-web-ui/src/containers/auth/Logout.js b/opendc-web/opendc-web-ui/src/containers/auth/Logout.js
index 94d4d061..37705c5d 100644
--- a/opendc-web/opendc-web-ui/src/containers/auth/Logout.js
+++ b/opendc-web/opendc-web-ui/src/containers/auth/Logout.js
@@ -1,11 +1,10 @@
import React from 'react'
-import { useDispatch } from 'react-redux'
-import { logOut } from '../../redux/actions/auth'
import LogoutButton from '../../components/navigation/LogoutButton'
+import { useAuth } from '../../auth'
const Logout = (props) => {
- const dispatch = useDispatch()
- return <LogoutButton {...props} onLogout={() => dispatch(logOut())} />
+ const { logout } = useAuth()
+ return <LogoutButton {...props} onLogout={() => logout({ returnTo: window.location.origin })} />
}
export default Logout
diff --git a/opendc-web/opendc-web-ui/src/containers/auth/ProfileName.js b/opendc-web/opendc-web-ui/src/containers/auth/ProfileName.js
index 3992c00f..70f5b884 100644
--- a/opendc-web/opendc-web-ui/src/containers/auth/ProfileName.js
+++ b/opendc-web/opendc-web-ui/src/containers/auth/ProfileName.js
@@ -1,13 +1,9 @@
import React from 'react'
-import { useUser } from '../../auth'
+import { useAuth } from '../../auth'
function ProfileName() {
- const user = useUser()
- return (
- <span>
- {user.givenName} {user.familyName}
- </span>
- )
+ const { isLoading, user } = useAuth()
+ return isLoading ? <span>Loading...</span> : <span>{user.name}</span>
}
export default ProfileName
diff --git a/opendc-web/opendc-web-ui/src/containers/projects/ProjectListContainer.js b/opendc-web/opendc-web-ui/src/containers/projects/ProjectListContainer.js
new file mode 100644
index 00000000..6632a8b5
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/containers/projects/ProjectListContainer.js
@@ -0,0 +1,34 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import ProjectList from '../../components/projects/ProjectList'
+import { useAuth } from '../../auth'
+import { useProjects } from '../../data/project'
+
+const getVisibleProjects = (projects, filter, userId) => {
+ switch (filter) {
+ case 'SHOW_ALL':
+ return projects
+ case 'SHOW_OWN':
+ return projects.filter((project) =>
+ project.authorizations.some((a) => a.userId === userId && a.level === 'OWN')
+ )
+ case 'SHOW_SHARED':
+ return projects.filter((project) =>
+ project.authorizations.some((a) => a.userId === userId && a.level !== 'OWN')
+ )
+ default:
+ return projects
+ }
+}
+
+const ProjectListContainer = ({ filter }) => {
+ const { user } = useAuth()
+ const projects = useProjects()
+ return <ProjectList projects={getVisibleProjects(projects, filter, user?.sub)} />
+}
+
+ProjectListContainer.propTypes = {
+ filter: PropTypes.string.isRequired,
+}
+
+export default ProjectListContainer
diff --git a/opendc-web/opendc-web-ui/src/containers/projects/VisibleProjectAuthList.js b/opendc-web/opendc-web-ui/src/containers/projects/VisibleProjectAuthList.js
deleted file mode 100644
index 8e1d063b..00000000
--- a/opendc-web/opendc-web-ui/src/containers/projects/VisibleProjectAuthList.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { useSelector } from 'react-redux'
-import ProjectList from '../../components/projects/ProjectList'
-
-const getVisibleProjectAuths = (projectAuths, filter) => {
- switch (filter) {
- case 'SHOW_ALL':
- return projectAuths
- case 'SHOW_OWN':
- return projectAuths.filter((projectAuth) => projectAuth.authorizationLevel === 'OWN')
- case 'SHOW_SHARED':
- return projectAuths.filter((projectAuth) => projectAuth.authorizationLevel !== 'OWN')
- default:
- return projectAuths
- }
-}
-
-const VisibleProjectAuthList = ({ filter }) => {
- const authorizations = useSelector((state) => {
- const denormalizedAuthorizations = state.projectList.authorizationsOfCurrentUser.map((authorizationIds) => {
- const authorization = state.objects.authorization[authorizationIds]
- authorization.user = state.objects.user[authorization.userId]
- authorization.project = state.objects.project[authorization.projectId]
- return authorization
- })
-
- return getVisibleProjectAuths(denormalizedAuthorizations, filter)
- })
- return <ProjectList authorizations={authorizations} />
-}
-
-VisibleProjectAuthList.propTypes = {
- filter: PropTypes.string.isRequired,
-}
-
-export default VisibleProjectAuthList