withUpdateEmailAddress in the plugins hoc

This commit is contained in:
okbel
2018-05-03 15:12:23 -03:00
parent bfb4b790d4
commit 8a9af89699
3 changed files with 49 additions and 48 deletions
@@ -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!) {
@@ -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);
@@ -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,
});
},
});
},
}),
}
);