From 9310a4734d940ac825889dde2523b9747b942291 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:16:41 +0200 Subject: [PATCH 1/7] Fix viewing/editing empty org contact email --- .../src/routes/Configure/components/OrganizationSettings.js | 3 +-- client/coral-framework/utils/index.js | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js b/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js index 2bbe1a230..f3daeffc2 100644 --- a/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js +++ b/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js @@ -84,7 +84,6 @@ class OrganizationSettings extends React.Component { render() { const { settings, slotPassthrough, canSave } = this.props; const hasErrors = this.state.errors.length; - return (

{t('configure.organization_info_copy')}

@@ -125,7 +124,7 @@ class OrganizationSettings extends React.Component { [styles.editable]: this.state.editing, })} onChange={this.updateEmail} - value={settings.organizationContactEmail} + value={settings.organizationContactEmail || ''} id={t('configure.organization_contact_email')} readOnly={!this.state.editing} /> diff --git a/client/coral-framework/utils/index.js b/client/coral-framework/utils/index.js index 66792b9b3..8dc8fe113 100644 --- a/client/coral-framework/utils/index.js +++ b/client/coral-framework/utils/index.js @@ -237,7 +237,11 @@ export function getTotalReactionsCount(actionSummaries) { // Like lodash merge but does not recurse into arrays. export function mergeExcludingArrays(objValue, srcValue) { - if (typeof srcValue === 'object' && !Array.isArray(srcValue)) { + if ( + typeof srcValue === 'object' && + !Array.isArray(srcValue) && + srcValue !== null + ) { return assignWith({}, objValue, srcValue, mergeExcludingArrays); } return srcValue; From e8cd938b65059b21b77bd5f169ee180c258df86c Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:18:17 +0200 Subject: [PATCH 2/7] Move next route out of state --- .../src/routes/Configure/containers/Configure.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 7f0951154..73e643343 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -20,7 +20,7 @@ import OrganizationSettings from './OrganizationSettings'; import { withRouter } from 'react-router'; class ConfigureContainer extends React.Component { - state = { nextRoute: '' }; + nextRoute = ''; savePending = async () => { await this.props.updateSettings(this.props.pending); @@ -40,10 +40,9 @@ class ConfigureContainer extends React.Component { }; gotoNextRoute = () => { - const { nextRoute } = this.state; - if (nextRoute) { - this.props.router.push(nextRoute); - this.setState({ nextRoute: '' }); + if (this.nextRoute) { + this.props.router.push(this.nextRoute); + this.nextRoute = ''; } }; @@ -51,7 +50,7 @@ class ConfigureContainer extends React.Component { const nextRoute = `/admin/configure/${section}`; if (this.shouldShowSaveDialog()) { - await this.setState({ nextRoute }); + this.nextRoute = nextRoute; this.props.showSaveDialog(); } else { // Just go to the section @@ -65,7 +64,7 @@ class ConfigureContainer extends React.Component { routeLeave = ({ pathname }) => { if (this.shouldShowSaveDialog()) { - this.setState({ nextRoute: pathname }); + this.nextRoute = pathname; this.props.showSaveDialog(); return false; } From fd3f5e511625a83d451547f05840834e878ed657 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:19:47 +0200 Subject: [PATCH 3/7] Cleanup leave hook --- .../src/routes/Configure/containers/Configure.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 73e643343..4910a2ec4 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -21,6 +21,7 @@ import { withRouter } from 'react-router'; class ConfigureContainer extends React.Component { nextRoute = ''; + unregisterLeaveHook = null; savePending = async () => { await this.props.updateSettings(this.props.pending); @@ -71,7 +72,14 @@ class ConfigureContainer extends React.Component { }; componentDidMount() { - this.props.router.setRouteLeaveHook(this.props.route, this.routeLeave); + this.unregisterLeaveHook = this.props.router.setRouteLeaveHook( + this.props.route, + this.routeLeave + ); + } + + componentWillUnmount() { + this.unregisterLeaveHook(); } render() { From 2af3a94ce476d6aab1cfbfaa966b15a459f82858 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:29:40 +0200 Subject: [PATCH 4/7] No dialog when switching sections --- .../src/routes/Configure/containers/Configure.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 4910a2ec4..6cba60524 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -49,14 +49,7 @@ class ConfigureContainer extends React.Component { handleSectionChange = async section => { const nextRoute = `/admin/configure/${section}`; - - if (this.shouldShowSaveDialog()) { - this.nextRoute = nextRoute; - this.props.showSaveDialog(); - } else { - // Just go to the section - this.props.router.push(nextRoute); - } + this.props.router.push(nextRoute); }; shouldShowSaveDialog = () => { From 68b1670a55c7832a0e146880ecf2e37b2e315525 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:33:21 +0200 Subject: [PATCH 5/7] Prevent reload or closing tab or window with pending data --- .../src/routes/Configure/containers/Configure.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 6cba60524..c4b8bc0ca 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -52,12 +52,20 @@ class ConfigureContainer extends React.Component { this.props.router.push(nextRoute); }; - shouldShowSaveDialog = () => { + navigationPrompt = e => { + if (this.hasPendingData()) { + const confirmationMessage = 'Changes that you made may not be saved.'; + e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+ + return confirmationMessage; // Gecko, WebKit, Chrome <34 + } + }; + + hasPendingData = () => { return !!Object.keys(this.props.pending).length; }; routeLeave = ({ pathname }) => { - if (this.shouldShowSaveDialog()) { + if (this.hasPendingData()) { this.nextRoute = pathname; this.props.showSaveDialog(); return false; @@ -69,10 +77,12 @@ class ConfigureContainer extends React.Component { this.props.route, this.routeLeave ); + window.addEventListener('beforeunload', this.navigationPrompt); } componentWillUnmount() { this.unregisterLeaveHook(); + window.removeEventListener('beforeunload', this.navigationPrompt); } render() { From 74821a4d4c36094d81204d8a088f7315e3efab67 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 18:14:07 +0200 Subject: [PATCH 6/7] Readd save dialog on section change --- .../src/routes/Configure/containers/Configure.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index c4b8bc0ca..3d2789974 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -49,7 +49,13 @@ class ConfigureContainer extends React.Component { handleSectionChange = async section => { const nextRoute = `/admin/configure/${section}`; - this.props.router.push(nextRoute); + if (this.hasPendingData()) { + this.nextRoute = nextRoute; + this.props.showSaveDialog(); + } else { + // Just go to the section + this.props.router.push(nextRoute); + } }; navigationPrompt = e => { From 06682225c892802ba36af4afdfdab54333974621 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Tue, 1 May 2018 13:25:33 -0400 Subject: [PATCH 7/7] Fix error message --- locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.yml b/locales/en.yml index ff0d7e487..393d01e23 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -250,7 +250,7 @@ en: ALREADY_EXISTS: "Resource already exists" INVALID_ASSET_URL: "Assert URL is invalid" CANNOT_IGNORE_STAFF: "Cannot ignore Staff members." - email: "Not a valid E-Mail" + email: "Please enter a valid email." confirm_password: "Passwords don't match. Please check again" network_error: "Failed to connect to server. Check your internet connection and try again." email_not_verified: "Email address {0} not verified."