delete
This commit is contained in:
parent
c93cdb1e43
commit
3d33a5b0d1
@ -51,6 +51,14 @@ const Edit = inject("rootStore") ( observer(
|
||||
* toggles window: open and close
|
||||
* - encryptionkey: String
|
||||
* encryption key of the password
|
||||
* - updateDoc: function
|
||||
* updates doc locally
|
||||
* - deleteDoc: function
|
||||
* deletes doc locally
|
||||
* - editIndex: Int
|
||||
* index of array with all docs. locale
|
||||
* - toggleEditWindow: function
|
||||
* Open or close edit window
|
||||
*/
|
||||
|
||||
//Stored information
|
||||
@ -59,6 +67,7 @@ const Edit = inject("rootStore") ( observer(
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.dice = this.dice.bind(this);
|
||||
this.delete = this.delete.bind(this);
|
||||
|
||||
this.state = {
|
||||
url: '',
|
||||
@ -132,6 +141,39 @@ const Edit = inject("rootStore") ( observer(
|
||||
}
|
||||
|
||||
|
||||
delete() {
|
||||
//Delete doc
|
||||
|
||||
alertify.confirm("Are you sure?", () => {
|
||||
const id = this.props.data[this.props.editIndex].id;
|
||||
const uid = this.stores.authStore.userData.uid;
|
||||
const editIndex = this.props.editIndex;
|
||||
|
||||
db.collection("passwords/"+uid+"/passwords").doc(id).delete().then(() => {
|
||||
//Delete doc locally
|
||||
this.props.deleteDoc(editIndex);
|
||||
|
||||
this.props.toggleEditWindow();
|
||||
|
||||
alertify.success("Document removed!");
|
||||
this.setState({
|
||||
loading: false
|
||||
});
|
||||
}).catch((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
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
handleSubmit() {
|
||||
const url = this.state.url;
|
||||
const login = encrypt(this.state.login, this.props.encryptionkey);
|
||||
@ -151,7 +193,7 @@ const Edit = inject("rootStore") ( observer(
|
||||
db.collection("passwords/"+uid+"/passwords").doc(id).set(data)
|
||||
.then(() => {
|
||||
console.log("Document updated");
|
||||
alertify.success("Document successfully updated!");
|
||||
alertify.success("Document updated!");
|
||||
|
||||
//Update a doc locally with the new values
|
||||
this.props.updateDoc(Object.assign(data, {id:id}), editIndex);
|
||||
@ -225,12 +267,15 @@ const Edit = inject("rootStore") ( observer(
|
||||
/>
|
||||
</Form.Field>
|
||||
|
||||
|
||||
|
||||
<p>Login and password are going to be encrypted with the key you have set.</p>
|
||||
|
||||
<Button loading={this.state.loading} type='submit' primary>Update</Button>
|
||||
<Button loading={this.state.loading} onClick={this.props.toggleEditWindow}><Icon name="x" />Cancel</Button>
|
||||
<Button loading={this.state.loading} type="button" onClick={this.props.toggleEditWindow}><Icon name="x" />Cancel</Button>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<Button loading={this.state.loading} type="button" onClick={this.delete} icon color="red"><Icon name="trash alternate" /></Button>
|
||||
|
||||
</Form>
|
||||
</Segment>
|
||||
@ -249,7 +294,7 @@ const Edit = inject("rootStore") ( observer(
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
position: 'fixed',
|
||||
zIndex: 1000,
|
||||
zIndex: 1,
|
||||
top: 0,
|
||||
left: 0,
|
||||
backgroundColor: 'rgba(255,255,255,0.9)',
|
||||
|
@ -51,6 +51,10 @@ const New = inject("rootStore") ( observer(
|
||||
* toggles window: open and close
|
||||
* - encryptionkey: String
|
||||
* encryption key of the password
|
||||
* - addDoc: function
|
||||
* adds a new doc locally
|
||||
* - toggleEditWindow: function
|
||||
* Open or close edit window
|
||||
*/
|
||||
|
||||
//Stored information
|
||||
@ -138,7 +142,7 @@ const New = inject("rootStore") ( observer(
|
||||
db.collection("passwords/"+uid+"/passwords").add(data)
|
||||
.then((docRef) => {
|
||||
console.log("Document written with ID: ", docRef.id);
|
||||
alertify.success("Document successfully added!");
|
||||
alertify.success("Document added!");
|
||||
|
||||
//Add a new doc locally so no new data transfer from firestore
|
||||
//is needed
|
||||
|
@ -2,7 +2,6 @@ import React, {Component} from 'react';
|
||||
import jss from 'jss';
|
||||
import preset from 'jss-preset-default';
|
||||
import { Container } from 'semantic-ui-react';
|
||||
import history from '../../stores/functions/history';
|
||||
|
||||
/*
|
||||
* Functions import
|
||||
@ -48,11 +47,6 @@ class Home extends Component {
|
||||
//Styles
|
||||
}
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
history.push('/');
|
||||
}
|
||||
|
||||
|
||||
componentWillUnmount() {
|
||||
this.sheet.detach()
|
||||
|
@ -59,6 +59,7 @@ const PasswordManager = inject("rootStore") ( observer(
|
||||
this.onChangeInput = this.onChangeInput.bind(this);
|
||||
this.addDoc = this.addDoc.bind(this);
|
||||
this.updateDoc = this.updateDoc.bind(this);
|
||||
this.deleteDoc = this.deleteDoc.bind(this);
|
||||
|
||||
this.state = {
|
||||
newWindowOpen: false,
|
||||
@ -111,6 +112,21 @@ const PasswordManager = inject("rootStore") ( observer(
|
||||
}
|
||||
|
||||
|
||||
deleteDoc(editIndex) {
|
||||
//Delete doc locally
|
||||
|
||||
var newArr = [];
|
||||
this.state.data.forEach(function(element, index) {
|
||||
if(index !== editIndex) {
|
||||
newArr.push(element);
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
data: newArr
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
onChangeInput(e) {
|
||||
//Encryption key and search input
|
||||
|
||||
@ -265,7 +281,7 @@ const PasswordManager = inject("rootStore") ( observer(
|
||||
<div>
|
||||
<New addDoc={this.addDoc} encryptionkey={this.state.key} open={this.state.newWindowOpen} toggleNewWindow={this.toggleNewWindow} />
|
||||
|
||||
<Edit updateDoc={this.updateDoc} data={this.state.data} editIndex={this.state.editIndex} encryptionkey={this.state.key} open={this.state.editWindowOpen} toggleEditWindow={this.toggleEditWindow} />
|
||||
<Edit updateDoc={this.updateDoc} deleteDoc={this.deleteDoc} data={this.state.data} editIndex={this.state.editIndex} encryptionkey={this.state.key} open={this.state.editWindowOpen} toggleEditWindow={this.toggleEditWindow} />
|
||||
|
||||
<Headline black="Password " red="manager" />
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user