report.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React, { Component } from 'react';
  2. import styled from 'styled-components';
  3. import axios from 'axios';
  4. import BodyWrapper from '../components/BodyWrapper';
  5. import { authUser } from '../actions';
  6. import TextInput from '../components/TextInput';
  7. import Button from '../components/Button';
  8. const Wrapper = styled.div`
  9. width: 600px;
  10. max-width: 97%;
  11. display: flex;
  12. flex-direction: column;
  13. align-items: flex-start;
  14. `;
  15. const Form = styled.form`
  16. position: relative;
  17. display: flex;
  18. `;
  19. const Message = styled.p`
  20. position: absolute;
  21. left: 0;
  22. bottom: -54px;
  23. font-size: 14px;
  24. color: ${props => (props.type === 'error' ? 'red' : 'green')};
  25. @media only screen and (max-width: 448px) {
  26. bottom: -44px;
  27. font-size: 12px;
  28. }
  29. `;
  30. class ReportPage extends Component {
  31. constructor(props) {
  32. super(props);
  33. this.state = {
  34. loading: false,
  35. message: {
  36. text: '',
  37. type: '',
  38. },
  39. url: '',
  40. };
  41. this.onChange = this.onChange.bind(this);
  42. this.onSubmit = this.onSubmit.bind(this);
  43. }
  44. onChange(e) {
  45. const url = e.target.value;
  46. this.setState({ url });
  47. }
  48. async onSubmit(e) {
  49. e.preventDefault();
  50. this.setState({ loading: true });
  51. try {
  52. await axios.post('/api/url/report', { link: this.state.url });
  53. this.setState({
  54. loading: false,
  55. message: {
  56. type: 'success',
  57. text: "Thanks for the report, we'll take actions shortly.",
  58. },
  59. url: '',
  60. });
  61. } catch (error) {
  62. this.setState({
  63. loading: false,
  64. message: {
  65. type: 'error',
  66. text: error.response.data.error,
  67. },
  68. url: '',
  69. });
  70. }
  71. setTimeout(() => {
  72. this.setState({
  73. message: {
  74. type: '',
  75. text: '',
  76. },
  77. });
  78. }, 5000);
  79. }
  80. render() {
  81. const { loading, message, url } = this.state;
  82. return (
  83. <BodyWrapper>
  84. <Wrapper>
  85. <h3>Report abuse</h3>
  86. <p>
  87. Report abuses, malware and phishing links to the below email address or use the form. We
  88. will take actions shortly.
  89. </p>
  90. <p>{(process.env.REPORT_EMAIL || '').replace('@', '[at]')}</p>
  91. <p>
  92. <b>URL containing malware/scam:</b>
  93. </p>
  94. <Form onSubmit={this.onSubmit}>
  95. <TextInput
  96. type="text"
  97. placeholder="kutt.it/example"
  98. value={url}
  99. onChange={this.onChange}
  100. height={44}
  101. small
  102. />
  103. <Button type="submit" icon={loading ? 'loader' : ''}>
  104. Send report
  105. </Button>
  106. <Message type={message.type}>{message.text}</Message>
  107. </Form>
  108. </Wrapper>
  109. </BodyWrapper>
  110. );
  111. }
  112. }
  113. ReportPage.getInitialProps = ({ req, reduxStore }) => {
  114. const token = req && req.cookies && req.cookies.token;
  115. if (token && reduxStore) reduxStore.dispatch(authUser(token));
  116. return {};
  117. };
  118. export default ReportPage;