report.tsx 2.6 KB

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