mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
moving mutations to /hocs folder
This commit is contained in:
@@ -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!) {
|
||||
|
||||
@@ -27,7 +27,5 @@ export {
|
||||
withSetCommentStatus,
|
||||
withChangePassword,
|
||||
withChangeUsername,
|
||||
withUpdateEmailAddress,
|
||||
withAttachLocalAuth,
|
||||
} from 'coral-framework/graphql/mutations';
|
||||
export { compose } from 'recompose';
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,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,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user