about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/filters/added_to_filter.jsx
blob: 2f3f98c813b01e1dbf70c79cd998b9aeee77c77a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { FormattedMessage } from 'react-intl';
import { toServerSideType } from 'flavours/glitch/utils/filters';
import Button from 'flavours/glitch/components/button';
import { connect } from 'react-redux';

const mapStateToProps = (state, { filterId }) => ({
  filter: state.getIn(['filters', filterId]),
});

class AddedToFilter extends React.PureComponent {

  static propTypes = {
    onClose: PropTypes.func.isRequired,
    contextType: PropTypes.string,
    filter: ImmutablePropTypes.map.isRequired,
    dispatch: PropTypes.func.isRequired,
  };

  handleCloseClick = () => {
    const { onClose } = this.props;
    onClose();
  };

  render () {
    const { filter, contextType } = this.props;

    let expiredMessage = null;
    if (filter.get('expires_at') && filter.get('expires_at') < new Date()) {
      expiredMessage = (
        <React.Fragment>
          <h4 className='report-dialog-modal__subtitle'><FormattedMessage id='filter_modal.added.expired_title' defaultMessage='Expired filter!' /></h4>
          <p className='report-dialog-modal__lead'>
            <FormattedMessage
              id='filter_modal.added.expired_explanation'
              defaultMessage='This filter category has expired, you will need to change the expiration date for it to apply.'
            />
          </p>
        </React.Fragment>
      );
    }

    let contextMismatchMessage = null;
    if (contextType && !filter.get('context').includes(toServerSideType(contextType))) {
      contextMismatchMessage = (
        <React.Fragment>
          <h4 className='report-dialog-modal__subtitle'><FormattedMessage id='filter_modal.added.context_mismatch_title' defaultMessage='Context mismatch!' /></h4>
          <p className='report-dialog-modal__lead'>
            <FormattedMessage
              id='filter_modal.added.context_mismatch_explanation'
              defaultMessage='This filter category does not apply to the context in which you have accessed this post. If you want the post to be filtered in this context too, you will have to edit the filter.'
            />
          </p>
        </React.Fragment>
      );
    }

    const settings_link = (
      <a href={`/filters/${filter.get('id')}/edit`}>
        <FormattedMessage
          id='filter_modal.added.settings_link'
          defaultMessage='settings page'
        />
      </a>
    );

    return (
      <React.Fragment>
        <h3 className='report-dialog-modal__title'><FormattedMessage id='filter_modal.added.title' defaultMessage='Filter added!' /></h3>
        <p className='report-dialog-modal__lead'>
          <FormattedMessage
            id='filter_modal.added.short_explanation'
            defaultMessage='This post has been added to the following filter category: {title}.'
            values={{ title: filter.get('title') }}
          />
        </p>

        {expiredMessage}
        {contextMismatchMessage}

        <h4 className='report-dialog-modal__subtitle'><FormattedMessage id='filter_modal.added.review_and_configure_title' defaultMessage='Filter settings' /></h4>
        <p className='report-dialog-modal__lead'>
          <FormattedMessage
            id='filter_modal.added.review_and_configure'
            defaultMessage='To review and further configure this filter category, go to the {settings_link}.'
            values={{ settings_link }}
          />
        </p>

        <div className='flex-spacer' />

        <div className='report-dialog-modal__actions'>
          <Button onClick={this.handleCloseClick}><FormattedMessage id='report.close' defaultMessage='Done' /></Button>
        </div>
      </React.Fragment>
    );
  }

}

export default connect(mapStateToProps)(AddedToFilter);