diff --git a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js index 7a22ef37f..1716de983 100644 --- a/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js +++ b/plugins/talk-plugin-profile-data/client/containers/DownloadCommentHistory.js @@ -5,7 +5,6 @@ import { compose, gql } from 'react-apollo'; import DownloadCommentHistory from '../components/DownloadCommentHistory'; import { withRequestDownloadLink } from '../hocs'; import { connect, withFragments } from 'plugin-api/beta/client/hocs'; -import { withRequestDownloadLink } from '../hocs'; import { notify } from 'coral-framework/actions/notification'; class DownloadCommentHistoryContainer extends Component { diff --git a/plugins/talk-plugin-profile-data/client/hocs/index.js b/plugins/talk-plugin-profile-data/client/hocs/index.js index a370c9ff0..c90ad21df 100644 --- a/plugins/talk-plugin-profile-data/client/hocs/index.js +++ b/plugins/talk-plugin-profile-data/client/hocs/index.js @@ -1,5 +1,7 @@ import { withMutation } from 'plugin-api/beta/client/hocs'; import { gql } from 'react-apollo'; +import moment from 'moment'; +import update from 'immutability-helper'; export const withRequestDownloadLink = withMutation( gql` @@ -17,3 +19,93 @@ export const withRequestDownloadLink = withMutation( }), } ); + +export const withRequestAccountDeletion = withMutation( + gql` + mutation RequestAccountDeletion { + requestAccountDeletion { + ...RequestAccountDeletionResponse + } + } + `, + { + props: ({ mutate }) => ({ + requestAccountDeletion: () => { + return mutate({ + variables: {}, + update: proxy => { + const RequestAccountDeletionQuery = gql` + query Talk_CancelAccountDeletion { + me { + id + scheduledDeletionDate + } + } + `; + + const prev = proxy.readQuery({ + query: RequestAccountDeletionQuery, + }); + + const scheduledDeletionDate = moment() + .add(24, 'hours') + .toDate(); + + const data = update(prev, { + me: { + scheduledDeletionDate: { $set: scheduledDeletionDate }, + }, + }); + + proxy.writeQuery({ + query: RequestAccountDeletionQuery, + data, + }); + }, + }); + }, + }), + } +); + +export const withCancelAccountDeletion = withMutation( + gql` + mutation RequestDownloadLink { + cancelAccountDeletion { + ...CancelAccountDeletionResponse + } + } + `, + { + props: ({ mutate }) => ({ + cancelAccountDeletion: () => { + return mutate({ + variables: {}, + update: proxy => { + const CancelAccountDeletionQuery = gql` + query Talk_CancelAccountDeletion { + me { + id + scheduledDeletionDate + } + } + `; + + const prev = proxy.readQuery({ query: CancelAccountDeletionQuery }); + + const data = update(prev, { + me: { + scheduledDeletionDate: { $set: null }, + }, + }); + + proxy.writeQuery({ + query: CancelAccountDeletionQuery, + data, + }); + }, + }); + }, + }), + } +);