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!

Created basic UserSettings page

Blaumausda9d8c485318
diff --git a/package.json b/package.json
index 3f52b3162..3aede2cac 100644
--- a/package.json
+++ b/package.json
@@ -9,11 +9,13 @@
"@testing-library/user-event": "^12.8.3",
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
+ "bootstrap-icons": "^1.4.1",
"node-sass": "^5.0.0",
"react": "^17.0.1",
"react-alert": "^7.0.2",
"react-alert-template-basic": "^1.0.0",
"react-bootstrap": "^1.5.2",
+ "react-bootstrap-icons": "^1.4.0",
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index dbbe8bacd..b543d19bc 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -1,6 +1,8 @@
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'
@@ -20,12 +22,18 @@ const Header = ({ authenticated }) => {
<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> }
</nav>
{ authenticated
? (
<>
- <Link to={routes.user_settings} className="p-2 text-dark">You</Link>
- <button className="p-2 text-dark btn btn-link" onClick={() => dispatch(authActions.logout())}>Exit</button>
+ <Link to={routes.dashboard} className="btn btn-outline-primary mr-3">Dashboard</Link>
+ <BoxArrowRight
+ color="#007bff"
+ size="24"
+ role="button"
+ onClick={() => dispatch(authActions.logout())}
+ />
</>
)
: <Link to={routes.signup} className="btn btn-outline-primary">Get started</Link>
diff --git a/src/index.js b/src/index.js
index 7ad115431..45c339439 100644
--- a/src/index.js
+++ b/src/index.js
@@ -8,7 +8,7 @@ import AlertTemplate from 'react-alert-template-basic'
import './index.scss'
import 'bootstrap/dist/css/bootstrap.min.css'
import App from './App'
-// import reportWebVitals from './reportWebVitals'
+import reportWebVitals from './reportWebVitals'
const options = {
position: positions.BOTTOM_RIGHT,
@@ -30,4 +30,4 @@ ReactDOM.render(
document.getElementById('root')
)
-// reportWebVitals()
\ No newline at end of file
+reportWebVitals()
\ No newline at end of file
diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsx
index e7c170448..c89ce7050 100644
--- a/src/pages/UserSettings/UserSettings.container.jsx
+++ b/src/pages/UserSettings/UserSettings.container.jsx
@@ -1,3 +1,33 @@
+import React from 'react'
+import { useDispatch } from 'react-redux'
+
import UserSettings from './UserSettings'
-export default UserSettings
\ No newline at end of file
+export default () => {
+ const dispatch = useDispatch()
+
+ const onDelete = () => {
+ // TODO
+ }
+
+ const onExport = () => {
+ // TODO
+ }
+
+ const onSubmit = () => {
+ // TODO
+ }
+
+ const onEmailConfirm = () => {
+ // TODO
+ }
+
+ return (
+ <UserSettings
+ onDelete={onDelete}
+ onExport={onExport}
+ onSubmit={onSubmit}
+ onEmailConfirm={onEmailConfirm}
+ />
+ )
+}
\ No newline at end of file
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index 84e214edc..f22553e58 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -1,8 +1,161 @@
-import React from 'react'
+import React, { useState, useEffect } from 'react'
+import { useSelector } from 'react-redux'
+import Form from 'react-bootstrap/Form'
+import { Mailbox } from 'react-bootstrap-icons'
-export default () => {
+import { isValidEmail, isValidPassword } from 'utils/validator'
+
+export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
+ const { user } = useSelector(state => state.auth)
+
+ const [form, setForm] = useState({
+ email: user.email,
+ password: '',
+ repeat: '',
+ })
+ const [validated, setValidated] = useState(false)
+ const [errors, setErrors] = useState({})
+ const [beenSubmitted, setBeenSubmitted] = useState(false)
+
+ useEffect(() => {
+ validate()
+ }, [form])
+
+ const handleInput = event => {
+ const t = event.target
+ const value = t.type === 'checkbox' ? t.checked : t.value
+
+ setForm(form => ({
+ ...form,
+ [t.name]: value,
+ }))
+ }
+
+ const handleSubmit = e => {
+ e.preventDefault()
+ e.stopPropagation()
+ setBeenSubmitted(true)
+
+ if (validated) {
+ onSubmit(form)
+ }
+ }
+
+ const validate = () => {
+ const allErrors = {}
+
+ if (!isValidEmail(form.email)) {
+ allErrors.email = 'Please provide a valid email.'
+ }
+
+ if (!isValidPassword(form.password)) {
+ allErrors.password = 'The password has to consist of at least 8 characters.'
+ }
+
+ if (form.password !== form.repeat || form.repeat === '') {
+ allErrors.repeat = 'Passwords have to match.'
+ }
+
+ if (!form.tos) {
+ allErrors.tos = 'You have to accept our TOS and privacy policy in order to use our services.'
+ }
+
+ const valid = Object.keys(allErrors).length === 0
+
+ setErrors(allErrors)
+ setValidated(valid)
+ }
return (
- <h1>UserSettings page</h1>
+ <div className="container">
+ <h2>Profile settings</h2>
+
+ <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.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}
+ 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="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}
+ isValid={!errors.hasOwnProperty('repeat')}
+ isInvalid={beenSubmitted && errors.hasOwnProperty('repeat')}
+ required
+ />
+ <Form.Control.Feedback type="invalid">
+ {errors.repeat}
+ </Form.Control.Feedback>
+ </Form.Group>
+ </Form.Row>
+ <button type="submit" className="btn btn-primary ml-auto">
+ Update profile
+ </button>
+ </Form>
+
+ {user?.isActive || (
+ <div className="mt-4">
+ <button className="btn btn-link" onClick={onExport}>
+ <Mailbox color="#007bff" size="24" className="mr-2" />
+ Didn't receive a link to confirm the email address? Request a new one!
+ </button>
+ </div>
+ )}
+
+ <div className="mt-4">
+ <button
+ className="btn btn-outline-primary"
+ onClick={onExport}
+ >
+ Request data export
+ </button>
+ &nbsp;
+ <button
+ className="btn btn-danger"
+ onClick={onDelete}
+ >
+ Delete account
+ </button>
+ </div>
+ </div>
)
}
\ No newline at end of file