Skip to content

Commit

Permalink
Merge pull request #521 from Bit-Nation/fix/delete-document-alert
Browse files Browse the repository at this point in the history
[documents] Added Confirm Alert while deleting document
  • Loading branch information
seland committed Sep 14, 2018
2 parents e0c0519 + 7a2e9da commit 2b2ac7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/global/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
"save": "Save",
"cancel": "$t(common.cancel)"
},
"confirmDelete": {
"title": "Confirm Delete",
"subtitle": "Are you sure you want to delete the document?",
"yes": "Yes",
"no": "No"
},
"error": {
"title": "Error",
"confirm": "$t(common.ok)"
Expand Down
20 changes: 17 additions & 3 deletions src/screens/Documents/View/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Image,
Text,
} from 'react-native';

import type { Navigator } from '../../../types/ReactNativeNavigation';
import NavigatorComponent from '../../../components/common/NavigatorComponent';
import { screen } from '../../../global/Screens';
Expand All @@ -21,6 +20,7 @@ import { imageSource } from '../../../utils/profile';
import { getOpenedDocument } from '../../../reducers/documents';
import MoreMenuModal from '../../../components/common/MoreMenuModal';
import { contentStorage } from '../../../services/documents';
import { alert } from '../../../global/alerts';

type Props = {
/**
Expand Down Expand Up @@ -101,16 +101,30 @@ class DocumentsViewScreen extends NavigatorComponent<Props & DocumentsState & Ac
};

onSelectDelete = () => {
alert('confirmDelete', [
{
name: 'yes',
onPress: () => this.confirmDelete(),
}, {
name: 'no',
onPress: () => this.cancelDelete(),
}]);
}

cancelDelete = () => {
this.setState({ moreMenuVisible: false });
}

confirmDelete = () => {
const { openedDocumentId } = this.props;
if (openedDocumentId == null) return;

this.props.deleteDocument(openedDocumentId);
this.setState({ moreMenuVisible: false }, () => {
setTimeout(() => {
this.props.navigator.dismissModal();
}, 1000);
});
};
}

render() {
const document = getOpenedDocument(this.props);
Expand Down

0 comments on commit 2b2ac7c

Please sign in to comment.