diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index 29ec3fc96..228911d4a 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -321,50 +321,6 @@ const SetUsernameFragment = gql` } `; -export const withUpdateEmailAddress = withMutation( - gql` - mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) { - updateEmailAddress(input: $input) { - ...UpdateEmailAddressResponse - } - } - `, - { - props: ({ mutate }) => ({ - updateEmailAddress: input => { - return mutate({ - 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, - }); - }, - }); - }, - }), - } -); - export const withChangeUsername = withMutation( gql` mutation ChangeUsername($id: ID!, $username: String!) { diff --git a/plugins/talk-plugin-local-auth/client/containers/Profile.js b/plugins/talk-plugin-local-auth/client/containers/Profile.js index 239304535..8f442ea43 100644 --- a/plugins/talk-plugin-local-auth/client/containers/Profile.js +++ b/plugins/talk-plugin-local-auth/client/containers/Profile.js @@ -3,10 +3,8 @@ import { bindActionCreators } from 'redux'; import { connect, withFragments } from 'plugin-api/beta/client/hocs'; import Profile from '../components/Profile'; import { notify } from 'coral-framework/actions/notification'; -import { - withChangeUsername, - withUpdateEmailAddress, -} from 'plugin-api/beta/client/hocs'; +import { withChangeUsername } from 'plugin-api/beta/client/hocs'; +import { withUpdateEmailAddress } from './hocs'; const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch); diff --git a/plugins/talk-plugin-local-auth/client/hocs/index.js b/plugins/talk-plugin-local-auth/client/hocs/index.js new file mode 100644 index 000000000..bcd439af2 --- /dev/null +++ b/plugins/talk-plugin-local-auth/client/hocs/index.js @@ -0,0 +1,47 @@ +import { gql } from 'react-apollo'; +import update from 'immutability-helper'; +import withMutation from 'coral-framework/hocs/withMutation'; + +export const withUpdateEmailAddress = withMutation( + gql` + mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) { + updateEmailAddress(input: $input) { + ...UpdateEmailAddressResponse + } + } + `, + { + props: ({ mutate }) => ({ + updateEmailAddress: input => { + return mutate({ + 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, + }); + }, + }); + }, + }), + } +);