API & Client - user can delete his account - fix #17
This commit is contained in:
@ -2,7 +2,7 @@ import FitTrackeeGenericApi from '../fitTrackeeApi'
|
||||
import FitTrackeeApi from '../fitTrackeeApi/auth'
|
||||
import { history } from '../index'
|
||||
import { generateIds } from '../utils'
|
||||
import { getOrUpdateData, updateLanguage } from './index'
|
||||
import { getOrUpdateData, setError, updateLanguage } from './index'
|
||||
|
||||
const AuthError = message => ({ type: 'AUTH_ERROR', message })
|
||||
|
||||
@ -133,3 +133,15 @@ export const deletePicture = () => dispatch =>
|
||||
.catch(error => {
|
||||
throw error
|
||||
})
|
||||
|
||||
export const deleteUser = username => dispatch =>
|
||||
FitTrackeeGenericApi.deleteData('users', username)
|
||||
.then(ret => {
|
||||
if (ret.status === 204) {
|
||||
dispatch(logout())
|
||||
history.push('/')
|
||||
} else {
|
||||
ret.json().then(r => dispatch(setError(`${r.message}`)))
|
||||
}
|
||||
})
|
||||
.catch(error => dispatch(setError(`user|${error}`)))
|
||||
|
@ -91,7 +91,7 @@ class ActivityDisplay extends React.Component {
|
||||
<div className="container">
|
||||
{displayModal && (
|
||||
<CustomModal
|
||||
title={t('activities:Confirmation')}
|
||||
title={t('common:Confirmation')}
|
||||
text={t(
|
||||
'activities:Are you sure you want to delete this activity?'
|
||||
)}
|
||||
|
@ -6,15 +6,17 @@ import { connect } from 'react-redux'
|
||||
import TimezonePicker from 'react-timezone'
|
||||
|
||||
import Message from '../Common/Message'
|
||||
import { handleProfileFormSubmit } from '../../actions/user'
|
||||
import { deleteUser, handleProfileFormSubmit } from '../../actions/user'
|
||||
import { history } from '../../index'
|
||||
import { languages } from '../NavBar/LanguageDropdown'
|
||||
import CustomModal from '../Common/CustomModal'
|
||||
|
||||
class ProfileEdit extends React.Component {
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
this.state = {
|
||||
formData: {},
|
||||
displayModal: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,9 +53,22 @@ class ProfileEdit extends React.Component {
|
||||
this.setState(formData)
|
||||
}
|
||||
|
||||
displayModal(value) {
|
||||
this.setState(prevState => ({
|
||||
...prevState,
|
||||
displayModal: value,
|
||||
}))
|
||||
}
|
||||
|
||||
render() {
|
||||
const { onHandleProfileFormSubmit, message, t, user } = this.props
|
||||
const { formData } = this.state
|
||||
const {
|
||||
message,
|
||||
onDeleteUser,
|
||||
onHandleProfileFormSubmit,
|
||||
t,
|
||||
user,
|
||||
} = this.props
|
||||
const { displayModal, formData } = this.state
|
||||
return (
|
||||
<div>
|
||||
<Helmet>
|
||||
@ -62,6 +77,20 @@ class ProfileEdit extends React.Component {
|
||||
<Message message={message} t={t} />
|
||||
{formData.isAuthenticated && (
|
||||
<div className="container">
|
||||
{displayModal && (
|
||||
<CustomModal
|
||||
title={t('common:Confirmation')}
|
||||
text={t(
|
||||
'user:Are you sure you want to delete your account? ' +
|
||||
'All data will be deleted, this cannot be undone.'
|
||||
)}
|
||||
confirm={() => {
|
||||
onDeleteUser(user.username)
|
||||
this.displayModal(false)
|
||||
}}
|
||||
close={() => this.displayModal(false)}
|
||||
/>
|
||||
)}
|
||||
<h1 className="page-title">{t('user:Profile Edition')}</h1>
|
||||
<div className="row">
|
||||
<div className="col-md-2" />
|
||||
@ -242,6 +271,11 @@ class ProfileEdit extends React.Component {
|
||||
className="btn btn-primary btn-lg btn-block"
|
||||
value={t('common:Submit')}
|
||||
/>
|
||||
<input
|
||||
className="btn btn-danger btn-lg btn-block"
|
||||
onClick={() => this.displayModal(true)}
|
||||
defaultValue={t('user:Delete my account')}
|
||||
/>
|
||||
<input
|
||||
type="submit"
|
||||
className="btn btn-secondary btn-lg btn-block"
|
||||
@ -271,6 +305,9 @@ export default withTranslation()(
|
||||
user: state.user,
|
||||
}),
|
||||
dispatch => ({
|
||||
onDeleteUser: username => {
|
||||
dispatch(deleteUser(username))
|
||||
},
|
||||
onHandleProfileFormSubmit: formData => {
|
||||
dispatch(handleProfileFormSubmit(formData))
|
||||
},
|
||||
|
@ -8,7 +8,6 @@
|
||||
"Ascent": "Ascent",
|
||||
"Average speed": "Average speed",
|
||||
"Chart": "Chart",
|
||||
"Confirmation": "Confirmation",
|
||||
"data from gpx, without any cleaning": "data from gpx, without any cleaning",
|
||||
"Date": "Date",
|
||||
"Delete activity": "Delete activity",
|
||||
|
@ -2,6 +2,7 @@
|
||||
"Add workout": "Add workout",
|
||||
"Back": "Back",
|
||||
"Cancel": "Cancel",
|
||||
"Confirmation": "Confirmation",
|
||||
"Dashboard": "Dashboard",
|
||||
"Edit": "Edit",
|
||||
"day": "day",
|
||||
|
@ -30,5 +30,6 @@
|
||||
"statistics": "statistiques",
|
||||
"User does not exist.": "User does not exist.",
|
||||
"Valid email must be provided.\n": "Valid email must be provided.",
|
||||
"You can not delete your account, no other user has admin rights.": "You can not delete your account, no other user has admin rights.",
|
||||
"You do not have permissions.": "You do not have permissions."
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"Admin": "Admin",
|
||||
"Are you sure you want to delete your account? All data will be deleted, this cannot be undone.": "Are you sure you want to delete your account? All data will be deleted, this cannot be undone.",
|
||||
"Bio": "Bio",
|
||||
"Birth Date": "Birth Date",
|
||||
"Delete my account": "Delete my account",
|
||||
"Delete picture": "Delete picture",
|
||||
"Edit Profile": "Edit Profile",
|
||||
"Email": "Email",
|
||||
|
@ -8,7 +8,6 @@
|
||||
"Ascent": "Dénivelé positif",
|
||||
"Average speed": "Vitesse moyenne",
|
||||
"Chart": "Analyse",
|
||||
"Confirmation": "Confirmation",
|
||||
"data from gpx, without any cleaning": "données issues du fichier gpx, sans correction",
|
||||
"Date": "Date",
|
||||
"Delete activity": "Supprimer l'activité",
|
||||
|
@ -2,6 +2,7 @@
|
||||
"Add workout": "Ajouter une activité",
|
||||
"Back": "Revenir à la page précédente",
|
||||
"Cancel": "Annuler",
|
||||
"Confirmation": "Confirmation",
|
||||
"Dashboard": "Tableau de Bord",
|
||||
"Edit": "Modifier",
|
||||
"day": "jour",
|
||||
|
@ -30,5 +30,6 @@
|
||||
"statistics": "statistics",
|
||||
"User does not exist.": "L'utilisateur n'existe pas.",
|
||||
"Valid email must be provided.\n": "L'email fourni n'est pas valide.",
|
||||
"You can not delete your account, no other user has admin rights.": "Vous ne pouvez pas supprimer votre compte, aucun autre utilisateur n'a des droits d'administration.",
|
||||
"You do not have permissions.": "Vous n'avez pas les permissions nécessaires."
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"Admin": "Admin",
|
||||
"Are you sure you want to delete your account? All data will be deleted, this cannot be undone.": "Etes-vous sûr de vouloir supprimer votre compte ? Toutes les données seront définitivement effacés.",
|
||||
"Bio": "Bio",
|
||||
"Birth Date": "Date de naissance",
|
||||
"Delete my account": "Supprimer mon compte",
|
||||
"Delete picture": "Supprimer l'image",
|
||||
"Edit Profile": "Editer le profil",
|
||||
"Email": "Email",
|
||||
|
Reference in New Issue
Block a user