From c7db780582a3c2fc9af25ec0138ab5bbce5b58ab Mon Sep 17 00:00:00 2001 From: okbel Date: Wed, 2 May 2018 16:46:20 -0300 Subject: [PATCH] Updating the cache with data from the fragment --- .../src/tabs/profile/containers/Profile.js | 2 +- client/coral-framework/graphql/mutations.js | 23 +++++++++++++++++++ .../components/ChangeEmailContentDialog.js | 4 ++-- .../client/components/Profile.js | 14 ++++------- .../client/containers/Profile.js | 2 ++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/client/coral-embed-stream/src/tabs/profile/containers/Profile.js b/client/coral-embed-stream/src/tabs/profile/containers/Profile.js index 0272c1535..4a84f1810 100644 --- a/client/coral-embed-stream/src/tabs/profile/containers/Profile.js +++ b/client/coral-embed-stream/src/tabs/profile/containers/Profile.js @@ -46,7 +46,7 @@ ProfileContainer.propTypes = { currentUser: PropTypes.object, }; -const slots = ['profileSections']; +const slots = ['profileSections', 'profileSettings', 'profileHeader']; const withProfileQuery = withQuery( gql` diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index 15596e9a7..29ec3fc96 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -336,6 +336,29 @@ export const withUpdateEmailAddress = withMutation( variables: { input, }, + update: proxy => { + const UpdateEmailAddressQuery = gql` + query Talk_UpdateEmailAddress { + me { + id + email + } + } + `; + + const prev = proxy.readQuery({ query: UpdateEmailAddressQuery }); + + const data = update(prev, { + me: { + email: { $set: input.email }, + }, + }); + + proxy.writeQuery({ + query: UpdateEmailAddressQuery, + data, + }); + }, }); }, }), diff --git a/plugins/talk-plugin-local-auth/client/components/ChangeEmailContentDialog.js b/plugins/talk-plugin-local-auth/client/components/ChangeEmailContentDialog.js index 02d02680e..4bc15757e 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangeEmailContentDialog.js +++ b/plugins/talk-plugin-local-auth/client/components/ChangeEmailContentDialog.js @@ -37,7 +37,7 @@ class ChangeEmailContentDialog extends React.Component {
{t('talk-plugin-local-auth.change_email.old_email')}:{' '} - {this.props.emailAddress} + {this.props.email} {t('talk-plugin-local-auth.change_email.new_email')}:{' '} @@ -86,7 +86,7 @@ ChangeEmailContentDialog.propTypes = { cancel: PropTypes.func, onChange: PropTypes.func, formData: PropTypes.object, - emailAddress: PropTypes.string, + email: PropTypes.string, }; export default ChangeEmailContentDialog; diff --git a/plugins/talk-plugin-local-auth/client/components/Profile.js b/plugins/talk-plugin-local-auth/client/components/Profile.js index 84474dbe3..949923e77 100644 --- a/plugins/talk-plugin-local-auth/client/components/Profile.js +++ b/plugins/talk-plugin-local-auth/client/components/Profile.js @@ -158,9 +158,7 @@ class Profile extends React.Component { render() { const { - username, - emailAddress, - root: { me: { state: { status } } }, + root: { me: { username, email, state: { status } } }, notify, } = this.props; const { editing, formData, showDialog } = this.state; @@ -193,8 +191,8 @@ class Profile extends React.Component { save={this.saveEmail} onChange={this.onChange} formData={this.state.formData} - emailAddress={emailAddress} - enable={formData.newEmail && emailAddress !== formData.newEmail} + email={email} + enable={formData.newEmail && email !== formData.newEmail} /> @@ -221,7 +219,7 @@ class Profile extends React.Component { id="newEmail" name="newEmail" onChange={this.onChange} - defaultValue={emailAddress} + defaultValue={email} validationType="email" columnDisplay /> @@ -230,9 +228,7 @@ class Profile extends React.Component { ) : (

{username}

- {emailAddress ? ( -

{emailAddress}

- ) : null} + {email ?

{email}

: null}
)} {editing ? ( diff --git a/plugins/talk-plugin-local-auth/client/containers/Profile.js b/plugins/talk-plugin-local-auth/client/containers/Profile.js index bebf127fd..239304535 100644 --- a/plugins/talk-plugin-local-auth/client/containers/Profile.js +++ b/plugins/talk-plugin-local-auth/client/containers/Profile.js @@ -15,6 +15,8 @@ const withData = withFragments({ fragment TalkPluginLocalAuth_Profile_root on RootQuery { me { id + email + username state { status { username {