From 6ac23dd61beac482ccec58aef6acfda9fda788f2 Mon Sep 17 00:00:00 2001
From: Francesco Esposito <33671357+frsposito@users.noreply.github.com>
Date: Tue, 6 Aug 2019 16:50:53 +0200
Subject: [PATCH] feat: add Settings component
---
src/Routes.js | 3 +
src/containers/Administration/Settings.js | 156 ++++++++++++++++++++++
2 files changed, 159 insertions(+)
create mode 100644 src/containers/Administration/Settings.js
diff --git a/src/Routes.js b/src/Routes.js
index ae3ba7f..70f50ab 100644
--- a/src/Routes.js
+++ b/src/Routes.js
@@ -16,6 +16,7 @@ import Login from "./containers/Administration/Login";
import Logout from "./containers/Logout";
import TicketList from "./containers/Administration/TicketList";
import TicketManager from "./containers/Administration/TicketManager";
+import Settings from './containers/Administration/Settings';
class Routes extends Component {
constructor(props) {
@@ -40,6 +41,8 @@ class Routes extends Component {
+
+
diff --git a/src/containers/Administration/Settings.js b/src/containers/Administration/Settings.js
new file mode 100644
index 0000000..12aa4dc
--- /dev/null
+++ b/src/containers/Administration/Settings.js
@@ -0,0 +1,156 @@
+import React, { Component } from 'react';
+import { Redirect } from 'react-router-dom';
+import { userAPI } from '../../api/user';
+
+import {
+ Row,
+ Col,
+ Form,
+ FormGroup,
+ Label,
+ Input
+} from 'reactstrap';
+
+import Card from '../../components/Card';
+import Button from '../../components/Button';
+
+class Settings extends Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ newPassword: '',
+ confirmPassword: '',
+ error: '',
+ updated: false
+ };
+
+ this.handleInputChange = this.handleInputChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ this.resetForm = this.resetForm.bind(this);
+ }
+
+ handleInputChange(event) {
+ const target = event.target;
+ const name = target.name;
+ const value = target.type === 'checkbox' ? target.checked : target.value;
+ this.setState({
+ [name]: value
+ });
+ }
+
+ handleSubmit(event) {
+ event.preventDefault();
+
+ const { newPassword, confirmPassword } = this.state;
+
+ if (newPassword && newPassword === confirmPassword) {
+ const user = {
+ newPassword,
+ }
+
+ userAPI.changePassword(user)
+ .then((json) => {
+ this.setState({ updated: true });
+ })
+ .catch((error) => {
+ this.setState({ error: error.message });
+ })
+ } else {
+ this.setState( {error: 'Check passwords'})
+ }
+ }
+
+ resetForm(event) {
+ event.preventDefault();
+
+ this.setState({ error: '' });
+ }
+
+ render() {
+ if (this.state.error) {
+ return (
+
+ {this.state.error}
+ Back to login
+
+ );
+ }
+
+
+ if (this.state.updated) {
+ alert('Password updated');
+
+ return (
+
+ )
+ }
+
+ return (
+
+
+
+ Change password
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+
+export default Settings;
\ No newline at end of file