From 30cda93bde53be58f72e4f33447707d6ecf70a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 5 Sep 2023 11:51:27 +0200 Subject: [PATCH] ContactDetailsScreen prevent double click on contact create --- ComApp/src/App/Views/ContactDetailsScreen.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ComApp/src/App/Views/ContactDetailsScreen.js b/ComApp/src/App/Views/ContactDetailsScreen.js index bc96d41..2e0f534 100644 --- a/ComApp/src/App/Views/ContactDetailsScreen.js +++ b/ComApp/src/App/Views/ContactDetailsScreen.js @@ -125,6 +125,8 @@ class ContactDetailsScreen extends React.Component { state = { /** @type {'add'|'edit} */ action: 'add', + /** Is Working Saving Contact */ + savingContact: false, /** @type {0|1} 0 is VISITS 1, is NOTES */ selectedVisitsOrNoteTab: 0, @@ -162,6 +164,9 @@ class ContactDetailsScreen extends React.Component { // * - CONTACT METHODS saveContact() { + this.setState({ + savingContact: true, + }); /** @type {typeof import('./../Models/Contact').ContactData} */ const contact = Object.assign({}, this.state.contact); @@ -186,6 +191,9 @@ class ContactDetailsScreen extends React.Component { lockedFields.forEach(fieldName => { const form = lockedForms.find(inputForm => inputForm.name === fieldName); if (!form) { + this.setState({ + savingContact: false, + }); throw new Error(`failed to get form ${fieldName}`); } if (contact[fieldName]?.length) { @@ -248,6 +256,9 @@ class ContactDetailsScreen extends React.Component { }); if (error.length > 0) { + this.setState({ + savingContact: false, + }); Alert.alert(i18n.t('global.warning') + ' !', error, [{ text: 'OK' }], { cancelable: false, }); @@ -268,6 +279,9 @@ class ContactDetailsScreen extends React.Component { setContactHook(this.props.currentUser, contact); if (this.state.action === 'edit') { + this.setState({ + savingContact: false, + }); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', type: 'success', @@ -636,6 +650,7 @@ class ContactDetailsScreen extends React.Component { title={i18n.t('global.save')} onPress={() => this.saveContact()} color={this.props.mainColor} + disabled={this.state.savingContact} />