diff --git a/src/components/PasswordManager/Edit.js b/src/components/PasswordManager/Edit.js
new file mode 100644
index 0000000..4baceb6
--- /dev/null
+++ b/src/components/PasswordManager/Edit.js
@@ -0,0 +1,227 @@
+import React, {Component} from 'react';
+import { observer, inject } from 'mobx-react';
+import jss from 'jss';
+import preset from 'jss-preset-default';
+import { Segment, Container, Form, Input, Button, Icon } from 'semantic-ui-react';
+import alertify from 'alertify.js';
+
+/*
+* Functions import
+*/
+import { encrypt, decrypt } from '../../stores/functions/encryption';
+
+/*
+* Component imports
+*/
+
+jss.setup(preset());
+
+//Firebase
+var firebase = require('../../stores/fb').fb;
+// Initialize Cloud Firestore through Firebase
+var db = firebase.firestore();
+
+
+/*
+###############################
+Components -- START
+###############################
+*/
+
+/*
+###############################
+Components -- END
+###############################
+*/
+
+
+
+const Edit = inject("rootStore") ( observer(
+ class Edit extends Component {
+ constructor(props){
+ super(props);
+ //Update an existing document
+
+ /*
+ * Expected props
+ * - open: bool
+ * display component or not
+ * - toggleEditWindow: function
+ * toggles window: open and close
+ * - encryptionkey: String
+ * encryption key of the password
+ */
+
+ //Stored information
+ this.stores = this.props.rootStore.stores;
+
+ this.handleChange = this.handleChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+
+ this.state = {
+ url: '',
+ login: '',
+ password: '',
+ loading: false
+ }
+
+ //Styles
+ this.styles = this.getStyles();
+ this.sheet = jss.createStyleSheet(this.styles);
+ const {classes} = this.sheet.attach();
+ this.classes = classes;
+ //Styles
+ }
+
+
+ componentWillReceiveProps(nextProps) {
+ if(nextProps.open !== this.props.open) {
+ var url;
+ var login;
+ var password;
+ if(nextProps.open) {
+ url = nextProps.data[nextProps.editIndex].url;
+ login = decrypt(nextProps.data[nextProps.editIndex].login, nextProps.encryptionkey);
+ password = decrypt(nextProps.data[nextProps.editIndex].password, nextProps.encryptionkey);
+ } else {
+ url = null;
+ login = null;
+ password = null;
+ }
+
+ //Empty input fields
+ this.setState({
+ url: url,
+ login: login,
+ password: password
+ });
+ }
+ }
+
+
+ componentDidUpdate() {
+
+ }
+
+
+ componentWillUnmount() {
+ this.sheet.detach()
+ }
+
+
+ handleChange(e) {
+ this.setState({
+ [e.target.name]: e.target.value
+ });
+ }
+
+
+ handleSubmit() {
+ const url = this.state.url;
+ const login = encrypt(this.state.login, this.props.encryptionkey);
+ const password = encrypt(this.state.password, this.props.encryptionkey);
+ const uid = this.stores.authStore.userData.uid;
+ const id = this.props.data[this.props.editIndex].id;
+ const editIndex = this.props.editIndex;
+
+ //Update a doc locally with the new values
+ const data = {
+ url: url,
+ login: login,
+ password: password,
+ time: new Date()
+ }
+
+ db.collection("passwords/"+uid+"/passwords").doc(id).set(data)
+ .then(() => {
+ console.log("Document updated");
+ alertify.success("Document successfully updated!");
+
+ //Update a doc locally with the new values
+ this.props.updateDoc(Object.assign(data, {id:id}), editIndex);
+
+ this.props.toggleEditWindow();
+ this.setState({
+ loading: false
+ });
+ })
+ .catch(function(error) {
+ console.error("Error updating the document: ", error);
+ alertify.error("Something went wrong! Please check your internet connection");
+ this.setState({
+ loading: false
+ });
+ });
+
+ this.setState({
+ loading: true
+ });
+ }
+
+
+ render() {
+ if(this.props.open) {
+ const url = this.state.url;
+ const login = this.state.login;
+ const password = this.state.password;
+
+ return(
+
+ );
+ } else {
+ return null;
+ }
+ }
+
+
+ getStyles() {
+ return {
+ box: {
+ width: '100vw',
+ height: '100vh',
+ position: 'fixed',
+ zIndex: 1000,
+ top: 0,
+ left: 0,
+ backgroundColor: 'rgba(255,255,255,0.9)',
+ paddingTop: '5%'
+ }
+ }
+ }
+ }
+));
+
+export default Edit;
diff --git a/src/components/PasswordManager/New.js b/src/components/PasswordManager/New.js
index c02d64a..63ad04e 100644
--- a/src/components/PasswordManager/New.js
+++ b/src/components/PasswordManager/New.js
@@ -128,22 +128,23 @@ const New = inject("rootStore") ( observer(
const password = encrypt(this.state.password, this.props.encryptionkey);
const uid = this.stores.authStore.userData.uid;
+ //Update a doc locally with the new values
const data = {
- uid: uid,
url: url,
login: login,
password: password,
time: new Date()
}
- //Add a new doc locally so no new data transfer from firestore
- //is needed
- this.props.addDoc(data);
-
db.collection("passwords/"+uid+"/passwords").add(data)
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
alertify.success("Document successfully added!");
+
+ //Add a new doc locally so no new data transfer from firestore
+ //is needed
+ this.props.addDoc(Object.assign(data, {id:docRef.id}));
+
this.props.toggleNewWindow();
this.setState({
loading: false
diff --git a/src/pages/Main.js b/src/pages/Main.js
index 92ecb4a..b00499a 100644
--- a/src/pages/Main.js
+++ b/src/pages/Main.js
@@ -73,7 +73,7 @@ class Main extends Component {