Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

moved to tailwindcss; moved redux into a separated folder; general fixed & improvements

Blue Mouse3473cdc0a73d
diff --git a/craco.config.js b/craco.config.js
new file mode 100644
index 000000000..1d1894c98
--- /dev/null
+++ b/craco.config.js
@@ -0,0 +1,10 @@
+module.exports = {
+ style: {
+ postcss: {
+ plugins: [
+ require('tailwindcss'),
+ require('autoprefixer'),
+ ],
+ },
+ },
+}
diff --git a/package.json b/package.json
index b062165e3..441fb9c26 100644
--- a/package.json
+++ b/package.json
@@ -3,13 +3,17 @@
"version": "0.1.0",
"private": true,
"dependencies": {
+ "@craco/craco": "^6.2.0",
+ "@headlessui/react": "^1.3.0",
+ "@heroicons/react": "^1.0.2",
"@material-ui/core": "^4.11.3",
+ "@tailwindcss/forms": "^0.3.3",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.8.3",
"axios": "^0.21.1",
"billboard.js": "^3.1.2",
- "bootstrap": "^4.6.0",
+ "bootstrap": "^5.0.2",
"bootstrap-icons": "^1.4.1",
"classnames": "^2.3.1",
"d3": "^7.0.0",
@@ -22,9 +26,10 @@
"react": "^17.0.1",
"react-alert": "^7.0.2",
"react-alert-template-basic": "^1.0.0",
- "react-bootstrap": "^1.5.2",
+ "react-bootstrap": "^v2.0.0-beta.2",
"react-bootstrap-icons": "^1.4.0",
"react-dom": "^17.0.1",
+ "react-feather": "^2.0.9",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
@@ -34,11 +39,11 @@
"web-vitals": "^1.1.1"
},
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build",
+ "start": "craco start",
+ "build": "craco build",
"build:css": "cross-env sass --no-source-map src:src --load-path ./node_modules --style compressed",
"watch:css": "cross-env npm run build-css && cross-env sass --no-source-map src:src --load-path ./node_modules --style compressed --watch",
- "test": "react-scripts test",
+ "test": "craco test",
"eject": "react-scripts eject"
},
"eslintConfig": {
@@ -60,7 +65,10 @@
]
},
"devDependencies": {
+ "autoprefixer": "^9.8.6",
"cross-env": "^7.0.3",
- "sass": "^1.35.2"
+ "postcss": "^7.0.36",
+ "sass": "^1.35.2",
+ "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.4"
}
}
diff --git a/src/App.js b/src/App.js
index 2cd94b154..a23600c43 100644
--- a/src/App.js
+++ b/src/App.js
@@ -19,9 +19,9 @@ import ViewProject from 'pages/Project/View'
import { isAuthenticated, notAuthenticated } from './hoc/protected'
import { getAccessToken } from 'utils/accessToken'
import { authMe } from './api'
-import { authActions } from 'actions/auth'
-import { errorsActions } from 'actions/errors'
-import { alertsActions } from 'actions/alerts'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+import { alertsActions } from 'redux/actions/alerts'
const ProtectedSignIn = notAuthenticated(SignIn)
const ProtectedSignUp = notAuthenticated(SignUp)
diff --git a/src/api/index.js b/src/api/index.js
index 6ddac10a5..64286682b 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -1,7 +1,7 @@
import axios from 'axios'
-import { store } from 'store'
+import { store } from 'redux/store'
import Debug from 'debug'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
import { getAccessToken, removeAccessToken } from 'utils/accessToken'
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 8977ccf32..116a63da2 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -1,45 +1,51 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { useDispatch } from 'react-redux'
-import { BoxArrowRight } from 'react-bootstrap-icons'
import routes from 'routes'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
const Header = ({ authenticated }) => {
const dispatch = useDispatch()
return (
- <header className="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
- <Link
- to="/"
- className="my-0 mr-md-auto font-weight-normal">
- Analytics
- </Link>
-
- <nav className="my-2 my-md-0 mr-md-3">
- <Link to="/" className="p-2 text-dark">Features</Link>
- <Link to="/" className="p-2 text-dark">Pricing</Link>
- <Link to="/" className="p-2 text-dark">FAQs</Link>
- <Link to="/" className="p-2 text-dark">Docs</Link>
- { authenticated && <Link to={routes.user_settings} className="p-2 text-dark">You</Link> }
- { !authenticated && <Link to={routes.signin} className="p-2 text-dark">Sign in</Link> }
- </nav>
- { authenticated
- ? (
- <>
- <Link to={routes.dashboard} className="btn btn-outline-primary mr-3">Dashboard</Link>
- <BoxArrowRight
- className="btn-hover"
- color="#007bff"
- size="24"
- role="button"
- onClick={() => dispatch(authActions.logout())}
- />
- </>
- )
- : <Link to={routes.signup} className="btn btn-outline-primary">Get started</Link>
- }
+ <header className='bg-indigo-600'>
+ <nav className='mx-auto px-4 sm:px-6 lg:px-8' aria-label='Top'>
+ <div className='w-full py-4 flex items-center justify-between border-b border-indigo-500 lg:border-none'>
+ <div className='flex items-center'>
+ <Link to={routes.main}>
+ <span className='sr-only'>Analytics</span>
+ <img className='h-10 w-auto' src='https://tailwindui.com/img/logos/workflow-mark.svg?color=white' alt='' />
+ </Link>
+ <div className='hidden ml-10 space-x-8 lg:block'>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Features'>Features</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Pricing'>Pricing</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='FAQs'>FAQs</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Docs'>Docs</Link>
+ </div>
+ </div>
+ <div className='ml-10 space-x-4'>
+ {authenticated ? (
+ <>
+ <Link to={routes.user_settings} className='text-base font-medium text-white hover:text-indigo-50'>You</Link>
+ <Link to={routes.dashboard} className='inline-block bg-white py-2 px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50'>Dashboard</Link>
+ <Link to='#' className='text-base font-medium text-white hover:text-indigo-50' onClick={() => dispatch(authActions.logout())}>Logout</Link>
+ </>
+ ) : (
+ <>
+ <Link to={routes.signin} className='inline-block bg-indigo-500 py-2 px-4 border border-transparent rounded-md text-base font-medium text-white hover:bg-opacity-75'>Sign in</Link>
+ <Link to={routes.signup} className='inline-block bg-white py-2 px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50'>Get started</Link>
+ </>
+ )}
+ </div>
+ </div>
+ <div className='py-4 flex flex-wrap justify-center space-x-6 lg:hidden'>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Features'>Features</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Pricing'>Pricing</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='FAQs'>FAQs</Link>
+ <Link to='/' className='text-base font-medium text-white hover:text-indigo-50' key='Docs'>Docs</Link>
+ </div>
+ </nav>
</header>
)
}
diff --git a/src/index.js b/src/index.js
index 9a9aa6f4e..7f8ee6d79 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,11 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter } from 'react-router-dom'
-import { store } from 'store'
+import { store } from 'redux/store'
import { Provider } from 'react-redux'
import { transitions, positions, Provider as AlertProvider } from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'
-import 'bootstrap/dist/css/bootstrap.min.css'
import 'billboard.js/dist/billboard.min.css'
import App from './App'
diff --git a/src/index.scss b/src/index.scss
index bfd058b99..10705c855 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -1,4 +1,6 @@
-// @import "bootstrap/dist/css/bootstrap.min.css";
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
body {
margin: 0;
@@ -43,7 +45,6 @@ code {
cursor: not-allowed;
}
-
.hoverable {
transition: opacity 300ms;
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx
index 57f8b18d9..3829944c0 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx
@@ -3,8 +3,8 @@ import { useHistory, useParams } from 'react-router-dom'
import CreateNewPassword from './CreateNewPassword'
import { createNewPassword } from 'api'
-import { errorsActions } from 'actions/errors'
-import { alertsActions } from 'actions/alerts'
+import { errorsActions } from 'redux/actions/errors'
+import { alertsActions } from 'redux/actions/alerts'
import routes from 'routes'
export default () => {
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
index 77848a821..f8150d9c3 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
@@ -1,8 +1,9 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
-import Form from 'react-bootstrap/Form'
import routes from 'routes'
+import Input from 'ui/Input'
+import Button from 'ui/Button'
import { isValidPassword } from 'utils/validator'
export default ({ onSubmit }) => {
@@ -56,54 +57,43 @@ export default ({ onSubmit }) => {
}
return (
- <div className="container">
- <h4 className="mb-3">Account recovery</h4>
- <Form validated={validated} onSubmit={handleSubmit} noValidate>
- <Form.Group className="mb-3">
- <Form.Label htmlFor="password">Your new password</Form.Label>
- <Form.Control
- type="password"
- value={form.password}
- placeholder="Password"
- id="password"
- className="form-control"
- name="password"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('password')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('password')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.password}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="mb-3">
- <Form.Label htmlFor="repeat">Repeat password</Form.Label>
- <Form.Control
- type="password"
- value={form.repeat}
- placeholder="Repeat password"
- id="repeat"
- className="form-control"
- name="repeat"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('repeat')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('repeat')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.repeat}
- </Form.Control.Feedback>
- </Form.Group>
- <div className="d-flex align-items-center mb-3">
- <Link to={routes.signin} className="btn btn-link">
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ Account recovery
+ </h2>
+ <Input
+ name='password'
+ id='password'
+ type='password'
+ label='Your new password'
+ hint='Longer than 8 chars'
+ value={form.password}
+ placeholder='Password'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.password}
+ />
+ <Input
+ name='repeat'
+ id='repeat'
+ type='password'
+ label='Repeat password'
+ value={form.password}
+ placeholder='Password'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.repeat}
+ />
+ <div className='flex justify-between mt-3'>
+ <Link to={routes.signin} className='underline text-blue-600 hover:text-indigo-800'>
Sign in instead
</Link>
- <button type="submit" className="btn btn-primary ml-auto">
+ <Button type='submit' primary large>
Save new password
- </button>
+ </Button>
</div>
- </Form>
+ </form>
</div>
)
}
\ No newline at end of file
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx
index abf6f99c2..9bfe37b7f 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx
@@ -3,8 +3,8 @@ import { useHistory } from 'react-router-dom'
import ForgotPassword from './ForgotPassword'
import { forgotPassword } from 'api'
-import { errorsActions } from 'actions/errors'
-import { alertsActions } from 'actions/alerts'
+import { errorsActions } from 'redux/actions/errors'
+import { alertsActions } from 'redux/actions/alerts'
import routes from 'routes'
export default () => {
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
index c1af7eed0..aca167ab0 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
@@ -1,8 +1,9 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
-import Form from 'react-bootstrap/Form'
import routes from 'routes'
+import Input from 'ui/Input'
+import Button from 'ui/Button'
import { isValidEmail, isValidPassword } from 'utils/validator'
export default ({ onSubmit }) => {
@@ -51,36 +52,31 @@ export default ({ onSubmit }) => {
}
return (
- <div className="container">
- <h4 className="mb-3">Account recovery</h4>
- <Form validated={validated} onSubmit={handleSubmit} noValidate>
- <Form.Group className="mb-3 has-validation">
- <Form.Label htmlFor="email">Email</Form.Label>
- <Form.Control
- type="email"
- value={form.email}
- placeholder="[email protected]"
- id="email"
- className="form-control"
- name="email"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('email')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('email')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.email}
- </Form.Control.Feedback>
- </Form.Group>
- <div className="d-flex align-items-center mb-3">
- <Link to={routes.signin} className="btn btn-link">
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ Account recovery
+ </h2>
+ <Input
+ name='email'
+ id='email'
+ type='email'
+ label='Email'
+ value={form.email}
+ placeholder='[email protected]'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.email}
+ />
+ <div className='flex justify-between mt-3'>
+ <Link to={routes.signin} className='mt-1 underline text-blue-600 hover:text-indigo-800'>
Sign in
</Link>
- <button type="submit" className="btn btn-primary ml-auto">
+ <Button type='submit' primary large>
Reset password
- </button>
+ </Button>
</div>
- </Form>
+ </form>
</div>
)
}
\ No newline at end of file
diff --git a/src/pages/Auth/Signin/Signin.container.jsx b/src/pages/Auth/Signin/Signin.container.jsx
index c34b72483..5531856dc 100644
--- a/src/pages/Auth/Signin/Signin.container.jsx
+++ b/src/pages/Auth/Signin/Signin.container.jsx
@@ -1,6 +1,6 @@
import Signin from './Signin'
import { useDispatch } from 'react-redux'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
export default () => {
const dispatch = useDispatch()
diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.jsx
index af390e800..5ad171586 100644
--- a/src/pages/Auth/Signin/Signin.jsx
+++ b/src/pages/Auth/Signin/Signin.jsx
@@ -1,8 +1,10 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
-import Form from 'react-bootstrap/Form'
import routes from 'routes'
+import Input from 'ui/Input'
+import Button from 'ui/Button'
+import Checkbox from 'ui/Checkbox'
import { isValidEmail, isValidPassword } from 'utils/validator'
export default ({ onSubmit }) => {
@@ -46,6 +48,10 @@ export default ({ onSubmit }) => {
allErrors.email = 'Please provide a valid email.'
}
+ if (!isValidPassword(form.password)) {
+ allErrors.password = 'The password has to consist of at least 8 characters.'
+ }
+
const valid = Object.keys(allErrors).length === 0
setErrors(allErrors)
@@ -53,66 +59,57 @@ export default ({ onSubmit }) => {
}
return (
- <div className="container">
- <h4 className="mb-3">Sign in</h4>
- <Form validated={validated} onSubmit={handleSubmit} noValidate>
- <Form.Group className="mb-3 has-validation">
- <Form.Label htmlFor="email">Email</Form.Label>
- <Form.Control
- type="email"
- value={form.email}
- placeholder="[email protected]"
- id="email"
- className="form-control"
- name="email"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('email')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('email')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.email}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="mb-3">
- <Form.Label htmlFor="password">Password</Form.Label>
- <Form.Control
- type="password"
- value={form.password}
- placeholder="Password"
- id="password"
- className="form-control"
- name="password"
- onChange={handleInput}
- required
- />
- </Form.Group>
- <Form.Group className="custom-control custom-checkbox">
- <Form.Control
- type="checkbox"
- checked={form.keep_signedin}
- id="keep_signedin"
- className="custom-control-input"
- name="keep_signedin"
- onChange={handleInput}
- />
- <Form.Label htmlFor="keep_signedin" className="custom-control-label">
- Don't remember me.
- </Form.Label>
- </Form.Group>
- <div className="d-flex align-items-center mb-3">
- <Link to={routes.reset_password} className="btn btn-link">
- Forgot password?
- </Link>
- <span> | </span>
- <Link to={routes.signup} className="btn btn-link">
- Sign up instead
- </Link>
- <button type="submit" className="btn btn-primary ml-auto">
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ Sign in to your account
+ </h2>
+ <Input
+ name='email'
+ id='email'
+ type='email'
+ label='Email'
+ value={form.email}
+ placeholder='[email protected]'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.email}
+ />
+ <Input
+ name='password'
+ id='password'
+ type='password'
+ label='Password'
+ hint='Longer than 8 chars'
+ value={form.password}
+ placeholder='Password'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.password}
+ />
+ <Checkbox
+ checked={form.keep_signedin}
+ onChange={handleInput}
+ name='keep_signedin'
+ id='keep_signedin'
+ className='mt-4'
+ label={'Don\'t remember me.'}
+ />
+ <div className='flex justify-between mt-3'>
+ <div className='pt-1'>
+ <Link to={routes.reset_password} className='underline text-blue-600 hover:text-indigo-800'>
+ Forgot password?
+ </Link>
+ <span>&nbsp;|&nbsp;</span>
+ <Link to={routes.signup} className='underline text-blue-600 hover:text-indigo-800'>
+ Sign up instead
+ </Link>
+ </div>
+ <Button type='submit' primary large>
Sign in
- </button>
+ </Button>
</div>
- </Form>
+ </form>
</div>
)
}
\ No newline at end of file
diff --git a/src/pages/Auth/Signup/Signup.container.jsx b/src/pages/Auth/Signup/Signup.container.jsx
index dfd10548d..ec9f5971b 100644
--- a/src/pages/Auth/Signup/Signup.container.jsx
+++ b/src/pages/Auth/Signup/Signup.container.jsx
@@ -1,6 +1,6 @@
import Signup from './Signup'
import { useDispatch } from 'react-redux'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
export default () => {
const dispatch = useDispatch()
diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.jsx
index 94d56f44e..dc3857577 100644
--- a/src/pages/Auth/Signup/Signup.jsx
+++ b/src/pages/Auth/Signup/Signup.jsx
@@ -1,8 +1,10 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
-import Form from 'react-bootstrap/Form'
import routes from 'routes'
+import Input from 'ui/Input'
+import Checkbox from 'ui/Checkbox'
+import Button from 'ui/Button'
import { isValidEmail, isValidPassword } from 'utils/validator'
export default ({ onSubmit }) => {
@@ -67,103 +69,70 @@ export default ({ onSubmit }) => {
}
return (
- <div className="container">
- <h4 className="mb-3">Sign up</h4>
- <Form validated={validated} onSubmit={handleSubmit} noValidate>
- <Form.Group className="mb-3 has-validation">
- <Form.Label htmlFor="email">Email</Form.Label>
- <Form.Control
- type="email"
- value={form.email}
- placeholder="[email protected]"
- id="email"
- className="form-control"
- name="email"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('email')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('email')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.email}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="mb-3">
- <Form.Label htmlFor="password">Password</Form.Label>
- <Form.Control
- type="password"
- value={form.password}
- placeholder="Password"
- id="password"
- className="form-control"
- name="password"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('password')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('password')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.password}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="mb-3">
- <Form.Label htmlFor="repeat">Repeat password</Form.Label>
- <Form.Control
- type="password"
- value={form.repeat}
- placeholder="Repeat password"
- id="repeat"
- className="form-control"
- name="repeat"
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('repeat')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('repeat')}
- required
- />
- <Form.Control.Feedback type="invalid">
- {errors.repeat}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="custom-control custom-checkbox">
- <Form.Control
- type="checkbox"
- checked={form.tos}
- id="tos"
- className="custom-control-input"
- name="tos"
- onChange={handleInput}
- isInvalid={beenSubmitted && errors.hasOwnProperty('tos')}
- required
- />
- <Form.Label htmlFor="tos" className="custom-control-label">
- I do accept terms and conditions and the privacy policy.
- </Form.Label>
- <Form.Control.Feedback type="invalid">
- {errors.tos}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="custom-control custom-checkbox">
- <Form.Control
- type="checkbox"
- checked={form.keep_signedin}
- id="keep_signedin"
- className="custom-control-input"
- name="keep_signedin"
- onChange={handleInput}
- />
- <Form.Label htmlFor="keep_signedin" className="custom-control-label">
- Don't remember me.
- </Form.Label>
- </Form.Group>
- <div className="d-flex align-items-center mb-3">
- <Link to={routes.signin} className="btn btn-link">
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ Sign up
+ </h2>
+ <Input
+ name='email'
+ id='email'
+ type='email'
+ label='Email'
+ value={form.email}
+ placeholder='[email protected]'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.email}
+ />
+ <Input
+ name='password'
+ id='password'
+ type='password'
+ label='Password'
+ hint='Longer than 8 chars'
+ value={form.password}
+ placeholder='Password'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.password}
+ />
+ <Input
+ name='repeat'
+ id='repeat'
+ type='password'
+ label='Repeat password'
+ value={form.repeat}
+ placeholder='Repeat password'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.repeat}
+ />
+ <Checkbox
+ checked={form.tos}
+ onChange={handleInput}
+ name='tos'
+ id='tos'
+ className='mt-4'
+ label='I do accept terms and conditions and the privacy policy.'
+ />
+ <Checkbox
+ checked={form.keep_signedin}
+ onChange={handleInput}
+ name='keep_signedin'
+ id='keep_signedin'
+ className='mt-4'
+ label={'Don\'t remember me.'}
+ />
+ <div className='pt-1 flex justify-between mt-3'>
+ <Link to={routes.signin} className='underline text-blue-600 hover:text-indigo-800'>
Sign in instead
</Link>
- <button type="submit" className="btn btn-primary ml-auto">
+ <Button type='submit' primary large>
Sign up
- </button>
+ </Button>
</div>
- </Form>
+ </form>
</div>
)
}
\ No newline at end of file
diff --git a/src/pages/Auth/VerifyEmail/index.jsx b/src/pages/Auth/VerifyEmail/index.jsx
index 7d29bdd51..d1e974074 100644
--- a/src/pages/Auth/VerifyEmail/index.jsx
+++ b/src/pages/Auth/VerifyEmail/index.jsx
@@ -3,7 +3,7 @@ import Spinner from 'react-bootstrap/Spinner'
import { useDispatch } from 'react-redux'
import { useParams } from 'react-router-dom'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
const VerifyEmail = () => {
const dispatch = useDispatch()
@@ -14,7 +14,6 @@ const VerifyEmail = () => {
useEffect(() => {
setLoading(true)
const path = window.location.pathname.split('/')[1]
- console.log(path)
dispatch(authActions.emailVerifyAsync(
{ path, id },
diff --git a/src/pages/Dashboard/Dashboard.container.jsx b/src/pages/Dashboard/Dashboard.container.jsx
index 2832d9174..927401a45 100644
--- a/src/pages/Dashboard/Dashboard.container.jsx
+++ b/src/pages/Dashboard/Dashboard.container.jsx
@@ -1,51 +1,10 @@
-import React, { useState, useEffect } from 'react'
-import Spinner from 'react-bootstrap/Spinner'
-import Alert from 'react-bootstrap/Alert'
-
+import { connect } from 'react-redux'
import Dashboard from './Dashboard'
-import { getProjects } from 'api'
-
-export default () => {
- const [projects, setProjects] = useState([])
- const [error, setError] = useState('')
- const [loading, setLoading] = useState(true)
-
- useEffect(() => {
- const fetchProjects = async () => {
- try {
- const fetchedProjects = await getProjects()
- setProjects(fetchedProjects.results)
- } catch (e) {
- setError(e)
- } finally {
- setLoading(false)
- }
- }
-
- fetchProjects()
- }, [])
-
- if (error && !loading) {
- return (
- <div className="container d-flex justify-content-center">
- <Alert variant="danger">
- {error}
- </Alert>
- </div>
- )
- }
- if (!loading) {
- return (
- <Dashboard projects={projects} />
- )
- }
+const mapStateToProps = (state) => ({
+ projects: state.ui.projects.projects,
+ isLoading: state.ui.projects.isLoading,
+ error: state.ui.projects.error,
+})
- return (
- <div className="container d-flex justify-content-center">
- <Spinner animation="border" role="status" variant="primary" className="spinner-lg">
- <span className="sr-only">Loading...</span>
- </Spinner>
- </div>
- )
-}
\ No newline at end of file
+export default connect(mapStateToProps)(Dashboard)
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index 148362dc3..555a90f49 100644
--- a/src/pages/Dashboard/Dashboard.jsx
+++ b/src/pages/Dashboard/Dashboard.jsx
@@ -1,74 +1,123 @@
-import React from 'react'
+import React, { memo } from 'react'
import { Link } from 'react-router-dom'
+import Spinner from 'react-bootstrap/Spinner'
+import Alert from 'react-bootstrap/Alert'
import PropTypes from 'prop-types'
+import _isEmpty from 'lodash/isEmpty'
+import _map from 'lodash/map'
+import { EyeIcon } from '@heroicons/react/outline'
+import { ChartBarIcon } from '@heroicons/react/outline'
+import { CalendarIcon } from '@heroicons/react/outline'
import routes from 'routes'
+const ProjectCart = ({ name, url }) => (
+ <li>
+ <Link to={url} className='block hover:bg-gray-50'>
+ <div className='px-4 py-4 sm:px-6'>
+ <div className='flex items-center justify-between'>
+ <p className='text-base font-medium text-indigo-600 truncate'>
+ {name}
+ </p>
+ <div class="ml-2 flex-shrink-0 flex">
+ <p class="px-2 inline-flex text-sm leading-5 font-semibold rounded-full bg-green-100 text-green-800">
+ Active
+ </p>
+ </div>
+ </div>
+ <div className='mt-2 sm:flex sm:justify-between'>
+ <div className='sm:flex flex-col'>
+ <p className='flex items-center text-sm text-gray-500'>
+ <EyeIcon className='flex-shrink-0 mr-1.5 h-5 w-5 text-gray-400' />
+ Pageviews
+ </p>
+ <p className='mt-2 flex items-center text-sm text-gray-500 sm:mt-0'>
+ <ChartBarIcon className='flex-shrink-0 mr-1.5 h-5 w-5 text-gray-400' />
+ Average load time
+ </p>
+ </div>
+ <div className='mt-2 flex items-center text-sm text-gray-500'>
+ <CalendarIcon className='flex-shrink-0 mr-1.5 h-5 w-5 text-gray-400' />
+ <p>
+ Created at <time datetime='2020-01-07'>January 7, 2020</time>
+ </p>
+ </div>
+ </div>
+ </div>
+ </Link>
+ </li>
+)
+
const NoProjects = () => (
- <div className="mt-5">
- <h3 className="text-center">
+ <div className='mt-5'>
+ <h3 className='text-center'>
You have not yet created any projects
</h3>
- <p className="text-center">
+ <p className='text-center'>
Create a new project here to start using our service
</p>
- <p className="text-center">
- <Link to={routes.new_project} className="btn btn-primary h-100 mt-3">
+ <p className='text-center'>
+ <Link to={routes.new_project} className='btn btn-primary h-100 mt-3'>
Create a project
</Link>
</p>
</div>
)
-const Dashboard = ({ projects }) => {
- // const projects = [{
- // id: 'nfvioqevisvn',
- // name: 'Project #1',
- // }, {
- // id: 'qwifjptirwnd',
- // name: 'Project #2',
- // }, {
- // id: 'zxvnpearinve',
- // name: 'Facebook',
- // }]
-
- return (
- <div className="container">
- <div className="d-flex justify-content-between">
- <h2>Dashboard</h2>
- <Link to={routes.new_project} className="btn btn-outline-primary h-100">
- New project
- </Link>
+const Dashboard = ({ projects, isLoading, error }) => {
+ if (error && !isLoading) {
+ return (
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <Alert variant='danger'>
+ {error}
+ </Alert>
</div>
+ )
+ }
- {
- projects.length > 0
- ? projects.map(({ name, id }) => (
- <div key={id} className="card mt-3">
- <Link
- to={{
- pathname: routes.project.replace(':id', id),
- state: { name, id },
- }}
- className="text-decoration-none text-reset">
- <div className="card-body list-group-item-action text-reset">
- {name}
- </div>
- </Link>
+ if (!isLoading) {
+ return (
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <div className='max-w-7xl w-full mx-auto'>
+ <div className='flex justify-between'>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>Dashboard</h2>
+ <Link to={routes.new_project} className='inline-flex items-center border border-transparent leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 px-4 py-2 text-sm'>
+ New project
+ </Link>
+ </div>
+ {_isEmpty(projects) ? (
+ <NoProjects />
+ ) : (
+ <div className='bg-white shadow overflow-hidden sm:rounded-md mt-10'>
+ <ul className='divide-y divide-gray-200'>
+ {_map(projects, ({ name, id }) => (
+ <ProjectCart key={id} name={name} url={routes.project.replace(':id', id)} />
+ ))}
+ </ul>
</div>
- ))
- : <NoProjects />
- }
+ )}
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <Spinner animation='border' role='status' variant='primary' className='spinner-lg'>
+ <span className='sr-only'>Loading...</span>
+ </Spinner>
</div>
)
}
Dashboard.propTypes = {
- projects: PropTypes.arrayOf(PropTypes.object),
+ projects: PropTypes.arrayOf(PropTypes.object).isRequired,
+ isLoading: PropTypes.bool.isRequired,
+ error: PropTypes.string,
}
Dashboard.defaultProps = {
- projects: [],
+ error: '',
}
-export default Dashboard
\ No newline at end of file
+export default memo(Dashboard)
diff --git a/src/pages/Project/Settings/ProjectSettings.container.jsx b/src/pages/Project/Settings/ProjectSettings.container.jsx
index 5f3c103b4..697e3c583 100644
--- a/src/pages/Project/Settings/ProjectSettings.container.jsx
+++ b/src/pages/Project/Settings/ProjectSettings.container.jsx
@@ -1,10 +1,14 @@
import { connect } from 'react-redux'
-import { alertsActions } from 'actions/alerts'
-import { errorsActions } from 'actions/errors'
+import UIActions from 'redux/actions/ui'
+import { alertsActions } from 'redux/actions/alerts'
+import { errorsActions } from 'redux/actions/errors'
import ProjectSettings from './ProjectSettings'
-// const mapStateToProps = (state) => ({ })
+const mapStateToProps = (state) => ({
+ projects: state.ui.projects.projects,
+ isLoading: state.ui.projects.isLoading,
+})
const mapDispatchToProps = (dispatch) => ({
updateProjectFailed: (message) => {
@@ -22,6 +26,12 @@ const mapDispatchToProps = (dispatch) => ({
deleteProjectFailed: (message) => {
dispatch(errorsActions.deleteProjectFailed(message))
},
+ loadProjects: () => {
+ dispatch(UIActions.loadProjects())
+ },
+ showError: (message) => {
+ dispatch(errorsActions.genericError(message))
+ },
})
-export default connect(null, mapDispatchToProps)(ProjectSettings)
+export default connect(mapStateToProps, mapDispatchToProps)(ProjectSettings)
diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsx
index 54fedcc06..3bd2c45fc 100644
--- a/src/pages/Project/Settings/ProjectSettings.jsx
+++ b/src/pages/Project/Settings/ProjectSettings.jsx
@@ -1,20 +1,24 @@
-import React, { useState, useEffect } from 'react'
-import { useLocation, useHistory, useParams, Link } from 'react-router-dom'
-import Form from 'react-bootstrap/Form'
+import React, { useState, useEffect, useMemo } from 'react'
+import { useLocation, useHistory, useParams } from 'react-router-dom'
import _isEmpty from 'lodash/isEmpty'
import _replace from 'lodash/replace'
+import _find from 'lodash/find'
import PropTypes from 'prop-types'
import { createProject, updateProject, deleteProject } from 'api'
+import Input from 'ui/Input'
+import Button from 'ui/Button'
import { nanoid } from 'utils/random'
import routes from 'routes'
import Modal from 'components/Modal'
const ProjectSettings = ({
updateProjectFailed, createNewProjectFailed, newProject, projectDeleted, deleteProjectFailed,
+ loadProjects, isLoading, projects, showError,
}) => {
const { pathname } = useLocation()
const { id } = useParams()
+ const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects])
const isSettings = !_isEmpty(id) && (_replace(routes.project_settings, ':id', id) === pathname)
const history = useHistory()
const [form, setForm] = useState({
@@ -27,6 +31,17 @@ const ProjectSettings = ({
const [beenSubmitted, setBeenSubmitted] = useState(false)
const [showDelete, setShowDelete] = useState(false)
+ useEffect(() => {
+ if (!isLoading && isSettings) {
+ if (_isEmpty(project)) {
+ showError('The selected project does not exist')
+ history.push(routes.dashboard)
+ } else {
+ setForm(project)
+ }
+ }
+ }, [project, isLoading, isSettings])
+
const onSubmit = async (data) => {
try {
if (isSettings) {
@@ -37,6 +52,7 @@ const ProjectSettings = ({
newProject('The project has been created')
}
+ loadProjects()
history.push(routes.dashboard)
} catch (e) {
if (isSettings) {
@@ -98,73 +114,67 @@ const ProjectSettings = ({
setValidated(valid)
}
+ const onCancel = () => {
+ history.push(isSettings ? _replace(routes.project, ':id', id) : routes.dashboard)
+ }
+
return (
- <div className='container'>
- <h4 className='mb-3'>{isSettings ? `${form.name} settings` : 'Create a new project'}</h4>
- <Form validated={validated} onSubmit={handleSubmit} noValidate>
- <Form.Group className='mb-3 has-validation'>
- <Form.Label htmlFor='name'>Project name</Form.Label>
- <Form.Control
- type='text'
- value={form.name}
- placeholder='My awesome project'
- id='name'
- className='form-control'
- name='name'
- onChange={handleInput}
- isValid={!errors.hasOwnProperty('name')}
- isInvalid={beenSubmitted && errors.hasOwnProperty('name')}
- required
- />
- <Form.Control.Feedback type='invalid'>
- {errors.name}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className='mb-3'>
- <Form.Label htmlFor='id'>Project ID</Form.Label>
- <Form.Control
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ {isSettings ? `${form.name} settings` : 'Create a new project'}
+ </h2>
+ <Input
+ name='name'
+ id='name'
+ type='text'
+ label='Project name'
+ value={form.name}
+ placeholder='My awesome project'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.name}
+ />
+ <Input
+ name='id'
+ id='id'
+ type='text'
+ label='Project ID'
+ value={form.id}
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.id}
+ disabled
+ />
+ {isSettings && (
+ <Input
+ name='origins'
+ id='origins'
type='text'
- value={form.id}
- id='id'
- className='form-control'
- name='id'
+ label='Allowed origins'
+ value={form.origins}
+ className='mt-4'
onChange={handleInput}
- isInvalid={beenSubmitted && errors.hasOwnProperty('id')}
- disabled
- required
+ error={beenSubmitted && errors.origins}
/>
- </Form.Group>
- {isSettings && (
- <Form.Group className='mb-3'>
- <Form.Label htmlFor='origins'>Allowed origins</Form.Label>
- <Form.Control
- type='text'
- value={form.origins}
- id='origins'
- className='form-control'
- name='origins'
- onChange={handleInput}
- />
- </Form.Group>
)}
- <div className='d-flex justify-content-between'>
+ <div className='flex justify-between mt-4'>
<div>
- <Link
- to={isSettings ? _replace(routes.project, ':id', id) : routes.dashboard}
- className='btn btn-outline-secondary'>
+ <Button className='mr-2' onClick={onCancel} secondary regular>
Cancel
- </Link>
- <button type='submit' className='btn btn-primary ml-2'>
+ </Button>
+ <Button type='submit' primary regular>
Save
- </button>
+ </Button>
</div>
{isSettings && (
- <button type='button' onClick={() => setShowDelete(true)} className='btn btn-danger'>
+ <Button onClick={() => setShowDelete(true)} danger large>
Delete project
- </button>
+ </Button>
)}
</div>
- </Form>
+ </form>
+
{showDelete &&
<Modal
onCancel={() => setShowDelete(false)}
@@ -185,6 +195,10 @@ ProjectSettings.propTypes = {
newProject: PropTypes.func.isRequired,
projectDeleted: PropTypes.func.isRequired,
deleteProjectFailed: PropTypes.func.isRequired,
+ loadProjects: PropTypes.func.isRequired,
+ projects: PropTypes.arrayOf(PropTypes.object).isRequired,
+ showError: PropTypes.func.isRequired,
+ isLoading: PropTypes.bool.isRequired,
}
export default ProjectSettings
\ No newline at end of file
diff --git a/src/pages/Project/View/Panels.jsx b/src/pages/Project/View/Panels.jsx
index e7ab214e6..d1f8d953a 100644
--- a/src/pages/Project/View/Panels.jsx
+++ b/src/pages/Project/View/Panels.jsx
@@ -1,6 +1,4 @@
import React, { memo, useState, useMemo, Fragment } from 'react'
-import Card from 'react-bootstrap/Card'
-import ProgressBar from 'react-bootstrap/ProgressBar'
import cx from 'classnames'
import _keys from 'lodash/keys'
import _map from 'lodash/map'
@@ -11,6 +9,8 @@ import _floor from 'lodash/floor'
import _size from 'lodash/size'
import _slice from 'lodash/slice'
+import Progress from 'ui/Progress'
+
const ENTRIES_PER_PANEL = 5
const Panel = ({ name, data }) => {
@@ -36,55 +36,55 @@ const Panel = ({ name, data }) => {
}
return (
- <Card style={{ height: '300px' }} className='w31-5 m-3 shadow-sm'>
- <Card.Body>
- <Card.Title>{name}</Card.Title>
- <Card.Text>
- {_isEmpty(data) ? (
- <p>There's currently no data for this parameter</p>
- ) : _map(keysToDisplay, key => {
- const perc = _round(data[key] / total * 100, 2)
-
- return (
- <Fragment key={key}>
- <div className='d-flex justify-content-between'>
- <span className='label'>{key}</span>
- <span className='ml-3'>
- {data[key]}&nbsp;
- <span className='text-secondary font-weight-light'>({perc}%)</span>
- </span>
- </div>
- <ProgressBar now={perc} />
- </Fragment>
- )
- })}
- {_size(keys) > 5 && (
- <div className='d-flex justify-content-between position-absolute fixed-bottom user-select-none pl-3 pr-3 mb-2'>
- <span
- className={cx('text-secondary font-weight-light', {
- hoverable: canGoPrev(),
- disabled: !canGoPrev(),
- })}
- role='button'
- onClick={onPrevious}
- >
- &lt; Previous
- </span>
- <span
- className={cx('text-secondary font-weight-light', {
- hoverable: canGoNext(),
- disabled: !canGoNext(),
- })}
- role='button'
- onClick={onNext}
- >
- Next &gt;
- </span>
- </div>
- )}
- </Card.Text>
- </Card.Body>
- </Card>
+ <div className='relative bg-white pt-5 px-4 pb-12 h-72 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden'>
+ <h3 className='text-lg leading-6 font-semibold mb-2 text-gray-900'>{name}</h3>
+ <div className='flex flex-col h-full'>
+ {_isEmpty(data) ? (
+ <p className="mt-1 text-base text-gray-700">There's currently no data for this parameter</p>
+ ) : _map(keysToDisplay, key => {
+ const perc = _round(data[key] / total * 100, 2)
+
+ return (
+ <Fragment key={key}>
+ <div className='flex justify-between mt-1'>
+ <span className='label'>{key}</span>
+ <span className='ml-3'>
+ {data[key]}&nbsp;
+ <span className='text-gray-500 font-light'>({perc}%)</span>
+ </span>
+ </div>
+ <Progress now={perc} />
+ </Fragment>
+ )
+ })}
+ {_size(keys) > 5 && (
+ <div className="absolute bottom-0 w-card-toggle">
+ <div className='flex justify-between select-none mb-2'>
+ <span
+ className={cx('text-gray-500 font-light', {
+ hoverable: canGoPrev(),
+ disabled: !canGoPrev(),
+ })}
+ role='button'
+ onClick={onPrevious}
+ >
+ &lt; Previous
+ </span>
+ <span
+ className={cx('text-gray-500 font-light', {
+ hoverable: canGoNext(),
+ disabled: !canGoNext(),
+ })}
+ role='button'
+ onClick={onNext}
+ >
+ Next &gt;
+ </span>
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
)
}
diff --git a/src/pages/Project/View/ViewProject.container.jsx b/src/pages/Project/View/ViewProject.container.jsx
index 533df0fb7..33443d213 100644
--- a/src/pages/Project/View/ViewProject.container.jsx
+++ b/src/pages/Project/View/ViewProject.container.jsx
@@ -1,5 +1,16 @@
+import { connect } from 'react-redux'
+import { errorsActions } from 'redux/actions/errors'
import ViewProject from './ViewProject'
-// TODO: Redux connect
+const mapStateToProps = (state) => ({
+ projects: state.ui.projects.projects,
+ isLoading: state.ui.projects.isLoading,
+})
-export default ViewProject
+const mapDispatchToProps = (dispatch) => ({
+ showError: (message) => {
+ dispatch(errorsActions.genericError(message))
+ },
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(ViewProject)
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 355111239..ec7d36fc0 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -1,9 +1,8 @@
-import React, { useState, useEffect, memo } from 'react'
-import { Link } from 'react-router-dom'
+import React, { useState, useEffect, useMemo, memo } from 'react'
+import { useHistory, useParams } from 'react-router-dom'
import bb, { area, zoom } from 'billboard.js'
import * as d3 from 'd3'
import dayjs from 'dayjs'
-import { useLocation } from 'react-router-dom'
import _keys from 'lodash/keys'
import _map from 'lodash/map'
import _reduce from 'lodash/reduce'
@@ -11,9 +10,13 @@ import _size from 'lodash/size'
import _isNull from 'lodash/isNull'
import _isEmpty from 'lodash/isEmpty'
import _replace from 'lodash/replace'
-import Spinner from 'react-bootstrap/Spinner'
-// import PropTypes from 'prop-types'
+import _find from 'lodash/find'
+import PropTypes from 'prop-types'
+import { tbPeriodPairs } from 'redux/constants'
+import Button from 'ui/Button'
+import Loader from 'ui/Loader'
+import Dropdown from 'ui/Dropdown'
import { Panel } from './Panels'
import routes from 'routes'
import { getProjectData } from 'api'
@@ -30,28 +33,48 @@ const typeNameMapping = {
lt: 'Load time',
}
-const ViewProject = () => {
- const location = useLocation()
- const { name, id } = location.state || {}
+const NoEvents = () => (
+ <div className='flex flex-col py-6 sm:px-6 lg:px-8 mt-5'>
+ <div className='max-w-7xl w-full mx-auto'>
+ <h2 className='text-4xl text-center leading-tight my-3'>No events yet</h2>
+ <h2 className='text-2xl mb-8 text-center leading-snug'>No events have been captured yet.</h2>
+ {/* todo: detailed description on how to create event, code example; link to docs & cdn / npm library */}
+ </div>
+ </div>
+)
+
+const ViewProject = ({
+ projects, isLoading, showError,
+}) => {
+ const { id } = useParams()
+ const history = useHistory()
+ const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects])
const [panelsData, setPanelsData] = useState({})
+ const [analyticsLoading, setAnalyticsLoading] = useState(true)
+ const [period, setPeriod] = useState(tbPeriodPairs[1].period)
+ const [timeBucket, setTimebucket] = useState(tbPeriodPairs[1].tbs[1])
+ const periodLabel = useMemo(() => _find(tbPeriodPairs, p => p.period === period).label, [period])
// const [bbChart, setBbChart] = useState([])
- useEffect(() => {
- (async function() {
- try {
- const data = await getProjectData(id)
+ const { name } = project
+ const loadAnalytics = async () => {
+ if (!isLoading && !_isEmpty(project)) {
+ try {
+ const data = await getProjectData(id, timeBucket, period)
+
if (_isEmpty(data)) {
+ setAnalyticsLoading(false)
return
}
-
+
const { chart, params } = data
-
+
setPanelsData({
types: _keys(params),
data: params,
})
-
+
const bbSettings = {
data: {
x: 'x',
@@ -87,56 +110,77 @@ const ViewProject = () => {
},
bindto: '#dataChart',
}
-
+
bb.generate(bbSettings)
+ setAnalyticsLoading(false)
} catch (e) {
console.error(e)
}
- })()
- }, [])
-
- const onSubmit = () => {
- // TODO
+ }
+ }
+
+ useEffect(() => {
+ loadAnalytics()
+ }, [project, period])
+
+ if (!isLoading && _isEmpty(project)) {
+ showError('The selected project does not exist')
+ history.push(routes.dashboard)
}
- if (id && name) {
+ const openSettingsHandler = () => {
+ history.push(_replace(routes.project_settings, ':id', id))
+ }
+
+ if (!isLoading) {
return (
- <div className='container-fluid'>
- <div className='d-flex justify-content-between'>
- <h2>{name}</h2>
- <Link
- to={{
- pathname: _replace(routes.project_settings, ':id', id),
- state: {
- project: { name, id },
- },
- }}
- className='btn btn-outline-primary h-100'>
- Settings
- </Link>
- </div>
- <div className='d-flex flex-wrap'>
- <div id='dataChart' />
- {_map(panelsData.types, type => (
- <Panel key={type} name={typeNameMapping[type]} data={panelsData.data[type]} />
- ))}
+ <div className='min-h-page bg-gray-50 py-6 sm:px-6 lg:px-8'>
+ <div className='flex justify-between h-10 mb-10'>
+ <h2 className='text-3xl font-extrabold text-gray-900'>{name}</h2>
+ <div className='flex'>
+ <Dropdown
+ items={tbPeriodPairs}
+ title={periodLabel}
+ labelExtractor={pair => pair.label}
+ keyExtractor={pair => pair.label}
+ onSelect={pair => setPeriod(pair.period)}
+ />
+ <div className='h-full ml-3'>
+ <Button onClick={openSettingsHandler} className='py-2.5' secondary large>
+ Settings
+ </Button>
+ </div>
+ </div>
</div>
+ {_isEmpty(panelsData) ? (
+ analyticsLoading ? (
+ <Loader />
+ ) : (
+ <NoEvents />
+ )
+ ) : (
+ <div>
+ <div id='dataChart' className='h4' />
+ <div className='mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3'>
+ {_map(panelsData.types, type => (
+ <Panel key={type} name={typeNameMapping[type]} data={panelsData.data[type]} />
+ ))}
+ </div>
+ </div>
+ )}
</div>
)
}
return (
- <div className='container d-flex justify-content-center'>
- <Spinner animation='border' role='status' variant='primary' className='spinner-lg'>
- <span className='sr-only'>Loading...</span>
- </Spinner>
- </div>
+ <Loader />
)
}
-// ViewProject.propTypes = {
- // id: PropTypes.string.isRequired,
- // name: PropTypes.string.isRequired,
-// }
+ViewProject.propTypes = {
+ projects: PropTypes.arrayOf(PropTypes.object).isRequired,
+ showError: PropTypes.func.isRequired,
+ isLoading: PropTypes.bool.isRequired,
+}
-export default memo(ViewProject)
\ No newline at end of file
+export default memo(ViewProject)
diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsx
index b7aa62ebc..efffa4bf4 100644
--- a/src/pages/UserSettings/UserSettings.container.jsx
+++ b/src/pages/UserSettings/UserSettings.container.jsx
@@ -1,9 +1,9 @@
import React from 'react'
import { useDispatch } from 'react-redux'
-import { authActions } from 'actions/auth'
-import { errorsActions } from 'actions/errors'
-import { alertsActions } from 'actions/alerts'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+import { alertsActions } from 'redux/actions/alerts'
import { getCookie, setCookie } from 'utils/cookie'
import { confirmEmail, exportUserData } from 'api'
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index 6de84b343..089d05e59 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -1,8 +1,9 @@
import React, { useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
-import Form from 'react-bootstrap/Form'
-import { Mailbox } from 'react-bootstrap-icons'
+import { MailIcon } from '@heroicons/react/outline'
+import Input from 'ui/Input'
+import Button from 'ui/Button'
import Modal from 'components/Modal'
import { isValidEmail, isValidPassword } from 'utils/validator'
@@ -67,97 +68,82 @@ const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
}
return (
- <div className="container">
- <h2>Profile settings</h2>
-
- <Form onSubmit={handleSubmit} noValidate>
- <Form.Group className="mb-3 has-validation">
- <Form.Label htmlFor="email">Email</Form.Label>
- <Form.Control
- type="email"
- value={form.email}
- placeholder="[email protected]"
- id="email"
- className="form-control"
- name="email"
+ <div className='min-h-page bg-gray-50 flex flex-col py-6 sm:px-6 lg:px-8'>
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-extrabold text-gray-900'>
+ Profile settings
+ </h2>
+ <Input
+ name='email'
+ id='email'
+ type='email'
+ label='Email'
+ value={form.email}
+ placeholder='[email protected]'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted && errors.email}
+ />
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6 mt-4'>
+ <Input
+ name='password'
+ id='password'
+ type='password'
+ label='Password'
+ hint='Longer than 8 chars'
+ value={form.password}
+ placeholder='Password'
+ className='sm:col-span-3'
+ onChange={handleInput}
+ error={beenSubmitted && errors.password}
+ />
+ <Input
+ name='repeat'
+ id='repeat'
+ type='password'
+ label='Repeat password'
+ value={form.repeat}
+ placeholder='Repeat password'
+ className='sm:col-span-3'
onChange={handleInput}
- isInvalid={beenSubmitted && errors.hasOwnProperty('email')}
- required
+ error={beenSubmitted && errors.repeat}
/>
- <Form.Control.Feedback type="invalid">
- {errors.email}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Row>
- <Form.Group className="col-md-6 mb-3">
- <Form.Label htmlFor="password">Password</Form.Label>
- <Form.Control
- type="password"
- value={form.password}
- placeholder="Password"
- id="password"
- className="form-control"
- name="password"
- onChange={handleInput}
- isInvalid={beenSubmitted && errors.hasOwnProperty('password')}
- />
- <Form.Control.Feedback type="invalid">
- {errors.password}
- </Form.Control.Feedback>
- </Form.Group>
- <Form.Group className="col-md-6 mb-3">
- <Form.Label htmlFor="repeat">Repeat password</Form.Label>
- <Form.Control
- type="password"
- value={form.repeat}
- placeholder="Repeat password"
- id="repeat"
- className="form-control"
- name="repeat"
- onChange={handleInput}
- isInvalid={beenSubmitted && errors.hasOwnProperty('repeat')}
- />
- <Form.Control.Feedback type="invalid">
- {errors.repeat}
- </Form.Control.Feedback>
- </Form.Group>
- </Form.Row>
- <button type="submit" className="btn btn-primary ml-auto">
+ </div>
+ <Button className='mt-4' type='submit' primary large>
Update profile
- </button>
- </Form>
-
- {user?.isActive || (
- <div className="mt-4">
- <button className="btn btn-link pl-0" onClick={() => onEmailConfirm(setError)}>
- <Mailbox color="#007bff" size="24" className="mr-2" />
- Didn't receive a link to confirm the email address? Request a new one!
- </button>
+ </Button>
+ {!user?.isActive && (
+ <div href='#' className='flex cursor-pointer mt-4 pl-0 underline text-blue-600 hover:text-indigo-800' onClick={() => onEmailConfirm(setError)}>
+ <MailIcon className='mt-0.5 mr-2 w-6 h-6 text-blue-500' />
+ Didn't receive a link to confirm the email address? Request a new one!
+ </div>
+ )}
+ <div className='flex justify-between mt-4'>
+ <Button
+ onClick={() => setShowExportModal(true)}
+ regular
+ primary
+ >
+ Request data export
+ </Button>
+ <Button
+ className='ml-3'
+ onClick={() => setShowModal(true)}
+ regular
+ danger
+ >
+ Delete account
+ </Button>
</div>
- )}
-
- <div className="mt-4">
- <button
- className="btn btn-outline-primary"
- onClick={() => setShowExportModal(true)}
- >
- Request data export
- </button>
- <button
- className="btn btn-danger ml-3"
- onClick={() => setShowModal(true)}
- >
- Delete account
- </button>
- </div>
+ </form>
{showExportModal && (
<Modal
onCancel={() => setShowExportModal(false)}
onSubmit={() => { setShowExportModal(false); onExport() }}
- submitText="Continue"
- cancelText="Close"
- title="Data export"
+ submitText='Continue'
+ cancelText='Close'
+ title='Data export'
text={'As requested by Art. 20 of General Data Protection Regulation (GDPR) the you have the right to receive your personal data that we store.\nThe data export will be ready within 24 hours and sent to your email account.\nNote: you can request the data export only once per two weeks.'}
/>
)}
@@ -165,9 +151,9 @@ const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
<Modal
onCancel={() => setShowModal(false)}
onSubmit={() => { setShowModal(false); onDelete() }}
- submitText="Delete my account"
- cancelText="Close"
- title="Delete your account?"
+ submitText='Delete my account'
+ cancelText='Close'
+ title='Delete your account?'
text={'By pressing \'Delete my account\' you understand, that this action is irreversible.\nAll your data will be deleted from our servers.'}
/>
)}
@@ -175,8 +161,8 @@ const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
<Modal
onSubmit={() => { setError('') }}
onCancel={() => { setError('') }}
- submitText="Got it"
- title="Error"
+ submitText='Got it'
+ title='Error'
text={error}
/>
)}
diff --git a/src/actions/alerts/index.js b/src/redux/actions/alerts/index.js
similarity index 100%
rename from src/actions/alerts/index.js
rename to src/redux/actions/alerts/index.js
diff --git a/src/actions/alerts/types.js b/src/redux/actions/alerts/types.js
similarity index 100%
rename from src/actions/alerts/types.js
rename to src/redux/actions/alerts/types.js
diff --git a/src/actions/auth/index.js b/src/redux/actions/auth/index.js
similarity index 100%
rename from src/actions/auth/index.js
rename to src/redux/actions/auth/index.js
diff --git a/src/actions/auth/types.js b/src/redux/actions/auth/types.js
similarity index 100%
rename from src/actions/auth/types.js
rename to src/redux/actions/auth/types.js
diff --git a/src/actions/errors/index.js b/src/redux/actions/errors/index.js
similarity index 92%
rename from src/actions/errors/index.js
rename to src/redux/actions/errors/index.js
index 0985cd6f4..2d2ad2bb5 100644
--- a/src/actions/errors/index.js
+++ b/src/redux/actions/errors/index.js
@@ -65,6 +65,13 @@ export const errorsActions = {
}
},
+ genericError(error) {
+ return {
+ type: types.GENERIC_ERROR,
+ payload: { error },
+ }
+ },
+
clearErrors() {
return {
type: types.CLEAR_ERRORS,
diff --git a/src/actions/errors/types.js b/src/redux/actions/errors/types.js
similarity index 93%
rename from src/actions/errors/types.js
rename to src/redux/actions/errors/types.js
index 1f974238b..61418b6e1 100644
--- a/src/actions/errors/types.js
+++ b/src/redux/actions/errors/types.js
@@ -11,6 +11,8 @@ export const types = {
UPDATE_PROJECT_FAILED: 'UPDATE_PROJECT_FAILED',
DELETE_PROJECT_FAILED: 'DELETE_PROJECT_FAILED',
+ GENERIC_ERROR: 'GENERIC_ERROR',
+
// Common
CLEAR_ERRORS: 'CLEAR_ERRORS',
}
diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.js
new file mode 100644
index 000000000..ef10123f2
--- /dev/null
+++ b/src/redux/actions/ui/index.js
@@ -0,0 +1,33 @@
+import { types } from './types'
+
+const loadProjects = () => ({
+ type: types.LOAD_PROJECTS,
+})
+
+const setProjects = (projects) => ({
+ type: types.SET_PROJECTS,
+ payload: {
+ projects,
+ }
+})
+
+const setProjectsError = (error) => ({
+ type: types.SET_PROJECTS_ERROR,
+ payload: {
+ error,
+ }
+})
+
+const setProjectsLoading = (isLoading) => ({
+ type: types.SET_PROJECTS_LOADING,
+ payload: {
+ isLoading,
+ }
+})
+
+export default {
+ loadProjects,
+ setProjects,
+ setProjectsError,
+ setProjectsLoading,
+}
diff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.js
new file mode 100644
index 000000000..6f9da68fc
--- /dev/null
+++ b/src/redux/actions/ui/types.js
@@ -0,0 +1,9 @@
+export const types = {
+ // Sync
+ LOAD_PROJECTS: 'LOAD_PROJECTS',
+ SET_PROJECTS_ERROR: 'SET_PROJECTS_ERROR',
+ SET_PROJECTS_LOADING: 'SET_PROJECTS_LOADING',
+
+ // Async
+ SET_PROJECTS: 'SET_PROJECTS',
+}
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
new file mode 100644
index 000000000..64efac364
--- /dev/null
+++ b/src/redux/constants/index.js
@@ -0,0 +1,33 @@
+export const tbPeriodPairs = [{
+ label: 'Today',
+ period: '1d',
+ tbs: ['hour'],
+ access: 'free',
+}, {
+ label: 'Last 7 days',
+ period: '7d',
+ tbs: ['hour', 'day'],
+ access: 'free',
+}, {
+ label: 'Last 4 weeks',
+ period: '4w',
+ tbs: ['day', 'week'],
+ access: 'free',
+}, {
+ label: 'Last 3 months',
+ period: '3m',
+ tbs: ['week', 'month'],
+ access: 'paid',
+}, {
+ label: 'Last 12 months',
+ period: '12m',
+ tbs: ['week', 'month'],
+ access: 'paid',
+}, {
+ label: 'Last 24 months',
+ period: '12m',
+ tbs: ['month'],
+ access: 'paid',
+}]
+
+export const TOKEN = 'access_token'
diff --git a/src/reducers/alerts.js b/src/redux/reducers/alerts.js
similarity index 90%
rename from src/reducers/alerts.js
rename to src/redux/reducers/alerts.js
index 6ff55383e..b797a002c 100644
--- a/src/reducers/alerts.js
+++ b/src/redux/reducers/alerts.js
@@ -1,4 +1,4 @@
-import { types } from 'actions/alerts/types'
+import { types } from 'redux/actions/alerts/types'
const initialState = {
message: null,
diff --git a/src/reducers/auth.js b/src/redux/reducers/auth.js
similarity index 94%
rename from src/reducers/auth.js
rename to src/redux/reducers/auth.js
index 343f624ac..dd488ff9c 100644
--- a/src/reducers/auth.js
+++ b/src/redux/reducers/auth.js
@@ -1,4 +1,4 @@
-import { types } from 'actions/auth/types'
+import { types } from 'redux/actions/auth/types'
const initialState = {
redirectPath: null,
diff --git a/src/reducers/errors.js b/src/redux/reducers/errors.js
similarity index 87%
rename from src/reducers/errors.js
rename to src/redux/reducers/errors.js
index ea8212485..97caa4613 100644
--- a/src/reducers/errors.js
+++ b/src/redux/reducers/errors.js
@@ -1,4 +1,4 @@
-import { types } from 'actions/errors/types'
+import { types } from 'redux/actions/errors/types'
const initialState = {
error: null
@@ -6,6 +6,7 @@ const initialState = {
export default (state = initialState, { type, payload }) => {
switch (type) {
+ case types.GENERIC_ERROR:
case types.LOGIN_FAILED:
case types.SIGN_UP_FAILED:
case types.UPDATE_USER_PROFILE_FAILED:
diff --git a/src/reducers/index.js b/src/redux/reducers/index.js
similarity index 60%
rename from src/reducers/index.js
rename to src/redux/reducers/index.js
index bb1bead0a..dd4e6b276 100644
--- a/src/reducers/index.js
+++ b/src/redux/reducers/index.js
@@ -2,5 +2,6 @@ import { combineReducers } from 'redux'
import auth from './auth'
import errors from './errors'
import alerts from './alerts'
+import ui from './ui'
-export default combineReducers({ auth, errors, alerts })
\ No newline at end of file
+export default combineReducers({ auth, errors, alerts, ui })
\ No newline at end of file
diff --git a/src/redux/reducers/ui/index.js b/src/redux/reducers/ui/index.js
new file mode 100644
index 000000000..e6c4a9794
--- /dev/null
+++ b/src/redux/reducers/ui/index.js
@@ -0,0 +1,4 @@
+import { combineReducers } from 'redux'
+import projects from './projects'
+
+export default combineReducers({ projects })
diff --git a/src/redux/reducers/ui/projects.js b/src/redux/reducers/ui/projects.js
new file mode 100644
index 000000000..0469dd0c7
--- /dev/null
+++ b/src/redux/reducers/ui/projects.js
@@ -0,0 +1,41 @@
+import { types } from 'redux/actions/ui/types'
+
+const getInitialState = () => {
+ return {
+ projects: [],
+ isLoading: true,
+ error: null,
+ }
+}
+
+export default (state = getInitialState(), { type, payload }) => {
+ switch (type) {
+ case types.SET_PROJECTS: {
+ const { projects } = payload
+ return {
+ ...state,
+ projects,
+ isLoading: false,
+ }
+ }
+
+ case types.SET_PROJECTS_ERROR: {
+ const { error } = payload
+ return {
+ ...state,
+ error,
+ }
+ }
+
+ case types.SET_PROJECTS_LOADING: {
+ const { isLoading } = payload
+ return {
+ ...state,
+ isLoading,
+ }
+ }
+
+ default:
+ return state
+ }
+}
diff --git a/src/sagas/auth/watchers/index.js b/src/redux/sagas/auth/watchers/index.js
similarity index 65%
rename from src/sagas/auth/watchers/index.js
rename to src/redux/sagas/auth/watchers/index.js
index 6185d252a..e1c51b375 100644
--- a/src/sagas/auth/watchers/index.js
+++ b/src/redux/sagas/auth/watchers/index.js
@@ -1,10 +1,10 @@
import { takeLatest, all, call } from 'redux-saga/effects'
-import { types } from 'actions/auth/types'
-import signIn from 'sagas/auth/workers/signin'
-import signUp from 'sagas/auth/workers/signup'
-import verifyEmail from 'sagas/auth/workers/verifyEmail'
-import updateUserProfile from 'sagas/auth/workers/updateUserProfile'
-import deleteUserAccount from "sagas/auth/workers/deleteUserAccount"
+import { types } from 'redux/actions/auth/types'
+import signIn from 'redux/sagas/auth/workers/signin'
+import signUp from 'redux/sagas/auth/workers/signup'
+import verifyEmail from 'redux/sagas/auth/workers/verifyEmail'
+import updateUserProfile from 'redux/sagas/auth/workers/updateUserProfile'
+import deleteUserAccount from 'redux/sagas/auth/workers/deleteUserAccount'
function* watchLogin() {
yield takeLatest(types.LOGIN_ASYNC, signIn)
diff --git a/src/sagas/auth/workers/deleteUserAccount.js b/src/redux/sagas/auth/workers/deleteUserAccount.js
similarity index 87%
rename from src/sagas/auth/workers/deleteUserAccount.js
rename to src/redux/sagas/auth/workers/deleteUserAccount.js
index 03ab6f6b5..700bc9087 100644
--- a/src/sagas/auth/workers/deleteUserAccount.js
+++ b/src/redux/sagas/auth/workers/deleteUserAccount.js
@@ -1,5 +1,5 @@
import { call, put } from 'redux-saga/effects'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
import { deleteUser } from 'api'
export default function* ({ payload: { errorCallback } }) {
diff --git a/src/sagas/auth/workers/signin.js b/src/redux/sagas/auth/workers/signin.js
similarity index 62%
rename from src/sagas/auth/workers/signin.js
rename to src/redux/sagas/auth/workers/signin.js
index 989437f96..5d7a05b75 100644
--- a/src/sagas/auth/workers/signin.js
+++ b/src/redux/sagas/auth/workers/signin.js
@@ -1,6 +1,8 @@
import { call, put } from 'redux-saga/effects'
-import { authActions } from 'actions/auth'
-import { errorsActions } from 'actions/errors'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+
+import UIActions from 'redux/actions/ui'
import { setAccessToken } from 'utils/accessToken'
import { login } from 'api'
@@ -9,8 +11,10 @@ export default function* ({ payload: { credentials } }) {
const response = yield call(login, credentials)
yield put(authActions.loginSuccess(response.user))
- yield call(setAccessToken, JSON.stringify(response.access_token))
+ yield call(setAccessToken, response.access_token)
+ yield put(UIActions.loadProjects())
} catch (error) {
+ console.error(error)
yield put(errorsActions.loginFailed(error.message))
} finally {
yield put(authActions.finishLoading())
diff --git a/src/sagas/auth/workers/signup.js b/src/redux/sagas/auth/workers/signup.js
similarity index 56%
rename from src/sagas/auth/workers/signup.js
rename to src/redux/sagas/auth/workers/signup.js
index e578d74cd..53fbd199c 100644
--- a/src/sagas/auth/workers/signup.js
+++ b/src/redux/sagas/auth/workers/signup.js
@@ -1,7 +1,9 @@
-import { call, put } from 'redux-saga/effects'
-import { authActions } from 'actions/auth'
-import { errorsActions } from 'actions/errors'
-import { setAccessToken } from "utils/accessToken"
+import { call, put } from 'redux-saga/effects'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+
+import UIActions from 'redux/actions/ui'
+import { setAccessToken } from 'utils/accessToken'
import { signup } from 'api'
export default function* ({ payload: { data, resetRecaptcha = () => {} } }) {
@@ -9,7 +11,8 @@ export default function* ({ payload: { data, resetRecaptcha = () => {} } }) {
const response = yield call(signup, data)
yield put(authActions.signupSuccess(response.user))
- yield call(setAccessToken, JSON.stringify(response.access_token))
+ yield call(setAccessToken, response.access_token)
+ yield put(UIActions.loadProjects())
} catch (error) {
yield put(errorsActions.signupFailed(error.message || (typeof error === 'string' ? error : error[0])))
resetRecaptcha()
diff --git a/src/sagas/auth/workers/updateUserProfile.js b/src/redux/sagas/auth/workers/updateUserProfile.js
similarity index 82%
rename from src/sagas/auth/workers/updateUserProfile.js
rename to src/redux/sagas/auth/workers/updateUserProfile.js
index 63bcee767..95888acf5 100644
--- a/src/sagas/auth/workers/updateUserProfile.js
+++ b/src/redux/sagas/auth/workers/updateUserProfile.js
@@ -1,6 +1,6 @@
import { call, put } from 'redux-saga/effects'
-import { authActions } from 'actions/auth'
-import { errorsActions } from 'actions/errors'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
import { changeUserDetails } from 'api'
export default function* ({ payload: { data, successfulCallback } }) {
diff --git a/src/sagas/auth/workers/verifyEmail.js b/src/redux/sagas/auth/workers/verifyEmail.js
similarity index 88%
rename from src/sagas/auth/workers/verifyEmail.js
rename to src/redux/sagas/auth/workers/verifyEmail.js
index 3d484ea1e..71950dede 100644
--- a/src/sagas/auth/workers/verifyEmail.js
+++ b/src/redux/sagas/auth/workers/verifyEmail.js
@@ -1,5 +1,5 @@
import { call, put } from 'redux-saga/effects'
-import { authActions } from 'actions/auth'
+import { authActions } from 'redux/actions/auth'
import { verifyEmail } from "api"
export default function* ({ payload: { data, successfulCallback, errorCallback } }) {
diff --git a/src/redux/sagas/index.js b/src/redux/sagas/index.js
new file mode 100644
index 000000000..14d55e0a2
--- /dev/null
+++ b/src/redux/sagas/index.js
@@ -0,0 +1,8 @@
+import { fork } from 'redux-saga/effects'
+import watchAuth from './auth/watchers'
+import uiSaga from './ui'
+
+export default function* rootSaga() {
+ yield fork(watchAuth)
+ yield fork(uiSaga)
+}
\ No newline at end of file
diff --git a/src/redux/sagas/ui/index.js b/src/redux/sagas/ui/index.js
new file mode 100644
index 000000000..335aa2820
--- /dev/null
+++ b/src/redux/sagas/ui/index.js
@@ -0,0 +1,10 @@
+import { takeEvery, fork } from 'redux-saga/effects'
+import { types } from '../../actions/ui/types'
+
+import loadProjects from './load_projects'
+import initialise from './initialise'
+
+export default function* () {
+ yield fork(initialise)
+ yield takeEvery(types.LOAD_PROJECTS, loadProjects)
+}
diff --git a/src/redux/sagas/ui/initialise.js b/src/redux/sagas/ui/initialise.js
new file mode 100644
index 000000000..fb912b67e
--- /dev/null
+++ b/src/redux/sagas/ui/initialise.js
@@ -0,0 +1,19 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import { getAccessToken } from 'utils/accessToken'
+import UIActions from 'redux/actions/ui'
+
+const debug = Debug('analytics:rx:s:initialise')
+
+export default function* () {
+ try {
+ const token = yield call(getAccessToken)
+
+ if (token) {
+ yield put(UIActions.loadProjects())
+ }
+ } catch (e) {
+ debug('An error occured whilst initialising: %s', e)
+ }
+}
diff --git a/src/redux/sagas/ui/load_projects.js b/src/redux/sagas/ui/load_projects.js
new file mode 100644
index 000000000..00903a0dd
--- /dev/null
+++ b/src/redux/sagas/ui/load_projects.js
@@ -0,0 +1,18 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import { getProjects } from '../../../api'
+import UIActions from 'redux/actions/ui'
+
+const debug = Debug('analytics:rx:s:load-projects')
+
+export default function* () {
+ try {
+ const { results } = yield call(getProjects)
+ yield put(UIActions.setProjects(results))
+ } catch (e) {
+ const { message } = e
+ yield put(UIActions.setProjectsError(message))
+ debug('failed to load projects: %s', message)
+ }
+}
diff --git a/src/store/index.js b/src/redux/store/index.js
similarity index 76%
rename from src/store/index.js
rename to src/redux/store/index.js
index d37d031cc..687ba2ebb 100644
--- a/src/store/index.js
+++ b/src/redux/store/index.js
@@ -1,7 +1,7 @@
import { createStore, applyMiddleware, compose } from 'redux'
import createSagaMiddleware from 'redux-saga'
-import root_reducer from 'reducers'
-import root_saga from 'sagas'
+import root_reducer from 'redux/reducers'
+import root_saga from 'redux/sagas'
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const sagaMiddleware = createSagaMiddleware()
diff --git a/src/sagas/index.js b/src/sagas/index.js
deleted file mode 100644
index a703d4542..000000000
--- a/src/sagas/index.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import { all, call } from 'redux-saga/effects'
-import watchAuth from 'sagas/auth/watchers'
-
-export default function* rootSaga() {
- yield all([call(watchAuth)])
-}
diff --git a/src/ui/Button.jsx b/src/ui/Button.jsx
new file mode 100644
index 000000000..cd704e2dc
--- /dev/null
+++ b/src/ui/Button.jsx
@@ -0,0 +1,53 @@
+import React, { memo } from 'react'
+import cx from 'classnames'
+import PropTypes from 'prop-types'
+
+const Button = ({
+ text, children, primary, secondary, danger, onClick, white, small, regular, large, giant, type, className,
+}) => (
+ <button type={type} onClick={onClick} className={cx('inline-flex items-center border border-transparent leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500', {
+ 'shadow-sm text-white bg-indigo-600 hover:bg-indigo-700': primary,
+ 'text-indigo-700 bg-indigo-100 hover:bg-indigo-200': secondary,
+ 'text-gray-700 bg-white hover:bg-gray-50': white,
+ 'text-white bg-red-500 hover:bg-red-600': danger,
+ 'px-2.5 py-1.5 text-xs': small,
+ 'px-4 py-2 text-sm': large,
+ 'px-6 py-3 text-base': giant,
+ 'px-3 py-2 text-sm': regular,
+ }, className)}>
+ {text || children}
+ </button>
+)
+
+Button.propTypes = {
+ text: PropTypes.string,
+ children: PropTypes.node,
+ onClick: PropTypes.func,
+ primary: PropTypes.bool,
+ secondary: PropTypes.bool,
+ white: PropTypes.bool,
+ danger: PropTypes.bool,
+ small: PropTypes.bool,
+ regular: PropTypes.bool,
+ large: PropTypes.bool,
+ giant: PropTypes.bool,
+ type: PropTypes.string,
+ className: PropTypes.string,
+}
+
+Button.defaultProps = {
+ text: null,
+ onClick: () => { },
+ primary: false,
+ secondary: false,
+ white: false,
+ small: false,
+ regular: false,
+ large: false,
+ danger: false,
+ giant: false,
+ type: 'button',
+ className: '',
+}
+
+export default memo(Button)
diff --git a/src/ui/Checkbox.jsx b/src/ui/Checkbox.jsx
new file mode 100644
index 000000000..ea1114b8f
--- /dev/null
+++ b/src/ui/Checkbox.jsx
@@ -0,0 +1,54 @@
+import React, { memo } from 'react'
+import cx from 'classnames'
+import PropTypes from 'prop-types'
+
+const Checkbox = ({
+ label, hint, id, name, className, onChange, checked,
+}) => {
+ const identifier = id || name
+
+ return (
+ <div className={cx('relative flex items-start', className)}>
+ <div className='flex items-center h-5'>
+ <input
+ id={identifier}
+ aria-describedby={`${identifier}-description`}
+ name={name}
+ type='checkbox'
+ checked={checked}
+ onChange={onChange}
+ className='focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded'
+ />
+ </div>
+ <div className='ml-3 text-sm'>
+ <label for={identifier} className='font-medium text-gray-700'>{label}</label>
+ {hint && (
+ <p id={`${identifier}-description`} className='text-gray-500'>{hint}</p>
+ )}
+ </div>
+ </div>
+ )
+}
+
+Checkbox.propTypes = {
+ label: PropTypes.oneOfType([
+ PropTypes.string, PropTypes.node,
+ ]).isRequired,
+ checked: PropTypes.bool.isRequired,
+ hint: PropTypes.string,
+ onChange: PropTypes.func,
+ id: PropTypes.string,
+ className: PropTypes.string,
+ name: PropTypes.string,
+}
+
+Checkbox.defaultProps = {
+ label: '',
+ hint: '',
+ onChange: () => { },
+ id: '',
+ className: '',
+ name: '',
+}
+
+export default memo(Checkbox)
diff --git a/src/ui/Dropdown.jsx b/src/ui/Dropdown.jsx
new file mode 100644
index 000000000..f4ecd81fd
--- /dev/null
+++ b/src/ui/Dropdown.jsx
@@ -0,0 +1,72 @@
+import React, { memo, Fragment } from 'react'
+import { Menu, Transition } from '@headlessui/react'
+import { ChevronDownIcon } from '@heroicons/react/solid'
+import cx from 'classnames'
+import _map from 'lodash/map'
+import _isObject from 'lodash/isObject'
+import PropTypes from 'prop-types'
+
+const Dropdown = ({
+ title, className, items, labelExtractor, keyExtractor, onSelect,
+}) => (
+ <Menu as='div' className={cx('relative inline-block text-left', className)}>
+ {({ open }) => (
+ <>
+ <div>
+ <Menu.Button className='inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500'>
+ {title}
+ <ChevronDownIcon className='-mr-1 ml-2 h-5 w-5' aria-hidden='true' />
+ </Menu.Button>
+ </div>
+
+ <Transition
+ show={open}
+ as={Fragment}
+ enter='transition ease-out duration-100'
+ enterFrom='transform opacity-0 scale-95'
+ enterTo='transform opacity-100 scale-100'
+ leave='transition ease-in duration-75'
+ leaveFrom='transform opacity-100 scale-100'
+ leaveTo='transform opacity-0 scale-95'
+ >
+ <Menu.Items static className='z-10 origin-top-right absolute right-0 mt-2 w-40 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none'>
+ <div className='py-1'>
+ {_map(items, item => (
+ <Menu.Item key={keyExtractor ? keyExtractor(item) : item}>
+ <span
+ className='text-gray-700 block px-4 py-2 text-sm cursor-pointer hover:bg-gray-200'
+ role='menuitem'
+ tabIndex='-1'
+ id='menu-item-0'
+ onClick={() => onSelect(item)}
+ >
+ {labelExtractor ? labelExtractor(item) : item}
+ </span>
+ </Menu.Item>
+ ))}
+ </div>
+ </Menu.Items>
+ </Transition>
+ </>
+ )}
+ </Menu>
+)
+
+Dropdown.propTypes = {
+ title: PropTypes.string.isRequired,
+ onSelect: PropTypes.func.isRequired,
+ items: PropTypes.arrayOf(PropTypes.oneOfType([
+ PropTypes.string, PropTypes.object,
+ ])),
+ className: PropTypes.string,
+ labelExtractor: PropTypes.func,
+ keyExtractor: PropTypes.func,
+}
+
+Dropdown.defaultProps = {
+ className: '',
+ labelExtractor: null,
+ keyExtractor: null,
+}
+
+export default memo(Dropdown)
diff --git a/src/ui/Input.jsx b/src/ui/Input.jsx
new file mode 100644
index 000000000..249f95075
--- /dev/null
+++ b/src/ui/Input.jsx
@@ -0,0 +1,77 @@
+import React, { memo } from 'react'
+import cx from 'classnames'
+import _isEmpty from 'lodash/isEmpty'
+import PropTypes from 'prop-types'
+import { ExclamationCircleIcon } from '@heroicons/react/solid'
+
+const Input = ({
+ label, hint, placeholder, type, id, name, className, onChange, error, value, disabled,
+}) => {
+ const identifier = id || name || type
+ const isError = !_isEmpty(error)
+
+ return (
+ <div className={className}>
+ <div className={cx({
+ 'flex justify-between': label && hint,
+ })}>
+ <label for={identifier} className='block text-sm font-medium text-gray-700'>{label}</label>
+ <span className='text-sm text-gray-500' id={`${identifier}-optional`}>{hint}</span>
+ </div>
+ <div className='mt-1 relative'>
+ <input
+ type={type}
+ value={value}
+ name={name}
+ id={identifier}
+ onChange={onChange}
+ className={cx('shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md', {
+ 'border-red-300 text-red-900 placeholder-red-300': isError,
+ })}
+ placeholder={placeholder}
+ aria-describedby={`${identifier}-optional`}
+ disabled={disabled}
+ />
+ {isError && (
+ <div className='absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none'>
+ <ExclamationCircleIcon className='h-5 w-5 text-red-500' aria-hidden />
+ </div>
+ )}
+ </div>
+ {isError && (
+ <p className='mt-2 text-sm text-red-600' id='email-error'>{error}</p>
+ )}
+ </div>
+ )
+}
+
+Input.propTypes = {
+ value: PropTypes.oneOfType([
+ PropTypes.string, PropTypes.number,
+ ]).isRequired,
+ label: PropTypes.string,
+ hint: PropTypes.string,
+ placeholder: PropTypes.string,
+ onChange: PropTypes.func,
+ id: PropTypes.string,
+ type: PropTypes.string,
+ className: PropTypes.string,
+ error: PropTypes.string,
+ name: PropTypes.string,
+ disabled: PropTypes.bool,
+}
+
+Input.defaultProps = {
+ label: '',
+ hint: '',
+ placeholder: '',
+ onChange: () => { },
+ id: '',
+ type: '',
+ className: '',
+ error: null,
+ name: '',
+ disabled: false,
+}
+
+export default memo(Input)
diff --git a/src/ui/Loader.jsx b/src/ui/Loader.jsx
new file mode 100644
index 000000000..b6589f14e
--- /dev/null
+++ b/src/ui/Loader.jsx
@@ -0,0 +1,11 @@
+import React from 'react'
+import { RefreshIcon } from '@heroicons/react/outline'
+
+const Loader = () => (
+ <div className='flex justify-center mt-10'>
+ <RefreshIcon className='animate-spin transform rotate-180 h-20 w-20 text-indigo-700' />
+ <span className='sr-only'>Loading...</span>
+ </div>
+)
+
+export default Loader
diff --git a/src/ui/Progress.jsx b/src/ui/Progress.jsx
new file mode 100644
index 000000000..394aecac8
--- /dev/null
+++ b/src/ui/Progress.jsx
@@ -0,0 +1,11 @@
+import React, { memo } from 'react'
+
+const Progress = ({ now }) => (
+ <div className='relative'>
+ <div className='overflow-hidden h-2 text-xs flex rounded bg-blue-200'>
+ <div style={{ width: `${now}%` }} className='shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500' />
+ </div>
+ </div>
+)
+
+export default memo(Progress)
diff --git a/src/utils/accessToken.js b/src/utils/accessToken.js
index be78a2856..3604e9326 100644
--- a/src/utils/accessToken.js
+++ b/src/utils/accessToken.js
@@ -1,29 +1,15 @@
-import Debug from 'debug'
import { getItem, setItem, removeItem } from './localstorage'
-
-const debug = Debug('analytics:utils:at')
+import { TOKEN } from 'redux/constants'
export const getAccessToken = () => {
- const accessToken = getItem('access_token')
- let token = null
-
- if (!accessToken) {
- return null
- }
-
- try {
- token = JSON.parse(accessToken)
- } catch(e) {
- debug('Error while parsing access token: %s', e)
- }
-
- return token
+ const accessToken = getItem(TOKEN)
+ return accessToken
}
export const setAccessToken = token => {
- setItem('access_token', token)
+ setItem(TOKEN, token)
}
export const removeAccessToken = () => {
- removeItem('access_token')
+ removeItem(TOKEN)
}
diff --git a/tailwind.config.js b/tailwind.config.js
new file mode 100644
index 000000000..d5e37b351
--- /dev/null
+++ b/tailwind.config.js
@@ -0,0 +1,21 @@
+module.exports = {
+ // mode: 'jit',
+ purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
+ darkMode: false, // or 'media' or 'class'
+ theme: {
+ extend: {
+ width: {
+ 'card-toggle': 'calc(100% - 3rem)',
+ }
+ },
+ minHeight: {
+ 'page': 'calc(100vh - 80px)', // header height -> 80px
+ }
+ },
+ variants: {
+ extend: {},
+ },
+ plugins: [
+ require('@tailwindcss/forms'),
+ ]
+}