report.js 3.0 KB

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