report.tsx 2.5 KB

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