📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Fixed UserSettings & other minor change
Blaumaus399f0b17129e
diff --git a/src/App.js b/src/App.jsindex fbd717043..7ffcb9425 100644--- a/src/App.js+++ b/src/App.js@@ -18,6 +18,7 @@ import { getAccessToken } from 'utils/accessToken'import { authMe } from './api'import { authActions } from 'actions/auth'import { errorsActions } from 'actions/errors'+import { alertsActions } from 'actions/alerts'const ProtectedSignIn = notAuthenticated(SignIn)const ProtectedSignUp = notAuthenticated(SignUp)@@ -30,6 +31,7 @@ const App = () => {const alert = useAlert()const { loading, authenticated } = useSelector(state => state.auth)const { error } = useSelector(state => state.errors)+ const { message, type } = useSelector(state => state.alerts)const accessToken = getAccessToken()useEffect(() => {@@ -53,6 +55,17 @@ const App = () => {}}, [error])+ useEffect(() => {+ if (message && type) {+ alert.show(message, {+ type,+ onClose: () => {+ dispatch(alertsActions.clearAlerts())+ }+ })+ }+ }, [message, type])+return ((!accessToken || !loading) && (<>@@ -64,7 +77,8 @@ const App = () => {<Route path={routes.dashboard} component={ProtectedDashboard} exact /><Route path={routes.user_settings} component={ProtectedUserSettings} exact /><Route path={routes.verify} component={VerifyEmail} exact />- <Route path={routes.recovery} component={ProtectedForgotPassword} exact />+ <Route path={routes.change_email} component={VerifyEmail} exact />+ <Route path={routes.reset_password} component={ProtectedForgotPassword} exact /><Redirect to={routes.main} /></Switch></>diff --git a/src/actions/alerts/index.js b/src/actions/alerts/index.jsnew file mode 100644index 000000000..7b3bbc5af--- /dev/null+++ b/src/actions/alerts/index.js@@ -0,0 +1,30 @@+import { types } from './types'++export const alertsActions = {+ accountDeleted(message, type = 'success') {+ return {+ type: types.ACCOUNT_DELETED,+ payload: { message, type }+ }+ },++ accountUpdated(message, type = 'success') {+ return {+ type: types.ACCOUNT_UPDATED,+ payload: { message, type }+ }+ },++ newPassword(message, type = 'success') {+ return {+ type: types.NEW_PASSWORD,+ payload: { message, type }+ }+ },++ clearAlerts() {+ return {+ type: types.CLEAR_ALERTS+ }+ },+}diff --git a/src/actions/alerts/types.js b/src/actions/alerts/types.jsnew file mode 100644index 000000000..c7a220af1--- /dev/null+++ b/src/actions/alerts/types.js@@ -0,0 +1,8 @@+export const types = {+ ACCOUNT_DELETED: 'ACCOUNT_DELETED',+ ACCOUNT_UPDATED: 'ACCOUNT_UPDATED',+ NEW_PASSWORD: 'NEW_PASSWORD',++ // Common+ CLEAR_ALERTS: 'CLEAR_ALERTS'+}diff --git a/src/api/index.js b/src/api/index.jsindex 7e670b5ca..d74c079e1 100644--- a/src/api/index.js+++ b/src/api/index.js@@ -81,7 +81,7 @@ export const changeUserDetails = (data) =>export const forgotPassword = (email) =>api- .post('/auth/user/reset-password', email)+ .post('/auth/reset-password', email).then((response) => response.data).catch((error) => {throw new Error(error.response.data.message)diff --git a/src/pages/Auth/CreateNewPassword/ForgotPassword.container.jsx b/src/pages/Auth/CreateNewPassword/ForgotPassword.container.jsxnew file mode 100644index 000000000..abf6f99c2--- /dev/null+++ b/src/pages/Auth/CreateNewPassword/ForgotPassword.container.jsx@@ -0,0 +1,28 @@+import { useDispatch } from 'react-redux'+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 routes from 'routes'++export default () => {+ const dispatch = useDispatch()+ const history = useHistory()++ const onSubmit = async (data) => {+ try {+ await forgotPassword(data)++ dispatch(alertsActions.newPassword('A password reset e-mail has been sent to the specified address'))+ history.push(routes.main)+ } catch (e) {+ dispatch(errorsActions.createNewPasswordFailed(e.toString()))+ }+ }++ return (+ <ForgotPassword onSubmit={onSubmit} />+ )+}\ No newline at end of filediff --git a/src/pages/Auth/CreateNewPassword/ForgotPassword.jsx b/src/pages/Auth/CreateNewPassword/ForgotPassword.jsxnew file mode 100644index 000000000..c1af7eed0--- /dev/null+++ b/src/pages/Auth/CreateNewPassword/ForgotPassword.jsx@@ -0,0 +1,86 @@+import React, { useState, useEffect } from 'react'+import { Link } from 'react-router-dom'+import Form from 'react-bootstrap/Form'++import routes from 'routes'+import { isValidEmail, isValidPassword } from 'utils/validator'++export default ({ onSubmit }) => {+ const [form, setForm] = useState({+ email: '',+ })+ 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.'+ }++ const valid = Object.keys(allErrors).length === 0++ setErrors(allErrors)+ setValidated(valid)+ }++ 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">+ Sign in+ </Link>+ <button type="submit" className="btn btn-primary ml-auto">+ Reset password+ </button>+ </div>+ </Form>+ </div>+ )+}\ No newline at end of filediff --git a/src/pages/Auth/CreateNewPassword/index.jsx b/src/pages/Auth/CreateNewPassword/index.jsxnew file mode 100644index 000000000..b35507343--- /dev/null+++ b/src/pages/Auth/CreateNewPassword/index.jsx@@ -0,0 +1,3 @@+import ForgotPassword from './ForgotPassword.container'++export default ForgotPassword\ No newline at end of filediff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsxindex 6710b9bc5..abf6f99c2 100644--- a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx@@ -1,8 +1,25 @@+import { useDispatch } from 'react-redux'+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 routes from 'routes'export default () => {- const onSubmit = data => {- console.log(data)+ const dispatch = useDispatch()+ const history = useHistory()++ const onSubmit = async (data) => {+ try {+ await forgotPassword(data)++ dispatch(alertsActions.newPassword('A password reset e-mail has been sent to the specified address'))+ history.push(routes.main)+ } catch (e) {+ dispatch(errorsActions.createNewPasswordFailed(e.toString()))+ }}return (diff --git a/src/pages/Auth/VerifyEmail/index.jsx b/src/pages/Auth/VerifyEmail/index.jsxindex 44c70b136..6e6a2d3e0 100644--- a/src/pages/Auth/VerifyEmail/index.jsx+++ b/src/pages/Auth/VerifyEmail/index.jsx@@ -16,6 +16,7 @@ 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/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsxindex b62b95c70..f3da4e427 100644--- a/src/pages/UserSettings/UserSettings.container.jsx+++ b/src/pages/UserSettings/UserSettings.container.jsx@@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux'import { authActions } from 'actions/auth'import { errorsActions } from 'actions/errors'+import { alertsActions } from 'actions/alerts'import UserSettings from './UserSettings'export default () => {@@ -22,8 +23,22 @@ export default () => {// TODO}- const onSubmit = () => {- // TODO+ const onSubmit = (data) => {+ delete data.repeat+ for (let key in data) {+ if (data[key] === '') {+ delete data[key]+ }+ }++ dispatch(+ authActions.updateUserProfileAsync(+ data,+ () => dispatch(+ alertsActions.accountUpdated('Your account settings have been updated!')+ )+ )+ );}const onEmailConfirm = () => {diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsxindex d74937fe6..cbef316eb 100644--- a/src/pages/UserSettings/UserSettings.jsx+++ b/src/pages/UserSettings/UserSettings.jsx@@ -10,7 +10,7 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {const { user } = useSelector(state => state.auth)const [form, setForm] = useState({- email: user.email,+ email: user.email || '',password: '',repeat: '',})@@ -50,6 +50,10 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {allErrors.email = 'Please provide a valid email.'}+ if (form.password.length > 0 && !isValidPassword(form.password)) {+ allErrors.password = 'The entered password is incorrect.'+ }+if (form.password !== form.repeat) {allErrors.repeat = 'Passwords have to match.'}@@ -64,7 +68,7 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {<div className="container"><h2>Profile settings</h2>- <Form validated={validated} onSubmit={handleSubmit} noValidate>+ <Form onSubmit={handleSubmit} noValidate><Form.Group className="mb-3 has-validation"><Form.Label htmlFor="email">Email</Form.Label><Form.Control@@ -94,9 +98,7 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {className="form-control"name="password"onChange={handleInput}- isValid={!errors.hasOwnProperty('password')}isInvalid={beenSubmitted && errors.hasOwnProperty('password')}- required/><Form.Control.Feedback type="invalid">{errors.password}@@ -112,9 +114,7 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {className="form-control"name="repeat"onChange={handleInput}- isValid={!errors.hasOwnProperty('repeat')}isInvalid={beenSubmitted && errors.hasOwnProperty('repeat')}- required/><Form.Control.Feedback type="invalid">{errors.repeat}@@ -128,7 +128,7 @@ export default ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {{user?.isActive || (<div className="mt-4">- <button className="btn btn-link" onClick={onExport}>+ <button className="btn btn-link" onClick={onEmailConfirm}><Mailbox color="#007bff" size="24" className="mr-2" />Didn't receive a link to confirm the email address? Request a new one!</button>diff --git a/src/reducers/alerts.js b/src/reducers/alerts.jsnew file mode 100644index 000000000..f019dcef8--- /dev/null+++ b/src/reducers/alerts.js@@ -0,0 +1,21 @@+import { types } from 'actions/alerts/types'++const initialState = {+ message: null,+ type: 'info'+}++export default (state = initialState, { type, payload }) => {+ switch (type) {+ case types.ACCOUNT_DELETED:+ case types.ACCOUNT_UPDATED:+ case types.NEW_PASSWORD:+ return { ...state, message: payload.message, type: payload.type }++ case types.CLEAR_ERRORS:+ return { ...state, message: null, type: 'info' }++ default:+ return state+ }+}diff --git a/src/reducers/index.js b/src/reducers/index.jsindex 40dd8c233..bb1bead0a 100644--- a/src/reducers/index.js+++ b/src/reducers/index.js@@ -1,5 +1,6 @@import { combineReducers } from 'redux'import auth from './auth'import errors from './errors'+import alerts from './alerts'-export default combineReducers({ auth, errors })\ No newline at end of file+export default combineReducers({ auth, errors, alerts })\ No newline at end of filediff --git a/src/routes.js b/src/routes.jsindex 24f8c71ea..b1c98bd4e 100644--- a/src/routes.js+++ b/src/routes.js@@ -6,4 +6,5 @@ export default Object.freeze({dashboard: '/dashboard',user_settings: '/settings',verify: '/verify/:id',+ change_email: '/change-email/:id',})\ No newline at end of file