mirror of
https://github.com/wassname/talk.git
synced 2026-08-13 12:40:11 +08:00
cleaned up download mutations
This commit is contained in:
@@ -26,9 +26,6 @@ export default {
|
||||
'UpdateAssetSettingsResponse',
|
||||
'UpdateAssetStatusResponse',
|
||||
'UpdateSettingsResponse',
|
||||
'RequestAccountDeletionResponse',
|
||||
'RequestDownloadLinkResponse',
|
||||
'CancelAccountDeletionResponse',
|
||||
'ChangePasswordResponse'
|
||||
),
|
||||
};
|
||||
|
||||
@@ -8,4 +8,5 @@ export {
|
||||
getErrorMessages,
|
||||
getDefinitionName,
|
||||
getShallowChanges,
|
||||
createDefaultResponseFragments,
|
||||
} from 'coral-framework/utils';
|
||||
|
||||
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import styles from './DownloadCommentHistory.css';
|
||||
import { getErrorMessages } from 'coral-framework/utils';
|
||||
|
||||
export const readableDuration = durAsHours => {
|
||||
const durAsDays = Math.ceil(durAsHours / 24);
|
||||
@@ -19,14 +20,25 @@ export const readableDuration = durAsHours => {
|
||||
class DownloadCommentHistory extends Component {
|
||||
static propTypes = {
|
||||
requestDownloadLink: PropTypes.func.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
root: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
requestDownloadLink = async () => {
|
||||
const { requestDownloadLink, notify } = this.props;
|
||||
try {
|
||||
await requestDownloadLink();
|
||||
notify(
|
||||
'success',
|
||||
'Account Download Preparing - Check your email shortly for a download link'
|
||||
);
|
||||
} catch (err) {
|
||||
notify('error', getErrorMessages(err));
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
root: { me: { lastAccountDownload } },
|
||||
requestDownloadLink,
|
||||
} = this.props;
|
||||
const { root: { me: { lastAccountDownload } } } = this.props;
|
||||
|
||||
const now = new Date();
|
||||
const lastAccountDownloadDate =
|
||||
@@ -52,7 +64,7 @@ class DownloadCommentHistory extends Component {
|
||||
</p>
|
||||
)}
|
||||
{canRequestDownload ? (
|
||||
<Button className={styles.button} onClick={requestDownloadLink}>
|
||||
<Button className={styles.button} onClick={this.requestDownloadLink}>
|
||||
<i className="material-icons" aria-hidden={true}>
|
||||
file_download
|
||||
</i>{' '}
|
||||
|
||||
@@ -1,27 +1,34 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { compose, gql } from 'react-apollo';
|
||||
import DownloadCommentHistory from '../components/DownloadCommentHistory';
|
||||
import { withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import { connect, withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import { withRequestDownloadLink } from '../mutations';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
|
||||
class DownloadCommentHistoryContainer extends Component {
|
||||
static propTypes = {
|
||||
requestDownloadLink: PropTypes.func.isRequired,
|
||||
root: PropTypes.object.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<DownloadCommentHistory
|
||||
root={this.props.root}
|
||||
notify={this.props.notify}
|
||||
requestDownloadLink={this.props.requestDownloadLink}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch);
|
||||
|
||||
const enhance = compose(
|
||||
connect(null, mapDispatchToProps),
|
||||
withFragments({
|
||||
root: gql`
|
||||
fragment TalkDownloadCommentHistory_DownloadCommentHistorySection_root on RootQuery {
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import update from 'immutability-helper';
|
||||
import { createDefaultResponseFragments } from 'coral-framework/utils';
|
||||
|
||||
export default {
|
||||
fragments: {
|
||||
...createDefaultResponseFragments(
|
||||
'RequestAccountDeletionResponse',
|
||||
'RequestDownloadLinkResponse',
|
||||
'CancelAccountDeletionResponse'
|
||||
),
|
||||
},
|
||||
mutations: {
|
||||
DownloadCommentHistory: () => ({
|
||||
RequestDownloadLink: () => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Profile: previousData =>
|
||||
update(previousData, {
|
||||
|
||||
@@ -13,11 +13,7 @@ export const withRequestDownloadLink = withMutation(
|
||||
`,
|
||||
{
|
||||
props: ({ mutate }) => ({
|
||||
requestDownloadLink: () => {
|
||||
return mutate({
|
||||
variables: {},
|
||||
});
|
||||
},
|
||||
requestDownloadLink: () => mutate({}),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user