mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
withUpdateEmailAddress in the plugins hoc
This commit is contained in:
@@ -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,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user