diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index dd54d0438..228911d4a 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -321,94 +321,6 @@ const SetUsernameFragment = gql` } `; -export const withAttachLocalAuth = withMutation( - gql` - mutation AttachLocalAuth($input: AttachLocalAuthInput!) { - attachLocalAuth(input: $input) { - ...AttachLocalAuthResponse - } - } - `, - { - props: ({ mutate }) => ({ - attachLocalAuth: input => { - return mutate({ - variables: { - input, - }, - update: proxy => { - const AttachLocalAuthQuery = gql` - query Talk_AttachLocalAuth { - me { - id - email - } - } - `; - - const prev = proxy.readQuery({ query: AttachLocalAuthQuery }); - - const data = update(prev, { - me: { - email: { $set: input.email }, - }, - }); - - proxy.writeQuery({ - query: AttachLocalAuthQuery, - data, - }); - }, - }); - }, - }), - } -); - -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/plugin-api/beta/client/hocs/index.js b/plugin-api/beta/client/hocs/index.js index 910969227..d7ca5fce9 100644 --- a/plugin-api/beta/client/hocs/index.js +++ b/plugin-api/beta/client/hocs/index.js @@ -27,7 +27,5 @@ export { withSetCommentStatus, withChangePassword, withChangeUsername, - withUpdateEmailAddress, - withAttachLocalAuth, } from 'coral-framework/graphql/mutations'; export { compose } from 'recompose'; diff --git a/plugins/talk-plugin-local-auth/client/containers/AddEmailAddressDialog.js b/plugins/talk-plugin-local-auth/client/containers/AddEmailAddressDialog.js index 7ab887183..841dc8420 100644 --- a/plugins/talk-plugin-local-auth/client/containers/AddEmailAddressDialog.js +++ b/plugins/talk-plugin-local-auth/client/containers/AddEmailAddressDialog.js @@ -4,7 +4,7 @@ import { connect, withFragments, excludeIf } from 'plugin-api/beta/client/hocs'; import AddEmailAddressDialog from '../components/AddEmailAddressDialog'; import { notify } from 'coral-framework/actions/notification'; -import { withAttachLocalAuth } from 'plugin-api/beta/client/hocs'; +import { withAttachLocalAuth } from '../hocs'; const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch); diff --git a/plugins/talk-plugin-local-auth/client/containers/Profile.js b/plugins/talk-plugin-local-auth/client/containers/Profile.js index 239304535..e1ed99ef6 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..573fa6b10 --- /dev/null +++ b/plugins/talk-plugin-local-auth/client/hocs/index.js @@ -0,0 +1,91 @@ +import { withMutation } from 'plugin-api/beta/client/hocs'; +import { gql } from 'react-apollo'; +import update from 'immutability-helper'; + +export const withAttachLocalAuth = withMutation( + gql` + mutation AttachLocalAuth($input: AttachLocalAuthInput!) { + attachLocalAuth(input: $input) { + ...AttachLocalAuthResponse + } + } + `, + { + props: ({ mutate }) => ({ + attachLocalAuth: input => { + return mutate({ + variables: { + input, + }, + update: proxy => { + const AttachLocalAuthQuery = gql` + query Talk_AttachLocalAuth { + me { + id + email + } + } + `; + + const prev = proxy.readQuery({ query: AttachLocalAuthQuery }); + + const data = update(prev, { + me: { + email: { $set: input.email }, + }, + }); + + proxy.writeQuery({ + query: AttachLocalAuthQuery, + data, + }); + }, + }); + }, + }), + } +); + +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, + }); + }, + }); + }, + }), + } +);