report.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, { useState } from "react";
  2. import axios from "axios";
  3. import { useFormState } from "react-use-form-state";
  4. import { Flex } from "reflexbox/styled-components";
  5. import AppWrapper from "../components/AppWrapper";
  6. import TextInput from "../components/TextInput";
  7. import { Button } from "../components/Button";
  8. import Text, { H2, Span } from "../components/Text";
  9. import { useMessage } from "../hooks";
  10. import { API } from "../consts";
  11. import { Col } from "../components/Layout";
  12. const ReportPage = () => {
  13. const [formState, { text }] = useFormState<{ url: string }>();
  14. const [loading, setLoading] = useState(false);
  15. const [message, setMessage] = useMessage(5000);
  16. const onSubmit = async e => {
  17. e.preventDefault();
  18. setLoading(true);
  19. setMessage();
  20. try {
  21. await axios.post(API.REPORT, { link: formState.values.url }); // TODO: better api calls
  22. setMessage("Thanks for the report, we'll take actions shortly.", "green");
  23. formState.clear();
  24. } catch (error) {
  25. setMessage(error?.response?.data?.error || "Couldn't send report.");
  26. }
  27. setLoading(false);
  28. };
  29. return (
  30. <AppWrapper>
  31. <Col width={600} maxWidth="97%" alignItems="flex-start">
  32. <H2 my={3} bold>
  33. Report abuse
  34. </H2>
  35. <Text mb={3}>
  36. Report abuses, malware and phishing links to the below email address
  37. or use the form. We will take actions shortly.
  38. </Text>
  39. <Text mb={4}>
  40. {(process.env.REPORT_EMAIL || "").replace("@", "[at]")}
  41. </Text>
  42. <Text mb={3}>
  43. <Span bold>URL containing malware/scam:</Span>
  44. </Text>
  45. <Flex
  46. as="form"
  47. flexDirection={["column", "row"]}
  48. alignItems={["flex-start", "center"]}
  49. justifyContent="flex-start"
  50. onSubmit={onSubmit}
  51. >
  52. <TextInput
  53. {...text("url")}
  54. placeholder="kutt.it/example"
  55. height={[44, 54]}
  56. width={[1, 1 / 2]}
  57. flex="0 0 auto"
  58. mr={3}
  59. required
  60. />
  61. <Button
  62. type="submit"
  63. icon={loading ? "loader" : ""}
  64. flex="0 0 auto"
  65. height={[40, 44]}
  66. mt={[3, 0]}
  67. >
  68. Send report
  69. </Button>
  70. </Flex>
  71. <Text fontSize={14} mt={3} color={message.color}>
  72. {message.text}
  73. </Text>
  74. </Col>
  75. </AppWrapper>
  76. );
  77. };
  78. export default ReportPage;